StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEEmcDb.cxx
1 #include <time.h>
2 #include <string.h>
3 
4 #include <TDatime.h>
5 
6 #include "StMaker.h"
7 
8 #include "St_DataSetIter.h"
9 
10 //#include "St_db_Maker/St_db_Maker.h" // tmp to ovveride time stamp
11 
12 #include "StEventTypes.h"
13 
14 #include "StEEmcDb.h"
15 
16 #include "EEmcDbItem.h"
17 #include "EEmcDbCrate.h"
18 #include "StEEmcUtil/EEfeeRaw/EEname2Index.h"
19 
20 #include "tables/St_eemcDbADCconf_Table.h"
21 #include "tables/St_eemcDbPMTcal_Table.h"
22 #include "tables/St_eemcDbPMTname_Table.h"
23 #include "tables/St_eemcDbPIXcal_Table.h"
24 #include "tables/St_eemcDbPMTped_Table.h"
25 #include "tables/St_eemcDbPMTstat_Table.h"
26 #include "tables/St_kretDbBlobS_Table.h"
27 #include "cstructs/eemcConstDB.hh"
28 #include "cstructs/kretConstDB.hh"
29 
30 #include <StMessMgr.h>
31 
32 ClassImp(StEEmcDb)
33 
34 //________________________________________________________
35 //________________________________________________________
36 StEEmcDb::StEEmcDb(const Char_t *name) : TDataSet(name) {
37  LOG_DEBUG<<endm;
38  mfirstSecID=mlastSecID=mNSector=0;
39 // myTimeStampDay=0;
40 // myTimeStampUnix=0;
41 
42  //................ allocate memory for lookup tables
43  byIndex=new EEmcDbItem[EEindexMax];
44 
45  byCrate=new EEmcDbItem ** [MaxAnyCrate];
46 
47  int i;
48  for(i=0;i<MaxAnyCrate;i++){
49  byCrate[i]=NULL;
50  if(i==0 || (i>MaxTwCrateID && i<MinMapmtCrateID) ) continue; // to save memory for nonexisting crates
51  byCrate[i]=new EEmcDbItem * [MaxAnyCh];
52  memset(byCrate[i],0,sizeof(EEmcDbItem *)*MaxAnyCh);// clear all pointers
53  }
54 
55  mDbFiber=0; nFiber=0;
56  setDBname("Calibrations/eemc");
57 
58  mAsciiDbase = "";
59 
60  mxChGain=8;
61  chGainL = new TString [mxChGain];
62  nChGain=0;
63 
64  mxChMask=8;
65  chMaskL = new TString [mxChMask];
66  nChMask=0;
67 
68  setThreshold(5.0); // defines threshold for ADCs
69  // should be +2 or +3 sigma in the future
70  // setPreferedFlavor("onlped","eemcPMTped"); // tmp for tests,JB
71 
72 }
73 
74 
75 //________________________________________________________
76 //________________________________________________________
77 //_______________________________________________________
78 StEEmcDb::~StEEmcDb(){
79 
80  if(mNSector) {
81  delete [] mDbADCconf;
82  delete [] mDbPMTcal;
83  delete [] mDbPMTname;
84  delete [] mDbPIXcal;
85  delete [] mDbPMTped;
86  delete [] mDbPMTstat;
87  delete [] mDbsectorID;
88  }
89 
90  delete mDbFiber;
91  delete [] chGainL;
92  delete [] chMaskL;
93 }
94 
95 //------------------
96 //------------------
97 void StEEmcDb::setThreshold(float x){
98  KsigOverPed=x;
99 LOG_INFO <<"::setThres KsigOverPed="<<KsigOverPed<<", threshold=ped+sig*KsigOverPed"<< endm;
100 }
101 
102 
103 //------------------
104 //------------------
105 void StEEmcDb::setPreferredFlavor(const char *flavor, const char *nameMask){
106  strncpy(dbFlavor.flavor,flavor,DbFlavor::mx);
107  strncpy(dbFlavor.nameMask,nameMask,DbFlavor::mx);
108  LOG_INFO << "::setPreferredFlavor(flav='"<<dbFlavor.flavor <<"', mask='"<< dbFlavor.nameMask<<"')" <<endm;
109 }
110 
111 //________________________________________________________
112 //________________________________________________________
113 //________________________________________________________
114 void StEEmcDb::setSectors(int sec1,int sec2)
115 {
116  // you can do it just once, no memory realocation implemented
117  mfirstSecID=sec1;
118  mlastSecID=sec2;
119  mNSector=mlastSecID - mfirstSecID+1;
120  if ( mNSector==0 ) {
121  LOG_ERROR << ":: Problem mNSector==0" <<endm;
122  } else {
123  mDbADCconf=(eemcDbADCconf_st **) new void *[mNSector];
124  mDbPMTcal= (eemcDbPMTcal_st **) new void *[mNSector];
125  mDbPMTname=(eemcDbPMTname_st **) new void *[mNSector];
126  mDbPIXcal= (eemcDbPIXcal_st **) new void *[mNSector];
127  mDbPMTped= (eemcDbPMTped_st **) new void *[mNSector];
128  mDbPMTstat=(eemcDbPMTstat_st **) new void *[mNSector];
129  mDbsectorID= new int [mNSector];
130 
131  clearItemArray();
132 
133  LOG_INFO << ":: Use sectors from "<< mfirstSecID<<" to "<< mlastSecID<<endm;
134  }
135 }
136 
137 //__________________________________________________
138 //__________________________________________________
139 //__________________________________________________
140 
141 const EEmcDbCrate* StEEmcDb::getFiber(int icr) const {
142  assert(icr>=0);
143  assert(icr<nFiber);
144  return mDbFiber+icr;
145 }
146 
147 //__________________________________________________
148 //__________________________________________________
149 //__________________________________________________
150 
151 void StEEmcDb::setFiberOff(int icr) {
152  if(icr<0 || icr>=nFiber ) {
153  LOG_WARN << "::setFiberOff(icr="<<icr<< ") out of range, ignorred" << endm;
154  return;
155  }
156  mDbFiber[icr].useIt=false;
157 }
158 
159 
160 
161 
162 //--------------------------------------------------
163 //--------------------------------------------------
164 void StEEmcDb::clearItemArray(){
165  //printf("%s::clearItemArray()\n",GetName());
166  nFound=0;
167 
168  int i;
169 
170  for(i=0; i<EEindexMax; i++)
171  byIndex[i].clear();
172 
173  int j;
174  for(i=0;i<MaxAnyCrate;i++) {
175  if(byCrate[i]==NULL) continue;
176  for(j=0;j<MaxAnyCh;j++)
177  byCrate[i][j]=0;
178  }
179 
180  memset(byStrip,0,sizeof(byStrip));
181 
182  if(mDbFiber) delete [] mDbFiber;
183  nFiber=0;
184  mDbFiberConfBlob=0;
185 
186 
187  nFound=0;
188 
189  if ( ! mDbADCconf ){
190  LOG_FATAL << ":: Cannot initialize arrays in clearItemArray()" << endm;
191  } else {
192  mDbADCconf[0]=0;
193  for(i=0; i<mNSector; i++) {// clear pointers old DB tables
194  mDbADCconf [i]=0;
195  mDbPMTcal [i]=0;
196  mDbPMTname [i]=0;
197  mDbPIXcal [i]=0;
198  mDbPMTped [i]=0;
199  mDbPMTstat [i]=0;
200  mDbsectorID[i]=-1;
201  }
202  }
203 
204 }
205 
206 
207 //__________________________________________________
208 //__________________________________________________
209 //__________________________________________________
210 
211 void StEEmcDb::loadTables(StMaker *anyMaker) {
212  if( mNSector==0) setSectors(1,12);//default
213 
214  // If an ascii file has been loaded, via setAsciiDatabase(),
215  // issue a warning and return.
216  if ( mAsciiDbase.Length() > 0 ) {
217  LOG_WARN << "loadTables: Database not reloaded, values taken from " << mAsciiDbase.Data() << endm;
218  } else {
219  LOG_INFO << "loadTables: use(flav='"<<dbFlavor.flavor <<"', mask='"<< dbFlavor.nameMask<<"')" <<endm;
220  clearItemArray();
221  requestDataBase(anyMaker);
222  //............ reload all lookup tables ...............
223  Bool_t ok = true;
224  for(int is = 0;(is < mNSector) && ok;is++) {
225  if (optimizeMapping(is)) {
226  LOG_FATAL<< "::loadTables Total failure, no DB info for Endcap was retrived, all ETOW channels will be cleared for every event. Fix the problem! JB"<<endm;
227  ok = false;
228  } else {
229  optimizeOthers(is);
230  }
231  }
232  if (ok) {
233  optimizeFibers();
234  // overload some of DB info
235  for(int is=0;is<nChGain;is++) changeGainsAction(chGainL[is].Data());
236  for(int is=0;is<nChMask;is++) changeMaskAction(chMaskL[is].Data());
237  // exportAscii(); //tmp
238  for(int icr = 0;icr < getNFiber();icr++) {
239  const EEmcDbCrate *fiber=getFiber(icr);
240  //printf(" eemcDB : ");
241  //fiber->print();
242  LOG_INFO<<(*fiber)<<endm; //JCW 01/26
243  }
244  LOG_INFO << "::loadTables Found "<< nFound<<" EEMC related tables "<<endm;
245  }
246  }
247 }
248 
249 
250 //__________________________________________________
251 //__________________________________________________
252 
253 void StEEmcDb::requestDataBase(StMaker *anyMaker){
254 
255  int ifl;
256  TString mask="";
257  for(ifl=0;ifl<2;ifl++) { // loop over flavors
258  if(ifl==1) {
259  if( dbFlavor.flavor[0]==0) continue; // drop flavor change
260  LOG_INFO << "::RequestDataBase()-->ifl="<<ifl<<" try flavor='"<<dbFlavor.flavor <<"' for mask='"<< dbFlavor.nameMask<<"')" <<endm;
261 
262  anyMaker->SetFlavor(dbFlavor.flavor,dbFlavor.nameMask);
263  mask=dbFlavor.nameMask;
264  }
265 
266  TDataSet *eedb = anyMaker ? anyMaker->GetDataBase(dbName) : 0;
267  if(!eedb) {
268  LOG_FATAL << "::RequestDataBase() Could not find dbName ="<<dbName <<endm;
269  return ;
270  // down-stream makers should check for presence of dataset
271  }
272  //eedb->ls(2);
273 
274  int is;
275  for(is=0; is< mNSector; is++) {
276  int secID=is+mfirstSecID;
277 
278  mDbsectorID[is]=secID;
279  getTable<St_eemcDbADCconf,eemcDbADCconf_st>(eedb,secID,"eemcADCconf",mask,mDbADCconf+is);
280 
281  getTable<St_eemcDbPMTcal,eemcDbPMTcal_st>(eedb,secID,"eemcPMTcal",mask,mDbPMTcal+is);
282 
283  getTable<St_eemcDbPMTname,eemcDbPMTname_st>(eedb,secID,"eemcPMTname",mask,mDbPMTname+is);
284 
285  getTable<St_eemcDbPIXcal,eemcDbPIXcal_st>(eedb,secID,"eemcPIXcal",mask,mDbPIXcal+is);
286 
287  getTable<St_eemcDbPMTped,eemcDbPMTped_st>(eedb,secID,"eemcPMTped",mask,mDbPMTped+is);
288 
289  getTable<St_eemcDbPMTstat,eemcDbPMTstat_st>(eedb,secID,"eemcPMTstat",mask,mDbPMTstat+is);
290 
291  } // end of loop over sectors
292 
293  // misc tables
294 
295  getTable<St_kretDbBlobS,kretDbBlobS_st>(eedb,13,"eemcCrateConf",mask,&mDbFiberConfBlob);
296  if(mDbFiberConfBlob) {
297  LOG_DEBUG<< "::RequestDataBase() eemcCrateConf dump "<<endm;
298  }
299 
300  }// end of loop over flavors
301 
302 }
303 
304 //--------------------------------------------------
305 //--------------------------------------------------
306 int StEEmcDb::optimizeMapping(int is){
307 
308  LOG_INFO <<" conf ADC map for sector="<< mDbsectorID[is] <<endm;
309  assert(mDbsectorID[is]>0);
310 
311  eemcDbADCconf_st *t= mDbADCconf[is];
312 
313  if(t==0) return -2; // it is fatal error
314  LOG_INFO <<"mapping="<< t->comment <<endm;
315 
316  int j;
317  for(j=0;j<EEMCDbMaxAdc; j++) { // loop over channels
318  char *name=t->name+j*EEMCDbMaxName;
319 
320  if(*name==EEMCDbStringDelim) continue;
321 
322  //printf("%d '%s' %d %d\n",j,name,t->crate[j],t->channel[j]);
323  // printf("%d %d %d\n",j,t->crate[j],t->channel[j]);
324 
325  int key=EEname2Index(name);
326  assert(key>=0 && key<EEindexMax);
327  EEmcDbItem *x=&byIndex[key];
328  if(!x->isEmpty()) {
329  //x->print(); // it is only on special error, never happends, too much changes needed
330  LOG_INFO<<(*x)<<endm; // JCW 01/26
331  assert(x->isEmpty());
332  }
333  x->crate=t->crate[j];
334  x->chan=t->channel[j];
335  x->setName(name);
336  x->key=key;
337  x->setDefaultTube(MinMapmtCrateID);
338  // x->print();
339 
340  assert(x->crate>=0 && x->crate<MaxAnyCrate);
341  assert(x->chan>=0 && x->chan<MaxAnyCh);
342  assert(byCrate[x->crate]);// ERROR: duplicated crate ID from DB
343  if(byCrate[x->crate][x->chan]) {
344  LOG_FATAL << "::Fatal Error of eemc DB records: the same crate="<<x->crate<<", ch="<<x->chan<<" entered twice. Whole EEMC DB is erased from memory, all data will be ignored, FIX IT !, JB"<<endm;
345  // byCrate[x->crate][x->chan]->print(); // first time
346  // x->print(); // second time
347  LOG_FATAL<<(*byCrate[x->crate][x->chan])<<endm;// JCW 1/26
348  LOG_FATAL<<(*x)<<endm;// JCW 1/26
349  clearItemArray();
350  return -1;
351  }
352  byCrate[x->crate][x->chan]=x;
353  if(x->isSMD()) byStrip[x->sec-1][x->plane-'U'][x->strip-1]=x;
354  }
355 
356  return 0;
357 
358 }
359 
360 
361 //--------------------------------------------------
362 //--------------------------------------------------
363 void StEEmcDb::optimizeOthers(int is){
364 
365  int secID= mDbsectorID[is];
366  // printf("\n optimizeDB for sector=%d\n",secID); //tmp
367  int ix1,ix2;
368  EEindexRange(secID,ix1,ix2);
369 
370  LOG_DEBUG<<" EEindexRange("<<secID<<","<<ix1<<","<<ix2<<")"<<endm;
371 
372  // if(dbg)printf(" Size: ped=%d cal=%d name=%d stat=%d \n",sizeof(ped->name)/EEMCDbMaxName,sizeof(cal->name)/EEMCDbMaxName,sizeof(tubeTw->name)/EEMCDbMaxName,sizeof(stat->name)/EEMCDbMaxName);
373 
374  assert(secID>0);
375 
376  eemcDbPMTcal_st *calT=mDbPMTcal[is];
377  if(calT) LOG_INFO <<"tower calib="<<calT->comment<<endm;
378  eemcDbPMTname_st *tubeTw=mDbPMTname[is];
379  if(tubeTw) LOG_INFO <<"PMT names="<<tubeTw->comment<<endm;
380 
381  eemcDbPIXcal_st *calM= mDbPIXcal[is];
382  if(calM) LOG_INFO <<"MAPMT calib="<<calM->comment<<endm;
383 
384  eemcDbPMTped_st *ped=mDbPMTped[is];
385  if(ped) LOG_INFO <<"ped tower & MAPMT="<<ped->comment<<endm;
386 
387  eemcDbPMTstat_st *stat=mDbPMTstat[is];
388  if(stat) LOG_INFO <<"status tower & MAPMT="<<stat->comment<<endm;
389 
390  int key;
391  for(key=ix1;key<ix2; key++) { // loop in this sector
392  EEmcDbItem *x=byIndex+key;
393  if(x->isEmpty()) continue;
394  char *name=x->name;
395 
396  if(ped) { // pedestals
397  int j;
398  int mx=sizeof(ped->name)/EEMCDbMaxName;
399  for(j=0;j<mx; j++) {
400  char *name1=ped->name+j*EEMCDbMaxName;
401  if(strncmp(name,name1,strlen(name))) continue;
402  x->ped=ped->ped[j];
403  x->sigPed=ped->sig[j];
404  x->thr=ped->ped[j]+KsigOverPed*ped->sig[j];
405  //printf("%d found %s %d %d\n",j,name,strlen(name),strncmp(name,name1,strlen(name)));
406  //x->print();
407  break;
408  }
409  } // end of pedestals
410 
411 
412  if(calT&& name[2]=='T') { // calibration for towers only
413  int j;
414  int mx=sizeof(calT->name)/EEMCDbMaxName;
415  for(j=0;j<mx; j++) {
416  char *name1=calT->name+j*EEMCDbMaxName;
417  if(strncmp(name,name1,strlen(name))) continue;
418  x->gain=calT->gain[j];
419  break;
420  }
421  } // end of Tower gains
422 
423 
424  if(calM && name[2]!='T') { // calibration for MAPMT
425  int j;
426  int mx=sizeof(calM->name)/EEMCDbMaxName;
427 
428  for(j=0;j<mx; j++) {
429  char *name1=calM->name+j*EEMCDbMaxName;
430  if(strncmp(name,name1,strlen(name))) continue;
431  x->gain=calM->gain[j];
432  break;
433  }
434  } // end of gains
435 
436  if(tubeTw && name[2]=='T') { // change tube for towers only
437  int j;
438  int mx=sizeof(tubeTw->name)/EEMCDbMaxName;
439  for(j=0;j<mx; j++) {
440  char *name1=tubeTw->name+j*EEMCDbMaxName;
441  if(strncmp(name,name1,strlen(name))) continue;
442  x->setTube(tubeTw->tubeName+j*EEMCDbMaxName);
443  //x->print();
444  break;
445  }
446  } // end of tube
447 
448 
449  if(stat) { // status
450  int j;
451  int mx=sizeof(stat->name)/EEMCDbMaxName;
452  for(j=0;j<mx; j++) {
453  char *name1=stat->name+j*EEMCDbMaxName;
454  if(strncmp(name,name1,strlen(name))) continue;
455  x->stat=stat->stat[j];
456  x->fail=stat->fail[j];
457  //x->print();
458  break;
459  }
460  } // end of status
461 
462 
463 
464  }// end of pixels in this sector
465 
466 
467 }
468 
469 //--------------------------------------------------
470 //--------------------------------------------------
471 void StEEmcDb::exportAscii(const char *fname) const{
472  LOG_INFO << "::exportAscii(\'" << fname << "') ..." << endm;
473 
474  FILE * fd=fopen(fname,"w");
475  assert(fd);
476  // fd=stdout;
477 
478  int nTot=0;
479 
480  fprintf(fd,"# EEmcDb::exportAscii(), see StRoot/StEEmcDb/EEmcDbItem::exportAscii() for definition\n");
481 
482  int j;
483 
484  fprintf(fd,"%d #fibers: {name,crID,crIDswitch,fiber,nCh,nHead,type,useIt}\n",nFiber);
485  for(j=0;j<nFiber;j++)
486  mDbFiber[j].exportAscii(fd);
487 
488  fprintf(fd,"#tw/pre/post: {name,crate,chan,sec,plane,strip,gain,ped,thr,stat,fail,tube,key}\n");
489  fprintf(fd,"#or \n");
490  fprintf(fd,"#smd: {name,crate,chan,sec,sub,eta,gain,ped,thr,stat,fail,tube,key}\n");
491 
492 
493  for(j=0;j<EEindexMax; j++) { // loop over channels
494  const EEmcDbItem *x=byIndex+j;
495  if(x->isEmpty())continue;
496  x->exportAscii(fd);
497  nTot++;
498  }
499  LOG_INFO << "::exportAscii() nTot=" << nTot << ", done" << endm;
500  fclose(fd);
501 }
502 
503 
504 
505 //__________________________________________________
506 //__________________________________________________
507 //__________________________________________________
508 
509 void StEEmcDb::optimizeFibers (){
510  int icr=0;
511 
512  if( mDbFiberConfBlob==0) {
513  LOG_FATAL <<" EEMC FiberConf not found"<<endm;
514  goto fatal;
515  }
516 
517  assert(mDbFiberConfBlob);
518  assert(nFiber==0);
519 
520  // printf("dataS='%s'\n",mDbFiberConfBlob->dataS);
521 
523  // for a new runs
529 
530  {
531  static char blobBuffer[KRETmxBlobSlen+1];
532  char *blob = blobBuffer;
533 
534 
535  int len = strlen(mDbFiberConfBlob->dataS);
536  assert(len<KRETmxBlobSlen ); // strnlen() is better but aborts under redhat72,JB
537  strncpy(blob,mDbFiberConfBlob->dataS,len);
538 
539  blob=strtok(blob,";"); // init iterator
540  if(strstr(blob,"<ver1>")==0) {
541  LOG_FATAL <<" EEMC FiberConf missing opening key "<<endm;
542  goto fatal;
543  }
544 
545  int i=0;
546  while((blob=strtok(0,";"))) { // advance by one nam{
547  i++;
548  if(strstr(blob,"<#>")) continue; // ignore some records
549  if(strstr(blob,"</ver1>")) goto done; // end of record, tmp
550 
551  // printf("i=%d -->'%s' \n",i,blob);
552  if(nFiber==0) {
553  nFiber=atoi(blob);
554  mDbFiber=new EEmcDbCrate[ nFiber];
555  LOG_DEBUG<<" mOptimizeFibers() map start: , nFiber="<<nFiber<<endm;
556  icr=0;
557  continue;
558  }
559  assert(icr<nFiber);
560  mDbFiber[icr].setAll(blob);
561  // mDbFiber[icr].print();
562  icr++;
563  };
564 
565  }
566 
567  LOG_FATAL <<" mOptimizeFibers() map missing/wrong terminating key "<<endm;
568 
569  fatal:
570  LOG_FATAL <<" EEMC FiberConf error, without it decoding of the _raw_ EEMC data from StEvent is not working (all data are dropped). However, this missing table is irreleveant for muDst analysis, JB"<<endm;
571  return;
572 
573  done:
574  LOG_INFO <<" mOptimizeFibers() map found for nFiber="<<nFiber<<endm;
575  if(icr==nFiber) return;
576 
577  LOG_FATAL <<" mOptimizeFibers() map nFiber missmatch is="<<icr<<" should be="<<nFiber<<endm;
578 goto fatal;
579 }
580 
581 //--------------------------------------------------
582 //--------------------------------------------------
583 const EEmcDbItem*
584 StEEmcDb::getByIndex(int i) const {
585  // Gets database entry by absolute index
586 
587  assert(i>=0);
588  assert(i<EEindexMax);
589  const EEmcDbItem *x=byIndex+i;
590  if(x->isEmpty()) return 0;
591  return x;
592 }
593 
594 
595 //--------------------------------------------------
596 //--------------------------------------------------
597 const EEmcDbItem* StEEmcDb::getByCrate(int crateID, int channel) const {
598  // crateID counts from 1, channel from 0
599  int type=0;
600  int max=0;
601  // printf("cr=%d ch=%d\n",crateID, channel);
602  if(crateID>=MinTwCrateID && crateID<=MaxTwCrateID) {
603  // Towers
604  type =1;
605  max=MaxTwCrateCh;
606  if(channel>=max) return 0; // not all data blocks are used
607 
608  } else if (crateID>=MinMapmtCrateID && crateID<=MaxMapmtCrateID ){
609  //MAPMT
610  type =2;
611  max=MaxMapmtCrateCh;
612  } else if (crateID>=17 && crateID<=46 ){ // only if working with ezTree
613  return 0; //BTOW
614  }
615 
616  // printf("id=%d type=%d ch=%d\n",crateID,type,channel);
617  //printf(" p=%p \n",byCrate[crateID]);
618 
619  assert(type);
620  assert( byCrate[crateID]);
621  assert(channel>=0);
622  assert(channel<max);
623  return byCrate[crateID][channel];
624 }
625 
626 
627 
628 //_________________________________________________________
629 //_________________________________________________________
630 //_________________________________________________________
631 
632 template <class St_T, class T_st> void StEEmcDb
633 ::getTable(TDataSet *eedb, int secID, TString tabName, TString mask, T_st** outTab ) {
634 
635  // printf("\n\n%s ::TTT --> %s, size=%d\n",GetName(),tabName.Data(),sizeof(T_st));
636 
637  // printf("%s ::TTT --> mask='%s' p=%p ss=%d\n",tabName.Data(),mask.Data(),*outTab,tabName.Contains(mask));
638 
639  if(!mask.IsNull() && !tabName.Contains(mask)) return ;
640  char name[1000];
641  if(secID<13)
642  sprintf(name,"sector%2.2d/%s",secID,tabName.Data());
643  else
644  sprintf(name,"misc/%s",tabName.Data());
645 
646 
647  LOG_DEBUG<<" request="<< name <<endm;
648 
649  St_T *ds= (St_T *)eedb->Find(name);
650  if(ds==0) {
651  LOG_WARN <<" sector="<<secID<<" table='"<< name <<" not Found in DB, continue "<<endm;
652  return ;
653  }
654 
655  if(ds->GetNRows()!=1) {
656  LOG_WARN <<" sector="<<secID<<" table='"<< name <<" no records, continue "<<endm;
657  return ;
658  }
659 
660  T_st *tab=(T_st *) ds->GetArray();
661 
662  if(tab==0) {
663  LOG_WARN <<" GetArray() failed"<<endm;
664  return ;
665  }
666 
667  *outTab=tab;
668  LOG_DEBUG<<" map="<< (*outTab)->comment<<"'"<<endm;
669 
670  nFound++;
671  return ; // copy the whole s-struct to allow flavor change;
672 }
673 
674 //__________________________________________________
675 //__________________________________________________
676 //__________________________________________________
677 
678 const EEmcDbItem*
679 StEEmcDb::getByStrip0(int isec, int iuv, int istrip) const {
680  // printf("isec=%d iuv=%d istrip=%d \n",isec,iuv,istrip);
681  assert(isec>=0 && isec<MaxSectors);
682  assert(iuv>=0 && iuv<MaxSmdPlains);
683  assert(istrip>=0 && istrip<MaxSmdStrips);
684  return byStrip[isec][iuv][istrip];
685 }
686 
687 
688 
689 //__________________________________________________
690 //__________________________________________________
691 //__________________________________________________
692 
693 const EEmcDbItem*
694 StEEmcDb::getTile(int sec, char sub, int eta, char type) const {
695  char name[20];
696  sprintf(name,"%2.2d%c%c%2.2d",sec,type,sub,eta);
697  int key=EEname2Index(name);
698  return byIndex+key;
699 }
700 
701 //__________________________________________________
702 //__________________________________________________
703 //__________________________________________________
704 
705 const EEmcDbItem*
706 StEEmcDb::getStrip(int sec, char uv, int strip) const {
707  char name[20];
708  sprintf(name,"%2.2d%c%3.3d",sec,uv,strip);
709  int key=EEname2Index(name);
710  return byIndex+key;
711 }
712 
713 
714 
715 //__________________________________________________
716 //__________________________________________________
717 //__________________________________________________
718 
719 void StEEmcDb::setAsciiDatabase( const Char_t *ascii )
720 {
721  // This method allows the user to initialize database
722  // values for each EEMC detector from an ascii file
723  // rather from a database query. InitRun() will be
724  // blocked from reloading the database on subsequent
725  // run numbers.
726 
727  mAsciiDbase = ascii;
728 
729  //-- Clear database values
730  //$$$ clearItemArray();
731 
732  //-- No provision (for now) for loading in partial info
733  Int_t sec1 = 1;
734  Int_t sec2 = 12;
735  nFound = 0;
736  mfirstSecID = sec1;
737  mlastSecID = sec2;
738  mNSector = mlastSecID - mfirstSecID + 1;
739 
740  //-- Open the specified file
741  FILE *fd=fopen(ascii,"r");
742  EEmcDbItem item;
743  int nd=0;
744  if(fd==0) goto crashIt;
745 
746 
747 
748  //-- Loop over all entries in the specified data file
749  while (1) {
750 
751  //-- Read in each individual entry. The return value is checked
752  //-- for success or failure
753  int ret = item.importAscii(fd);
754 
755  if(ret==0) break;
756  if(ret==1) continue;
757  if(ret <0) goto crashIt;
758 
759  //-- Index for the specified (named) item
760  int key=EEname2Index(item.name);
761 
762  //-- Apply a sanity check on the item
763  if(key!=item.key) {
764  LOG_WARN<<Form(": name='%s' key=%d!=inpKey=%d, inpKey ignored",item.name,key,item.key)<<endm;
765  item.key=key;
766  }
767  assert(key>=0 && key<EEindexMax);
768 
769 
770  int isec=item.sec-sec1;
771  if (sec1>sec2 ) isec+=12;
772 
773  if( isec <0 ) continue;
774  if( isec >= mNSector) continue;
775  nd++;
776 
777  //-- Copy the database record read in from the file into
778  //-- our local arrays.
779  EEmcDbItem *x=&byIndex[key];
780  if(!x->isEmpty()) goto crashIt;
781  *x=item; // copy this DB record
782  // x->print();
783 
784  assert(byCrate[x->crate]); // ERROR: unsupported crate ID
785  if(byCrate[x->crate][x->chan]) {
786  LOG_FATAL<<Form("Fatal Error of eemc DB records: the same crate=%d / channel=%d entered twice for :",x->crate,x->chan)<<endm;
787  // byCrate[x->crate][x->chan]->print(); // first time
788  // x->print(); // second time
789  LOG_FATAL<<(*byCrate[x->crate][x->chan])<<endm;// JCW 1/26
790  LOG_FATAL<<(*x)<<endm;// JCW 1/26
791  assert(1==2);
792  }
793  byCrate[x->crate][x->chan]=x;
794  // assert(2==311);
795  }
796 
797  //--
798  //-- Initialize the byStrip lookup table
799  //--
800  for ( Int_t mySec = 1; mySec <= 12; mySec++ )
801  for ( Char_t uv = 'U'; uv <= 'V'; uv++ )
802  for ( Int_t myStrip = 1; myStrip <= 288; myStrip++ ) byStrip[mySec-1][uv-'U'][myStrip-1] = (EEmcDbItem*)getStrip(mySec,uv,myStrip);
803 
804 
805  //--
806  LOG_INFO<<Form("setAsciiDataBase() done, found %d valid records",nd)<<endm;
807 
808  return;
809 
810  crashIt:// any failure of reading of the data
811  LOG_FATAL<<Form("EEmcDb - no/corrupted input file, continue")<<endm;
812  //clearItemArray();
813  // assert(2==3);
814 
815 
816 }
817 
818 //________________________________________________________
819 //________________________________________________________
820 void StEEmcDb::changeGains(char *fname) {
821  assert(nChGain+1< mxChGain);
822  chGainL[nChGain]=fname;
823  nChGain++;
824 }
825 
826 //________________________________________________________
827 //________________________________________________________
828 void
829 StEEmcDb::changeMask(char *fname) {
830  assert(nChMask+1< mxChMask);
831  chMaskL[nChMask]=fname;
832  nChMask++;
833 }
834 
835 
836 //________________________________________________________
837 //________________________________________________________
838 void StEEmcDb::changeGainsAction(const char *fname) {
839 
840  /* Replace gains only for channels already initialized from the DB
841  format : {name, gains anythingElse}
842  lines starting with '#' are ignored
843  empty lines are not permitted
844  */
845 
846  LOG_WARN <<" ::changeGains('"<<fname<<"')"<<endm;
847  FILE *fd=fopen(fname,"r");
848  int nd=0,nl=0;
849  const int mx=1000;
850  char buf[mx];
851 
852  if(fd==0) goto end;
853  char cVal[100];
854  float xVal;
855 
856  while(1) {
857  char *ret=fgets(buf,mx,fd);
858  if(ret==0) break;
859 
860  nl++;
861  if(buf[0]=='#') continue;
862  int n=sscanf(buf,"%s %f",cVal,&xVal);
863  assert(n==2);
864  int key=EEname2Index(cVal);
865  EEmcDbItem *x=byIndex+key;
866  // printf("%s %p\n",cVal,x);
867  if(x->isEmpty()) continue;
868  // replace only initialized channels
869  if(xVal<=0) LOG_WARN<<Form("Warning ! buf=%s=",buf)<<endm;
870  // assert(xVal>0);
871  x->gain=xVal;
872  nd++;
873  }
874  fclose(fd);
875 
876  end:
877  LOG_INFO <<" ::changeGains('"<<fname<<"') done inpLines="<<nl<<" nChanged="<<nd<<endm;
878  return;
879 
880 }
881 
882 //________________________________________________________
883 //________________________________________________________
884 void StEEmcDb::changeMaskAction(const char *fname) {
885 
886  /* Replace gains only for channels already initialized from the DB
887  format : {name, stat, fail enythingElse}
888  lines starting with '#' are ignored
889  empty lines are not permitted
890  */
891 
892  LOG_INFO <<" ::changeMask('"<<fname<<"') "<<endm;
893 
894  FILE *fd=fopen(fname,"r");
895 
896  int nd=0,nl=0;
897  const int mx=1000;
898  char buf[mx];
899 
900  if(fd==0) goto end;
901  char cVal[100];
902  int xStat,xFail ;
903 
904  while(1) {
905  char *ret=fgets(buf,mx,fd);
906  if(ret==0) break;
907 
908  nl++;
909  if(buf[0]=='#') continue;
910  int n=sscanf(buf,"%s %d %d",cVal,&xStat,&xFail);
911  assert(n==3);
912  int key=EEname2Index(cVal);
913  EEmcDbItem *x=byIndex+key;
914  if(x->isEmpty()) continue;
915  assert(xStat>=0);
916  assert(xFail>=0);
917  x->stat=xStat;
918  x->fail=xFail;
919  nd++;
920  }
921  fclose(fd);
922 
923  end:
924  LOG_INFO <<" ::changeMask('"<<fname<<"') done inpLines="<<nl<<" nChanged="<<nd<<endm;
925  return;
926 
927 }
928 
929 //-------------------------------------------------------------------
930 //-------------------------------------------------------------------
937 const EEmcDbItem *
938 StEEmcDb::StBarrelIndex2Item(int StDetId , int Bmod, int Beta, int Bsub) const {
939 
940  const EEmcDbItem *x=0;
941  int sec=Bmod; // range 1-12
942 
943  //..... towers,pre,post
944  char sub='X'; // range 'A' - 'E'
945  char cT='Y'; // range 'T','P','Q','R'
946  int eta=Beta; // range 1-12
947  //...... SMD
948  char uv='U'; // range 'U' or 'V'
949  int strip=Beta; // range 1-288
950 
951  switch(StDetId) { // covers all 6 layers of EEMC
952 
953  case kEndcapEmcTowerId:
954  sub='A'+Bsub-1; cT='T';
955  x=getTile(sec,sub,eta,cT); break;
956 
957  case kEndcapEmcPreShowerId:
958  sub='A'+(Bsub-1)%5; cT='P'+(Bsub-1)/5;
959  x=getTile(sec,sub,eta,cT); break;
960 
961  case kEndcapSmdVStripId:
962  uv++;
963  case kEndcapSmdUStripId:
964  x=getByStrip(sec,uv,strip); break;
965 
966  default:
967  LOG_WARN <<"::getDb(), wrong detectorId=" << StDetId << ". This is fatal - bug in the code, fix it, JB"<<endm;
968  assert(1==2); // trap for bug in the code
969  }
970 
971  return x;
972 }
const EEmcDbItem * getByIndex(int ikey) const
returns full DB info for one pixel
Definition: StEEmcDb.cxx:584
char name[StEEmcNameLen]
ASCII name of the channel, see Readme.
Definition: EEmcDbItem.h:20
int useIt
flag to ignore data from misconfig/broken crate/box
Definition: EEmcDbCrate.h:19
const EEmcDbItem * StBarrelIndex2Item(int StDetId, int Bmod, int Beta, int Bsub) const
Definition: StEEmcDb.cxx:938
void loadTables(StMaker *anyMaker)
to access STAR-DB
Definition: StEEmcDb.cxx:211
void setSectors(int, int)
limit the range of sectors for speed
Definition: StEEmcDb.cxx:114
int chan
hardware channel
Definition: EEmcDbItem.h:28
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362