mcr_included/AccessZebra_MultiRun.C

00001 #ifndef FROOT_ZEBRA_ACCESS
00002 #define FROOT_ZEBRA_ACCESS
00003 
00004 #include <Riostream.h>
00005 #include "TROOT.h"
00006 #include "TSystem.h"
00007 #include "TApplication.h"
00008 
00009 #include "TString.h"
00010 #include "TObject.h"
00011 
00012 #include "TFndHdt.h"
00013 #include "TFndPreanMan.h"
00014 #include "TFndPrean.h"
00015 
00016 
00017 class TZebraAccess: public TObject{
00018   
00019 private:
00020   TFndProcessRec *fPrec;
00021   
00022   TFndPreanMan *fPreanMan;
00023   
00024   Bool_t fFillDst;
00025 
00026   TString fDBhost;
00027   TString fDataPath;
00028   TString fRunType;
00029   
00030   Int_t fFirstRun;
00031   Int_t fLastRun;
00032   Bool_t fIsLastRun;
00033   
00034   Int_t fDebugLevel;
00035   
00036   Int_t fTotEvCount;
00037   Int_t fTotEvTgt;
00038   Int_t fEvPerRunTgt;
00039   Int_t fCurEv;
00040   Int_t fIncrement;
00041   Int_t fCurrentRun;
00042   
00043 public:
00044 
00045   TZebraAccess();
00046   ~TZebraAccess();
00047 
00048   virtual void Init(const TString &db_host,const TString &data_path,const TString &run_type,Int_t first_run,Int_t last_run,Int_t n_evs_run,Int_t n_evs_tot,Int_t debug_lev);
00049 
00050   virtual void SetFillDst(const Bool_t &fill_dst) { fFillDst = fill_dst; }
00051 
00052   virtual void UseProcessRec_GES()=0;
00053   virtual void UseProcessRec_DST()=0;
00054   virtual void EventLoop();
00055   virtual Int_t ProcessSingleRun();
00056   virtual Int_t RunLoop();
00057 
00058   virtual void Pre_Run_Operation() = 0;
00059   virtual void Post_Run_Operation() = 0;
00060 
00061   //  ClassDef(TZebraAccess,1)
00062 };
00063 
00064 #endif // FROOT_ZEBRA_ACCESS
00065 
00066 //ClassImp(TZebraAccess)
00067 
00068 //___________________________________
00069 TZebraAccess::TZebraAccess():
00070   fPrec(),fPreanMan(),
00071   fFillDst(),fDBhost(),fDataPath(),fRunType(),
00072   fFirstRun(),fLastRun(),fDebugLevel(),
00073   fTotEvCount(),fTotEvTgt(),fEvPerRunTgt(),
00074   fCurEv(),fIncrement(),fCurrentRun()
00075 {
00076   
00077   fFillDst = kTRUE;
00078 }
00079 
00080 //___________________________________
00081 TZebraAccess::~TZebraAccess(){
00082   //  cout << "DEBUG1" << endl;
00083   delete fPreanMan;
00084   //  cout << "DEBUG2" << endl;
00085 }
00086 
00087 //___________________________________
00088 void TZebraAccess::Init(const TString &db_host,const TString &data_path,const TString &run_type,Int_t first_run,Int_t last_run,Int_t n_evs_run,Int_t n_evs_tot,Int_t debug_lev){
00089   
00090   fDBhost = db_host;
00091   fDataPath = data_path;
00092   fRunType = run_type;
00093   fEvPerRunTgt = n_evs_run;
00094   fTotEvTgt = n_evs_tot;
00095   fDebugLevel = debug_lev;
00096   //
00097   fFirstRun = first_run;
00098   fLastRun = last_run;
00099   //
00100   fPreanMan = new TFndPreanMan(fDBhost,fDataPath,fDebugLevel);
00101 }
00102 
00103 //___________________________________
00104 void TZebraAccess::EventLoop(){
00105   
00106   fPrec = fPreanMan->GetProcessRec();
00107   if(!fPrec) TerminateFroot(0,"fPrec not available!");
00108 
00109   while(1){
00110     if( fCurEv % 300 == 0 ) gROOT->Info("EventLoop","Processing run %s-%d ===> event %d",fRunType.Data(),fCurrentRun,fCurEv);
00111     if(fTotEvTgt != -1 && fTotEvCount > fTotEvTgt){
00112       Printf("EventLoop ---> maximum number of events reached for current preanalysis process");
00113       return;
00114     }
00115     if(fEvPerRunTgt != -1 && fCurEv > fEvPerRunTgt){
00116       Printf("EventLoop ---> maximum number of events reached for current run");
00117       return;
00118     }
00119     if( fPreanMan->GetNextFidaEvent() != 0) return; // Fill FGES
00120     UseProcessRec_GES();
00121     //    fPreanMan->AnalyzeJFGES(); // used by pre-analysis
00122     
00123     if(fFillDst){
00124       if( fPreanMan->ReconstructFidaEvent() !=0) return; // Fill FDST (exit loop in case of problems)
00125       UseProcessRec_DST();
00126       //    fPreanMan->AnalyzeJFDST(); // used by pre-analysis
00127     }
00128 
00129     fCurEv++;
00130     fTotEvCount++;
00131   } // event loop completed
00132   
00133 }
00134 
00135 //___________________________________
00136 Int_t TZebraAccess::ProcessSingleRun(){
00137   // return value:
00138   //              0: ok
00139   //             -1: run initialization not possible 
00140 
00141   Pre_Run_Operation();
00142 
00143   Int_t initval = fPreanMan->InitNewPreanRun(fRunType,fCurrentRun); // offline mode
00144   if(initval!=0){
00145     //      Printf("initval: %d",initval);
00146     fPreanMan->FinishPreanRun(kFALSE,kFALSE);
00147     fCurrentRun += fIncrement;
00148     Printf("\n --- --- --- --- \n"); // simply nice ;)
00149     return -1;
00150   }
00151   
00152   Printf("New run started (%s %d)",fRunType.Data(),fCurrentRun);
00153   
00154   fCurEv = 1; // reset single run event counter
00155   
00156   // ---
00157   EventLoop();
00158   // ---
00159   
00160   fPreanMan->FinishPreanRun(fIsLastRun,kFALSE); // last run completed
00161   
00162   Printf("\n --- --- --- --- \n"); // simply nice ;)
00163 
00164   Post_Run_Operation();
00165   
00166   return 0;
00167 }
00168 
00169 //___________________________________
00170 Int_t TZebraAccess::RunLoop(){
00171   
00172   if(!fPreanMan){
00173     gROOT->Error("RunLoop","fPreanMan not defined");
00174     TerminateFroot();
00175   }
00176 
00177   gROOT->Info("RunLoop","Starting loop on runs (%d -> %d)",fFirstRun,fLastRun);
00178 
00179   fCurrentRun = fFirstRun;
00180   fIncrement = (fLastRun >= fFirstRun) ? +1 : -1;
00181   
00182   while(1){ // run loop
00183     //    cout << "DEBUG 0 ===> " << fCurrentRun << endl;
00184 
00185     if(fLastRun >= fFirstRun && fCurrentRun > fLastRun) break;    
00186     else if(fLastRun < fFirstRun && fCurrentRun < fLastRun) break; // allow reverse processing
00187     
00188     if(fTotEvTgt != -1 && fTotEvCount >= fTotEvTgt){
00189       Printf("RunLoop ---> maximum number of events reached for current preanalysis process");
00190       break;
00191     }
00192     
00193     fIsLastRun = (fCurrentRun == fLastRun)? kTRUE : kFALSE;
00194     if(ProcessSingleRun() == -1) continue;
00195 
00196     //    
00197     if(fCurrentRun == -1) break; // one initialization only in online-mode
00198     //
00199 
00200     //
00201     fCurrentRun += fIncrement;
00202   } // run loop completed
00203   
00204   //  cout << "DEBUG 1" << endl;
00205   fPreanMan->CloseInterface(); // close used reconstruction (dynamic) library
00206   //  cout << "DEBUG 2" << endl;
00207   
00208   return 0;
00209   
00210 }
00211 
00212 //___________________________________
00213 //___________________________________
00214 //___________________________________
00215 // void AccessZebra_MultiRun(TString run_type="FINU",Int_t first_run = -1,Int_t last_run = -1,Int_t n_evs_run=-1,Int_t n_evs_tot=-1){
00216   
00217 //   TZebraAccess *zac = new TZebraAccess();
00218 //   // --- INIT ---
00219 //   Int_t debug_lev = 0;
00220 //   //
00221 //   zac->Init("$MSQL_DB_HOST","$RDT",run_type,first_run,last_run,n_evs_run,n_evs_tot,debug_lev);
00222   
00223 
00224 //   zac->RunLoop();
00225 //   delete zac;
00226 // }

Generated on Tue Oct 16 15:40:47 2007 by  doxygen 1.5.2