CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDQMStatusWriter.cc
Go to the documentation of this file.
1 /*
2  * \file EcalDQMStatusWriter.cc
3  *
4  * \author G. Della Ricca
5  *
6 */
7 
8 #include <fstream>
9 #include <iostream>
10 #include <string>
11 #include <cstring>
12 #include <time.h>
13 #include <unistd.h>
14 
17 
19 
24 
26 
28 
30 
31  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
32 
33  typedef std::vector<edm::ParameterSet> Parameters;
34  Parameters toPut = ps.getParameter<Parameters>("toPut");
35 
36  for ( Parameters::iterator itToPut=toPut.begin(); itToPut!=toPut.end(); itToPut++ ) {
37  inpFileName_.push_back(itToPut->getUntrackedParameter<std::string>("inputFile"));
38  objectName_.push_back(itToPut->getUntrackedParameter<std::string>("conditionType"));
39  since_.push_back(itToPut->getUntrackedParameter<unsigned int>("since"));
40  }
41 
42 }
43 
45 
47 
49  if ( !dbservice.isAvailable() ){
50  std::cout << "PoolDBOutputService is unavailable" << std::endl;
51  return;
52  }
53 
54  for ( unsigned int i=0; i<objectName_.size(); i++ ) {
55 
56  bool toAppend;
57  cond::Time_t newTime;
58 
59  if ( dbservice->isNewTagRequest( objectName_[i]+std::string("Rcd") ) ) {
60  // This is the first object for this tag.
61  // Append mode should be off.
62  // newTime is the end of this new objects IOV.
63  toAppend = false;
64  newTime = dbservice->beginOfTime();
65  } else {
66  // There should already be an object in the DB for this tag.
67  // Append IOV mode should be on.
68  // newTime is the beginning of this new objects IOV.
69  toAppend = true;
70  newTime = (cond::Time_t) since_[i];
71  }
72 
73  std::cout << "Reading " << objectName_[i] << " from file and writing to DB with newTime " << newTime << std::endl;
74 
75  if (objectName_[i] == "EcalDQMChannelStatus") {
76 
78 
79  if ( !toAppend ) {
80  dbservice->createNewIOV<EcalDQMChannelStatus>(status, newTime, dbservice->endOfTime(), "EcalDQMChannelStatusRcd");
81  } else {
82  dbservice->appendSinceTime<EcalDQMChannelStatus>(status, newTime, "EcalDQMChannelStatusRcd");
83  }
84 
85  } else if (objectName_[i] == "EcalDQMTowerStatus") {
86 
88 
89  if ( !toAppend ) {
90  dbservice->createNewIOV<EcalDQMTowerStatus>(status, newTime, dbservice->endOfTime(), "EcalDQMTowerStatusRcd");
91  } else {
92  dbservice->appendSinceTime<EcalDQMTowerStatus>(status, newTime, "EcalDQMTowerStatusRcd");
93  }
94 
95  } else {
96 
97  std::cout << "Object " << objectName_[i] << " is not supported by this program." << std::endl;
98 
99  }
100 
101  }
102 
103 }
104 
106 
108 
109  std::vector<EcalDQMStatusDictionary::codeDef> dictionary;
111 
112  // barrel
113  for ( int ism=1; ism<=36; ism++ ) {
114  int jsm = Numbers::iSM(ism, EcalBarrel);
115  for ( int ic=1; ic<=1700; ic++ ) {
116  EBDetId id(jsm, ic, EBDetId::SMCRYSTALMODE);
117  status->setValue(id, 0);
118  }
119  }
120 
121  // endcap
122  for ( int ix=1; ix<=100; ix++ ) {
123  for ( int iy=1; iy<=100; iy++ ) {
124  if ( EEDetId::validDetId(ix, iy, +1) ) {
125  EEDetId id(ix, iy, +1);
126  status->setValue(id, 0);
127  }
128  if ( EEDetId::validDetId(ix, iy, -1) ) {
129  EEDetId id(ix, iy, -1);
130  status->setValue(id, 0);
131  }
132  }
133  }
134 
135  std::cout << "Reading channel status from file " << inputFile << std::endl;
136  FILE *ifile = fopen( inputFile ,"r" );
137 
138  if ( !ifile ) throw cms::Exception ("Cannot open file") ;
139 
140  char line[256];
141 
142  int ii = 0;
143  while ( fgets(line, 255, ifile) ) {
144 
145  std::stringstream stream;
146 
147  ii++;
149  stream << line;
150  if ( verbose_ ) std::cout << line;
151  stream >> key;
152 
153  if ( key.size() == 0 || strcmp(key.c_str(), " ") == 0 || strncmp(key.c_str(), "#", 1) == 0 ) {
154 
155  // skip comments
156 
157  } else if ( strcmp(key.c_str(), "EB") == 0 ) {
158 
159  int index;
160  uint32_t code;
161  stream >> index >> code;
162 
163  EBDetId id = EBDetId::unhashIndex(index);
164  code = convert(code);
165 
167  if ( it != status->end() ) code |= it->getStatusCode();
168  status->setValue(id, code);
169 
170  } else if ( strcmp(key.c_str(), "EE") == 0 ) {
171 
172  int ix, iy, iz;
173  uint32_t code;
174  stream >> ix >> iy >> iz >> code;
175 
176  EEDetId id(ix, iy, iz);
177  code = convert(code);
178 
180  if ( it != status->end() ) code |= it->getStatusCode();
181  status->setValue(id, code);
182 
183  } else if ( strcmp(key.c_str(), "Crystal") == 0 ) {
184 
186  stream >> module;
187 
188  if ( strncmp(module.c_str(), "EB+", 3) == 0 || strncmp(module.c_str(), "EB-", 3) == 0 ) {
189 
190 #if 0
191  int ie, ip;
192  std::string token;
193  stream >> ie >> ip >> token;
194 
195  int sm = atoi( module.substr(2, module.size()-2).c_str() );
196 
197  int ism = (sm>=1&&sm<=18) ? sm+18 : -sm;
198  int jsm = Numbers::iSM(ism, EcalBarrel);
199  int ic = 20*(ie-1)+(ip-1)+1;
200 #else
201  int ic;
202  std::string token;
203  stream >> ic >> token;
204 
205  int sm = atoi( module.substr(2, module.size()-2).c_str() );
206 
207  int ism = (sm>=1&&sm<=18) ? sm+18 : -sm;
208  int jsm = Numbers::iSM(ism, EcalBarrel);
209 #endif
210 
211  EBDetId id(jsm, ic, EBDetId::SMCRYSTALMODE);
212  uint32_t code = 0;
213  for ( unsigned int i=0; i<dictionary.size(); i++ ) {
214  if ( strcmp(token.c_str(), dictionary[i].desc) == 0 ) {
215  code = dictionary[i].code;
216  }
217  }
218  if ( code == 0 ) {
219  std::cout << " --> not found in the dictionary: " << token << std::endl;
220  continue;
221  }
222 
224  if ( it != status->end() ) code |= it->getStatusCode();
225  status->setValue(id, code);
226 
227  } else if ( strncmp(module.c_str(), "EE+", 3) == 0 || strncmp(module.c_str(), "EE-", 3) == 0 ) {
228 
229 #if 0
230  int jx, jy;
231  std::string token;
232  stream >> jx >> jy >> token;
233 #else
234  int index;
235  std::string token;
236  stream >> index >> token;
237  int jx = index/1000;
238  int jy = index%1000;
239 #endif
240 
241  int sm = atoi( module.substr(2, module.size()-2).c_str() );
242 
243  int ism = 0;
244  if( sm == -99 ) sm = -1;
245  if( sm == +99 ) sm = +1;
246  switch ( sm ) {
247  case -7: ism = 1; break;
248  case -8: ism = 2; break;
249  case -9: ism = 3; break;
250  case -1: ism = 4; break;
251  case -2: ism = 5; break;
252  case -3: ism = 6; break;
253  case -4: ism = 7; break;
254  case -5: ism = 8; break;
255  case -6: ism = 9; break;
256  case +7: ism = 10; break;
257  case +8: ism = 11; break;
258  case +9: ism = 12; break;
259  case +1: ism = 13; break;
260  case +2: ism = 14; break;
261  case +3: ism = 15; break;
262  case +4: ism = 16; break;
263  case +5: ism = 17; break;
264  case +6: ism = 18; break;
265  }
266 
267  EEDetId id(jx, jy, (ism>=1&&ism<=9)?-1:+1);
268  uint32_t code = 0;
269  for ( unsigned int i=0; i<dictionary.size(); i++ ) {
270  if ( strcmp(token.c_str(), dictionary[i].desc) == 0 ) {
271  code = dictionary[i].code;
272  }
273  }
274  if ( code == 0 ) {
275  std::cout << " --> not found in the dictionary: " << token << std::endl;
276  continue;
277  }
278 
280  if ( it != status->end() ) code |= it->getStatusCode();
281  status->setValue(id, code);
282 
283  } else {
284 
285  std:: cout << "--> unknown token at line #" << ii << " : " << line;
286 
287  }
288 
289  } else if ( strcmp(key.c_str(), "TT") == 0 ) {
290 
291  // see readEcalDQMTowerStatusFromFile
292 
293  } else if ( strcmp(key.c_str(), "PN") == 0 || strcmp(key.c_str(), "MemCh") == 0 || strcmp(key.c_str(), "MemTT") == 0 ) {
294 
295  std::cout << "--> unsupported key at line #" << ii << " : " << line;
296 
297  } else {
298 
299  std:: cout << "--> skipped line #" << ii << " : " << line;
300 
301  }
302 
303  }
304 
305  fclose(ifile);
306 
307  return status;
308 
309 }
310 
312 
314 
315  std::vector<EcalDQMStatusDictionary::codeDef> dictionary;
317 
318  // barrel
319  for ( int ix=1; ix<=17; ix++ ) {
320  for ( int iy=1; iy<=72; iy++ ) {
321  if ( EcalTrigTowerDetId::validDetId(+1, EcalBarrel, ix, iy) ) {
322  EcalTrigTowerDetId id(+1, EcalBarrel, ix, iy);
323  status->setValue(id, 0);
324  }
325  if ( EcalTrigTowerDetId::validDetId(-1, EcalBarrel, ix, iy) ) {
326  EcalTrigTowerDetId id(-1, EcalBarrel, ix, iy);
327  status->setValue(id, 0);
328  }
329  }
330  }
331 
332  // endcap
333  for ( int ix=1; ix<=20; ix++ ) {
334  for ( int iy=1; iy<=20; iy++ ) {
335  if ( EcalScDetId::validDetId(ix, iy, +1) ) {
336  EcalScDetId id(ix, iy, +1);
337  status->setValue(id, 0);
338  }
339  if ( EcalScDetId::validDetId(ix, iy, -1) ) {
340  EcalScDetId id(ix, iy, -1);
341  status->setValue(id, 0);
342  }
343  }
344  }
345 
346  std::cout << "Reading tower status from file " << inputFile << std::endl;
347  FILE *ifile = fopen( inputFile ,"r" );
348 
349  if ( !ifile ) throw cms::Exception ("Cannot open file") ;
350 
351  char line[256];
352 
353  int ii = 0;
354  while ( fgets(line, 255, ifile) ) {
355 
356  std::stringstream stream;
357 
358  ii++;
360  stream << line;
361  if ( verbose_ ) std::cout << line;
362  stream >> key;
363 
364  if ( key.size() == 0 || strcmp(key.c_str(), " ") == 0 || strncmp(key.c_str(), "#", 1) == 0 ) {
365 
366  // skip comments
367 
368  } else if ( strcmp(key.c_str(), "EB") == 0 ) {
369 
370  // see readEcalDQMChannelStatusFromFile
371 
372  } else if ( strcmp(key.c_str(), "EE") == 0 ) {
373 
374  // see readEcalDQMChannelStatusFromFile
375 
376  } else if ( strcmp(key.c_str(), "Crystal") == 0 ) {
377 
378  // see readEcalDQMChannelStatusFromFile
379 
380  } else if ( strcmp(key.c_str(), "TT") == 0 ) {
381 
383  stream >> module;
384 
385  if ( strncmp(module.c_str(), "EB+", 3) == 0 || strncmp(module.c_str(), "EB-", 3) == 0 ) {
386 
387  int itt;
388  std::string token;
389  stream >> itt >> token;
390 
391  if ( itt >= 1 && itt <= 68 ) {
392 
393  int sm = atoi( module.substr(2, module.size()-2).c_str() );
394 
395  int iet = (itt-1)/4+1;
396  int ipt = (itt-1)%4+1;
397 
398  if ( sm<0 ) {
399  ipt = ipt+(std::abs(sm)-1)*4-2;
400  if ( ipt < 1 ) ipt = ipt+72;
401  if ( ipt > 72 ) ipt = ipt-72;
402  } else {
403  ipt = (5-ipt)+(std::abs(sm)-1)*4-2;
404  if ( ipt < 1 ) ipt = ipt+72;
405  if ( ipt > 72 ) ipt = ipt-72;
406  }
407 
408  EcalTrigTowerDetId id((sm<0)?-1:+1, EcalBarrel, iet, ipt);
409  uint32_t code = 0;
410  for ( unsigned int i=0; i<dictionary.size(); i++ ) {
411  if ( strcmp(token.c_str(), dictionary[i].desc) == 0 ) {
412  code = dictionary[i].code;
413  }
414  }
415  if ( code == 0 ) {
416  std::cout << " --> not found in the dictionary: " << token << std::endl;
417  continue;
418  }
419 
420  EcalDQMTowerStatus::const_iterator it = status->find(id);
421  if ( it != status->end() ) code |= it->getStatusCode();
422  status->setValue(id, code);
423 
424  } else {
425 
426  std::cout << "--> unsupported configuration at line #" << ii << " : " << line;
427 
428  }
429 
430  } else if ( strncmp(module.c_str(), "EE+", 3) == 0 || strncmp(module.c_str(), "EE-", 3) == 0 ) {
431 
432  int isc;
433  std::string token;
434  stream >> isc >> token;
435 
436  if ( isc >= 1 && isc <= 68 ) {
437 
438  int sm = atoi( module.substr(2, module.size()-2).c_str() );
439 
440  int ism = 0;
441  switch ( sm ) {
442  case -7: ism = 1; break;
443  case -8: ism = 2; break;
444  case -9: ism = 3; break;
445  case -1: ism = 4; break;
446  case -2: ism = 5; break;
447  case -3: ism = 6; break;
448  case -4: ism = 7; break;
449  case -5: ism = 8; break;
450  case -6: ism = 9; break;
451  case +7: ism = 10; break;
452  case +8: ism = 11; break;
453  case +9: ism = 12; break;
454  case +1: ism = 13; break;
455  case +2: ism = 14; break;
456  case +3: ism = 15; break;
457  case +4: ism = 16; break;
458  case +5: ism = 17; break;
459  case +6: ism = 18; break;
460  }
461 
462  int idcc = (ism>=1&&ism<=9) ? ism : ism-9+45;
463 
464  std::vector<DetId>* crystals = Numbers::crystals(idcc, isc);
465 
466  for ( unsigned int i=0; i<crystals->size(); i++ ) {
467 
468  EcalScDetId id = ((EEDetId) (*crystals)[i]).sc();
469  uint32_t code = 0;
470  for ( unsigned int i=0; i<dictionary.size(); i++ ) {
471  if ( strcmp(token.c_str(), dictionary[i].desc) == 0 ) {
472  code = dictionary[i].code;
473  }
474  }
475  if ( code == 0 ) {
476  std::cout << " --> not found in the dictionary: " << token << std::endl;
477  continue;
478  }
479 
480  EcalDQMTowerStatus::const_iterator it = status->find(id);
481  if ( it != status->end() ) code |= it->getStatusCode();
482  status->setValue(id, code);
483 
484  }
485 
486  } else {
487 
488  std::cout << "--> unsupported configuration at line #" << ii << " : " << line;
489 
490  }
491 
492  } else {
493 
494  std:: cout << "--> unknown token at line #" << ii << " : " << line;
495 
496  }
497 
498  } else if ( strcmp(key.c_str(), "PN") == 0 || strcmp(key.c_str(), "MemCh") == 0 || strcmp(key.c_str(), "MemTT") == 0 ) {
499 
500  std::cout << "--> unsupported key at line #" << ii << " : " << line;
501 
502  } else {
503 
504  std:: cout << "--> skipped line #" << ii << " : " << line;
505 
506  }
507 
508  }
509 
510  fclose(ifile);
511 
512  return status;
513 
514 }
515 
516 uint32_t EcalDQMStatusWriter::convert(uint32_t chStatus) {
517 
518  if ( chStatus == 1 || (chStatus >= 8 && chStatus <= 12 )) {
519 
520  chStatus = 0;
535  chStatus |= 1 << EcalDQMStatusHelper::LASER_MEAN_ERROR;
536  chStatus |= 1 << EcalDQMStatusHelper::LASER_RMS_ERROR;
539  chStatus |= 1 << EcalDQMStatusHelper::LED_MEAN_ERROR;
540  chStatus |= 1 << EcalDQMStatusHelper::LED_RMS_ERROR;
543 
544  } else if ( chStatus == 2 ) {
545 
546  chStatus = 0;
547  chStatus |= 1 << EcalDQMStatusHelper::LASER_MEAN_ERROR;
548  chStatus |= 1 << EcalDQMStatusHelper::LASER_RMS_ERROR;
551  chStatus |= 1 << EcalDQMStatusHelper::LED_MEAN_ERROR;
552  chStatus |= 1 << EcalDQMStatusHelper::LED_RMS_ERROR;
555 
556  } else if ( chStatus == 3 ) {
557 
558  chStatus = 0;
568 
569  } else if ( chStatus == 4 ) {
570 
571  chStatus = 0;
580 
581  } else if ( chStatus == 13 || chStatus == 14 ) {
582 
583  chStatus = 0;
585 
586  } else if ( (chStatus&0x3f) == 13 || (chStatus&0x7f) == 13 ||
587  (chStatus&0x3f) == 14 || (chStatus&0x7f) == 14 ) {
588 
589  chStatus = 0;
604  chStatus |= 1 << EcalDQMStatusHelper::LASER_MEAN_ERROR;
605  chStatus |= 1 << EcalDQMStatusHelper::LASER_RMS_ERROR;
608  chStatus |= 1 << EcalDQMStatusHelper::LED_MEAN_ERROR;
609  chStatus |= 1 << EcalDQMStatusHelper::LED_RMS_ERROR;
613 
614  }
615 
616  return( chStatus );
617 
618 }
619 
static bool validDetId(int ix, int iy, int iz)
Definition: EcalScDetId.cc:64
T getParameter(std::string const &) const
static const int LED_MEAN_ERROR
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
static const int PEDESTAL_MIDDLE_GAIN_RMS_ERROR
static const int LASER_MEAN_ERROR
static const int TESTPULSE_LOW_GAIN_RMS_ERROR
static const int PHYSICS_BAD_CHANNEL_WARNING
std::vector< unsigned long long > since_
Some &quot;id&quot; conversions.
static const int LASER_TIMING_RMS_ERROR
static const int PEDESTAL_HIGH_GAIN_MEAN_ERROR
static const int PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR
static const int TESTPULSE_MIDDLE_GAIN_MEAN_ERROR
static const int PEDESTAL_LOW_GAIN_RMS_ERROR
EcalDQMTowerStatus * readEcalDQMTowerStatusFromFile(const char *)
int ii
Definition: cuy.py:588
void setValue(const uint32_t id, const Item &item)
const_iterator find(uint32_t rawId) const
static const int PEDESTAL_HIGH_GAIN_RMS_ERROR
static const int STATUS_FLAG_ERROR
void setValue(const uint32_t id, const Item &item)
static const int TESTPULSE_MIDDLE_GAIN_RMS_ERROR
static std::vector< DetId > * crystals(const EcalTrigTowerDetId &id)
Definition: Numbers.cc:582
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
EcalDQMChannelStatusMap EcalDQMChannelStatus
unsigned long long Time_t
Definition: Time.h:16
vector< ParameterSet > Parameters
static void getDictionary(std::vector< codeDef > &dict)
bool isNewTagRequest(const std::string &recordName)
uint32_t convert(uint32_t c)
EcalDQMTowerStatusMap EcalDQMTowerStatus
EcalDQMChannelStatus * readEcalDQMChannelStatusFromFile(const char *)
bool isAvailable() const
Definition: Service.h:46
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const int TESTPULSE_HIGH_GAIN_RMS_ERROR
static const int LED_TIMING_MEAN_ERROR
void beginRun(const edm::Run &r, const edm::EventSetup &c)
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
static const int PEDESTAL_LOW_GAIN_MEAN_ERROR
std::vector< std::string > inpFileName_
static const int TESTPULSE_LOW_GAIN_MEAN_ERROR
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:47
std::vector< std::string > objectName_
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int LED_TIMING_RMS_ERROR
std::vector< Item >::const_iterator const_iterator
static const int PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR
static const int LASER_TIMING_MEAN_ERROR
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
static bool validDetId(int iz, EcalSubdetector sd, int i, int j)
check if a valid index combination
list key
Definition: combine.py:13
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:243
const_iterator find(uint32_t rawId) const
tuple cout
Definition: gather_cfg.py:121
const_iterator end() const
static const int LED_RMS_ERROR
EcalDQMStatusWriter(const edm::ParameterSet &ps)
static const int PEDESTAL_MIDDLE_GAIN_MEAN_ERROR
static const int TESTPULSE_HIGH_GAIN_MEAN_ERROR
tuple status
Definition: ntuplemaker.py:245
static const int LASER_RMS_ERROR
static const int SMCRYSTALMODE
Definition: EBDetId.h:167
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
Definition: Run.h:41