--- PamelaLevel2/doc/examples/Loop.cpp 2006/12/06 11:07:35 1.1 +++ PamelaLevel2/doc/examples/Loop.cpp 2007/01/15 11:51:39 1.4 @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,13 @@ //=================================== // global variables //=================================== +Bool_t DEBUG; +TString DIR; +TString LIST; +TString OPTIONS; +ULong64_t MAXEV; +TString OUTFILE; + PamLevel2 *event = NULL; TChain *tree = NULL; TFile *outfh = NULL; @@ -33,7 +41,7 @@ // Functions to be provided externally //==================================== bool Select(PamLevel2*); -void CreateHistos(); +void CreateHistos(TFile *); void FillHistos(PamLevel2*); void SaveHistos(TFile *); @@ -51,14 +59,19 @@ return 0; } fieldpath.Append("/trk-param/field_param-0/"); - event->LoadField(fieldpath.Data()); + event->GetTrkLevel2()->LoadField(fieldpath.Data()); //------------------------------ // create output histos/trees //------------------------------ - if(fillHistos) CreateHistos(); - if(fillTree) event->CreateCloneTrees(tree); + if(fillHistos) CreateHistos(outfh); + if(fillTree){ +// outft->cd(); +// event->CreateCloneTrees(tree,outft); + event->CreateCloneTrees(outft); + } +// gDirectory->ls(); cout << "\nBegin() - done\n\n"; return 1; @@ -70,19 +83,11 @@ bool Process(int iev){ - //------------------------------ - // create output histos/trees - //------------------------------ - - event->Clear(); - tree->GetEntry(iev); if( !Select(event) )return false; -// cout <TrkLevel2::ntrk()<FillCloneTrees(); -// if(fillHistos)FillHistos(event); + if(fillTree)event->FillCloneTrees(); + if(fillHistos)FillHistos(event); return true; @@ -112,6 +117,8 @@ //000000000000000000000000000000000000000000 //========================================== Int_t Loop(TString ddir,TString list, ULong64_t nmax, TString options, TString outfile){ + +// gObjectTable->Print(); if(options.Contains("fillTree"))fillTree=true; if(options.Contains("fillHisto"))fillHistos=true; @@ -154,16 +161,18 @@ // read input file/list // -------------------- event = new PamLevel2(); + if(DEBUG)gObjectTable->Print(); if(list.Contains(".root")){ stringstream command; command.str(""); command << " echo "< list-temp.txt"; cout << command.str().c_str() << endl; gSystem->Exec(command.str().c_str()); - tree = event->GetPamTree(event->GetListOfLevel2Files(ddir,"list-temp.txt"),options); + tree = event->GetPamTree(ddir,"list-temp.txt",options); }else{ - tree = event->GetPamTree(event->GetListOfLevel2Files(ddir,list),options); + tree = event->GetPamTree(ddir,list,options); }; +// gObjectTable->Print(); tree->SetCacheSize(0); // --------------- @@ -174,37 +183,43 @@ // ----------------- // loop over events // ----------------- - ULong64_t nevents = tree->GetEntriesFast(); + ULong64_t nevents = tree->GetEntries(); if(!nmax)nmax = numeric_limits::max(); if(nevents < nmax)nmax=nevents; cout << endl<<" Start loop over events: "<< nmax<Start("event-loop"); TString current_file = ""; - for(ULong64_t iev=60000; ievPrint(); + for(ULong64_t iev=0; ievGetEntry(iev); - if( Process(iev) )sel++; - - if(current_file.CompareTo(tree->GetFile()->GetName())){ - current_file=tree->GetFile()->GetName(); - cout << iev<< " -> "<< current_file << endl; -// cout << tree->GetFile()->GetName() << endl; + event->Clear(); + if( tree->GetEntry(iev) ){ + get++; + if( Process(iev) ){ + sel++; + } + if(current_file.CompareTo(tree->GetFile()->GetName())){ + current_file=tree->GetFile()->GetName(); + cout << iev<< " -> "<< current_file << endl; + }; + }else{ + cout << "Chain entry "<Print(); - if(event->TrkLevel2::ntrk() >0)ntrk++; - if(!(iev%100))cout << iev << endl; - }; benchmark->Show("event-loop"); - cout << ntrk <<" tracks over "<Print(); + event->Clear(); // -------------- // close and exit // -------------- @@ -216,23 +231,34 @@ ///////////////////////////////////////////////////////////////// -#if !defined(__CINT__) +#if !defined(__CINT__) -// input parameters -Bool_t DEBUG; -TString DIR; -TString LIST; -ULong64_t MAXEV; -TString OUTFILE; +// // input parameters +// Bool_t DEBUG; +// TString DIR; +// TString LIST; +// TString OPTIONS; +// ULong64_t MAXEV; +// TString OUTFILE; void usage(){ + + cout << "------------------------------------------------------------"< create an output file with histograms \n"; + cout << " fillTree --> create an output file with trees storing the selected events \n "; + cout << " +(-)ALL --> inlcude(exclude) all trees and branches \n " ; + cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) trees and branches \n" ; + cout << "------------------------------------------------------------"<WorkingDirectory(); - LIST = ""; - OUTFILE = "TrkLevel1Report_output.root"; - MAXEV = numeric_limits::max(); -*/ + DEBUG = false; + DIR = gSystem->WorkingDirectory(); + LIST = ""; + OUTFILE = ""; + OPTIONS = "+ALL fillTree"; + MAXEV = 0; for (int i = 1; i < argc; i++){ @@ -284,6 +310,17 @@ continue; } // -----------------------------------------------------// + else if (!strcmp(argv[i], "-options")){ + if (++i >= argc) throw -1; + OPTIONS = argv[i]; + if( OPTIONS.Contains("[") ){ + do{ + if (++i >= argc) throw -1; + OPTIONS.Append(argv[i]); + }while(!OPTIONS.Contains("]")); + }else cout << "wrong option format --> ignoring " << endl; + } + // -----------------------------------------------------// else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-g")){ DEBUG = true; continue; @@ -312,7 +349,9 @@ if( HandleInputPar(argc,argv) )return(1); - Loop(DIR,LIST,MAXEV,"-ALL+TRK1+TRK2+CAL1+CAL2+TOF+AC fillHisto fillTree",OUTFILE); +// Loop(DIR,LIST,MAXEV,"-ALL+TRK1+TRK2+CAL1+CAL2+TOF+AC",OUTFILE); + cout << "OPTIONS "<