////////////////////////////////////////////////////////////////////////// // // Hall A analyzer replay script core // // https://hallaweb.jlab.org/wiki/index.php/ReplayCore // // Call this script after loading all the detectors to run replay // // if there is no rootlogon.C, execute following command in analyzer first // gSystem->Load(".so"); // if you want to compile this script then you will also need // gSystem->AddIncludePath("-I"); // gInterpreter->AddIncludePath(""); // ////////////////////////////////////////////////////////////////////////// // // Author : Jin Huang (jinhuang@jlab.org) Aug 2007 // // Modify History: // Mar 2008 Jin Huang // add physics module support // Mar 2008 Jin Huang // separate two modes: physics replay and detector replay // also make it smarter // Apr 2008 Jin Huang // rootfile overwrite proof // May 2008 Jin Huang // Separate core code of replay script to ReplayCore.C // May 2008 Jin Huang // Support Start Analyzing from an arbitary event number // Support Exit when getting an invalid answer. // Fix Bugs // Oct 2008 Jin Huang // Support raw data file name which do not have an endfix index // Nov 2008 Jin Huang // Clear Cut list before run // Nov 2008 Jin Huang // Support >2G file size on older compilers // Dec 2008 Jin Huang // Auto Runs // ////////////////////////////////////////////////////////////////////////// #ifndef ROOT_REPLAY_CORE #define ROOT_REPLAY_CORE //#include "def.h" #include #include #include #include #include #include #ifndef __CINT__ //header file for compile #include "TSystem.h" #include "TROOT.h" #include "THaEvent.h" #include "THaRun.h" #include "THaAnalyzer.h" #include "TTree.h" #include "TFile.h" #include "TString.h" #endif//#ifdef __CINT__ Bool_t IsFileExist(const Char_t * fname); using namespace std; void ReplayCore( Int_t runnumber=0, //run # Int_t all=0, //-1=replay all;0=ask for a number Int_t DefReplayNum=-1, //defaut replay event num char* OutFileFormat="%s/e06010_test_%d.root", //output file format char* OutDefineFile="replay_test.odef", //out define char* CutDefineFile="replay_test.cdef", //cut define Bool_t EnableScalar=false, //Enable Scalar? Int_t FirstEventNum=0, //First Event To Replay Bool_t QuietRun = kFALSE //whether not ask question? ) { //general replay script core // // to do replay, use a script to load detectors then call this function // // it's also convenient to load detector manually in analyzer // command line then call me // step 1: Init analyzer cout<<"replay: Init analyzer ..."<Close(); } else { analyzer = new THaAnalyzer; } gHaCuts->Clear(); //Enable scalers if (EnableScalar) { cout<<"replay: Enabling Scalars"<EnableScalers(); } // step 2: setup run information cout<<"replay: configuring analyzer ..."<> nrun; fgets(buf,300,stdin);//get the extra '\n' from stdin if( nrun<=0 ) break; } } else nrun=runnumber; path=PATHS; while ( path && *path ) { sprintf(filename,RAW_DATA_FORMAT,*path,nrun,0); cout<<"replay: Try file "<0) runnumber=0; } } if(nrun<=0) { gHaApps->Delete(); gHaPhysics->Delete(); gHaScalers->Delete(); analyzer->Close(); return; } if (all==0) { if (QuietRun) { nev=DefReplayNum; } else { cout << "\nreplay: Number of Events to analyze " <<" (default="; if (DefReplayNum>0) cout<Get("T"); if (t!=0) NEnt = (t->GetEntries()); } delete f; TString DefOverWriting; if (NEnt==DefReplayNum || DefReplayNum<0 || NEnt==0) DefOverWriting="no"; else DefOverWriting="yes"; if (NEnt<=0) { cout <Delete(); gHaPhysics->Delete(); analyzer->Close(); return; } } } cout<SetOutFile( outname ); analyzer->SetOdefFile(OutDefineFile); analyzer->SetCutFile(CutDefineFile); char sumname[300]; sprintf(sumname,SUMMARY_PHYSICS_FORMAT,nrun); analyzer->SetSummaryFile(sumname); // optional analyzer->SetEvent( new THaEvent ); //analyzer->SetMarkInterval(ANA_MARK_INTERVAL); //correct the offset on the last event if first event is above 0 if (nev>=0) nev+=FirstEventNum; // step 3: run it cout<<"replay: Start Process ..."<SetFilename(filename); } else { run = new THaRun(filename); } runlist[runidx]=run; runidx++; if(nev>=0) run->SetLastEvent(nev); run->SetFirstEvent(FirstEventNum); //run->Print(); analyzer->Process(run); //NeveAna=run->GetNumAnalyzed(); //cout << "replay: "<=(UInt_t)nev) exit=true; run->Close(); if (!oldrun) oldrun = run; //else delete run; } } // step 3: clean up cout<<"replay: Cleaning up ... "<=0;runidx--){ assert(runlist[runidx]); delete runlist[runidx]; } gHaApps->Delete(); gHaPhysics->Delete(); gHaScalers->Delete(); analyzer->Close(); cout<<"replay: YOU JUST ANALYZED RUN number "<