本文整理汇总了C++中TTree::GetListOfBranches方法的典型用法代码示例。如果您正苦于以下问题:C++ TTree::GetListOfBranches方法的具体用法?C++ TTree::GetListOfBranches怎么用?C++ TTree::GetListOfBranches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TTree
的用法示例。
在下文中一共展示了TTree::GetListOfBranches方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: branches
void branches(TString input, TString treeName="Events")
{
TFile *file = new TFile(input);
TTree *tree = (TTree*)file->Get(treeName);
if(treeName.Contains("Events")) {
for(int i = 0; i < tree->GetListOfAliases()->LastIndex(); i++)
std::cout << "branch: " << tree->GetListOfAliases()->At(i)->GetName() << std::endl;
} else {
for(int i = 0; i < tree->GetListOfBranches()->LastIndex(); i++)
std::cout << "branch: " << tree->GetListOfBranches()->At(i)->GetName() << std::endl;
}
}
示例2: runtime_error
/// Open new data file
bool DDG4EventHandler::Open(const std::string&, const std::string& name) {
if ( m_file.first ) m_file.first->Close();
m_hasFile = false;
m_hasEvent = false;
TFile* f = TFile::Open(name.c_str());
if ( f && !f->IsZombie() ) {
m_file.first = f;
TTree* t = (TTree*)f->Get("EVENT");
if ( t ) {
TObjArray* br = t->GetListOfBranches();
m_file.second = t;
m_entry = -1;
m_branches.clear();
for(Int_t i=0; i<br->GetSize(); ++i) {
TBranch* b = (TBranch*)br->At(i);
if ( !b ) continue;
m_branches[b->GetName()] = make_pair(b,(void*)0);
printout(INFO,"DDG4EventHandler::open","+++ Branch %s has %ld entries.",b->GetName(),b->GetEntries());
}
for(Int_t i=0; i<br->GetSize(); ++i) {
TBranch* b = (TBranch*)br->At(i);
if ( !b ) continue;
b->SetAddress(&m_branches[b->GetName()].second);
}
m_hasFile = true;
return true;
}
throw runtime_error("+++ Failed to access tree EVENT in ROOT file:"+name);
}
throw runtime_error("+++ Failed to open ROOT file:"+name);
}
示例3: GetTreeSize
void GetTreeSize(TString FileName, TString TreeName)
{
TFile *inf = TFile::Open(FileName);
TTree *tr = (TTree*)inf->Get(TreeName);
TObjArray *branches = (TObjArray*)tr->GetListOfBranches();
int size(0);
cout.setf(ios::right);
int N(branches->GetEntries());
TH1F *hSize = new TH1F("size","size",N,0,N);
for(int ib=0;ib<N;ib++) {
TString name(branches->At(ib)->GetName());
TBranch *br = (TBranch*)tr->GetBranch(name);
hSize->Fill(name,br->GetZipBytes()/1e+3);
size += br->GetZipBytes();
}
cout<<"Total size: "<<size<<endl;
for(int ib=0;ib<N;ib++) {
TString name(branches->At(ib)->GetName());
TBranch *br = (TBranch*)tr->GetBranch(name);
float percent = TMath::Ceil(1000*float(br->GetZipBytes())/float(size))/10;
cout<<ib<<setw(20)<<name<<setw(15)<<br->GetZipBytes()<<" "<<percent<<"%"<<endl;
}
TCanvas *can = new TCanvas("TreeSize","TreeSize",1000,400);
hSize->GetXaxis()->SetTitle("Branch Name");
hSize->GetXaxis()->SetLabelSize(0.04);
hSize->GetYaxis()->SetTitle("Size (KB)");
hSize->SetFillColor(kGray);
hSize->Draw();
}
示例4: VariablePrint1
void VariablePrint1() {
TFile *f = new TFile("/home/francji/data/subsets/small_training_sample/p17_CC_diboson_EqOneTag_EqThreeJet_zero_Topo_small_training_sample.root");
TTree *t = (TTree *) f->Get("TopologicalVariables");
TObjArray *arr = t->GetListOfBranches();
for (int i = 0; i < arr->GetSize(); i++) {
char s[1000];
strcpy(s, arr->At(i)->GetTitle());
char c = s[strlen(s)-1];
s[strlen(s)-2] = '\0';
printf("%i %s \n", i, s);
}
}
示例5: dumpDDG4
int dumpDDG4(const char* fname, int event_num) {
TFile* data = TFile::Open(fname);
if ( !data || data->IsZombie() ) {
printf("+ File seems to not exist. Exiting\n");
usage();
return -1;
}
TTree* tree = (TTree*)data->Get("EVENT");
for(int event=0, num=tree->GetEntries(); event<num; ++event) {
TObjArray* arr = tree->GetListOfBranches();
if ( event_num>= 0 ) event = event_num;
for(int j=0, nj=arr->GetEntries(); j<nj; ++j) {
TBranch* b = (TBranch*)arr->At(j);
typedef vector<void*> _E;
_E* e = 0;
b->SetAddress(&e);
int nbytes = b->GetEvent(event);
if ( nbytes > 0 ) {
if ( e->empty() ) {
continue;
}
string br_name = b->GetName();
string cl_name = b->GetClassName();
if ( cl_name.find("dd4hep::sim::Geant4Tracker::Hit") != string::npos ) {
typedef vector<Geant4Tracker::Hit*> _H;
printHits(br_name,(_H*)e);
}
else if ( cl_name.find("dd4hep::sim::Geant4Calorimeter::Hit") != string::npos ) {
typedef vector<Geant4Calorimeter::Hit*> _H;
printHits(br_name,(_H*)e);
}
else if ( cl_name.find("dd4hep::sim::Geant4Particle") != string::npos ) {
typedef vector<Geant4Particle*> _H;
::printf("%s\n+ Particle Dump of event %8d [%8d bytes] +\n%s\n",
line,event,nbytes,line);
printParticles(br_name,(_H*)e);
}
}
}
if ( event_num >= 0 ) break;
}
delete data;
return 0;
}
示例6: VariablesPrint
void VariablesPrint() {
TFile *f = new TFile("/work/budvar-clued0/francji/subsets/small_training_sample/p17_CC_diboson_EqOneTag_EqThreeJet_zero_Topo_small_training_sample.root");
TTree *t = (TTree *) f->Get("TopologicalVariables");
TObjArray *arr = t->GetListOfBranches();
int j = 1;
for (int i = 0; i < arr->GetSize(); i++) {
char s[1000];
strcpy(s, arr->At(i)->GetTitle());
char c = s[strlen(s)-1];
s[strlen(s)-2] = '\0';
if (c == 'D') {
printf("%5i D %s \n", j, s);
j++;
} else if (c == 'I') {
printf("%5i I %s \n", j, s);
j++;
} else {};
}
}
示例7: main
int main (int argc, char** argv)
{
// check number of inpt parameters
if (argc < 3)
{
cerr << argv[0] << " filename branchname" << endl ;
return 1 ;
}
TFile f (argv[1], "update") ;
TTree *T = (TTree*) f.Get ("HTauTauTree") ;
TBranch *b = T->GetBranch (argv[2]) ;
T->GetListOfBranches ()->Remove (b) ;
T->Write () ;
f.Close () ;
return 0 ;
}
示例8: nextlf
NTPReplay( Char_t* fname, Int_t qfRecon = -1 )
{
// Histogram energies, momenta, from Tree created by kinematics generator
// AcquMC....ensure physics library is loaded 1st
gROOT->Reset();
if (!gROOT->GetClass("TLorentzVector")) gSystem->Load("libPhysics");
//
// Tree file contains 4-momenta produced by MCGenerator
TFile* tFile = new TFile( fname );
TTree* tree = (TTree*)tFile->Get("h1");
tree->Print();
Int_t nbr = tree->GetNbranches();
Int_t nparticle = (nbr - 3)/5; // # particles in reaction
printf(" %d particles in experiment\n", nparticle );
TObjArray* leaves = tree->GetListOfBranches(); // linked list of leaves
printf(" %d leaves in branch\n",nbr);
TIter nextlf( tree->GetListOfBranches() );
char** hname = new char*[nbr]; // histogram parameters
Float_t* p4i = new Float_t[nbr];
for( Int_t n=0; n<nbr; n++ ){
TBranch* lf = (TBranch*)nextlf(); // Double_t leaf
hname[n] = lf->GetName(); // its name
tree->SetBranchAddress(hname[n], p4i+n);
}
Int_t nevent = tree->GetEntries(); // # events generated
printf(" %d events started\n", nevent );
//
// Create linked list of 1D histograms
Int_t i,j,k;
// for(i=0,j=0; i<nparticle; i++) if( Track[i] ) j++; // #particles tracked
j = nparticle;
printf(" %d final-state particles tracked\n", j );
Int_t np4 = j;
Int_t nhist = 4*j + 7; // # 1D histograms
Int_t nchan = 1000; // 1000 channels each
Char_t* title; // title is file name
if( !(title = strrchr(fname,'/')) ) title = fname;
else title++;
TList* hl = new TList();
TList* hAng = new TList();
TH1F* h;
for( i=0; i<nhist; i++ ){
h = new TH1F( hname[i], title, nchan, 0, 0 );
hl->AddLast(h);
}
Char_t angName[256];
// Angular ranges (deg) for plotting
Double_t thetaMin[] = {
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
};
Double_t thetaMax[] = {
0.5, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0,
180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0
};
Double_t phiMin[] = {
-200, -200, -200, -200, -200, -200, -200, -200, -200, -200,
-200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200
};
Double_t phiMax[] = {
200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0
};
for( i=0; i<=np4; i++ ){
sprintf( angName, "Theta_%d", i );
h = new TH1F( angName, title, 180, thetaMin[i], thetaMax[i] );
hAng->AddLast(h);
sprintf( angName, "Phi_%d", i );
h = new TH1F( angName, title, 180, phiMin[i], phiMax[i] );
hAng->AddLast(h);
sprintf( angName, "P_%d", i );
h = new TH1F( angName, title, 1000, 0, 0 );
hAng->AddLast(h);
}
TIter next(hl); // list iterator
TIter nextAng(hAng); // list iterator
//
// For some 4-momentum analysis
TLorentzVector* P4 = new TLorentzVector[nparticle];
TLorentzVector P4tot;
TLorentzVector P4beamQF;
i = 0;
TH2F* h2a = new TH2F("Vertex-X-Y",title,300,-3,3,300,-3,3);
TH2F* h2b = new TH2F("Vertex-Z-R",title,300,-3,3,300,-3,3);
TH1F* h1a = new TH1F("Momentum-Balance",title,1000,-1,1);
TH1F* h1b;
if( qfRecon >= 0 ) h1b = new TH1F("QF-recon-Beam-Energy",title,2000,-5,5);
//
// Read events from branch
Double_t r;
Float_t* p;
for(i=0; i<nevent; i++){
next.Reset();
nextAng.Reset();
tree->GetEntry(i);
p = p4i + 3;
P4tot.SetXYZT(0,0,0,0);
if( qfRecon >= 0 )P4beamQF.SetXYZT(0,0,0,0);
for(j=0; j<=np4; j++,p+=5){
P4[j].SetXYZT(p[0]*p[3],p[1]*p[3],p[2]*p[3],p[4]);
//.........这里部分代码省略.........
示例9: makeHeaderFile
//-------------------------------------------------------------------------------------------------
void makeHeaderFile(TFile *f, const string& treeName, bool paranoid, const string& Classname, const string& nameSpace, const string& objName) {
headerf << "// -*- C++ -*-" << endl;
headerf << "#ifndef " << Classname << "_H" << endl;
headerf << "#define " << Classname << "_H" << endl;
headerf << "#include \"Math/LorentzVector.h\"" << endl;
headerf << "#include \"Math/Point3D.h\"" << endl;
headerf << "#include \"TMath.h\"" << endl;
headerf << "#include \"TBranch.h\"" << endl;
headerf << "#include \"TTree.h\"" << endl;
headerf << "#include \"TH1F.h\"" << endl;
headerf << "#include \"TFile.h\"" << endl;
headerf << "#include \"TBits.h\"" << endl;
headerf << "#include <vector>" << endl;
headerf << "#include <unistd.h>" << endl;
headerf << "typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > LorentzVector;" << endl << endl;
if (paranoid)
headerf << "#define PARANOIA" << endl << endl;
headerf << "using namespace std; " << endl;
headerf << "class " << Classname << " {" << endl;
headerf << "private: " << endl;
headerf << "protected: " << endl;
headerf << "\tunsigned int index;" << endl;
// TTree *ev = (TTree*)f->Get("Events");
TList* list_of_keys = f->GetListOfKeys();
std::string tree_name = "";
if (treeName.empty()) {
unsigned int ntrees = 0;
for (unsigned int idx = 0; idx < (unsigned int)list_of_keys->GetSize(); idx++) {
const char* obj_name = list_of_keys->At(idx)->GetName();
TObject* obj = f->Get(obj_name);
if (obj->InheritsFrom("TTree")) {
++ntrees;
tree_name = obj_name;
}
}
if (ntrees == 0) {
std::cout << "Did not find a tree. Exiting." << std::endl;
return;
}
if (ntrees > 1) {
std::cout << "Found more than one tree. Please specify a tree to use." << std::endl;
return;
}
}
else
tree_name = treeName;
TTree *ev = (TTree*)f->Get(tree_name.c_str());
TSeqCollection *fullarray = ev->GetListOfAliases();
bool have_aliases = true;
if (!fullarray) {
have_aliases = false;
fullarray = ev->GetListOfBranches();
}
// if (have_aliases && fullarray->GetSize() != ev->GetListOfBranches()->GetSize()) {
// std::cout << "Tree has " << fullarray->GetSize() << " aliases and " << ev->GetListOfBranches()->GetSize() << " branches. Exiting." << std::endl;
// return;
// }
TList *aliasarray = new TList();
for(Int_t i = 0; i < fullarray->GetEntries(); ++i) {
TString aliasname(fullarray->At(i)->GetName());
// TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data()));
TBranch *branch = 0;
if (have_aliases)
branch = ev->GetBranch(ev->GetAlias(aliasname.Data()));
else
branch = (TBranch*)fullarray->At(i);
TString branchname(branch->GetName());
TString branchtitle(branch->GetTitle());
TString branchclass(branch->GetClassName());
if(!branchname.BeginsWith("int") &&
!branchname.BeginsWith("uint") &&
!branchname.BeginsWith("bool") &&
!branchname.BeginsWith("float") &&
!branchname.BeginsWith("double") &&
!branchtitle.EndsWith("/F") &&
!branchtitle.EndsWith("/I") &&
!branchtitle.EndsWith("/i") &&
!branchtitle.EndsWith("/O") &&
!branchtitle.BeginsWith("TString") &&
!branchtitle.BeginsWith("TBits") &&
!branchclass.Contains("LorentzVector") &&
!branchclass.Contains("int") &&
!branchclass.Contains("uint") &&
!branchclass.Contains("bool") &&
!branchclass.Contains("float") &&
!branchclass.Contains("double") &&
!branchclass.Contains("TString"))
continue;
// if (branchclass.Contains("TString"))
//.........这里部分代码省略.........
示例10: main
int main(int argc, char** argv){
// RETRIEVING LIST OF FILENAMES TO CHECK
if (argc != 3) {
cout << "Usage: ./TopTreeContentDump --inputfiles file1;file2;fileN\n\n" << endl;
exit(0);
} else if (argc == 3 && !strstr(argv[1],"--inputfiles")) {
cout << "Usage: ./TopTreeContentDump --inputfiles file1;file2;fileN\n\n" << endl;
exit(0);
}
vector<string> fileNames;
Tokenize(argv[2], fileNames, ";");
// CHECKING THE FILECONTENT FOR FILE 0 AND COUNT EVENTS FOR ALL FILES
unsigned int nEvents = 0;
for (int fileID=0; fileID < fileNames.size(); fileID++) {
//cout << fileNames.at(fileID) << endl;
TFile* f = TFile::Open(fileNames.at(fileID).c_str());
TTree* runTree = (TTree*) f->Get("runTree");
TTree* eventTree = (TTree*) f->Get("eventTree");
TBranch* run_br = (TBranch *) runTree->GetBranch("runInfos");
TRootRun* runInfos = 0;
run_br->SetAddress(&runInfos);
TBranch* event_br = (TBranch *) eventTree->GetBranch("Event");
TRootEvent* event = 0;
event_br->SetAddress(&event);
nEvents += eventTree->GetEntriesFast();
if (fileID == 0) {
cout << "* Dumping the event content of the TopTree" << endl;
for (int i=1; i<eventTree->GetListOfBranches()->GetEntriesFast(); i++) {
TBranch * branch = (TBranch *)eventTree->GetListOfBranches()->At(i);
TObject* obj = branch->GetListOfLeaves()->At(0);
std::string ObjName = obj->GetName();
string::size_type position = ObjName.find_last_of("_");
std::string className = "";
if (strstr(ObjName.c_str(),"CaloJet"))
className="TopTree::TRootCaloJet";
else if (strstr(ObjName.c_str(),"PFJet"))
className="TopTree::TRootPFJet";
else if (strstr(ObjName.c_str(),"JPTJet"))
className="TopTree::TRootJPTJet";
else if (strstr(ObjName.c_str(),"GenJet"))
className="TopTree::TRootGenJet";
else if (strstr(ObjName.c_str(),"MCParticles"))
className="TopTree::TRootMCParticle";
else if (strstr(ObjName.c_str(),"NPGenEvent"))
className="TopTree::TRootNPGenEvent";
else if (strstr(ObjName.c_str(),"GenEvent"))
className="TopTree::TRootGenEvent";
else if (strstr(ObjName.c_str(),"Muon"))
className="TopTree::TRootMuon";
else if (strstr(ObjName.c_str(),"Electron"))
className="TopTree::TRootElectron";
else if (strstr(ObjName.c_str(),"TCMET"))
className="TopTree::TRootMET";
else if (strstr(ObjName.c_str(),"CaloMET"))
className="TopTree::TRootCaloMET";
else if (strstr(ObjName.c_str(),"PFMET"))
className="TopTree::TRootPFMET";
else if (strstr(ObjName.c_str(),"MET"))
className="TopTree::TRootMET";
else if (strstr(ObjName.c_str(), "TrackMET"))
className="TopTree::TRootTrackMET";
else if (strstr(ObjName.c_str(),"MHT"))
className="TopTree::TRootMHT";
else if (strstr(ObjName.c_str(),"PrimaryVertex"))
className="TopTree::TRootVertex";
cout << "- " << className << setw(5) << " -> " << "\"" << ObjName.substr(0,position) << "\"" << endl;
}
//.........这里部分代码省略.........
示例11: runPrefetchReading
Int_t runPrefetchReading(bool caching = false)
{
//const char *options = 0;
Int_t freq = 1000;
Int_t cachesize = -1;
Float_t percententries = 1.00;
Float_t percentbranches = 1.00;
TStopwatch sw;
//set the reading mode to async prefetching
gEnv->SetValue("TFile.AsyncPrefetching", 1);
//enable the local caching of blocks
TString cachedir="file:/tmp/xcache/";
// or using xrootd on port 2000
// TString cachedir="root://localhost:2000//tmp/xrdcache1/";
if (caching) gEnv->SetValue("Cache.Directory", cachedir.Data());
// open the local if any
TString filename("atlasFlushed.root");
if (gSystem->AccessPathName(filename,kReadPermission) && filename.Index(":") == kNPOS) {
// otherwise open the http file
filename.Prepend("https://root.cern.ch/files/");
//filename.Prepend("root://cache01.usatlas.bnl.gov//data/test1/");
//filename.Prepend( "root://pcitdss1401//tmp/" );
//filename.Prepend("http://www-root.fnal.gov/files/");
//filename.Prepend("http://oink.fnal.gov/distro/roottest/");
}
TString library("atlasFlushed/atlasFlushed");
fprintf(stderr,"Starting to load the library\n");
gSystem->Load(library);
fprintf(stderr,"Starting to open the file\n");
TFile *file = TFile::Open( filename, "TIMEOUT=30" );
if (!file || file->IsZombie()) {
Error("runPrefetchReading","Could not open the file %s within 30s",filename.Data());
return 1;
}
fprintf(stderr,"The file has been opened, setting up the TTree\n");
// file->MakeProject("atlasFlushed","*","RECREATE+");
// Try the known names :)
const char *names [] = { "E","Events","CollectionTree","ntuple","T" };
TTree *T = NULL;
for (unsigned int i = 0; i < sizeof(names)/sizeof(names[0]); ++i) {
file->GetObject(names[i], T);
if (T) break;
}
if (T==0) {
Error("runPrefetchReading","Could not find a tree which the conventional names in %s.",filename.Data());
return 2;
}
TFile::SetReadaheadSize(0); // (256*1024);
Long64_t nentries = T->GetEntries();
int efirst = 0;
int elast = efirst+nentries;
if (cachesize == -2) {
gEnv->SetValue("TFile.AsyncReading", 0);
cachesize = -1;
}
T->SetCacheSize(cachesize);
if (cachesize != 0) {
T->SetCacheEntryRange(efirst,elast);
if (percentbranches < 1.00) {
int nb = T->GetListOfBranches()->GetEntries();
int incr = nb * percentbranches;
for(int b=0;b < nb; b += incr) T->AddBranchToCache(((TBranch*)T->GetListOfBranches()->At(b)),kTRUE);
} else {
T->AddBranchToCache("*");
}
T->StopCacheLearningPhase();
}
//...........................................................................
// First read, with saving the info in cache
//...........................................................................
fprintf(stderr,"Setup done. Starting to read the entries\n");
TRandom r;
for (Long64_t i = efirst; i < elast; i++) {
//if (i%100 == 0 || i>2000) fprintf(stderr,"i.debug = %lld\n",i);
// if (i==2000) gDebug = 7;
if (i % freq == 0){
// for (Long64_t i=elast-1;i>=efirst;i--) {
if (i%freq == 0 || i==(elast-1)) fprintf(stderr,"i = %lld\n",i);
if (r.Rndm() > percententries) continue;
T->LoadTree(i);
if (percentbranches < 1.00) {
int nb = T->GetListOfBranches()->GetEntries();
int incr = nb * percentbranches;
for(int b=0;b<nb; b += incr) ((TBranch*)T->GetListOfBranches()->At(b))->GetEntry(i);
int count = 0;
int maxcount = 1000 + 100 ;
for(int x = 0; x < maxcount; ++x ) { /* waste cpu */ count = sin(cos((double)count)); }
} else {
T->GetEntry(i);
}
//.........这里部分代码省略.........
示例12: main
int main(int argc, char *argv[]) {
using namespace boost::program_options;
using namespace std;
string programName(argv[0]);
string descString(programName);
descString += " [options] ";
descString += "data_file \nAllowed options";
options_description desc(descString);
desc.add_options()(kHelpCommandOpt, "produce help message")(kAutoLoadCommandOpt,
"automatic library loading (avoid root warnings)")(
kDataFileCommandOpt, value<string>(), "data file")(kAlphabeticOrderCommandOpt,
"sort by alphabetic order (default: sort by size)")(
kPlotCommandOpt, value<string>(), "produce a summary plot")(
kPlotTopCommandOpt, value<int>(), "plot only the <arg> top size branches")(
kSavePlotCommandOpt, value<string>(), "save plot into root file <arg>")(kVerboseCommandOpt, "verbose printout");
positional_options_description p;
p.add(kDataFileOpt, -1);
variables_map vm;
try {
store(command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
notify(vm);
} catch (const error &) {
return 7000;
}
if (vm.count(kHelpOpt)) {
cout << desc << std::endl;
return 0;
}
if (!vm.count(kDataFileOpt)) {
string shortDesc("ConfigFileNotFound");
cerr << programName << ": no data file given" << endl;
return 7001;
}
gROOT->SetBatch();
if (vm.count(kAutoLoadOpt) != 0) {
gSystem->Load("libFWCoreFWLite");
FWLiteEnabler::enable();
}
string fileName = vm[kDataFileOpt].as<string>();
TFile file(fileName.c_str());
if (!file.IsOpen()) {
cerr << programName << ": unable to open data file " << fileName << endl;
return 7002;
}
TObject *o = file.Get("Events");
if (o == 0) {
cerr << programName << ": no object \"Events\" found in file: " << fileName << endl;
return 7003;
}
TTree *events = dynamic_cast<TTree *>(o);
if (events == 0) {
cerr << programName << ": object \"Events\" is not a TTree in file: " << fileName << endl;
return 7004;
}
TObjArray *branches = events->GetListOfBranches();
if (branches == 0) {
cerr << programName << ": tree \"Events\" in file " << fileName << " contains no branches" << endl;
return 7004;
}
bool verbose = vm.count(kVerboseOpt) > 0;
BranchVector v;
const size_t n = branches->GetEntries();
cout << fileName << " has " << n << " branches" << endl;
for (size_t i = 0; i < n; ++i) {
TBranch *b = dynamic_cast<TBranch *>(branches->At(i));
assert(b != 0);
string name(b->GetName());
if (name == "EventAux")
continue;
size_type s = GetTotalSize(b, verbose);
v.push_back(make_pair(b->GetName(), s));
}
if (vm.count(kAlphabeticOrderOpt)) {
sort(v.begin(), v.end(), sortByName());
} else {
sort(v.begin(), v.end(), sortByCompressedSize());
}
bool plot = (vm.count(kPlotOpt) > 0);
bool save = (vm.count(kSavePlotOpt) > 0);
int top = n;
if (vm.count(kPlotTopOpt) > 0)
top = vm[kPlotTopOpt].as<int>();
TH1F uncompressed("uncompressed", "branch sizes", top, -0.5, -0.5 + top);
TH1F compressed("compressed", "branch sizes", top, -0.5, -0.5 + top);
int x = 0;
//.........这里部分代码省略.........
示例13: AnalyseFile
void KVSimDir::AnalyseFile(const Char_t* filename)
{
// Analyse ROOT file given as argument.
// If there is a TTree in the file, then we look at all of its branches until we find one
// containing objects which derive from KVEvent:
//
// -- if they inherit from KVSimEvent, we add the file to the list of simulated data:
// * a KVSimFile is created. The title of the TTree where data were found will
// be used as 'Information' on the nature of the simulation.
// -- if they inherit from KVReconstructedEvent, we add the file to the list of filtered data.
// * a KVSimFile is created. Informations on the filtered data are extracted from
// TNamed objects in the file with names 'Dataset', 'System', 'Run', 'Geometry'
// (type of geometry used, 'ROOT' or 'KV'), 'Origin' (i.e. the name of the simulation
// file which was filtered), 'Filter' (type of filter: Geo, GeoThresh or Full).
// These objects are automatically created when data is filtered using KVEventFiltering.
//
// Analysis of the file stops after the first TTree with a branch satisfying one of the
// two criteria is found (it is assumed that in each file there is only one TTree containing
// either simulated or filtered data).
Info("AnalyseFile", "Analysing file %s...", filename);
TString fullpath;
AssignAndDelete(fullpath, gSystem->ConcatFileName(GetDirectory(), filename));
TFile* file = TFile::Open(fullpath);
if (!file || file->IsZombie()) return;
// look for TTrees in file
TIter next(file->GetListOfKeys());
TKey* key;
while ((key = (TKey*)next())) {
TString cn = key->GetClassName();
if (cn == "TTree") {
// look for branch with KVEvent objects
TTree* tree = (TTree*)file->Get(key->GetName());
TSeqCollection* branches = tree->GetListOfBranches();
TIter nextB(branches);
TBranchElement* branch;
while ((branch = (TBranchElement*)nextB())) {
TString branch_classname = branch->GetClassName();
TClass* branch_class = TClass::GetClass(branch_classname, kFALSE, kTRUE);
if (branch_class && branch_class->InheritsFrom("KVEvent")) {
if (branch_class->InheritsFrom("KVSimEvent")) {
fSimData.Add(new KVSimFile(this, filename, tree->GetTitle(), tree->GetEntries(), tree->GetName(), branch->GetName()));
delete file;
return;
} else if (branch_class->InheritsFrom("KVReconstructedEvent")) {
// filtered data. there must be TNamed called 'Dataset', 'System', & 'Run' in the file.
TNamed* ds = (TNamed*)file->Get("Dataset");
TNamed* orig = (TNamed*)file->Get("Origin");
TNamed* sys = (TNamed*)file->Get("System");
TNamed* r = (TNamed*)file->Get("Run");
TNamed* g = (TNamed*)file->Get("Geometry");
TNamed* f = (TNamed*)file->Get("Filter");
TString dataset;
if (ds) dataset = ds->GetTitle();
TString system;
if (sys) system = sys->GetTitle();
TString run;
if (r) run = r->GetTitle();
TString origin;
if (orig) origin = orig->GetTitle();
TString geometry;
if (g) geometry = g->GetTitle();
TString filter;
if (f) filter = f->GetTitle();
Int_t run_number = run.Atoi();
fFiltData.Add(new KVSimFile(this, filename, tree->GetTitle(), tree->GetEntries(), tree->GetName(), branch->GetName(),
dataset, system, run_number, geometry, origin, filter));
delete file;
delete ds;
delete sys;
delete r;
delete f;
return;
}
}
}
}
}
}
示例14: generateCodeFromStreamers
std::string generateCodeFromStreamers(std::string url, std::string treeLocation, std::vector<std::string> &classNames, std::string &errorMessage) {
TFile *tfile = TFile::Open(url.c_str());
if (tfile == nullptr || !tfile->IsOpen()) {
errorMessage = std::string("File not found: ") + url;
return std::string();
}
if (tfile->IsZombie()) {
errorMessage = std::string("Not a ROOT file: ") + url;
return std::string();
}
TTreeReader reader(treeLocation.c_str(), tfile);
if (reader.IsZombie()) {
errorMessage = std::string("Not a TTree: ") + treeLocation.c_str() + std::string(" in file: ") + url;
return std::string();
}
TTree *ttree = reader.GetTree();
std::set<std::string> includes;
std::vector<ClassStructure> classes;
TIter listOfBranches = ttree->GetListOfBranches();
for (TBranch *tbranch = (TBranch*)listOfBranches.Next(); tbranch != nullptr; tbranch = (TBranch*)listOfBranches.Next()) {
TClass *tclass = TClass::GetClass(tbranch->GetClassName());
if (tclass != nullptr && tbranch->GetListOfBranches()->GetEntries() > 0)
classesFromBranch(tbranch, tclass, classes, 0, includes);
}
for (int i = 0; i < classes.size(); i++)
classNames.push_back(classes[i].fullName);
tfile->Close();
std::string out;
for (std::set<std::string>::iterator iter = includes.begin(); iter != includes.end(); ++iter)
out += *iter + "\n";
out += "\n";
for (std::vector<ClassStructure>::iterator iter = classes.begin(); iter != classes.end(); ++iter) {
int i = 0;
for (; i < iter->splitName.size() - 1; i++)
out += std::string(i * 2, ' ') + "namespace " + iter->splitName[i] + " {\n";
out += std::string(i * 2, ' ') + "class " + iter->splitName.back() + ";\n";
i--;
for (; i >= 0; i--)
out += std::string(i * 2, ' ') + "}\n";
}
out += "\n";
for (std::vector<ClassStructure>::iterator iter = classes.begin(); iter != classes.end(); ++iter) {
int i = 0;
for (; i < iter->splitName.size() - 1; i++)
out += std::string(i * 2, ' ') + "namespace " + iter->splitName[i] + " {\n";
out += iter->cpp(i * 2) + "\n";
i--;
for (; i >= 0; i--)
out += std::string(i * 2, ' ') + "}\n";
}
for (std::vector<ClassStructure>::iterator iter = classes.begin(); iter != classes.end(); ++iter) {
int i = 0;
for (; i < iter->splitName.size() - 1; i++)
out += std::string(i * 2, ' ') + "namespace " + iter->splitName[i] + " {\n";
out += std::string(i * 2, ' ') + "ClassImp(" + iter->splitName.back() + ")\n";
i--;
for (; i >= 0; i--)
out += std::string(i * 2, ' ') + "}\n";
}
return out;
}
示例15: Test_dpd
void Test_dpd(std::string argStr, int DEBUG, int write_branches){
//Define number of messages by value of DEBUG; if int DEBUG == 1 print all messages into txt file
//write_branches == 1 => will write list of branches into txt file list_of_branches.txt
if (DEBUG != 1) DEBUG = 0;
if (write_branches != 1) write_branches = 0;
//First part: Read in file list
/*
std::string argStr;
char buf[256+1];
unsigned int delpos;
std::ifstream ifs("input.txt");
while (true)
{
ifs.read(buf,256);
if (ifs.eof())
{
if (ifs.gcount() == 0) break;
delpos = ifs.gcount()-1;
}
else
{
delpos = ifs.gcount();
}
buf[delpos] = 0x00;
argStr += buf;
}
*/
std::ofstream ofs("output.txt");
std::ofstream ofs2;
int error_counter = 0;
// split by ','
std::vector<std::string> fileList;
for (size_t i=0,n; i <= argStr.length(); i=n+1)
{
n = argStr.find_first_of(',',i);
if (n == string::npos)
n = argStr.length();
std::string tmp = argStr.substr(i,n-i);
std::string ttmp;
for(unsigned int j=0; j<tmp.size(); j++)
{
if(tmp[j]==' ' || tmp[j]=='\n') continue;
ttmp+=tmp[j];
}
fileList.push_back(ttmp);
}
// open input files
int open_tree = 0;
TChain * chain = new TChain("susy","");
for (unsigned int iFile=0; iFile<fileList.size(); ++iFile)
{
std::cout << "open " << fileList[iFile].c_str() << std::endl;
ofs << "open " << fileList[iFile].c_str() << std::endl;
open_tree = chain->AddFile(fileList[iFile].c_str(),0);
if (DEBUG==1) cout << "Status of file appened to chain: " << open_tree << endl;
if (open_tree == 0) {
ofs << "Error: File cannot be opened or tree \'susy\' does not exist" << endl;
error_counter++;
}
}
TTree *tree;
tree = chain;
Long64_t entries = tree->GetEntries();
if (DEBUG==1) cout << "Number of entries in tree: " << entries << endl;
if (DEBUG==1) ofs << "Number of entries in tree: " << entries << endl;
if (entries ==0) {
cout << "Error: Tree has no entries" << endl;
ofs << "Error: Tree has no entries" << endl;
error_counter++;
}
Long64_t b = 0;
TObjArray * list_of_branches = (TObjArray*)tree->GetListOfBranches();
int number_of_branches = 0;
if(write_branches == 1 && !ofs2.is_open()) ofs2.open("list_of_branches.txt");
for (int j=0; j<=list_of_branches->LastIndex(); j++)
{
number_of_branches++;
std::string tmp_branch = ((TBranch*)list_of_branches->At(j))->GetName();
if(write_branches == 1) ofs2 << tmp_branch << endl;
if(tmp_branch!="" && tree->GetBranch(tmp_branch.c_str())) {
b = (tree->GetBranch(tmp_branch.c_str()))->GetTotalSize();
if (DEBUG==1) cout << "Size of branch " << tmp_branch << ": " << b << endl;
if (DEBUG==1) ofs << "Size of branch " << tmp_branch << ": " << b << endl;
if (b <= 0) {
//.........这里部分代码省略.........