11 #include "EemcTrigUtil.h"
18 DsmThreshold _pp2006Long1a = {20060323,181204,20060406,210325,{6,12,18},{1,17,31},{32,49,69},2,2,71,21,0,3,109};
19 DsmThreshold _pp2006Trans1a = {20060406,210325,20060509, 10815,{6,12,22},{1,17,31},{32,49,69},2,2,71,21,0,3,109};
20 DsmThreshold _pp2006Trans1b = {20060509, 10815,20060509, 24937,{6,13,22},{1,21,31},{32,49,69},2,2,71,21,0,3,109};
21 DsmThreshold _pp2006Trans1c = {20060509, 24937,20060509, 30315,{6,12,22},{1,17,31},{36,49,69},2,2,71,21,0,3,109};
22 DsmThreshold _pp2006Trans1d = {20060509, 30315,20060510,204714,{6,13,22},{1,21,31},{32,49,69},2,2,71,21,0,3,109};
23 DsmThreshold _pp2006Long2a = {20060510,204714,20060512,192554,{6,12,22},{1,20,31},{38,49,69},2,2,71,21,0,3,109};
24 DsmThreshold _pp2006Long2b = {20060512,192554,20060513,215249,{6,17,22},{1,20,31},{39,50,69},2,2,71,21,0,3,109};
25 DsmThreshold _pp2006Long2c = {20060513,215249,20060607,234011,{6,16,22},{1,20,31},{39,52,69},2,2,71,21,0,3,109};
35 DsmThreshold _pp2009_500GeV = {20090217, 0,20090415, 0,{20,40,-1},{-1,-1,-1},{28,35,52},-1,2,71,21,0,3,109};
36 DsmThreshold _pp2009_200GeV = {20090415, 1,20090515, 0,{17,23,-1},{-1,-1,-1},{20,28,35},-1,2,71,21,0,3,109};
42 _pp2006Long1a, _pp2006Trans1a, _pp2006Trans1b, _pp2006Trans1c, _pp2006Trans1d, _pp2006Long2a, _pp2006Long2b, _pp2006Long2c,
43 _pp2009_500GeV, _pp2009_200GeV
52 EemcTrigUtil::getDsmThresholds(
int yyyymmdd,
int hhmmss,
DsmThreshold &thresholds) {
53 thresholds.date_start = 0;
54 thresholds.time_start = 0;
55 thresholds.date_finish = 0;
56 thresholds.time_finish = 0;
57 thresholds.HT[0] = -1;
58 thresholds.HT[1] = -1;
59 thresholds.HT[2] = -1;
60 thresholds.TP[0] = -1;
61 thresholds.TP[1] = -1;
62 thresholds.TP[2] = -1;
63 thresholds.JP[0] = -1;
64 thresholds.JP[1] = -1;
65 thresholds.JP[2] = -1;
66 thresholds.HTTPselect = 2;
68 double wallTime= yyyymmdd+ hhmmss/1e6;
70 for (UInt_t i = 0;(i <
sizeof(_thresholds) /
sizeof(_thresholds[0])) && !go;i++)
72 Double_t wallStart = _thresholds[i].date_start + _thresholds[i].time_start / 1.0E6;
73 Double_t wallEnd = _thresholds[i].date_finish + _thresholds[i].time_finish / 1.0E6;
74 if ( wallTime >= wallStart && wallTime < wallEnd ) {
76 thresholds = _thresholds[i];
77 LOG_INFO<<Form(
"Load DSM thresholds for %8i %06i: HT %02i %02i %02i TP %02i %02i %02i JP %02i %02i %02i",
79 thresholds.HT[0], thresholds.HT[1], thresholds.HT[2],
80 thresholds.TP[0], thresholds.TP[1], thresholds.TP[2],
81 thresholds.JP[0], thresholds.JP[1], thresholds.JP[2]
86 LOG_ERROR <<
"timestamp out of range of lookup table in EemcTrigUtil" << endm;
94 EemcTrigUtil::getFeePed4(
const char *path,
int yyyyyymmdd,
int hhmmss,
int mxChan,
int *feePed4){
95 if (yyyyyymmdd<20060307) {
96 LOG_ERROR <<
"not implemented before 2006" << endm;
98 if (yyyyyymmdd<=20060620) {
99 const char *dataSet =
"03.07.2006";
100 if (yyyyyymmdd>=20060406) dataSet =
"04.06.2006";
101 if (yyyyyymmdd>=20060428) dataSet =
"04.28.2006";
102 LOG_DEBUG << Form(
"getEndcap FeePed4 input set=%s\n",dataSet) << endm;
103 char dir[FILENAME_MAX];
104 sprintf(dir,
"%s/%s",path,dataSet);
105 readPed4(dir,mxChan,feePed4);
109 LOG_DEBUG << Form(
"set Endcap FeePed4 to val=%d\n",ped4val) << endm;
110 genPed4(ped4val,mxChan, feePed4);
117 static int filter(
const struct dirent* d)
119 int month, day, year;
120 return strlen(d->d_name) == 10 && sscanf(d->d_name,
"%d.%d.%d",&month,&day,&year) == 3;
123 static TDatime getDateTime(
const char* dirname)
125 int month, day, year;
126 sscanf(dirname,
"%d.%d.%d",&month,&day,&year);
127 return TDatime(year,month,day,0,0,0);
130 static void scanDirForDates(
const char* dir, vector<TDatime>& dates)
132 struct dirent** namelist;
133 int n = scandir(dir,&namelist,filter,0);
136 dates.push_back(getDateTime(namelist[n]->d_name));
140 sort(dates.begin(),dates.end());
143 static TDatime getTimeStampFromDates(
const TDatime& date,
const vector<TDatime>& dates)
145 for (vector<TDatime>::const_reverse_iterator i = dates.rbegin(); i != dates.rend(); ++i)
146 if (date > *i)
return *i;
147 return dates.front();
150 void EemcTrigUtil::getFeePed4(
const TDatime& date,
int mxChan,
int *feePed4)
152 char dir[FILENAME_MAX];
153 struct passwd* pw = getpwnam(
"pibero");
154 sprintf(dir,
"%s/public/StarTrigSimuSetup/ped",pw->pw_dir);
155 vector<TDatime> dates;
156 scanDirForDates(dir,dates);
158 for (
size_t i = 0; i < dates.size(); ++i) {
159 if (dates[i].GetDate() == 20090506) dates[i].Set(
"2009-05-06 10:00:00");
160 if (dates[i].GetDate() == 20090513) dates[i].Set(
"2009-05-13 17:00:00");
161 if (dates[i].GetDate() == 20090517) dates[i].Set(
"2009-05-17 23:30:00");
162 if (dates[i].GetDate() == 20090520) dates[i].Set(
"2009-05-20 07:00:00");
163 if (dates[i].GetDate() == 20090606) dates[i].Set(
"2009-06-06 18:00:00");
165 TDatime timeStamp = getTimeStampFromDates(date,dates);
166 TString timeStampString = Form(
"%02d.%02d.%4d",timeStamp.GetMonth(),timeStamp.GetDay(),timeStamp.GetYear());
167 char pathname[FILENAME_MAX];
168 sprintf(pathname,
"%s/%s",dir,timeStampString.Data());
169 LOG_INFO <<
"Using ped4 directory " << pathname << endm;
170 readPed4(pathname,mxChan,feePed4);
173 for (
int crate = 1; crate <= 6; ++crate) {
174 for (
int board = 1; board <= 4; ++board) {
175 sprintf(pathname,
"%s/%s_crate%dboard%d.ped4",dir,timeStampString.Data(),crate,board);
176 if (FILE* fp = fopen(pathname,
"r")) {
177 LOG_INFO <<
"Using ped4 file " << pathname << endm;
179 for (
int chan = 0; fscanf(fp,
"%d",&ped4val)!= EOF; ++chan) {
180 int rdo = (crate-1)*mxChan+(board-1)*32+chan;
181 feePed4[rdo] = ped4val;
182 LOG_DEBUG << Form(
"crate=%d board=%d chan=%d rdo=%d ped4=%d",crate,board,chan,rdo,ped4val) << endm;
193 static int maskFilter(
const struct dirent* d)
195 int month, day, year;
196 return strlen(d->d_name) == 16 && sscanf(d->d_name,
"eec.%d-%d-%d.dat",&month,&day,&year) == 3;
199 static TDatime getMaskDateTime(
const char* maskfile)
201 int month, day, year;
202 sscanf(maskfile,
"eec.%d-%d-%d.dat",&month,&day,&year);
203 return TDatime(2000+year,month,day,0,0,0);
206 static void scanMaskDirForDates(
const char* dir, vector<TDatime>& dates)
208 struct dirent** namelist;
209 int n = scandir(dir,&namelist,maskFilter,0);
212 dates.push_back(getMaskDateTime(namelist[n]->d_name));
216 sort(dates.begin(),dates.end());
219 void EemcTrigUtil::getFeeOutMask(
const char* maskfile,
int* highTowerMask,
int* patchSumMask)
221 FILE* fp = fopen(maskfile,
"r");
224 while (fgets(line,
sizeof(line),fp) != NULL) {
225 if (*line ==
'#')
continue;
226 int jetpatch, triggerpatch;
229 int n = sscanf(line,
"%d %d %s %s\n",&jetpatch,&triggerpatch,s1,s2);
232 getTriggerPatchFromSteveJetPatchAndTriggerPatch(jetpatch,triggerpatch,triggerpatch2);
233 LOG_INFO << Form(
"JP=%d TP=%d %s %s (%d)",jetpatch,triggerpatch,s1,s2,triggerpatch2) << endm;
234 if (strncmp(s1,
"HT",2) == 0 || strncmp(s2,
"HT",2) == 0) highTowerMask[triggerpatch2] = 0;
235 if (strncmp(s1,
"TP",2) == 0 || strncmp(s2,
"TP",2) == 0) patchSumMask[triggerpatch2] = 0;
242 void EemcTrigUtil::getDsmAndChannelFromSteveJetPatchAndTriggerPatch(
int jetpatch,
int triggerpatch,
int& dsm,
int& chan)
245 static const int dsmMap[6][15] = {
246 { 7,7,8,7,7,8,7,7,8,7,7,8,7,7,8 },
247 { 9,9,8,9,9,8,9,9,8,9,9,8,9,9,8 },
248 { 1,1,2,1,1,2,1,1,2,1,1,2,1,1,2 },
249 { 3,3,2,3,3,2,3,3,2,3,3,2,3,3,2 },
250 { 4,4,5,4,4,5,4,4,5,4,4,5,4,4,5 },
251 { 6,6,5,6,6,5,6,6,5,6,6,5,6,6,5 }
253 static const int chanMap[6][15] = {
254 { 0,1,0,2,3,1,4,5,2,6,7,3,8,9,4 },
255 { 0,1,5,2,3,6,4,5,7,6,7,8,8,9,9 },
256 { 0,1,0,2,3,1,4,5,2,6,7,3,8,9,4 },
257 { 0,1,5,2,3,6,4,5,7,6,7,8,8,9,9 },
258 { 0,1,0,2,3,1,4,5,2,6,7,3,8,9,4 },
259 { 0,1,5,2,3,6,4,5,7,6,7,8,8,9,9 }
261 dsm = dsmMap[jetpatch-1][triggerpatch-1];
262 chan = chanMap[jetpatch-1][triggerpatch-1];
265 void EemcTrigUtil::getTriggerPatchFromDsmAndChannel(
int dsm,
int chan,
int& triggerpatch)
267 triggerpatch = (dsm-1)*10+chan;
270 void EemcTrigUtil::getTriggerPatchFromSteveJetPatchAndTriggerPatch(
int jetpatch,
int triggerpatch,
int& triggerpatch2)
273 getDsmAndChannelFromSteveJetPatchAndTriggerPatch(jetpatch,triggerpatch,dsm,chan);
274 getTriggerPatchFromDsmAndChannel(dsm,chan,triggerpatch2);
277 void EemcTrigUtil::getFeeOutMask(
const TDatime& date,
int* highTowerMask,
int* patchSumMask)
279 char maskdir[FILENAME_MAX];
280 struct passwd* pw = getpwnam(
"pibero");
281 sprintf(maskdir,
"%s/public/StarTrigSimuSetup/mask",pw->pw_dir);
282 vector<TDatime> dates;
283 scanMaskDirForDates(maskdir,dates);
284 TDatime timestamp = getTimeStampFromDates(date,dates);
285 char maskfile[FILENAME_MAX];
286 sprintf(maskfile,
"%s/eec.%02d-%02d-%02d.dat",maskdir,timestamp.GetMonth(),timestamp.GetDay(),timestamp.GetYear()%100);
287 LOG_INFO <<
"Using mask file " << maskfile << endm;
288 getFeeOutMask(maskfile,highTowerMask,patchSumMask);
291 void EemcTrigUtil::getFeeBoardFromSteveTriggerPatch(
int triggerpatch,
int& board)
294 static const int boardMap[15] = { 1,3,1,1,3,1,2,4,2,2,4,2,3,4,3 };
295 board = boardMap[triggerpatch-1];
298 void EemcTrigUtil::getFeeBoardMask(
const TDatime& date,
int* highTower)
300 char maskdir[FILENAME_MAX];
301 struct passwd* pw = getpwnam(
"pibero");
302 sprintf(maskdir,
"%s/public/StarTrigSimuSetup/mask",pw->pw_dir);
303 vector<TDatime> dates;
304 scanDirForDates(maskdir,dates);
305 TDatime timestamp = getTimeStampFromDates(date,dates);
306 char timestampString[12];
307 sprintf(timestampString,
"/%02d.%02d.%4d",timestamp.GetMonth(),timestamp.GetDay(),timestamp.GetYear());
308 strcat(maskdir,timestampString);
309 LOG_INFO <<
"Using mask directory " << maskdir << endm;
310 for (
int jetpatch = 1; jetpatch <= 6; ++jetpatch) {
312 fill(boardmask,boardmask+5,0);
313 char maskfile[FILENAME_MAX];
314 sprintf(maskfile,
"%s/tower-%d-current_beam_config.dat",maskdir,jetpatch);
315 LOG_INFO <<
"Scanning mask file " << maskfile << endm;
316 FILE* fp = fopen(maskfile,
"r");
320 while (fscanf(fp,
"%x %s\n",&value,name) != EOF) {
321 if (strcmp(name,
"board1mask") == 0) boardmask[0] = value;
322 if (strcmp(name,
"board2mask") == 0) boardmask[1] = value;
323 if (strcmp(name,
"board3mask") == 0) boardmask[2] = value;
324 if (strcmp(name,
"board4mask") == 0) boardmask[3] = value;
325 if (strcmp(name,
"board5mask") == 0) boardmask[4] = value;
329 for (
int triggerpatch = 1; triggerpatch <= 15; ++triggerpatch) {
331 getFeeBoardFromSteveTriggerPatch(triggerpatch,board);
332 if (boardmask[board-1]) {
334 getTriggerPatchFromSteveJetPatchAndTriggerPatch(jetpatch,triggerpatch,triggerpatch2);
335 highTower[triggerpatch2] = 0;
336 LOG_INFO << Form(
"JP=%d TP=%d Brd=%d (%d)",jetpatch,triggerpatch,board,triggerpatch2) << endm;
346 EemcTrigUtil::genPed4(
int ped4val,
int mxChan,
int *feePed4){
347 for (
int crate=1; crate<=6; crate++){
348 for (
int board=1; board<=4; board++){
349 for (
int chan=0; chan<32; chan++){
350 int rdo = (crate-1)*mxChan+(board-1)*32+chan;
351 feePed4[rdo]=ped4val;
352 LOG_DEBUG << Form(
"crate=%d board=%d chan=%d rdo=%d ped4=%d",crate,board,chan,rdo,ped4val) << endm;
362 EemcTrigUtil::readPed4(
const char *path,
int mxChan,
int *feePed4) {
363 for (
int crate = 1; crate <= 6; ++crate) {
364 for (
int board = 1; board <= 4; ++board) {
365 char fname[FILENAME_MAX];
366 sprintf(fname,
"%s/crate%dboard%d.ped4",path,crate,board);
367 FILE* fd = fopen(fname,
"r");
369 LOG_ERROR <<
"Could not open " << fname <<
" for reading" << endm;
372 LOG_DEBUG <<
"Reading " << fname << endm;
374 for (chan = 0; chan < 32; ++chan) {
376 if (fscanf(fd,
"%d",&ped4) == EOF)
break;
377 int rdo = (crate-1)*mxChan+(board-1)*32+chan;
379 LOG_DEBUG << Form(
"crate=%d board=%d chan=%d rdo=%d ped4=%d",crate,board,chan,rdo,ped4) << endm;
381 LOG_DEBUG <<
"Read " << chan <<
" channels" << endm;