--- PamelaLevel2/doc/examples/Loop.cpp 2006/12/06 11:07:35 1.1 +++ PamelaLevel2/doc/examples/Loop.cpp 2007/08/17 16:57:11 1.6 @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -20,11 +21,23 @@ //=================================== // global variables //=================================== +Bool_t DEBUG; +TString DIR; +TString LIST; +TString I_OPTIONS; +TString O_OPTIONS; +ULong64_t MINEV; +ULong64_t MAXEV; +TString OUTFILE; +Bool_t SIMU; + PamLevel2 *event = NULL; TChain *tree = NULL; +TChain *runt = NULL; TFile *outfh = NULL; TFile *outft = NULL; TTree *otree = NULL; +GL_RUN *run = NULL; bool fillTree = false; bool fillHistos = false; @@ -33,7 +46,8 @@ // Functions to be provided externally //==================================== bool Select(PamLevel2*); -void CreateHistos(); +//void CreateHistos(PamLevel2*, TFile *); +void CreateHistos(PamLevel2*, TFile *); void FillHistos(PamLevel2*); void SaveHistos(TFile *); @@ -42,23 +56,12 @@ //========================================== bool Begin(){ - //------------------------ - // load magnetic field - //------------------------ - TString fieldpath = gSystem->Getenv("PAM_CALIB"); - if(fieldpath.IsNull()){ - cout << " **ERROR** : No PAMELA environment variables defined "<LoadField(fieldpath.Data()); - - //------------------------------ // create output histos/trees //------------------------------ - if(fillHistos) CreateHistos(); - if(fillTree) event->CreateCloneTrees(tree); + //if(fillHistos) CreateHistos(event,outfh); + if(fillHistos) CreateHistos(event, outfh); + if(fillTree)event->CreateCloneTrees(outft); cout << "\nBegin() - done\n\n"; return 1; @@ -70,19 +73,10 @@ 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(fillHistos)FillHistos(event); + if(fillTree)event->FillCloneTrees();//must be after fillhisto return true; @@ -93,15 +87,15 @@ bool Finish(){ + if(fillHistos){ + SaveHistos(outfh); + outfh->Close(); + } if(fillTree){ outft->cd(); event->WriteCloneTrees(); outft->Close(); } - if(fillHistos){ - SaveHistos(outfh); - outfh->Close(); - } cout << "Finish() - done\n"; @@ -111,14 +105,21 @@ //========================================== //000000000000000000000000000000000000000000 //========================================== -Int_t Loop(TString ddir,TString list, ULong64_t nmax, TString options, TString outfile){ - - if(options.Contains("fillTree"))fillTree=true; - if(options.Contains("fillHisto"))fillHistos=true; +Int_t Loop(TString ddir,TString list, ULong64_t nmax, ULong64_t nmin, TString ioptions, TString ooptions, TString outfile){ +// gObjectTable->Print(); + +// ------------------------ +// check output options (I) +// ------------------------ + if(ooptions.Contains("fillTree"))fillTree=true; + if(ooptions.Contains("fillHisto"))fillHistos=true; + // ------------------- // create output files // ------------------- + TTree::SetMaxTreeSize(1000*Long64_t(2000000000)); //m 070308 + dimensione oltre la quale divide il file di uscita: 2TB + TString outfile_t =0; TString outfile_h =0; if( outfile.IsNull() ){ @@ -154,18 +155,39 @@ // read input file/list // -------------------- event = new PamLevel2(); + event->SetGP(SIMU);//new + if(SIMU)cout << " >> SIMULATION << "<IsGP()<SetDBConnection(); + if(DEBUG)gObjectTable->Print(); if(list.Contains(".root")){ + TString tempfile = gSystem->BaseName(list.Data()); +// tempfile.Replace(tempfile.Index(".root",5),5,".txt",4); + tempfile.Append(".txt"); + cout << "Creating temporary file: "< list-temp.txt"; + command << " echo "< "<Exec(command.str().c_str()); - tree = event->GetPamTree(event->GetListOfLevel2Files(ddir,"list-temp.txt"),options); + tree = event->GetPamTree(ddir,tempfile.Data(),ioptions); + runt = event->GetRunTree(ddir,tempfile.Data()); + command.str(""); + command << "rm -f "<Exec(command.str().c_str()); }else{ - tree = event->GetPamTree(event->GetListOfLevel2Files(ddir,list),options); + tree = event->GetPamTree(ddir,list,ioptions); + runt = event->GetRunTree(ddir,list); }; + + +// gObjectTable->Print(); tree->SetCacheSize(0); +// ------------------------- +// check output options (II) +// ------------------------- + if(fillTree)event->SetWhichTrees(ooptions); + // --------------- // initializations // --------------- @@ -174,37 +196,49 @@ // ----------------- // loop over events // ----------------- - ULong64_t nevents = tree->GetEntriesFast(); + ULong64_t nevents = tree->GetEntries(); if(!nmax)nmax = numeric_limits::max(); if(nevents < nmax)nmax=nevents; + nmax=nmax-nmin; - cout << endl<<" Start loop over events: "<< nmax<Start("event-loop"); TString current_file = ""; - for(ULong64_t iev=60000; ievPrint(); + for(ULong64_t iev=nmin; 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) ){ + if( event->GetEntry(iev) ){ //<<< new feature + get++; + if( Process(iev) ){ +// cout << "%%%% "<GetFile()->GetName())){ + current_file=tree->GetFile()->GetName(); + cout < "<< current_file << endl; + }; + }else{ + cout << "Chain entry "<TrkLevel2::ntrk() >0)ntrk++; - if(!(iev%100))cout << iev << endl; + if( !(iev%5000) && DEBUG)gObjectTable->Print(); + if( !(iev%1000) )cout <<"|"; + }; + cout <Show("event-loop"); - cout << ntrk <<" tracks over "<Print(); + event->Clear(); // -------------- // close and exit // -------------- @@ -216,23 +250,43 @@ ///////////////////////////////////////////////////////////////// -#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 << "------------------------------------------------------------"< inlcude(exclude) all default level1/level2 trees and branches \n " ; + cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) level1/level2 trees and branches \n" ; + cout << " +TRK0 +CAL0 +TOF0 --> include level0 branches \n" ; + cout << "-output-options [ options ] - options: \n"; + cout << " fillHistos --> create an output file with histograms \n"; + cout << " fillTree --> create an output file with trees storing the selected events \n "; + cout << " == NB == "< inlcude(exclude) all trees and branches \n " ; + cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) trees and branches \n" ; + cout << "--simulation, -s - simulation file \n"; + cout << "------------------------------------------------------------"<WorkingDirectory(); - LIST = ""; - OUTFILE = "TrkLevel1Report_output.root"; - MAXEV = numeric_limits::max(); -*/ + DEBUG = false; + DIR = gSystem->WorkingDirectory(); + LIST = ""; + OUTFILE = ""; + I_OPTIONS = "+ALL "; + O_OPTIONS = "fillTree"; + MAXEV = 0; + MINEV = 0; + SIMU = false; for (int i = 1; i < argc; i++){ @@ -276,6 +333,13 @@ cout << "outputFile "<= argc) throw -1; + MINEV = atoi(argv[i]); + cout << "FirstEvent "<= argc) throw -1; @@ -284,11 +348,38 @@ continue; } // -----------------------------------------------------// + else if (!strcmp(argv[i], "-input-options")){ + if (++i >= argc) throw -1; + I_OPTIONS = argv[i]; + if( I_OPTIONS.Contains("[") ){ + do{ + if (++i >= argc) throw -1; + I_OPTIONS.Append(argv[i]); + }while(!I_OPTIONS.Contains("]")); + }else cout << "wrong option format --> ignoring " << endl; + } + // -----------------------------------------------------// + else if (!strcmp(argv[i], "-output-options")){ + if (++i >= argc) throw -1; + O_OPTIONS = argv[i]; + if( O_OPTIONS.Contains("[") ){ + do{ + if (++i >= argc) throw -1; + O_OPTIONS.Append(argv[i]); + }while(!O_OPTIONS.Contains("]")); + }else cout << "wrong option format --> ignoring " << endl; + } + // -----------------------------------------------------// else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-g")){ DEBUG = true; continue; } // -----------------------------------------------------// + else if (!strcmp(argv[i], "--simulation") || !strcmp(argv[i], "-s")){ + SIMU = true; + continue; + } + // -----------------------------------------------------// else{ cout << "Unidentified input parameter. Ignored."<< endl; }; @@ -312,7 +403,10 @@ 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 << "INPUT OPTIONS "<