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
00062 };
00063
00064 #endif // FROOT_ZEBRA_ACCESS
00065
00066
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
00083 delete fPreanMan;
00084
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;
00120 UseProcessRec_GES();
00121
00122
00123 if(fFillDst){
00124 if( fPreanMan->ReconstructFidaEvent() !=0) return;
00125 UseProcessRec_DST();
00126
00127 }
00128
00129 fCurEv++;
00130 fTotEvCount++;
00131 }
00132
00133 }
00134
00135
00136 Int_t TZebraAccess::ProcessSingleRun(){
00137
00138
00139
00140
00141 Pre_Run_Operation();
00142
00143 Int_t initval = fPreanMan->InitNewPreanRun(fRunType,fCurrentRun);
00144 if(initval!=0){
00145
00146 fPreanMan->FinishPreanRun(kFALSE,kFALSE);
00147 fCurrentRun += fIncrement;
00148 Printf("\n --- --- --- --- \n");
00149 return -1;
00150 }
00151
00152 Printf("New run started (%s %d)",fRunType.Data(),fCurrentRun);
00153
00154 fCurEv = 1;
00155
00156
00157 EventLoop();
00158
00159
00160 fPreanMan->FinishPreanRun(fIsLastRun,kFALSE);
00161
00162 Printf("\n --- --- --- --- \n");
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){
00183
00184
00185 if(fLastRun >= fFirstRun && fCurrentRun > fLastRun) break;
00186 else if(fLastRun < fFirstRun && fCurrentRun < fLastRun) break;
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;
00198
00199
00200
00201 fCurrentRun += fIncrement;
00202 }
00203
00204
00205 fPreanMan->CloseInterface();
00206
00207
00208 return 0;
00209
00210 }
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226