test/TestTFndPreanMan_MultiRun.C

00001 #include <Riostream.h>
00002 #include "TROOT.h"
00003 #include "TSystem.h"
00004 #include "TApplication.h"
00005 
00006 #include "TString.h"
00007 
00008 #include "TFndHdt.h"
00009 #include "TFndPreanMan.h"
00010 #include "TFndPrean.h"
00011 
00012 TFndProcessRec *fPrec;
00013 
00014 TFndPreanMan *fPreanMan;
00015 
00016 TString fDBhost;
00017 TString fDataPath;
00018 TString fRunType;
00019 
00020 Int_t fFirstRun;
00021 Int_t fLastRun;
00022 Bool_t fIsLastRun;
00023 
00024 Int_t fDebugLevel;
00025 
00026 Int_t fTotEvCount;
00027 Int_t fTotEvTgt;
00028 Int_t fEvPerRunTgt;
00029 Int_t fCurEv;
00030 Int_t fIncrement;
00031 Int_t fCurrentRun;
00032 
00033 //___________________________________
00034 void UseProcessRec_GES(){
00035 
00036   Int_t JFGES = fPrec->GetJFGES();
00037   Int_t trigbit = fPrec->GetIQ(JFGES+3);
00038   Int_t rnum = fPrec->GetIQ(JFGES+1);
00039   Int_t evnum = fPrec->GetIQ(JFGES+2);
00040   cout << "JFGES = " << JFGES 
00041        << " ---> trig: " << trigbit
00042        << "; rnum: " << rnum
00043        << "; evnum: " << evnum << endl;
00044   
00045   Int_t L_DCH1 = fPrec->GetLQ(JFGES-4);
00046   while(L_DCH1){
00047     Int_t dch_num = fPrec->GetIQ(L_DCH1+1);
00048     cout << "dch_num = " << dch_num << endl;
00049     
00050     L_DCH1 = fPrec->GetLQ(L_DCH1);
00051   }
00052 
00053 }
00054 
00055 //___________________________________
00056 void UseProcessRec_DST(){
00057 
00058   Int_t JFDST = fPrec->GetJFDST();
00059   Int_t trigbit = fPrec->GetIQ(JFDST+3);
00060   Int_t rnum = fPrec->GetIQ(JFDST+1);
00061   Int_t evnum = fPrec->GetIQ(JFDST+2);
00062   cout << "JFDST = " << JFDST 
00063        << " ---> trig: " << trigbit
00064        << "; rnum: " << rnum
00065        << "; evnum: " << evnum << endl;
00066   
00067 
00068 
00069 }
00070 
00071 //___________________________________
00072 void EventLoop(){
00073   
00074   fPrec = fPreanMan->GetProcessRec();
00075   if(!fPrec) TerminateFroot(0,"fPrec not available!");
00076 
00077   while(1){
00078     if( fCurEv % 300 == 0 ) gROOT->Info("FinudaPreanalysis","Processing run %s-%d ===> event %d",fRunType.Data(),fCurrentRun,fCurEv);
00079     if(fTotEvTgt != -1 && fTotEvCount > fTotEvTgt){
00080       Printf("PreanalyzeRun ---> maximum number of events reached for current preanalysis process");
00081       return;
00082     }
00083     if(fEvPerRunTgt != -1 && fCurEv > fEvPerRunTgt){
00084       Printf("PreanalyzeRun ---> maximum number of events reached for current run");
00085       return;
00086     }
00087     if( fPreanMan->GetNextFidaEvent() != 0) return; // Fill FGES
00088     UseProcessRec_GES();
00089     //    fPreanMan->AnalyzeJFGES(); // used by pre-analysis
00090     if( fPreanMan->ReconstructFidaEvent() !=0) return; // Fill FDST (exit loop in case of problems)
00091     UseProcessRec_DST();
00092     //    fPreanMan->AnalyzeJFDST(); // used by pre-analysis
00093     fCurEv++;
00094     fTotEvCount++;
00095   } // event loop completed
00096   
00097 }
00098 
00099 //___________________________________
00100 Int_t ProcessSingleRun(){
00101   // return value:
00102   //              0: ok
00103   //             -1: run initialization not possible 
00104 
00105   Int_t initval = fPreanMan->InitNewPreanRun(fRunType,fCurrentRun); // offline mode
00106   if(initval!=0){
00107     //      Printf("initval: %d",initval);
00108     fPreanMan->FinishPreanRun(kFALSE);
00109     fCurrentRun += fIncrement;
00110     Printf("\n --- --- --- --- \n"); // simply nice ;)
00111     return -1;
00112   }
00113   
00114   Printf("New run started (%s %d)",fRunType.Data(),fCurrentRun);
00115   
00116   fCurEv = 1; // reset single run event counter
00117   
00118   // ---
00119   EventLoop();
00120   // ---
00121   
00122   fPreanMan->FinishPreanRun(fIsLastRun); // last run completed
00123   
00124   Printf("\n --- --- --- --- \n"); // simply nice ;)
00125   
00126   return 0;
00127 }
00128 
00129 //___________________________________
00130 Int_t RunLoop(){
00131   
00132   if(!fPreanMan){
00133     gROOT->Error("RunLoop","fPreanMan not defined");
00134     TerminateFroot();
00135   }
00136 
00137   gROOT->Info("RunLoop","Starting loop on runs (%d -> %d)",fFirstRun,fLastRun);
00138 
00139   fCurrentRun = fFirstRun;
00140   fIncrement = (fLastRun >= fFirstRun) ? +1 : -1;
00141   
00142   while(1){ // run loop
00143     if(fLastRun >= fFirstRun && fCurrentRun > fLastRun) break;    
00144     else if(fLastRun < fFirstRun && fCurrentRun < fLastRun) break; // allow reverse processing
00145     
00146     if(fTotEvTgt != -1 && fTotEvCount >= fTotEvTgt){
00147       Printf("RunLoop ---> maximum number of events reached for current preanalysis process");
00148       break;
00149     }
00150     
00151     fIsLastRun = (fCurrentRun == fLastRun)? kTRUE : kFALSE;
00152     if(ProcessSingleRun() == -1) continue;
00153 
00154     //    
00155     if(fCurrentRun == -1) break; // one initialization only in online-mode
00156     //
00157 
00158     //
00159     fCurrentRun += fIncrement;
00160   } // run loop completed
00161   
00162   fPreanMan->CloseInterface(); // close used reconstruction (dynamic) library
00163   
00164   return 0;
00165   
00166 }
00167 
00168 //___________________________________
00169 //___________________________________
00170 //___________________________________
00171 void TestTFndPreanMan_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){
00172   
00173   // --- INIT ---
00174   Int_t debug_lev = 0;
00175   //
00176   fDBhost = "$MSQL_DB_HOST";
00177   fDataPath = "$RDT";
00178   fRunType = run_type;
00179   fEvPerRunTgt = n_evs_run;
00180   fTotEvTgt = n_evs_tot;
00181   fDebugLevel = debug_lev;
00182   //
00183   fFirstRun = first_run;
00184   fLastRun = last_run;
00185   //
00186   fPreanMan = new TFndPreanMan(fDBhost,fDataPath,fDebugLevel);
00187 
00188   RunLoop();
00189 }

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