9 #include "StBemcTables.h"
11 #include "StEmcUtil/others/emcDetectorName.h"
12 #include "StDaqLib/EMC/StEmcDecoder.h"
14 #include "St_db_Maker/St_db_Maker.h"
15 #include "StEmcRawMaker/defines.h"
41 mBtowMapFix = btowMapFix;
42 mBprsMapFix = bprsMapFix;
68 if(mDecoder)
delete mDecoder;
74 if(mBtowP) mBtowP = NULL;
75 if(mBtowS) mBtowS = NULL;
76 if(mBtowC) mBtowC = NULL;
77 if(mBtowG) mBtowG = NULL;
79 if(mBprsP) mBprsP = NULL;
80 if(mBprsS) mBprsS = NULL;
81 if(mBprsC) mBprsC = NULL;
82 if(mBprsG) mBprsG = NULL;
84 if(mSmdeP) mSmdeP = NULL;
85 if(mSmdeS) mSmdeS = NULL;
86 if(mSmdeC) mSmdeC = NULL;
87 if(mSmdeG) mSmdeG = NULL;
89 if(mSmdpP) mSmdpP = NULL;
90 if(mSmdpS) mSmdpS = NULL;
91 if(mSmdpC) mSmdpC = NULL;
92 if(mSmdpG) mSmdpG = NULL;
94 int date = (maker->GetDBTime()).GetDate();
95 int time = (maker->GetDBTime()).GetTime();
96 mDecoder->SetDateTime(date, time);
100 if(date >= 20060101) mBtowMapFix = kFALSE;
103 if(date >= 20080101) mBprsMapFix = kFALSE;
107 DB = maker->GetInputDB(
"Calibrations/emc/y3bemc");
109 St_emcPed* bemcPed = (St_emcPed*)DB->
Find(
"bemcPed");
111 mBtowP = bemcPed->GetTable();
112 updateValidity(maker, bemcPed);
115 St_emcStatus* bemcStatus = (St_emcStatus*)DB->
Find(
"bemcStatus");
117 mBtowS = bemcStatus->GetTable();
118 updateValidity(maker, bemcStatus);
121 St_emcCalib* bemcCalib = (St_emcCalib*)DB->
Find(
"bemcCalib");
123 mBtowC = bemcCalib->GetTable();
124 updateValidity(maker, bemcCalib);
127 St_emcGain* bemcGain = (St_emcGain*)DB->
Find(
"bemcGain");
129 mBtowG = bemcGain->GetTable();
130 updateValidity(maker, bemcGain);
134 DB = maker->GetInputDB(
"Calibrations/emc/y3bprs");
136 St_emcPed* bprsPed = (St_emcPed*)DB->
Find(
"bprsPed");
138 mBprsP = bprsPed->GetTable();
139 updateValidity(maker, bprsPed);
142 St_emcStatus* bprsStatus = (St_emcStatus*)DB->
Find(
"bprsStatus");
144 mBprsS = bprsStatus->GetTable();
145 updateValidity(maker, bprsStatus);
148 St_emcCalib* bprsCalib = (St_emcCalib*)DB->
Find(
"bprsCalib");
150 mBprsC = bprsCalib->GetTable();
151 updateValidity(maker, bprsCalib);
154 St_emcGain* bprsGain = (St_emcGain*)DB->
Find(
"bprsGain");
156 mBprsG = bprsGain->GetTable();
157 updateValidity(maker, bprsGain);
161 DB = maker->GetInputDB(
"Calibrations/emc/y3bsmde");
163 St_smdPed* bsmdePed = (St_smdPed*)DB->
Find(
"bsmdePed");
165 mSmdeP = bsmdePed->GetTable();
166 updateValidity(maker, bsmdePed);
169 St_smdStatus* bsmdeStatus = (St_smdStatus*)DB->
Find(
"bsmdeStatus");
171 mSmdeS = bsmdeStatus->GetTable();
172 updateValidity(maker, bsmdeStatus);
175 St_smdCalib* bsmdeCalib = (St_smdCalib*)DB->
Find(
"bsmdeCalib");
177 mSmdeC = bsmdeCalib->GetTable();
178 updateValidity(maker, bsmdeCalib);
181 St_smdGain* bsmdeGain = (St_smdGain*)DB->
Find(
"bsmdeGain");
183 mSmdeG = bsmdeGain->GetTable();
184 updateValidity(maker, bsmdeGain);
188 DB = maker->GetInputDB(
"Calibrations/emc/y3bsmdp");
190 St_smdPed* bsmdpPed = (St_smdPed*)DB->
Find(
"bsmdpPed");
192 mSmdpP = bsmdpPed->GetTable();
193 updateValidity(maker, bsmdpPed);
196 St_smdStatus* bsmdpStatus = (St_smdStatus*)DB->
Find(
"bsmdpStatus");
198 mSmdpS = bsmdpStatus->GetTable();
199 updateValidity(maker, bsmdpStatus);
202 St_smdCalib* bsmdpCalib = (St_smdCalib*)DB->
Find(
"bsmdpCalib");
204 mSmdpC = bsmdpCalib->GetTable();
205 updateValidity(maker, bsmdpCalib);
208 St_smdGain* bsmdpGain = (St_smdGain*)DB->
Find(
"bsmdpGain");
210 mSmdpG = bsmdpGain->GetTable();
211 updateValidity(maker, bsmdpGain);
215 DB = maker->GetInputDB(
"Calibrations/emc/trigger");
217 St_emcTriggerStatus* bemcTriggerStatus = (St_emcTriggerStatus*)DB->
Find(
"bemcTriggerStatus");
218 if(bemcTriggerStatus) {
219 mTrigS = bemcTriggerStatus->GetTable();
220 updateValidity(maker, bemcTriggerStatus);
223 St_emcTriggerPed* bemcTriggerPed = (St_emcTriggerPed*)DB->
Find(
"bemcTriggerPed");
225 mTrigP = bemcTriggerPed->GetTable();
226 updateValidity(maker, bemcTriggerPed);
229 St_bemcTriggerPed4* bemcTriggerPed4 = (St_bemcTriggerPed4*)DB->
Find(
"bemcTriggerPed4");
230 if(bemcTriggerPed4) {
231 mTrigP4 = bemcTriggerPed4->GetTable();
232 updateValidity(maker, bemcTriggerPed4);
235 St_emcTriggerLUT* bemcTriggerLUT = (St_emcTriggerLUT*)DB->
Find(
"bemcTriggerLUT");
237 mTrigL = bemcTriggerLUT->GetTable();
238 updateValidity(maker, bemcTriggerLUT);
243 void StBemcTables::updateValidity(
StMaker* maker,
TTable* table) {
245 St_db_Maker::GetValidity(table,datime);
246 string tableName = table->GetName();
247 string beginTime = datime[0].AsSQLString();
248 string endTime = datime[1].AsSQLString();
250 map<string, pair<string, string> >::iterator iter = mValidRanges.find(tableName);
251 if(iter == mValidRanges.end()) {
252 mValidRanges[tableName] = make_pair(beginTime, endTime);
253 LOG_INFO << Form(
"loaded a new %20s table with beginTime %s and endTime %s", tableName.c_str(), beginTime.c_str(), endTime.c_str()) << endm;
255 else if( beginTime != (iter->second).first ) {
256 (iter->second).first = beginTime;
257 (iter->second).second = endTime;
258 LOG_INFO << Form(
"loaded a new %20s table with beginTime %s and endTime %s", tableName.c_str(), beginTime.c_str(), endTime.c_str()) << endm;
262 const char* StBemcTables::beginTime(
const char * tableName)
const {
263 string t = tableName;
264 map<string, pair<string, string> >::const_iterator iter = mValidRanges.find(t);
265 if(iter == mValidRanges.end()) {
266 LOG_WARN <<
"Couldn't find a table named " << tableName << endm;
270 return (iter->second).first.c_str();
274 const char* StBemcTables::endTime(
const char * tableName)
const {
275 string t = tableName;
276 map<string, pair<string, string> >::const_iterator iter = mValidRanges.find(t);
277 if(iter == mValidRanges.end()) {
278 LOG_WARN <<
"Couldn't find a table named " << tableName << endm;
282 return (iter->second).second.c_str();
288 Int_t StBemcTables::getOldId(
int det, Int_t newId)
const {
296 return newId + shift;
304 if(det==BTOW && mBtowP)
307 if(mBtowMapFix) id1 = getOldId(BTOW,
id);
308 P = ((Float_t)mBtowP[0].AdcPedestal[id1-1])/100;
309 R = ((Float_t)mBtowP[0].AdcPedestalRMS[id1-1])/100;
312 if(det==BPRS && mBprsP)
315 if(mBprsMapFix) id1 = getOldId(BPRS,
id);
316 P = ((Float_t)mBprsP[0].AdcPedestal[id1-1])/100;
317 R = ((Float_t)mBprsP[0].AdcPedestalRMS[id1-1])/100;
320 if(det==BSMDE && mSmdeP)
325 P = ((Float_t)mSmdeP[0].AdcPedestal[
id-1][C])/100;
326 R = ((Float_t)mSmdeP[0].AdcPedestalRMS[
id-1][C])/100;
329 if(det==BSMDP && mSmdpP)
334 P = ((Float_t)mSmdpP[0].AdcPedestal[
id-1][C])/100;
335 R = ((Float_t)mSmdpP[0].AdcPedestalRMS[
id-1][C])/100;
343 if(det==BTOW && mBtowS)
346 if(mBtowMapFix) id1 = getOldId(BTOW,
id);
347 if(!strcmp(option,
"calib")) { S = (Int_t)mBtowC[0].Status[id1-1];
return; }
348 if(!strcmp(option,
"pedestal")) { S = (Int_t)mBtowP[0].Status[id1-1];
return; }
349 if(!strcmp(option,
"gain")) { S = (Int_t)mBtowG[0].Status[id1-1];
return; }
350 S = (Int_t)mBtowS[0].Status[id1-1];
353 if(det==BPRS && mBprsS) {
355 if(mBprsMapFix) id1 = getOldId(BPRS,
id);
356 if(!strcmp(option,
"calib")) { S = (Int_t)mBprsC[0].Status[id1-1];
return; }
357 if(!strcmp(option,
"pedestal")) { S = (Int_t)mBprsP[0].Status[id1-1];
return; }
358 if(!strcmp(option,
"gain")) { S = (Int_t)mBprsG[0].Status[id1-1];
return; }
359 S = (Int_t)mBprsS[0].Status[id1-1];
return;
361 if(det==BSMDE && mSmdeS) {
362 if(!strcmp(option,
"calib")) { S = (Int_t)mSmdeC[0].Status[
id-1];
return; }
363 if(!strcmp(option,
"pedestal")) { S = (Int_t)mSmdeP[0].Status[
id-1];
return; }
364 if(!strcmp(option,
"gain")) { S = (Int_t)mSmdeG[0].Status[
id-1];
return; }
365 S = (Int_t)mSmdeS[0].Status[
id-1];
return;
367 if(det==BSMDP && mSmdpS) {
368 if(!strcmp(option,
"calib")) { S = (Int_t)mSmdpC[0].Status[
id-1];
return; }
369 if(!strcmp(option,
"pedestal")) { S = (Int_t)mSmdpP[0].Status[
id-1];
return; }
370 if(!strcmp(option,
"gain")) { S = (Int_t)mSmdpG[0].Status[
id-1];
return; }
371 S = (Int_t)mSmdpS[0].Status[
id-1];
return;
378 if(det==BTOW && mBtowG)
381 if(mBtowMapFix) id1 = getOldId(BTOW,
id);
382 G = (Float_t)mBtowG[0].
Gain[id1-1];
385 if(det==BPRS && mBprsG) {
387 if(mBprsMapFix) id1 = getOldId(BPRS,
id);
388 G = (Float_t)mBprsG[0].
Gain[id1-1];
return;
390 if(det==BSMDE && mSmdeG) { G = (Float_t)mSmdeG[0].
Gain[
id-1];
return;}
391 if(det==BSMDP && mSmdpG) { G = (Float_t)mSmdpG[0].
Gain[
id-1];
return;}
397 if(det==BTOW && mBtowC)
400 if(mBtowMapFix) id1 = getOldId(BTOW,
id);
401 C = (Float_t)mBtowC[0].AdcToE[id1-1][power];
404 if(det==BPRS && mBprsC) {
406 if(mBprsMapFix) id1 = getOldId(BPRS,
id);
407 C = (Float_t)mBprsC[0].AdcToE[id1-1][power];
return;
409 if(det==BSMDE && mSmdeC) { C = (Float_t)mSmdeC[0].AdcToE[
id-1][power];
return;}
410 if(det==BSMDP && mSmdpC) { C = (Float_t)mSmdpC[0].AdcToE[
id-1][power];
return;}
418 if(mTrigS && patch>=0 && patch<NBEMCTRIGGERTOWER)
419 STATUS = (Int_t)mTrigS[0].PatchStatus[patch];
424 if(mTrigS && hightower>=0 && hightower<NBEMCTRIGGERTOWER)
425 STATUS = (Int_t)mTrigS[0].HighTowerStatus[hightower];
430 if(mTrigS && crate>0 && crate<=MAXCRATES && index>=0 && index<NTOWERSPERCRATE)
431 STATUS = (Int_t)mTrigS[0].TowerStatus[crate-1][index];
436 if(mTrigP && crate>0 && crate<=MAXCRATES && index>=0 && index<NTOWERSPERCRATE)
437 PEDESTAL = ((Float_t)mTrigP[0].Ped[crate-1][index])/100.0;
442 if(mTrigP && crate>0 && crate<=MAXCRATES && patch>=0 && patch<NPATCHESPERCRATE) {
443 BIT = (Int_t)mTrigP[0].BitConversionMode[crate-1][patch];
448 if (mTrigP) pedestalShift = (Int_t)mTrigP->PedShift / 100;
451 void StBemcTables::getTriggerPed4(Int_t softId, Short_t& PED4)
const {
453 if (mTrigP4 && softId>0 && softId<=4800)
454 PED4 = (Short_t)mTrigP4->Ped4[softId];
458 if (mTrigL) formula = (Int_t)mTrigL->FormulaTag[crate-1][index];
463 parameters[0] = (Int_t)mTrigL->FormulaParameter0[crate-1][index];
464 parameters[1] = (Int_t)mTrigL->FormulaParameter1[crate-1][index];
465 parameters[2] = (Int_t)mTrigL->FormulaParameter2[crate-1][index];
466 parameters[3] = (Int_t)mTrigL->FormulaParameter3[crate-1][index];
467 parameters[4] = (Int_t)mTrigL->FormulaParameter4[crate-1][index];
468 parameters[5] = (Int_t)mTrigL->FormulaParameter5[crate-1][index];
474 float StBemcTables::calib(
int det,
int softId,
int power)
const {
480 float StBemcTables::pedestal(
int det,
int softId,
int cap)
const {
486 float StBemcTables::pedestalRMS(
int det,
int softId,
int cap)
const {
492 float StBemcTables::gain(
int det,
int softId)
const {
506 int StBemcTables::triggerPatchStatus(
int triggerPatchId)
const {
512 int StBemcTables::triggerHighTowerStatus(
int triggerPatchId)
const {
518 int StBemcTables::triggerTowerStatus(
int crate,
int sequence)
const {
524 float StBemcTables::triggerPedestal(
int crate,
int sequence)
const {
530 int StBemcTables::triggerBitConversion(
int crate,
int patchSequence)
const {
536 int StBemcTables::triggerPedestalShift()
const {
542 short StBemcTables::triggerPed4(
int softId)
const {
544 getTriggerPed4(softId,val);
548 int StBemcTables::triggerFormulaTag(
int crate,
int patchSequence)
const {
554 int* StBemcTables::triggerFormulaParameters(
int crate,
int patchSequence)
const {
555 int *
params =
new int[6];
562 int StBemcTables::triggerPatchStatusByID(
int softId)
const {
565 return this->triggerPatchStatus(patchId);
567 LOG_ERROR <<
"Problem with StEmcDecoder::GetTriggerPatchFromTowerId for softId " << softId << endm;
571 int StBemcTables::triggerHighTowerStatusByID(
int softId)
const {
574 return this->triggerHighTowerStatus(patchId);
576 LOG_ERROR <<
"Problem with StEmcDecoder::GetTriggerPatchFromTowerId for softId " << softId << endm;
580 int StBemcTables::triggerTowerStatusByID(
int softId)
const {
583 return this->triggerTowerStatus(crate, sequence);
585 LOG_ERROR <<
"Problem with StEmcDecoder::GetCrateFromTowerId for softId " << softId << endm;
589 float StBemcTables::triggerPedestalByID(
int softId)
const {
592 return this->triggerPedestal(crate, sequence);
594 LOG_ERROR <<
"Problem with StEmcDecoder::GetCrateFromTowerId for softId " << softId << endm;
598 int StBemcTables::triggerBitConversionByID(
int softId)
const {
599 int patchId, crate, patchSequence;
602 if( (patchSequence%16 != 0) || (patchId%10 != patchSequence/16) ) {
603 LOG_ERROR <<
"Please ask Adam what the heck is going on" << endm;
605 return this->triggerBitConversion(crate, patchSequence/16);
607 LOG_ERROR <<
"Problem with StEmcDecoder::GetCrateAndSequenceFromTriggerPatch for patchId " << patchId << endm;
609 LOG_ERROR <<
"Problem with StEmcDecoder::GetTriggerPatchFromTowerId for softId " << softId << endm;
613 int StBemcTables::triggerFormulaTagByID(
int softId)
const {
614 int patchId, crate, patchSequence;
617 if( (patchSequence%16 != 0) || (patchId%10 != patchSequence/16) ) {
618 LOG_ERROR <<
"Please ask Adam what the heck is going on" << endm;
620 return this->triggerFormulaTag(crate, patchSequence/16);
622 LOG_ERROR <<
"Problem with StEmcDecoder::GetCrateAndSequenceFromTriggerPatch for patchId " << patchId << endm;
624 LOG_ERROR <<
"Problem with StEmcDecoder::GetTriggerPatchFromTowerId for softId " << softId << endm;
628 int* StBemcTables::triggerFormulaParametersByID(
int softId)
const {
629 int patchId, crate, patchSequence;
632 if( (patchSequence%16 != 0) || (patchId%10 != patchSequence/16) ) {
633 LOG_ERROR <<
"Please ask Adam what the heck is going on" << endm;
635 return this->triggerFormulaParameters(crate, patchSequence/16);
637 LOG_ERROR <<
"Problem with StEmcDecoder::GetCrateAndSequenceFromTriggerPatch for patchId " << patchId << endm;
639 LOG_ERROR <<
"Problem with StEmcDecoder::GetTriggerPatchFromTowerId for softId " << softId << endm;
void getTriggerFormulaParameters(Int_t crate, Int_t index, Int_t *parameters) const
Return LUT formula parameters.
int status(int det, int softId, const char *option="") const
void getTriggerBitConv(Int_t crate, Int_t patch, Int_t &bit) const
Return 6 bits conversion mode.
void getGain(Int_t det, Int_t softId, Float_t &gain) const
Return gain correction factor.
void getTriggerTowerStatus(Int_t crate, Int_t index, Int_t &status) const
Return trigger single tower status.
virtual ~StBemcTables()
StBemcTables destructor.
void getPedestal(Int_t det, Int_t softId, Int_t cap, Float_t &ped, Float_t &rms) const
Return pedestal mean and rms.
void getTriggerPatchStatus(Int_t patch, Int_t &status) const
Return trigger patch status.
int GetPreshowerBugCorrectionShift(int id_original, int &shift) const
Returns the index shift for the preshower in original map.
void loadTables(StMaker *anyMaker)
load tables.
int GetCrateAndSequenceFromTriggerPatch(int patchId, int &crate, int &sequence) const
returns the crate number and start point for a given trigger patch
void getTriggerFormulaTag(Int_t crate, Int_t index, Int_t &formula) const
Return LUT formula.
int GetCrateFromTowerId(int softId, int &crate, int &sequence) const
Get crate number and position in crate for Software Id.
void getCalib(Int_t det, Int_t softId, Int_t power, Float_t &calib) const
Return calibration constant.
void getTriggerHighTowerStatus(Int_t hightower, Int_t &status) const
Return trigger highTower status.
void getTriggerPedestal(Int_t crate, Int_t index, Float_t &pedestal) const
Return tower pedestal loaded in trigger.
void getTriggerPedestalShift(Int_t &pedestalShift) const
Return target pedestal shift.
int GetTriggerPatchFromTowerId(int softId, int &patchId) const
Get trigger patch that contains software Id.
int GetTowerBugCorrectionShift(int id_original, int &shift) const
Returns the index shift for the tower in original map.
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.
virtual TDataSet * Find(const char *path) const