00001 #include <time.h>
00002 #include <string.h>
00003
00004 #include <TDatime.h>
00005
00006 #include "StMaker.h"
00007
00008 #include "St_DataSetIter.h"
00009
00010
00011
00012 #include "StEventTypes.h"
00013
00014 #include "StEEmcDb.h"
00015
00016 #include "EEmcDbItem.h"
00017 #include "EEmcDbCrate.h"
00018 #include "StEEmcUtil/EEfeeRaw/EEname2Index.h"
00019
00020 #include "tables/St_eemcDbADCconf_Table.h"
00021 #include "tables/St_eemcDbPMTcal_Table.h"
00022 #include "tables/St_eemcDbPMTname_Table.h"
00023 #include "tables/St_eemcDbPIXcal_Table.h"
00024 #include "tables/St_eemcDbPMTped_Table.h"
00025 #include "tables/St_eemcDbPMTstat_Table.h"
00026 #include "tables/St_kretDbBlobS_Table.h"
00027 #include "cstructs/eemcConstDB.hh"
00028 #include "cstructs/kretConstDB.hh"
00029
00030 #include <StMessMgr.h>
00031
00032 ClassImp(StEEmcDb)
00033
00034
00035
00036 StEEmcDb::StEEmcDb(const Char_t *name) : TDataSet(name) {
00037 LOG_DEBUG<<endm;
00038 mfirstSecID=mlastSecID=mNSector=0;
00039
00040
00041
00042
00043 byIndex=new EEmcDbItem[EEindexMax];
00044
00045 byCrate=new EEmcDbItem ** [MaxAnyCrate];
00046
00047 int i;
00048 for(i=0;i<MaxAnyCrate;i++){
00049 byCrate[i]=NULL;
00050 if(i==0 || (i>MaxTwCrateID && i<MinMapmtCrateID) ) continue;
00051 byCrate[i]=new EEmcDbItem * [MaxAnyCh];
00052 memset(byCrate[i],0,sizeof(EEmcDbItem *)*MaxAnyCh);
00053 }
00054
00055 mDbFiber=0; nFiber=0;
00056 setDBname("Calibrations/eemc");
00057
00058 mAsciiDbase = "";
00059
00060 mxChGain=8;
00061 chGainL = new TString [mxChGain];
00062 nChGain=0;
00063
00064 mxChMask=8;
00065 chMaskL = new TString [mxChMask];
00066 nChMask=0;
00067
00068 setThreshold(5.0);
00069
00070
00071
00072 }
00073
00074
00075
00076
00077
00078 StEEmcDb::~StEEmcDb(){
00079
00080 if(mNSector) {
00081 delete [] mDbADCconf;
00082 delete [] mDbPMTcal;
00083 delete [] mDbPMTname;
00084 delete [] mDbPIXcal;
00085 delete [] mDbPMTped;
00086 delete [] mDbPMTstat;
00087 delete [] mDbsectorID;
00088 }
00089
00090 delete mDbFiber;
00091 delete [] chGainL;
00092 delete [] chMaskL;
00093 }
00094
00095
00096
00097 void StEEmcDb::setThreshold(float x){
00098 KsigOverPed=x;
00099 LOG_INFO <<"::setThres KsigOverPed="<<KsigOverPed<<", threshold=ped+sig*KsigOverPed"<< endm;
00100 }
00101
00102
00103
00104
00105 void StEEmcDb::setPreferredFlavor(const char *flavor, const char *nameMask){
00106 strncpy(dbFlavor.flavor,flavor,DbFlavor::mx);
00107 strncpy(dbFlavor.nameMask,nameMask,DbFlavor::mx);
00108 LOG_INFO << "::setPreferredFlavor(flav='"<<dbFlavor.flavor <<"', mask='"<< dbFlavor.nameMask<<"')" <<endm;
00109 }
00110
00111
00112
00113
00114 void StEEmcDb::setSectors(int sec1,int sec2)
00115 {
00116
00117 mfirstSecID=sec1;
00118 mlastSecID=sec2;
00119 mNSector=mlastSecID - mfirstSecID+1;
00120 if ( mNSector==0 ) {
00121 LOG_ERROR << ":: Problem mNSector==0" <<endm;
00122 } else {
00123 mDbADCconf=(eemcDbADCconf_st **) new void *[mNSector];
00124 mDbPMTcal= (eemcDbPMTcal_st **) new void *[mNSector];
00125 mDbPMTname=(eemcDbPMTname_st **) new void *[mNSector];
00126 mDbPIXcal= (eemcDbPIXcal_st **) new void *[mNSector];
00127 mDbPMTped= (eemcDbPMTped_st **) new void *[mNSector];
00128 mDbPMTstat=(eemcDbPMTstat_st **) new void *[mNSector];
00129 mDbsectorID= new int [mNSector];
00130
00131 clearItemArray();
00132
00133 LOG_INFO << ":: Use sectors from "<< mfirstSecID<<" to "<< mlastSecID<<endm;
00134 }
00135 }
00136
00137
00138
00139
00140
00141 const EEmcDbCrate* StEEmcDb::getFiber(int icr) const {
00142 assert(icr>=0);
00143 assert(icr<nFiber);
00144 return mDbFiber+icr;
00145 }
00146
00147
00148
00149
00150
00151 void StEEmcDb::setFiberOff(int icr) {
00152 if(icr<0 || icr>=nFiber ) {
00153 LOG_WARN << "::setFiberOff(icr="<<icr<< ") out of range, ignorred" << endm;
00154 return;
00155 }
00156 mDbFiber[icr].useIt=false;
00157 }
00158
00159
00160
00161
00162
00163
00164 void StEEmcDb::clearItemArray(){
00165
00166 nFound=0;
00167
00168 int i;
00169
00170 for(i=0; i<EEindexMax; i++)
00171 byIndex[i].clear();
00172
00173 int j;
00174 for(i=0;i<MaxAnyCrate;i++) {
00175 if(byCrate[i]==NULL) continue;
00176 for(j=0;j<MaxAnyCh;j++)
00177 byCrate[i][j]=0;
00178 }
00179
00180 memset(byStrip,0,sizeof(byStrip));
00181
00182 if(mDbFiber) delete [] mDbFiber;
00183 nFiber=0;
00184 mDbFiberConfBlob=0;
00185
00186
00187 nFound=0;
00188
00189 if ( ! mDbADCconf ){
00190 LOG_FATAL << ":: Cannot initialize arrays in clearItemArray()" << endm;
00191 } else {
00192 mDbADCconf[0]=0;
00193 for(i=0; i<mNSector; i++) {
00194 mDbADCconf [i]=0;
00195 mDbPMTcal [i]=0;
00196 mDbPMTname [i]=0;
00197 mDbPIXcal [i]=0;
00198 mDbPMTped [i]=0;
00199 mDbPMTstat [i]=0;
00200 mDbsectorID[i]=-1;
00201 }
00202 }
00203
00204 }
00205
00206
00207
00208
00209
00210
00211 void StEEmcDb::loadTables(StMaker *anyMaker) {
00212 if( mNSector==0) setSectors(1,12);
00213
00214
00215
00216 if ( mAsciiDbase.Length() > 0 ) {
00217 LOG_WARN << "loadTables: Database not reloaded, values taken from " << mAsciiDbase.Data() << endm;
00218 } else {
00219 LOG_INFO << "loadTables: use(flav='"<<dbFlavor.flavor <<"', mask='"<< dbFlavor.nameMask<<"')" <<endm;
00220 clearItemArray();
00221 requestDataBase(anyMaker);
00222
00223 Bool_t ok = true;
00224 for(int is = 0;(is < mNSector) && ok;is++) {
00225 if (optimizeMapping(is)) {
00226 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;
00227 ok = false;
00228 } else {
00229 optimizeOthers(is);
00230 }
00231 }
00232 if (ok) {
00233 optimizeFibers();
00234
00235 for(int is=0;is<nChGain;is++) changeGainsAction(chGainL[is].Data());
00236 for(int is=0;is<nChMask;is++) changeMaskAction(chMaskL[is].Data());
00237
00238 for(int icr = 0;icr < getNFiber();icr++) {
00239 const EEmcDbCrate *fiber=getFiber(icr);
00240
00241
00242 LOG_INFO<<(*fiber)<<endm;
00243 }
00244 LOG_INFO << "::loadTables Found "<< nFound<<" EEMC related tables "<<endm;
00245 }
00246 }
00247 }
00248
00249
00250
00251
00252
00253 void StEEmcDb::requestDataBase(StMaker *anyMaker){
00254
00255 int ifl;
00256 TString mask="";
00257 for(ifl=0;ifl<2;ifl++) {
00258 if(ifl==1) {
00259 if( dbFlavor.flavor[0]==0) continue;
00260 LOG_INFO << "::RequestDataBase()-->ifl="<<ifl<<" try flavor='"<<dbFlavor.flavor <<"' for mask='"<< dbFlavor.nameMask<<"')" <<endm;
00261
00262 anyMaker->SetFlavor(dbFlavor.flavor,dbFlavor.nameMask);
00263 mask=dbFlavor.nameMask;
00264 }
00265
00266 TDataSet *eedb = anyMaker ? anyMaker->GetDataBase(dbName) : 0;
00267 if(!eedb) {
00268 LOG_FATAL << "::RequestDataBase() Could not find dbName ="<<dbName <<endm;
00269 return ;
00270
00271 }
00272
00273
00274 int is;
00275 for(is=0; is< mNSector; is++) {
00276 int secID=is+mfirstSecID;
00277
00278 mDbsectorID[is]=secID;
00279 getTable<St_eemcDbADCconf,eemcDbADCconf_st>(eedb,secID,"eemcADCconf",mask,mDbADCconf+is);
00280
00281 getTable<St_eemcDbPMTcal,eemcDbPMTcal_st>(eedb,secID,"eemcPMTcal",mask,mDbPMTcal+is);
00282
00283 getTable<St_eemcDbPMTname,eemcDbPMTname_st>(eedb,secID,"eemcPMTname",mask,mDbPMTname+is);
00284
00285 getTable<St_eemcDbPIXcal,eemcDbPIXcal_st>(eedb,secID,"eemcPIXcal",mask,mDbPIXcal+is);
00286
00287 getTable<St_eemcDbPMTped,eemcDbPMTped_st>(eedb,secID,"eemcPMTped",mask,mDbPMTped+is);
00288
00289 getTable<St_eemcDbPMTstat,eemcDbPMTstat_st>(eedb,secID,"eemcPMTstat",mask,mDbPMTstat+is);
00290
00291 }
00292
00293
00294
00295 getTable<St_kretDbBlobS,kretDbBlobS_st>(eedb,13,"eemcCrateConf",mask,&mDbFiberConfBlob);
00296 if(mDbFiberConfBlob) {
00297 LOG_DEBUG<< "::RequestDataBase() eemcCrateConf dump "<<endm;
00298 }
00299
00300 }
00301
00302 }
00303
00304
00305
00306 int StEEmcDb::optimizeMapping(int is){
00307
00308 LOG_INFO <<" conf ADC map for sector="<< mDbsectorID[is] <<endm;
00309 assert(mDbsectorID[is]>0);
00310
00311 eemcDbADCconf_st *t= mDbADCconf[is];
00312
00313 if(t==0) return -2;
00314 LOG_INFO <<"mapping="<< t->comment <<endm;
00315
00316 int j;
00317 for(j=0;j<EEMCDbMaxAdc; j++) {
00318 char *name=t->name+j*EEMCDbMaxName;
00319
00320 if(*name==EEMCDbStringDelim) continue;
00321
00322
00323
00324
00325 int key=EEname2Index(name);
00326 assert(key>=0 && key<EEindexMax);
00327 EEmcDbItem *x=&byIndex[key];
00328 if(!x->isEmpty()) {
00329
00330 LOG_INFO<<(*x)<<endm;
00331 assert(x->isEmpty());
00332 }
00333 x->crate=t->crate[j];
00334 x->chan=t->channel[j];
00335 x->setName(name);
00336 x->key=key;
00337 x->setDefaultTube(MinMapmtCrateID);
00338
00339
00340 assert(x->crate>=0 && x->crate<MaxAnyCrate);
00341 assert(x->chan>=0 && x->chan<MaxAnyCh);
00342 assert(byCrate[x->crate]);
00343 if(byCrate[x->crate][x->chan]) {
00344 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;
00345
00346
00347 LOG_FATAL<<(*byCrate[x->crate][x->chan])<<endm;
00348 LOG_FATAL<<(*x)<<endm;
00349 clearItemArray();
00350 return -1;
00351 }
00352 byCrate[x->crate][x->chan]=x;
00353 if(x->isSMD()) byStrip[x->sec-1][x->plane-'U'][x->strip-1]=x;
00354 }
00355
00356 return 0;
00357
00358 }
00359
00360
00361
00362
00363 void StEEmcDb::optimizeOthers(int is){
00364
00365 int secID= mDbsectorID[is];
00366
00367 int ix1,ix2;
00368 EEindexRange(secID,ix1,ix2);
00369
00370 LOG_DEBUG<<" EEindexRange("<<secID<<","<<ix1<<","<<ix2<<")"<<endm;
00371
00372
00373
00374 assert(secID>0);
00375
00376 eemcDbPMTcal_st *calT=mDbPMTcal[is];
00377 if(calT) LOG_INFO <<"tower calib="<<calT->comment<<endm;
00378 eemcDbPMTname_st *tubeTw=mDbPMTname[is];
00379 if(tubeTw) LOG_INFO <<"PMT names="<<tubeTw->comment<<endm;
00380
00381 eemcDbPIXcal_st *calM= mDbPIXcal[is];
00382 if(calM) LOG_INFO <<"MAPMT calib="<<calM->comment<<endm;
00383
00384 eemcDbPMTped_st *ped=mDbPMTped[is];
00385 if(ped) LOG_INFO <<"ped tower & MAPMT="<<ped->comment<<endm;
00386
00387 eemcDbPMTstat_st *stat=mDbPMTstat[is];
00388 if(stat) LOG_INFO <<"status tower & MAPMT="<<stat->comment<<endm;
00389
00390 int key;
00391 for(key=ix1;key<ix2; key++) {
00392 EEmcDbItem *x=byIndex+key;
00393 if(x->isEmpty()) continue;
00394 char *name=x->name;
00395
00396 if(ped) {
00397 int j;
00398 int mx=sizeof(ped->name)/EEMCDbMaxName;
00399 for(j=0;j<mx; j++) {
00400 char *name1=ped->name+j*EEMCDbMaxName;
00401 if(strncmp(name,name1,strlen(name))) continue;
00402 x->ped=ped->ped[j];
00403 x->sigPed=ped->sig[j];
00404 x->thr=ped->ped[j]+KsigOverPed*ped->sig[j];
00405
00406
00407 break;
00408 }
00409 }
00410
00411
00412 if(calT&& name[2]=='T') {
00413 int j;
00414 int mx=sizeof(calT->name)/EEMCDbMaxName;
00415 for(j=0;j<mx; j++) {
00416 char *name1=calT->name+j*EEMCDbMaxName;
00417 if(strncmp(name,name1,strlen(name))) continue;
00418 x->gain=calT->gain[j];
00419 break;
00420 }
00421 }
00422
00423
00424 if(calM && name[2]!='T') {
00425 int j;
00426 int mx=sizeof(calM->name)/EEMCDbMaxName;
00427
00428 for(j=0;j<mx; j++) {
00429 char *name1=calM->name+j*EEMCDbMaxName;
00430 if(strncmp(name,name1,strlen(name))) continue;
00431 x->gain=calM->gain[j];
00432 break;
00433 }
00434 }
00435
00436 if(tubeTw && name[2]=='T') {
00437 int j;
00438 int mx=sizeof(tubeTw->name)/EEMCDbMaxName;
00439 for(j=0;j<mx; j++) {
00440 char *name1=tubeTw->name+j*EEMCDbMaxName;
00441 if(strncmp(name,name1,strlen(name))) continue;
00442 x->setTube(tubeTw->tubeName+j*EEMCDbMaxName);
00443
00444 break;
00445 }
00446 }
00447
00448
00449 if(stat) {
00450 int j;
00451 int mx=sizeof(stat->name)/EEMCDbMaxName;
00452 for(j=0;j<mx; j++) {
00453 char *name1=stat->name+j*EEMCDbMaxName;
00454 if(strncmp(name,name1,strlen(name))) continue;
00455 x->stat=stat->stat[j];
00456 x->fail=stat->fail[j];
00457
00458 break;
00459 }
00460 }
00461
00462
00463
00464 }
00465
00466
00467 }
00468
00469
00470
00471 void StEEmcDb::exportAscii(const char *fname) const{
00472 LOG_INFO << "::exportAscii(\'" << fname << "') ..." << endm;
00473
00474 FILE * fd=fopen(fname,"w");
00475 assert(fd);
00476
00477
00478 int nTot=0;
00479
00480 fprintf(fd,"# EEmcDb::exportAscii(), see StRoot/StEEmcDb/EEmcDbItem::exportAscii() for definition\n");
00481
00482 int j;
00483
00484 fprintf(fd,"%d #fibers: {name,crID,crIDswitch,fiber,nCh,nHead,type,useIt}\n",nFiber);
00485 for(j=0;j<nFiber;j++)
00486 mDbFiber[j].exportAscii(fd);
00487
00488 fprintf(fd,"#tw/pre/post: {name,crate,chan,sec,plane,strip,gain,ped,thr,stat,fail,tube,key}\n");
00489 fprintf(fd,"#or \n");
00490 fprintf(fd,"#smd: {name,crate,chan,sec,sub,eta,gain,ped,thr,stat,fail,tube,key}\n");
00491
00492
00493 for(j=0;j<EEindexMax; j++) {
00494 const EEmcDbItem *x=byIndex+j;
00495 if(x->isEmpty())continue;
00496 x->exportAscii(fd);
00497 nTot++;
00498 }
00499 LOG_INFO << "::exportAscii() nTot=" << nTot << ", done" << endm;
00500 fclose(fd);
00501 }
00502
00503
00504
00505
00506
00507
00508
00509 void StEEmcDb::optimizeFibers (){
00510 int icr=0;
00511
00512 if( mDbFiberConfBlob==0) {
00513 LOG_FATAL <<" EEMC FiberConf not found"<<endm;
00514 goto fatal;
00515 }
00516
00517 assert(mDbFiberConfBlob);
00518 assert(nFiber==0);
00519
00520
00521
00523
00529
00530 {
00531 static char blobBuffer[KRETmxBlobSlen+1];
00532 char *blob = blobBuffer;
00533
00534
00535 int len = strlen(mDbFiberConfBlob->dataS);
00536 assert(len<KRETmxBlobSlen );
00537 strncpy(blob,mDbFiberConfBlob->dataS,len);
00538
00539 blob=strtok(blob,";");
00540 if(strstr(blob,"<ver1>")==0) {
00541 LOG_FATAL <<" EEMC FiberConf missing opening key "<<endm;
00542 goto fatal;
00543 }
00544
00545 int i=0;
00546 while((blob=strtok(0,";"))) {
00547 i++;
00548 if(strstr(blob,"<#>")) continue;
00549 if(strstr(blob,"</ver1>")) goto done;
00550
00551
00552 if(nFiber==0) {
00553 nFiber=atoi(blob);
00554 mDbFiber=new EEmcDbCrate[ nFiber];
00555 LOG_DEBUG<<" mOptimizeFibers() map start: , nFiber="<<nFiber<<endm;
00556 icr=0;
00557 continue;
00558 }
00559 assert(icr<nFiber);
00560 mDbFiber[icr].setAll(blob);
00561
00562 icr++;
00563 };
00564
00565 }
00566
00567 LOG_FATAL <<" mOptimizeFibers() map missing/wrong terminating key "<<endm;
00568
00569 fatal:
00570 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;
00571 return;
00572
00573 done:
00574 LOG_INFO <<" mOptimizeFibers() map found for nFiber="<<nFiber<<endm;
00575 if(icr==nFiber) return;
00576
00577 LOG_FATAL <<" mOptimizeFibers() map nFiber missmatch is="<<icr<<" should be="<<nFiber<<endm;
00578 goto fatal;
00579 }
00580
00581
00582
00583 const EEmcDbItem*
00584 StEEmcDb::getByIndex(int i) const {
00585
00586
00587 assert(i>=0);
00588 assert(i<EEindexMax);
00589 const EEmcDbItem *x=byIndex+i;
00590 if(x->isEmpty()) return 0;
00591 return x;
00592 }
00593
00594
00595
00596
00597 const EEmcDbItem* StEEmcDb::getByCrate(int crateID, int channel) const {
00598
00599 int type=0;
00600 int max=0;
00601
00602 if(crateID>=MinTwCrateID && crateID<=MaxTwCrateID) {
00603
00604 type =1;
00605 max=MaxTwCrateCh;
00606 if(channel>=max) return 0;
00607
00608 } else if (crateID>=MinMapmtCrateID && crateID<=MaxMapmtCrateID ){
00609
00610 type =2;
00611 max=MaxMapmtCrateCh;
00612 } else if (crateID>=17 && crateID<=46 ){
00613 return 0;
00614 }
00615
00616
00617
00618
00619 assert(type);
00620 assert( byCrate[crateID]);
00621 assert(channel>=0);
00622 assert(channel<max);
00623 return byCrate[crateID][channel];
00624 }
00625
00626
00627
00628
00629
00630
00631
00632 template <class St_T, class T_st> void StEEmcDb
00633 ::getTable(TDataSet *eedb, int secID, TString tabName, TString mask, T_st** outTab ) {
00634
00635
00636
00637
00638
00639 if(!mask.IsNull() && !tabName.Contains(mask)) return ;
00640 char name[1000];
00641 if(secID<13)
00642 sprintf(name,"sector%2.2d/%s",secID,tabName.Data());
00643 else
00644 sprintf(name,"misc/%s",tabName.Data());
00645
00646
00647 LOG_DEBUG<<" request="<< name <<endm;
00648
00649 St_T *ds= (St_T *)eedb->Find(name);
00650 if(ds==0) {
00651 LOG_WARN <<" sector="<<secID<<" table='"<< name <<" not Found in DB, continue "<<endm;
00652 return ;
00653 }
00654
00655 if(ds->GetNRows()!=1) {
00656 LOG_WARN <<" sector="<<secID<<" table='"<< name <<" no records, continue "<<endm;
00657 return ;
00658 }
00659
00660 T_st *tab=(T_st *) ds->GetArray();
00661
00662 if(tab==0) {
00663 LOG_WARN <<" GetArray() failed"<<endm;
00664 return ;
00665 }
00666
00667 *outTab=tab;
00668 LOG_DEBUG<<" map="<< (*outTab)->comment<<"'"<<endm;
00669
00670 nFound++;
00671 return ;
00672 }
00673
00674
00675
00676
00677
00678 const EEmcDbItem*
00679 StEEmcDb::getByStrip0(int isec, int iuv, int istrip) const {
00680
00681 assert(isec>=0 && isec<MaxSectors);
00682 assert(iuv>=0 && iuv<MaxSmdPlains);
00683 assert(istrip>=0 && istrip<MaxSmdStrips);
00684 return byStrip[isec][iuv][istrip];
00685 }
00686
00687
00688
00689
00690
00691
00692
00693 const EEmcDbItem*
00694 StEEmcDb::getTile(int sec, char sub, int eta, char type) const {
00695 char name[20];
00696 sprintf(name,"%2.2d%c%c%2.2d",sec,type,sub,eta);
00697 int key=EEname2Index(name);
00698 return byIndex+key;
00699 }
00700
00701
00702
00703
00704
00705 const EEmcDbItem*
00706 StEEmcDb::getStrip(int sec, char uv, int strip) const {
00707 char name[20];
00708 sprintf(name,"%2.2d%c%3.3d",sec,uv,strip);
00709 int key=EEname2Index(name);
00710 return byIndex+key;
00711 }
00712
00713
00714
00715
00716
00717
00718
00719 void StEEmcDb::setAsciiDatabase( const Char_t *ascii )
00720 {
00721
00722
00723
00724
00725
00726
00727 mAsciiDbase = ascii;
00728
00729
00730
00731
00732
00733 Int_t sec1 = 1;
00734 Int_t sec2 = 12;
00735 nFound = 0;
00736 mfirstSecID = sec1;
00737 mlastSecID = sec2;
00738 mNSector = mlastSecID - mfirstSecID + 1;
00739
00740
00741 FILE *fd=fopen(ascii,"r");
00742 EEmcDbItem item;
00743 int nd=0;
00744 if(fd==0) goto crashIt;
00745
00746
00747
00748
00749 while (1) {
00750
00751
00752
00753 int ret = item.importAscii(fd);
00754
00755 if(ret==0) break;
00756 if(ret==1) continue;
00757 if(ret <0) goto crashIt;
00758
00759
00760 int key=EEname2Index(item.name);
00761
00762
00763 if(key!=item.key) {
00764 LOG_WARN<<Form(": name='%s' key=%d!=inpKey=%d, inpKey ignored",item.name,key,item.key)<<endm;
00765 item.key=key;
00766 }
00767 assert(key>=0 && key<EEindexMax);
00768
00769
00770 int isec=item.sec-sec1;
00771 if (sec1>sec2 ) isec+=12;
00772
00773 if( isec <0 ) continue;
00774 if( isec >= mNSector) continue;
00775 nd++;
00776
00777
00778
00779 EEmcDbItem *x=&byIndex[key];
00780 if(!x->isEmpty()) goto crashIt;
00781 *x=item;
00782
00783
00784 assert(byCrate[x->crate]);
00785 if(byCrate[x->crate][x->chan]) {
00786 LOG_FATAL<<Form("Fatal Error of eemc DB records: the same crate=%d / channel=%d entered twice for :",x->crate,x->chan)<<endm;
00787
00788
00789 LOG_FATAL<<(*byCrate[x->crate][x->chan])<<endm;
00790 LOG_FATAL<<(*x)<<endm;
00791 assert(1==2);
00792 }
00793 byCrate[x->crate][x->chan]=x;
00794
00795 }
00796
00797
00798
00799
00800 for ( Int_t mySec = 1; mySec <= 12; mySec++ )
00801 for ( Char_t uv = 'U'; uv <= 'V'; uv++ )
00802 for ( Int_t myStrip = 1; myStrip <= 288; myStrip++ ) byStrip[mySec-1][uv-'U'][myStrip-1] = (EEmcDbItem*)getStrip(mySec,uv,myStrip);
00803
00804
00805
00806 LOG_INFO<<Form("setAsciiDataBase() done, found %d valid records",nd)<<endm;
00807
00808 return;
00809
00810 crashIt:
00811 LOG_FATAL<<Form("EEmcDb - no/corrupted input file, continue")<<endm;
00812
00813
00814
00815
00816 }
00817
00818
00819
00820 void StEEmcDb::changeGains(char *fname) {
00821 assert(nChGain+1< mxChGain);
00822 chGainL[nChGain]=fname;
00823 nChGain++;
00824 }
00825
00826
00827
00828 void
00829 StEEmcDb::changeMask(char *fname) {
00830 assert(nChMask+1< mxChMask);
00831 chMaskL[nChMask]=fname;
00832 nChMask++;
00833 }
00834
00835
00836
00837
00838 void StEEmcDb::changeGainsAction(const char *fname) {
00839
00840
00841
00842
00843
00844
00845
00846 LOG_WARN <<" ::changeGains('"<<fname<<"')"<<endm;
00847 FILE *fd=fopen(fname,"r");
00848 int nd=0,nl=0;
00849 const int mx=1000;
00850 char buf[mx];
00851
00852 if(fd==0) goto end;
00853 char cVal[100];
00854 float xVal;
00855
00856 while(1) {
00857 char *ret=fgets(buf,mx,fd);
00858 if(ret==0) break;
00859
00860 nl++;
00861 if(buf[0]=='#') continue;
00862 int n=sscanf(buf,"%s %f",cVal,&xVal);
00863 assert(n==2);
00864 int key=EEname2Index(cVal);
00865 EEmcDbItem *x=byIndex+key;
00866
00867 if(x->isEmpty()) continue;
00868
00869 if(xVal<=0) LOG_WARN<<Form("Warning ! buf=%s=",buf)<<endm;
00870
00871 x->gain=xVal;
00872 nd++;
00873 }
00874 fclose(fd);
00875
00876 end:
00877 LOG_INFO <<" ::changeGains('"<<fname<<"') done inpLines="<<nl<<" nChanged="<<nd<<endm;
00878 return;
00879
00880 }
00881
00882
00883
00884 void StEEmcDb::changeMaskAction(const char *fname) {
00885
00886
00887
00888
00889
00890
00891
00892 LOG_INFO <<" ::changeMask('"<<fname<<"') "<<endm;
00893
00894 FILE *fd=fopen(fname,"r");
00895
00896 int nd=0,nl=0;
00897 const int mx=1000;
00898 char buf[mx];
00899
00900 if(fd==0) goto end;
00901 char cVal[100];
00902 int xStat,xFail ;
00903
00904 while(1) {
00905 char *ret=fgets(buf,mx,fd);
00906 if(ret==0) break;
00907
00908 nl++;
00909 if(buf[0]=='#') continue;
00910 int n=sscanf(buf,"%s %d %d",cVal,&xStat,&xFail);
00911 assert(n==3);
00912 int key=EEname2Index(cVal);
00913 EEmcDbItem *x=byIndex+key;
00914 if(x->isEmpty()) continue;
00915 assert(xStat>=0);
00916 assert(xFail>=0);
00917 x->stat=xStat;
00918 x->fail=xFail;
00919 nd++;
00920 }
00921 fclose(fd);
00922
00923 end:
00924 LOG_INFO <<" ::changeMask('"<<fname<<"') done inpLines="<<nl<<" nChanged="<<nd<<endm;
00925 return;
00926
00927 }
00928
00929
00930
00937 const EEmcDbItem *
00938 StEEmcDb::StBarrelIndex2Item(int StDetId , int Bmod, int Beta, int Bsub) const {
00939
00940 const EEmcDbItem *x=0;
00941 int sec=Bmod;
00942
00943
00944 char sub='X';
00945 char cT='Y';
00946 int eta=Beta;
00947
00948 char uv='U';
00949 int strip=Beta;
00950
00951 switch(StDetId) {
00952
00953 case kEndcapEmcTowerId:
00954 sub='A'+Bsub-1; cT='T';
00955 x=getTile(sec,sub,eta,cT); break;
00956
00957 case kEndcapEmcPreShowerId:
00958 sub='A'+(Bsub-1)%5; cT='P'+(Bsub-1)/5;
00959 x=getTile(sec,sub,eta,cT); break;
00960
00961 case kEndcapSmdVStripId:
00962 uv++;
00963 case kEndcapSmdUStripId:
00964 x=getByStrip(sec,uv,strip); break;
00965
00966 default:
00967 LOG_WARN <<"::getDb(), wrong detectorId=" << StDetId << ". This is fatal - bug in the code, fix it, JB"<<endm;
00968 assert(1==2);
00969 }
00970
00971 return x;
00972 }