StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
makeOnlinePed.C
1 
3 class StChain;
4 class StEmcOnl;
5 class St_db_Maker;
8 class StEmcEqualMaker;
9 class StEmcMipMaker;
10 StChain *chain=0;
11 StEmcOnl *emcIo = 0;
12 St_db_Maker *dbMk = 0;
13 StEmcCalibrationMaker *calib = 0;
14 StEmcPedestalMaker *ped[4];
15 
16 TMemStat memory;
17 
18 ped[0] = 0;
19 ped[1] = 0;
20 ped[2] = 0;
21 ped[3] = 0;
22 
23 int nEventsProc = 0;
24 int NEVENTS = 2000;
25 bool ok[4];
26 
27 bool processFile(char* line, char* dir)
28 {
29  bool DONE = false;
30  cout <<"Processing file "<<line<<endl;
31  emcIo->createEvPool(line,dir);
32  int istat =0 ;
33  int NE[4];
34  int NP = 0;
35  do
36  {
37  chain->Clear();
38  if(emcIo)
39  {
40  istat = emcIo->Make();
41  if(istat==0)
42  {
43  for(int i=0;i<4;i++) if(ped[i]) NE[i] = ped[i]->getNEvents();
44  if(nEventsProc%100==0)
45  {
46  //cout << "---------------------- Online Calibration Event : " << nEventsProc+1 << " ----------------------" << endl;
47  //for(int i=0;i<4;i++) if(ped[i]) cout <<" NEvents for "<<ped[i]->GetName()<<" = "<< NE[i] <<endl;
48  cout << "Event " << nEventsProc << endl;
49  }
50  if(dbMk) dbMk->Make();
51  if(calib) calib->Make();
52  DONE = true;
53  bool HASPROCESSED = false;
54  for(int i=0;i<4;i++)
55  {
56  if(ped[i] && !ok[i])
57  {
58  ped[i]->Make();
59  if(ped[i]->getNEvents()>NE[i]) HASPROCESSED = true;
60  if(ped[i]->getNEvents()>=(NEVENTS+10)) ok[i] = true;
61  }
62  if(!ok[i]) DONE=false;
63  }
64  if(DONE) goto EXIT;
65  nEventsProc++;
66  if(!HASPROCESSED) NP++; else NP = 0;
67  if(NP>50)
68  {
69  cout <<"Skiping this file. No bemc data have been processed for more than 50 events\n";
70  return false;
71  }
72  if ((nEventsProc % 100) == 0) memory.PrintMem(0);
73  }
74  }
75  } while(istat==0 || istat==1);
76 
77  return false;
78 
79  EXIT:
80  return true;
81 }
82 
83 void makeOnlinePed(char* list = "./runlist.txt", bool isList = true) {
84  TDatime startTime;
85  TStopwatch timer;
86  cout << "Started: " << startTime.AsSQLString() << endl;
87  timer.Start();
88  memory.PrintMem(0);
89 
90  const Char_t *EVP_READER_LIB = gSystem->Getenv("EVP_READER_LIB");
91  TString dirStr = gSystem->Getenv("EVP_DIR");
92  TString savePathStr = gSystem->Getenv("EMCONLINE_PED_BACKUP_DIR");
93  TString tablesPathStr = gSystem->Getenv("EMCONLINE_PED_TABLES_DIR");
94  TString lastTablePathStr = gSystem->Getenv("EMCONLINE_PED_LASTTABLES_DIR");
95  TString tempPathStr = gSystem->Getenv("EMCONLINE_PED_TEMP_DIR");
96  TString pedCrateFilenameFormatStr = gSystem->Getenv("CRATE_PEDESTAL_FILES_FORMAT");
97  TString bemcStatusStr = gSystem->Getenv("EMCONLINE_PED_BEMCSTATUS_FILE");
98 
99  TString neventsStr = gSystem->Getenv("EMCONLINE_PED_NEVENTS");
100  Int_t nevents = neventsStr.Atoi();
101  TString saveDbStr = gSystem->Getenv("EMCONLINE_PED_SAVEDB");
102  Bool_t saveDb = (saveDbStr == "true");
103  TString saveTablesStr = gSystem->Getenv("EMCONLINE_PED_SAVETABLES");
104  Bool_t saveTables = (saveTablesStr == "true");
105  TString compareLastTableDBStr = gSystem->Getenv("EMCONLINE_PED_COMPARELASTTABLEDB");
106  Bool_t compareLastTableDB = (compareLastTableDBStr == "true");
107  TString useBemcStatusStr = gSystem->Getenv("EMCONLINE_PED_USEBEMCSTATUS");
108  Bool_t useBemcStatus = (useBemcStatusStr == "true");
109 
110  // BTOW
111  TString minPedDiffDBStr_BTOW = gSystem->Getenv("EMCONLINE_PED_MINPEDDIFFDB_BTOW");
112  Float_t minPedDiffDB_BTOW = minPedDiffDBStr_BTOW.Atof();
113  TString minPedDiffNumStr_BTOW = gSystem->Getenv("EMCONLINE_PED_MINPEDDIFFNUM_BTOW");
114  Int_t minPedDiffNum_BTOW = minPedDiffNumStr_BTOW.Atoi();
115  TString minPedDiffMinTimeStr_BTOW = gSystem->Getenv("EMCONLINE_PED_MINPEDDIFFMINTIME_BTOW");
116  Float_t minPedDiffMinTime_BTOW = minPedDiffMinTimeStr_BTOW.Atof();
117 
118  // BPRS
119  TString minPedDiffDBStr_BPRS = gSystem->Getenv("EMCONLINE_PED_MINPEDDIFFDB_BPRS");
120  Float_t minPedDiffDB_BPRS = minPedDiffDBStr_BPRS.Atof();
121  TString minPedDiffNumStr_BPRS = gSystem->Getenv("EMCONLINE_PED_MINPEDDIFFNUM_BPRS");
122  Int_t minPedDiffNum_BPRS = minPedDiffNumStr_BPRS.Atoi();
123  TString minPedDiffMinTimeStr_BPRS = gSystem->Getenv("EMCONLINE_PED_MINPEDDIFFMINTIME_BPRS");
124  Float_t minPedDiffMinTime_BPRS = minPedDiffMinTimeStr_BPRS.Atof();
125 
126  // BSMD
127  TString minPedDiffDBStr_BSMD = gSystem->Getenv("EMCONLINE_PED_MINPEDDIFFDB_BSMD");
128  Float_t minPedDiffDB_BSMD = minPedDiffDBStr_BSMD.Atof();
129  TString minPedDiffNumStr_BSMD = gSystem->Getenv("EMCONLINE_PED_MINPEDDIFFNUM_BSMD");
130  Int_t minPedDiffNum_BSMD = minPedDiffNumStr_BSMD.Atoi();
131  TString minPedDiffMinTimeStr_BSMD = gSystem->Getenv("EMCONLINE_PED_MINPEDDIFFMINTIME_BSMD");
132  Float_t minPedDiffMinTime_BSMD = minPedDiffMinTimeStr_BSMD.Atof();
133 
134  // Load needed shared libs
135  gSystem->Load(EVP_READER_LIB);
136  gSystem->Load("St_base");
137  gSystem->Load("St_Tables");
138  gSystem->Load("StUtilities");
139  gSystem->Load("StChain");
140  gSystem->Load("StEvent");
141  gSystem->Load("StDbLib");
142  gSystem->Load("StDbBroker");
143  gSystem->Load("St_db_Maker");
144  gSystem->Load("StDaqLib");
145  gSystem->Load("StEmcUtil");
146  gSystem->Load("StEmcOnlineUtil");
147  gSystem->Load("StEmcCalibrationMaker");
148 
149  memory.PrintMem(0);
150  NEVENTS = nevents;
151 
152  cout << "Backup directory: " << savePathStr << endl;
153  cout << "Backup tables directory: " << tablesPathStr << endl;
154  cout << "Last tables directory: " << lastTablePathStr << endl;
155  cout << "Temp directory: " << tempPathStr << endl;
156  cout << "Event pool: " << dirStr << endl;
157  cout << "bemcStatus.txt: " << bemcStatusStr << endl;
158  cout << "Number of events to process: " << NEVENTS << endl;
159  cout << "Save tables to DB: " << saveDb << endl;
160  cout << "Save tables locally: " << saveTables << endl;
161  cout << "Compare to the last saved table: " << compareLastTableDB << endl;
162  cout << "Use bemcStatus.txt: " << useBemcStatus << endl;
163  cout << "Ped crate filename format: " << pedCrateFilenameFormatStr << endl;
164  cout << "BTOW:" << endl;
165  cout << "Min ped diff from the last table: " << minPedDiffDB_BTOW << endl;
166  cout << "Min ped diff num from the last table: " << minPedDiffNum_BTOW << endl;
167  cout << "Min time from the last table: " << minPedDiffMinTime_BTOW << endl;
168  cout << "BPRS:" << endl;
169  cout << "Min ped diff from the last table: " << minPedDiffDB_BPRS << endl;
170  cout << "Min ped diff num from the last table: " << minPedDiffNum_BPRS << endl;
171  cout << "Min time from the last table: " << minPedDiffMinTime_BPRS << endl;
172  cout << "BSMD:" << endl;
173  cout << "Min ped diff from the last table: " << minPedDiffDB_BSMD << endl;
174  cout << "Min ped diff num from the last table: " << minPedDiffNum_BSMD << endl;
175  cout << "Min time from the last table: " << minPedDiffMinTime_BSMD << endl;
176 
177  // create chain ///////////////////////////////////////////////
178  chain = new StChain("StChain");
179 
180  // create StEmcOnl
181  emcIo = new StEmcOnl();
182  //emcIo->setPrintInfo(kTRUE);
183 
184  // create database
185  dbMk = new St_db_Maker("StarDb","$STAR/StarDb","MySQL:StarDb");
186 
187  // create calibraton maker
188  calib = new StEmcCalibrationMaker();
189 
190  TString name[] = {"bemcPed", "bprsPed", "bsmdePed", "bsmdpPed"};
191  for(int i=0;i<4;i++)
192  {
193  ok[i] = false;
194  ped[i] = new StEmcPedestalMaker(name[i].Data());
195  ped[i]->setDetector(i+1);
196  TString filename = tempPathStr + "/" + name[i] + ".root";
197  ped[i]->setFile(filename);
198  ped[i]->setNPedEvents(NEVENTS);
199  ped[i]->setPedInterval(24*100);
200  ped[i]->setRange(300);
201  ped[i]->setAutoSaveDB(saveDb);
202  //ped[i]->setCTBMax(3000);
203  ped[i]->setSavePath(savePathStr.Data());
204  ped[i]->setTablesPath(tablesPathStr.Data());
205  ped[i]->setLastTablePath(lastTablePathStr.Data());
206  ped[i]->setSaveTables(saveTables);
207  ped[i]->setCompareLastTableDB(compareLastTableDB);
208  ped[i]->setPedCrateFilenameFormat(pedCrateFilenameFormatStr.Data());
209  ped[i]->setBemcStatusFilename(bemcStatusStr.Data());
210  ped[i]->setUseBemcStatus(useBemcStatus);
211  if (i == 0) {
212  ped[i]->setPedDiffSaveDB(minPedDiffDB_BTOW);
213  ped[i]->setPedDiffSaveNum(minPedDiffNum_BTOW);
214  ped[i]->setPedDiffSaveMinTime(minPedDiffMinTime_BTOW);
215  } else if (i == 1) {
216  ped[i]->setPedDiffSaveDB(minPedDiffDB_BPRS);
217  ped[i]->setPedDiffSaveNum(minPedDiffNum_BPRS);
218  ped[i]->setPedDiffSaveMinTime(minPedDiffMinTime_BPRS);
219  } else if ((i == 2) || (i == 3)) {
220  ped[i]->setPedDiffSaveDB(minPedDiffDB_BSMD);
221  ped[i]->setPedDiffSaveNum(minPedDiffNum_BSMD);
222  ped[i]->setPedDiffSaveMinTime(minPedDiffMinTime_BSMD);
223  }
224  }
225 
226  memory.PrintMem(0);
227  chain->Init();
228  memory.PrintMem(0);
229  nEventsProc = 0;
230 
231  if(isList)
232  {
233  ifstream INPUT(list);
234  Char_t line[1024];
235  while(!INPUT.eof())
236  {
237  INPUT >> line;
238  bool isDone = processFile(line,dirStr.Data());
239  if(isDone) goto EXIT;
240  }
241  }
242  else processFile(list,dirStr.Data());
243 
244  EXIT:
245  cout <<"FINISHED\n";
246  memory.PrintMem(0);
247 
248  TDatime stopTime;
249  timer.Stop();
250  cout << "Finished: " << stopTime.AsSQLString() << endl;
251  timer.Print();
252 }
virtual Int_t Make()
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77