CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDumpRaw.cc
Go to the documentation of this file.
1 //emacs settings:-*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 /*
3  *
4  * Author: Ph Gras. CEA/IRFU - Saclay
5  *
6  */
7 
9 
10 #include <iostream>
11 #include <fstream>
12 #include <iomanip>
13 #include <limits>
14 #include <algorithm>
15 #include <sys/time.h>
16 
20 
25 
26 // FE BX counter starts at 0, while OD BX starts at 1.
27 // For some reason, I do not understand myself,
28 // Bx offset is often set such that:
29 // BX_FE = BX_OD for BX_OD < 3564
30 // and BX_FE = BX_OD - 3564 for BX_OD = 3564
31 // set feBxOffset to 1 if this FE BX shift is operated, 0 otherwise
32 //Ph. Gras.
33 const int feBxOffset = 1;
34 
35 const int EcalDumpRaw::ttId_[nTccTypes_][maxTpgsPerTcc_] = {
36  //EB-
37  { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
38  17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
39  33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
40  49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
41  65, 66, 67, 68
42  },
43 
44  //EB+
45  { 4, 3, 2, 1, 8, 7, 6, 5, 12, 11, 10, 9, 16, 15, 14, 13,
46  20, 19, 18, 17, 24, 23, 22, 21, 28, 27, 26, 25, 32, 31, 30, 29,
47  36, 35, 34, 33, 40, 39, 38, 37, 44, 43, 42, 41, 48, 47, 46, 45,
48  52, 51, 50, 49, 56, 55, 54, 53, 60, 59, 58, 57, 64, 63, 62, 61,
49  68, 67, 66, 65
50  },
51 
52  //inner EE
53  { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
54  17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 0, 0, 0, 0,
55  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57  0, 0, 0, 0
58  },
59 
60  //outer EE
61  { 1, 2, 3, 4, 5, 6, 7, 8, 9,
62  0, 0, 0, 0, 0, 0, 0, 0, 0,
63  10, 11, 12, 13, 14, 15, 16, 0, 0,
64  0, 0, 0, 0, 0, 0, 0, 0, 0,
65  0, 0, 0, 0, 0, 0, 0, 0, 0,
66  0, 0, 0, 0, 0, 0, 0, 0, 0,
67  0, 0, 0, 0, 0, 0, 0, 0, 0,
68  0, 0, 0, 0, 0
69  }
70 };
71 
72 using namespace std;
73 
74 static const char* const trigNames[] = {
75  "Unknown",
76  "Phys",
77  "Calib",
78  "Test",
79  "Ext",
80  "Simu",
81  "Trace",
82  "Err"
83 };
84 
85 static const char* const detailedTrigNames[] = {
86  "?", //000
87  "?", //001
88  "?", //010
89  "?", //011
90  "Las", //100
91  "Led", //101
92  "TP", //110
93  "Ped" //111
94 };
95 
96 static const char* const colorNames[] = {
97  "Blue",
98  "Green",
99  "Red",
100  "IR"
101 };
102 
103 static const char* const ttsNames[] = {
104  "Discon'd", //0000
105  "OvFWarn", //0001
106  "OoS", //0010
107  "Forb", //0011
108  "Busy", //0100
109  "Forb", //0101
110  "Forb", //0110
111  "Forb", //0111
112  "Ready", //1000
113  "Forb", //1001
114  "Idle", //1010
115  "Forb", //1011
116  "Err", //1100
117  "Forb", //1101
118  "Forb", //1110
119  "Discon'd" //1111
120 };
121 
122 //double mgpaGainFactors[] = {12., 1., 12./6., 12.}; //index 0->saturation
123 // gain setting: sat 12 6 1 //index 0->saturation
124 // gain setting: 1(sat) 12 6 1
125 //index 0->saturation
126 static const double mgpaGainFactors[] = {10.63, 1., 10.63/5.43, 10.63};
127 
129  iEvent_(0),
130  adc_(nSamples, 0.),
131  amplCut_(ps.getUntrackedParameter<double>("amplCut", 5.)),
132  dump_(ps.getUntrackedParameter<bool>("dump", true)),
133  dumpAdc_(ps.getUntrackedParameter<bool>("dumpAdc", true)),
134  l1aHistory_(ps.getUntrackedParameter<bool>("l1aHistory", true)),
135  // doHisto_(ps.getUntrackedParameter<bool>("doHisto", true)),
136  maxEvt_(ps.getUntrackedParameter<int>("maxEvt", 10000)),
137  profileFedId_(ps.getUntrackedParameter<int>("profileFedId", 0)),
138  profileRuId_(ps.getUntrackedParameter<int>("profileRuId", 1)),
139  l1aMinX_(ps.getUntrackedParameter<int>("l1aMinX", 1)),
140  l1aMaxX_(ps.getUntrackedParameter<int>("l1aMaxX", 601)),
141  lastOrbit_(nDccs_, numeric_limits<uint32_t>::max()),
142  eventId_(numeric_limits<unsigned>::max()),
143  eventList_(ps.getUntrackedParameter<vector<unsigned> >("eventList", vector<unsigned>())),
144  minEventId_(999999),
145  maxEventId_(0),
146  orbit0_(0),
147  orbit0Set_(false),
148  bx_(-1),
149  l1a_(-1),
150  l1amin_(numeric_limits<int>::max()),
151  l1amax_(-numeric_limits<int>::min()),
152  simpleTrigType_(-1),
153  detailedTrigType_(-1),
154  // histo_("hist.root", "RECREATE"),
155  l1as_(36+2),
156  orbits_(36+2),
157  tpg_(maxTccsPerDcc_, std::vector<int>(maxTpgsPerTcc_)),
158  nTpgs_(maxTccsPerDcc_, 0),
159  dccChStatus_(70, 0),
160  srpL1a_(-1),
161  tccL1a_(-1),
162  nTts_(-1),
163  tccBlockLen64_(19),
164  feL1a_(nRu_,-1),
165  srpBx_(-1),
166  tccBx_(-1),
167  tccType_(0),
168  feBx_(nRu_,-1),
169  feRuId_(nRu_,-1),
170  iTow_(0),
171  pulsePerRu_(ps.getUntrackedParameter<bool>("pulsePerRu", true)),
172  pulsePerLmod_(ps.getUntrackedParameter<bool>("pulsePerLmod", true)),
173  pulsePerLme_(ps.getUntrackedParameter<bool>("pulsePerLme", true)),
174  tccId_(0),
175  fedRawDataCollectionTag_(ps.getParameter<edm::InputTag>("fedRawDataCollectionTag")),
176  l1AcceptBunchCrossingCollectionTag_(ps.getParameter<edm::InputTag>("l1AcceptBunchCrossingCollectionTag"))
177 {
178  verbosity_= ps.getUntrackedParameter<int>("verbosity",1);
179 
180  beg_fed_id_= ps.getUntrackedParameter<int>("beg_fed_id",601);
181  end_fed_id_= ps.getUntrackedParameter<int>("end_fed_id",654);
182 
183 
184  first_event_ = ps.getUntrackedParameter<int>("first_event",1);
185  last_event_ = ps.getUntrackedParameter<int>("last_event",
187 
188  writeDcc_ = ps.getUntrackedParameter<bool>("writeDCC",false);
189  filename_ = ps.getUntrackedParameter<string>("filename","dump.bin");
190  if(writeDcc_){
191  dumpFile_.open(filename_.c_str());
192  if(dumpFile_.bad()){
193  /*edm::LogError("EcalDumpRaw")*/ std::cout << "Failed to open file '"
194  << filename_.c_str() << "' specified by "
195  << "parameter filename for writing. DCC data "
196  " dump will be disabled.";
197  writeDcc_ = false;
198  }
199  }
200 }
201 
203 }
204 
206 }
207 
208 // ------------ method called to analyze the data ------------
209 void
211  ++iEvent_;
212  eventId_ = event.id().event();
213 
214  if(eventList_.size()!=0 && find(eventList_.begin(), eventList_.end(),
215  eventId_) == eventList_.end()){
216  cout << "Skipping event " << eventId_ << ".\n";
217  return;
218  }
219 
220  if ((first_event_ > 0 && iEvent_ < first_event_) ||
221  (last_event_ > 0 && last_event_ < iEvent_)) return;
222  timeval start;
223  timeval stop;
224  gettimeofday(&start, 0);
225 
227  event.getByLabel(fedRawDataCollectionTag_, rawdata);
228 
229  if(dump_ || l1aHistory_) cout << "\n======================================================================\n"
230  << toNth(iEvent_)
231  << " read event. "
232  << "Event id: "
233  << " " << eventId_
234  << "\n----------------------------------------------------------------------\n";
235 
236  if(l1aHistory_){
238  event.getByLabel(l1AcceptBunchCrossingCollectionTag_, l1aHist);
239  if(!l1aHist.isValid()) {
240  cout << "L1A history not found.\n";
241  } else if (l1aHist->size() == 0) {
242  cout << "L1A history is empty.\n";
243  } else{
244  cout << "L1A history: \n";
245  for(L1AcceptBunchCrossingCollection::const_iterator it = l1aHist->begin();
246  it != l1aHist->end();
247  ++it){
248  cout << "L1A offset: " << it->l1AcceptOffset() << "\t"
249  << "BX: " << it->bunchCrossing() << "\t"
250  << "Orbit ID: " << it->orbitNumber() << "\t"
251  << "Trigger type: " << it->eventType() << " ("
252  << trigNames[it->eventType()&0xF] << ")\n";
253  }
254  }
255  cout << "----------------------------------------------------------------------\n";
256  }
257 
258  if(eventId_ < minEventId_) minEventId_ = eventId_;
259  if(eventId_ > maxEventId_) maxEventId_ = eventId_;
260 
261 #if 1
262 
263  bool dccIdErr = false;
264  unsigned iFed = 0;
265  unsigned refDccId = 0;
266  // static bool recordNextPhys = false;
267  //static int bxCalib = -1;
268  //x static int nCalib = 0;
269 
270  for (int id = 0; id<=FEDNumbering::lastFEDId(); ++id){
271 
272  if (id < beg_fed_id_ || end_fed_id_ < id) continue;
273 
274  const FEDRawData& data = rawdata->FEDData(id);
275 
276  if (data.size()>4){
277  ++iFed;
278  if ((data.size() % 8) !=0){
279  cout << "***********************************************\n";
280  cout << " Fed size in bits not multiple of 64, strange.\n";
281  cout << "***********************************************\n";
282  }
283 
284 
285  size_t nWord32 = data.size()/4;
286  const uint32_t * pData = ( reinterpret_cast<uint32_t*>(const_cast<unsigned char*> ( data.data())));
287  stringstream s;
288  srpL1a_ = -1;
289  tccL1a_ = -1;
290  srpBx_ = -1;
291  tccBx_ = -1;
292  iTow_ = 0;
293  iRu_ = 0;
294  nTts_ = -1;
295  iTcc_ = 0;
296  tccType_ = 0;
297 
298  for(int i = 0; i < nRu_; ++i){
299  feL1a_[i] = -1;
300  feBx_[i] = -1;
301  feRuId_[i] = -1;
302  }
303 
304  fill(nTpgs_.begin(), nTpgs_.end(), 0);
305 
306  fill(dccChStatus_.begin(), dccChStatus_.end(), 0);
307 
308  bool rc;
309  for(size_t iWord32=0; iWord32 < nWord32; iWord32+=2){
310  s.str("");
311  if(id>=601 && id<=654){// ECAL DCC data
312  rc = decode(pData+iWord32, iWord32/2, s);
313  } else{
314  rc = true;
315  }
316  if(rc && dump_){
317  cout << setfill('0') << hex
318  << "[" << setw(8) << iWord32*4 << "] "
319  << setw(4) << (pData[iWord32+1]>>16 & 0xFFFF) << " "
320  << setw(4) << (pData[iWord32+1]>>0 & 0xFFFF) << " "
321  << setw(4) << (pData[iWord32]>>16 & 0xFFFF) << " "
322  << setw(4) << (pData[iWord32]>>0 & 0xFFFF) << " "
323  << setfill(' ') << dec
324  << s.str() << "\n";
325  }
326  }
327 
328  if(iFed==1){
329  refDccId = dccId_;
330  } else{
331  if(dccId_!=refDccId){
332  dccIdErr = true;
333  }
334  }
335 
336  if(dump_) cout << flush; //flushing cout before writing to cerr
337 
338  if(srpBx_!=-1 && srpBx_!=bx_){
339  cerr << "Bx discrepancy between SRP and DCC, Bx(SRP) = "
340  << srpBx_ << ", Bx(DCC) = " << bx_
341  << " in " << toNth(iEvent_) << " event, FED "
342  << id << endl;
343  }
344 
345  if(tccBx_!=-1 && tccBx_!=bx_){
346  cerr << "Bx discrepancy between TCC and DCC, Bx(TCC) = "
347  << srpBx_ << ", Bx(DCC) = " << bx_
348  << " in " << toNth(iEvent_) << " event, FED "
349  << id << endl;
350  }
351 
352  bool feBxErr = false;
353  for(int i=0; i < nRu_; ++i){
354  int expectedFeBx;
355  if(feBxOffset==0){
356  expectedFeBx = bx_ - 1;
357  } else{
358  expectedFeBx = (bx_==3564) ? 0 : bx_;
359  }
360  if(feBx_[i]!=-1 && feBx_[i]!=expectedFeBx){
361  cerr << "BX error for " << toNth(i+1) << " RU, RU ID "
362  << feRuId_[i];
363  if((unsigned) feRuId_[i] <= dccChStatus_.size()){
364  bool detected = (dccChStatus_[feRuId_[i]-1] == 10 || dccChStatus_[feRuId_[i]-1] == 11);
365  cerr << (detected?" ":" not ") << "detected by DCC (ch status: "
366  << dccChStatus_[feRuId_[i]-1] << ")";
367  }
368  cerr << " in " << toNth(iEvent_) << " event, FED "
369  << id << "." << endl;
370 
371  feBxErr = true;
372  }
373  }
374  if(feBxErr) cerr << "Bx discrepancy between DCC and at least one FE"
375  << " in " << toNth(iEvent_) << " event, FED "
376  << id << "\n";
377 
378 
379  int localL1a = l1a_ & 0xFFF;
380  if(srpL1a_!=-1 && srpL1a_!=localL1a){
381  cerr << "Discrepancy between SRP and DCC L1a counter, L1a(SRP) = "
382  << srpL1a_ << ", L1a(DCC) & 0xFFF = " << localL1a
383  << " in " << toNth(iEvent_) << " event, FED "
384  << id << endl;
385 
386  }
387 
388  if(tccL1a_!=-1 && tccL1a_!=localL1a){
389  cerr << "Discrepancy between TCC and DCC L1a counter, L1a(TCC) = "
390  << srpL1a_ << ", L1a(DCC) & 0xFFF = " << localL1a
391  << " in " << toNth(iEvent_) << " event, FED "
392  << id << endl;
393 
394  }
395 
396  bool feL1aErr = false;
397  for(int i=0; i < nRu_; ++i){
398  if(feL1a_[i] != -1 && feL1a_[i] != ((localL1a-1) & 0xFFF)){
399  cerr << "FE L1A error for " << toNth(i+1) << " RU, RU ID "
400  << feRuId_[i];
401  if((unsigned) feRuId_[i] <= dccChStatus_.size()){
402  bool detected = (dccChStatus_[feRuId_[i]-1] == 9 || dccChStatus_[feRuId_[i]-1] == 11);
403  cerr << (detected?" ":" not ") << "detected by DCC (ch status: "
404  << dccChStatus_[feRuId_[i]-1] << ")";
405  }
406  cerr << " in " << toNth(iEvent_) << " event, FED "
407  << id << "." << endl;
408  feL1aErr = true;
409  }
410  }
411  if(feL1aErr) cerr << "Discrepancy in L1a counter between DCC "
412  "and at least one FE (L1A(DCC) & 0xFFF = " << localL1a << ")"
413  << " in " << toNth(iEvent_) << " event, FED "
414  << id << "\n";
415 
416 
417  if(iTow_>0 && iTow_< nRu_ && feRuId_[iTow_] < feRuId_[iTow_-1]){
418  cerr << "Error in RU ID (TT/SC ID)"
419  << " in " << toNth(iEvent_) << " event, FED "
420  << id << endl;
421  }
422 
423  if (beg_fed_id_ <= id && id <= end_fed_id_ && writeDcc_){
424  dumpFile_.write( reinterpret_cast <const char *> (pData), nWord32*4);
425  }
426 
427  if(dump_) cout << "\n";
428  } else{
429  // cout << "No data for FED " << id << ". Size = "
430  // << data.size() << " byte(s).\n";
431  }
432  } //next fed
433 
434  if(dump_) cout << "Number of selected FEDs with a data block: "
435  << iFed << "\n";
436 
437  if(dccIdErr){
438  cout << flush;
439  cerr << "DCC ID discrepancy in detailed trigger type "
440  << " of " << toNth(iEvent_) << " event." << endl;
441  }
442 
443  if(l1a_>0 && l1a_< l1amin_) l1amin_ = l1a_;
444  if(l1a_>l1amax_) l1amax_ = l1a_;
445 
446 
447 #endif
448 
449  gettimeofday(&stop, 0);
450  // double dt = (stop.tv_sec-start.tv_sec)*1.e3
451  // + (stop.tv_usec-start.tv_usec)*1.e-3;
452  // histo_.fillD("hCodeTime", "Code execution time;Duration (ms);Event count",
453  // PGXAxis(100, 0, 100),
454  // dt);
455 }
456 
457 string EcalDumpRaw::toNth(int n){
458  stringstream s;
459  s << n;
460  if(n%100<10 || n%100>20){
461  switch(n%10){
462  case 1:
463  s << "st";
464  break;
465  case 2:
466  s << "nd";
467  break;
468  case 3:
469  s << "rd";
470  break;
471  default:
472  s << "th";
473  }
474  } else{
475  s << "th";
476  }
477  return s.str();
478 }
479 
480 
481 bool EcalDumpRaw::decode(const uint32_t* data, int iWord64, ostream& out){
482  bool rc = true;
483  const bool d = dump_;
484  if(iWord64==0){//start of event
485  iSrWord64_ = 0;
486  iTccWord64_ = 0;
487  iTowerWord64_ = 0;
488  }
489  int dataType = (data[1] >>28) & 0xF;
490  const int boe = 5;
491  const int eoe = 10;
492  if(dataType==boe){//Begin of Event header
493  /**********************************************************************
494  * DAQ header
495  *
496  **********************************************************************/
497  simpleTrigType_ = (data[1] >>24) & 0xF;
498  l1a_ = (data[1]>>0 ) & 0xFFffFF;
499  bx_ = (data[0] >>20) & 0xFFF;
500  fedId_ = (data[0] >>8 ) & 0xFFF;
501  if(d) out << "Trigger type: " << simpleTrigType_
502  << "(" << trigNames[(data[1]>>24) & 0xF] << ")"
503  << " L1A: " << l1a_
504  << " BX: " << bx_
505  << " FED ID: " << fedId_
506  << " FOV: " << ((data[0] >>4 ) & 0xF)
507  << " H: " << ((data[0] >>3 ) & 0x1);
508  } else if((dataType>>2)==0){//DCC header
509  /**********************************************************************
510  * ECAL DCC header
511  *
512  **********************************************************************/
513  int dccHeaderId = (data[1] >>24) & 0x3F;
514  switch(dccHeaderId){
515  case 1:
516  if(d) out << "Run #: " << ((data[1] >>0 ) & 0xFFFFFF)
517  << " DCC Err: " << ((data[0] >>24) & 0xFF)
518  << " Evt Len: " << ((data[0] >>0 ) & 0xFFFFFF);
519  break;
520  case 2:
521  side_ = (data[1] >>11) & 0x1;
522  detailedTrigType_ = (data[1] >>8 ) & 0x7;
523  dccId_ = (data[1] >>0 ) & 0x3F;
524  if(d) out << "DCC FOV: " << ((data[1] >>16) & 0xF)
525  << " Side: " << side_
526  << " Trig.: " << detailedTrigType_
527  << " (" << detailedTrigNames[(data[1]>>8)&0x7] << ")"
528  << " Color: " << ((data[1] >>6 ) & 0x3)
529  << " (" << colorNames[(data[1]>>6)&0x3] << ")"
530  << " DCC ID: " << dccId_;
531  break;
532  case 3:
533  {
534  if(d) out << "TCC Status ch<4..1>: 0x"
535  << hex << ((data[1]>>8) & 0xFFFF) << dec
536  << " SR status: " << ((data[1] >>4 ) & 0xF)
537  << " TZS: " << ((data[1] >>2 ) & 0x1)
538  << " ZS: " << ((data[1] >>1 ) & 0x1)
539  << " SR: " << ((data[1] >>0 ) & 0x1);
540  orbit_ = data[0];
541  if(d) out << " Orbit: " << orbit_;
542  if(!orbit0Set_){
543  orbit0_ = orbit_;
544  orbit0Set_ = true;
545  }
546  int iDcc0 = fedId_-fedStart_;
547  if((unsigned)iDcc0<nDccs_){
549  if(d) out << " (+" << (int)orbit_-(int)lastOrbit_[iDcc0] <<")";
550  }
551  lastOrbit_[iDcc0] = orbit_;
552  }
553  }
554  break;
555  case 4:
556  case 5:
557  case 6:
558  case 7:
559  case 8:
560  {
561  int chOffset = (dccHeaderId-4)*14;
562  dccChStatus_[13+chOffset] = ((data[1] >>20) & 0xF);
563  dccChStatus_[12+chOffset] = ((data[1] >>16) & 0xF);
564  dccChStatus_[11+chOffset] = ((data[1] >>12) & 0xF);
565  dccChStatus_[10+chOffset] = ((data[1] >>8 ) & 0xF);
566  dccChStatus_[ 9+chOffset] = ((data[1] >>4 ) & 0xF);
567  dccChStatus_[ 8+chOffset] = ((data[1] >>0) & 0xF);
568  dccChStatus_[ 7+chOffset] = ((data[0] >>28) & 0xF);
569  dccChStatus_[ 6+chOffset] = ((data[0] >>24) & 0xF);
570  dccChStatus_[ 5+chOffset] = ((data[0] >>20) & 0xF);
571  dccChStatus_[ 4+chOffset] = ((data[0] >>16) & 0xF);
572  dccChStatus_[ 3+chOffset] = ((data[0] >>12) & 0xF);
573  dccChStatus_[ 2+chOffset] = ((data[0] >>8 ) & 0xF);
574  dccChStatus_[ 1+chOffset] = ((data[0] >>4 ) & 0xF);
575  dccChStatus_[ 0+chOffset] = ((data[0] >>0 ) & 0xF);
576 
577  if(d){
578  out << "FE CH status:";
579  for(int i = chOffset; i < chOffset + 14; ++i){
580  out << " #" << (i+1) << ":" << dccChStatus_[i];
581  }
582  }
583  }
584  break;
585  default:
586  if(d) out << " bits<63..62>=0 (DCC header) bits<61..56>=" << dccHeaderId
587  << "(unknown=>ERROR?)";
588  }
589  } else if((dataType>>1)==3){//TCC block
590  /**********************************************************************
591  * TCC block
592  *
593  **********************************************************************/
594  if(iTccWord64_==0){
595  //header
596  tccL1a_ = (data[1] >>0 ) & 0xFFF;
597  tccId_ = ((data[0] >>0 ) & 0xFF);
598  nTts_ = ((data[1] >>16) & 0x7F);
600  ++iTcc_;
601  if(d) out << "LE1: " << ((data[1] >>28) & 0x1)
602  << " LE0: " << ((data[1] >>27) & 0x1)
603  << " N_samples: " << ((data[1] >>23) & 0x1F)
604  << " N_TTs: " << nTts_
605  << " E1: " << ((data[1] >>12) & 0x1)
606  << " L1A: " << tccL1a_
607  << " '3': " << ((data[0] >>29) & 0x7)
608  << " E0: " << ((data[0] >>28) & 0x1)
609  << " Bx: " << ((data[0] >>16) & 0xFFF)
610  << " TTC ID: " << tccId_;
611  if(nTts_==68){ //EB TCC (TCC68)
612  if(fedId_ < 628) tccType_ = ebmTcc_;
613  else tccType_ = ebpTcc_;
614  } else if(nTts_ == 16){//Inner EE TCC (TCC48)
616  } else if(nTts_ == 28){//Outer EE TCC (TCC48)
618  } else {
619  cout << flush;
620  cerr << "Error in #TT field of TCC block."
621  "This field is normally used to determine type of TCC "
622  "(TCC48 or TCC68). Type of TCC will be deduced from the TCC ID.\n";
623  if(tccId_ < 19) tccType_ = eeInnerTcc_;
624  else if(tccId_ < 37) tccType_ = eeOuterTcc_;
625  else if(tccId_ < 55) tccType_ = ebmTcc_;
626  else if(tccId_ < 73) tccType_ = ebpTcc_;
627  else if(tccId_ < 91) tccType_ = eeOuterTcc_;
628  else if(tccId_ < 109) tccType_ = eeInnerTcc_;
629  else{
630  cerr << "TCC ID is also invalid. EB- TCC type will be assumed.\n";
631  tccType_ = ebmTcc_;
632  }
633  cerr << flush;
634  }
635  tccBlockLen64_ = (tccType_==ebmTcc_ || tccType_==ebpTcc_) ? 18 : 9;
636  } else{// if(iTccWord64_<18){
637  int tpgOffset = (iTccWord64_-1)*4;
638  if(iTcc_ > maxTccsPerDcc_){
639  out << "Too many TCC blocks";
640  } else if(tpgOffset > (maxTpgsPerTcc_ - 4)){
641  out << "Too many TPG in one TCC block";
642  } else{
643  tpg_[iTcc_-1][3+tpgOffset] = (data[1] >>16) & 0x1FF;
644  tpg_[iTcc_-1][2+tpgOffset] = (data[1] >>0 ) & 0x1FF;
645  tpg_[iTcc_-1][1+tpgOffset] = (data[0] >>16) & 0x1FF;
646  tpg_[iTcc_-1][0+tpgOffset] = (data[0] >>0 ) & 0x1FF;
647  //int n[2][4] = {{1,2,3,4},
648  // {4,3,2,1}};
649  //int iorder = (628<=fedId_ && fedId_<=645)?1:0;
650  if(d) out << ttfTag(tccType_, 3+tpgOffset) << ":" //"TTF# " << setw(2) << ttId_[3 + tpgOffset] << ":"
651  << ((data[1] >>25) & 0x7) << " "
652  << tpgTag(tccType_, 3+tpgOffset) << ":" //" TPG# "<< setw(2) << ttId_[3 + tpgOffset] << ":"
653  << setw(3) << tpg_[iTcc_-1][3+tpgOffset] << " "
654  << ttfTag(tccType_, 2+tpgOffset) << ":" //" TTF# "<< setw(2) << ttId_[2 + tpgOffset] << ":"
655  << ((data[1] >>9 ) & 0x7) << " "
656  << tpgTag(tccType_, 2+tpgOffset) << ":" //" TPG# "<< setw(2) << ttId_[2 + tpgOffset] << ":"
657  << setw(3) << tpg_[iTcc_-1][2+tpgOffset] << " "
658  << " '3': " << ((data[0] >>29) & 0x7) << " "
659  << ttfTag(tccType_, 1+tpgOffset) << ":" //" TTF# "<< setw(2) << ttId_[1 + tpgOffset] << ":"
660  << ((data[0] >>25) & 0x7) << " "
661  << setw(3) << tpgTag(tccType_, 1+tpgOffset) << ": "//" TPG# "<< setw(2) << ttId_[1 + tpgOffset] << ":"
662  << tpg_[iTcc_-1][1+tpgOffset] << " "
663  << ttfTag(tccType_, 0+tpgOffset) << ":" //" TTF# "<< setw(2) << ttId_[0 + tpgOffset] << ":"
664  << ((data[0] >>9 ) & 0x7) << " "
665  << setw(3) << tpgTag(tccType_, 0+tpgOffset) << ":" //" TPG# "<< setw(2) << ttId_[0 + tpgOffset] << ":"
666  << tpg_[iTcc_-1][0+tpgOffset];
667  }
668  }// else{
669  // if(d) out << "ERROR";
670  //}
671  ++iTccWord64_;
672  if(iTccWord64_ >= (unsigned)tccBlockLen64_) iTccWord64_ = 0;
673  } else if((dataType>>1)==4){//SRP block
674  /**********************************************************************
675  * SRP block
676  *
677  **********************************************************************/
678  if(iSrWord64_==0){//header
679  srpL1a_ = (data[1] >>0 ) & 0xFFF;
680  srpBx_ = (data[0] >>16) & 0xFFF;
681  if(d) out << "LE1: " << ((data[1] >>28) & 0x1)
682  << " LE0: " << ((data[1] >>27) & 0x1)
683  << " N_SRFs: " << ((data[1] >>16) & 0x7F)
684  << " E1: " << ((data[1] >>12) & 0x1)
685  << " L1A: " << srpL1a_
686  << " '4': " << ((data[0] >>29) & 0x7)
687  << " E0: " << ((data[0] >>28) & 0x1)
688  << " Bx: " << srpBx_
689  << " SRP ID: " << ((data[0] >>0 ) & 0xFF);
690  } else if(iSrWord64_<6){
691  int ttfOffset = (iSrWord64_-1)*16;
692  if(d){
693  if(iSrWord64_<5){
694  out <<"SRF# " << setw(6) << right << srRange(12+ttfOffset)/*16+ttfOffset << "..#" << 13+ttfOffset*/ << ": "
695  << oct << ((data[1] >>16) & 0xFFF) << dec
696  << " SRF# " << srRange(8+ttfOffset) /*12+ttfOffset << "..#" << 9+ttfOffset*/ << ": "
697  << oct << ((data[1] >>0 ) & 0xFFF) << dec
698  << " '4':" << ((data[0] >>29) & 0x7)
699  << " SRF# " << srRange(4+ttfOffset) /*8+ttfOffset << "..#" << 5+ttfOffset*/ << ": "
700  << oct << ((data[0] >>16) & 0xFFF) << dec;
701  } else{//last 64-bit word has only 4 SRFs.
702  out << " ";
703  }
704  out << " SRF# " << srRange(ttfOffset) /*4+ttfOffset << "..#" << 1+ttfOffset*/ << ": "
705  << oct << ((data[0] >>0 ) & 0xFFF) << dec;
706  }
707  } else{
708  if(d) out << "ERROR";
709  }
710  ++iSrWord64_;
711  } else if((dataType>>2)==3){//Tower block
712  /**********************************************************************
713  * "Tower" block (crystal channel data from a RU (=1 FE cards))
714  *
715  **********************************************************************/
716  if(iTowerWord64_==0){//header
717  towerBlockLength_ = (data[1]>>16) & 0x1FF;
718  int l1a;
719  int bx;
720  l1a = (data[1] >>0 ) & 0xFFF;
721  bx = (data[0] >>16) & 0xFFF;
722  dccCh_=(data[0] >>0 ) & 0xFF;
723  if(d) out << "Block Len: " << towerBlockLength_
724  << " E1: " << ((data[1] >>12) & 0x1)
725  << " L1A: " << l1a
726  << " '3': " << ((data[0] >>30) & 0x3)
727  << " E0: " << ((data[0] >>28) & 0x1)
728  << " Bx: " << bx
729  << " N_samples: " << ((data[0] >>8 ) & 0x7F)
730  << " RU ID: " << dccCh_;
731  if(iRu_ < nRu_){
732  feL1a_[iRu_] = l1a;
733  feBx_[iRu_] = bx;
734  feRuId_[iRu_] = dccCh_;
735  ++iRu_;
736  }
737  } else if((unsigned)iTowerWord64_<towerBlockLength_){
738  if(!dumpAdc_){
739  //no output.
740  rc = false;
741  }
742  const bool da = dumpAdc_ && dump_;
743  switch((iTowerWord64_-1)%3){
744  int s[4];
745  int g[4];
746  case 0:
747  s[0]=(data[0] >>16) & 0xFFF;
748  g[0]=(data[0] >>28) & 0x3;
749  s[1]=(data[1] >>0 ) & 0xFFF;
750  g[1]=(data[1] >>12) & 0x3;
751  s[2]=(data[1] >>16) & 0xFFF;
752  g[2]=(data[1] >>28) & 0x3;
753  fill(adc_.begin(), adc_.end(), 0.);
754  if(da) out << "GMF: " << ((data[0] >>11) & 0x1)
755  << " SMF: " << ((data[0] >>9 ) & 0x1)
756  << " M: " << ((data[0] >>8 ) & 0x1)
757  << " XTAL: " << ((data[0] >>4 ) & 0x7)
758  << " STRIP: " << ((data[0] >>0 ) & 0x7)
759  << " " << setw(4) << s[0]
760  << "G" << g[0]
761  << " " << setw(4) << s[1]
762  << "G" << g[1]
763  << " " << setw(4) << s[2]
764  << "G" << g[2];
765  for(int i=0; i<3; ++i) adc_[i] = s[i]*mgpaGainFactors[g[i]];
766  break;
767  case 1:
768  s[0]=(data[0] >>0 ) & 0xFFF;
769  g[0]=(data[0] >>12) & 0x3;
770  s[1]=(data[0] >>16) & 0xFFF;
771  g[1]=(data[0] >>28) & 0x3;
772  s[2]=(data[1] >>0 ) & 0xFFF;
773  g[2]=(data[1] >>12) & 0x3;
774  s[3]=(data[1] >>16) & 0xFFF;
775  g[3]=(data[1] >>28) & 0x3;
776  if(da) out << " "
777  << " " << setw(4) << s[0]
778  << "G" << g[0]
779  << " " << setw(4) << s[1]
780  << "G" << g[1]
781  << " " << setw(4) << s[2]
782  << "G" << g[2]
783  << " " << setw(4) << s[3]
784  << "G" << g[3];
785  for(int i=0; i<4; ++i) adc_[i+3] = s[i]*mgpaGainFactors[g[i]];
786  break;
787  case 2:
788  if(da) out << "TZS: " << ((data[1] >>14) & 0x1);
789 
790  s[0]=(data[0] >>0 ) & 0xFFF;
791  g[0]=(data[0] >>12) & 0x3;
792  s[1]=(data[0] >>16) & 0xFFF;
793  g[1]=(data[0] >>28) & 0x3;
794  s[2]=(data[1] >>0 ) & 0xFFF;
795  g[2]=(data[1] >>12) & 0x3 ;
796 
797  for(int i=0; i<3; ++i) adc_[i+7] = s[i]*mgpaGainFactors[g[i]];
798  if(dccCh_<=68){
799  unsigned bom0; //Bin of Maximum, starting counting from 0
800  double ampl = max(adc_, bom0)-min(adc_);
801  if(da) out << " Ampl: " << setw(4) << ampl
802  << (ampl>amplCut_?"*":" ")
803  << " BoM:" << setw(2) << (bom0+1)
804  << " ";
805  if(fedId_ == dccId_ + 600 //block of the read-out SM
806  //if laser, only one side:
807  && (detailedTrigType_!=4 || sideOfRu(dccCh_)==(int)side_)
808  ){
809  }
810  } else{
811  if(da) out << setw(29) << "";
812  }
813  if(da) out << " " << setw(4) << s[0]
814  << "G" << g[0]
815  << " " << setw(4) << s[1]
816  << "G" << g[1]
817  << " " << setw(4) << s[2]
818  << "G" << g[2];
819  break;
820  default:
821  assert(false);
822  }
823  } else {
824  if(d) out << "ERROR";
825  }
826  ++iTowerWord64_;
829  ++dccCh_;
830  }
831  } else if(dataType==eoe){//End of event trailer
832  /**********************************************************************
833  * Event DAQ trailer
834  *
835  **********************************************************************/
836  int tts = (data[0] >>4) & 0xF;
837  if(d) out << "Evt Len.: " << ((data[1] >>0 ) & 0xFFFFFF)
838  << " CRC16: " << ((data[0] >>16) & 0xFFFF)
839  << " Evt Status: " << ((data[0] >>8 ) & 0xF)
840  << " TTS: " << tts
841  << " (" << ttsNames[tts] << ")"
842  << " T:" << ((data[0] >>3) & 0x1);
843  } else{
844  if(d) out << " incorrect 64-bit word type marker (see MSBs)";
845  }
846  return rc;
847 }
848 
849 // The following method was not removed due to package maintainer
850 // (Philippe Gras <philippe.gras@cern.ch>) request.
851 
852 //int EcalDumpRaw::lme(int dcc1, int side){
853 // int fedid = ((dcc1-1)%600) + 600; //to handle both FED and DCC id.
854 // vector<int> lmes;
855 // // EE -
856 // if( fedid <= 609 ) {
857 // if ( fedid <= 607 ) {
858 // lmes.push_back(fedid-601+83);
859 // } else if ( fedid == 608 ) {
860 // lmes.push_back(90);
861 // lmes.push_back(91);
862 // } else if ( fedid == 609 ) {
863 // lmes.push_back(92);
864 // }
865 // } //EB
866 // else if ( fedid >= 610 && fedid <= 645 ) {
867 // lmes.push_back(2*(fedid-610)+1);
868 // lmes.push_back(lmes[0]+1);
869 // } // EE+
870 // else if ( fedid >= 646 ) {
871 // if ( fedid <= 652 ) {
872 // lmes.push_back(fedid-646+73);
873 // } else if ( fedid == 653 ) {
874 // lmes.push_back(80);
875 // lmes.push_back(81);
876 // } else if ( fedid == 654 ) {
877 // lmes.push_back(82);
878 // }
879 // }
880 // return lmes.size()==0?-1:lmes[std::min(lmes.size(), (size_t)side)];
881 //}
882 
883 
885  if(ru1 < 5 || (ru1-5)%4 >= 2){
886  return 0;
887  } else{
888  return 1;
889  }
890 }
891 
892 
893 int EcalDumpRaw::modOfRu(int ru1){
894  int iEta0 = (ru1-1)/4;
895  if(iEta0<5){
896  return 1;
897  } else{
898  return 2 + (iEta0-5)/4;
899  }
900 }
901 
903  int iEta0 = (ru1-1)/4;
904  int iPhi0 = (ru1-1)%4;
905  int rs;
906  if(iEta0==0){
907  rs = 1;
908  } else{
909  rs = 2 + ((iEta0-1)/4)*2 + (iPhi0%4)/2;
910  }
911  // cout << "ru1 = " << ru1 << " -> lmod = " << rs << "\n";
912  return rs;
913 }
914 
916  int min = offset+1;
917  int max = offset+4;
918  stringstream buf;
919  if(628 <= fedId_ && fedId_ <= 646){//EB+
920  buf << right << min << ".."
921  << left << max;
922  } else{
923  buf << right << max << ".."
924  << left << min;
925  }
926  string s = buf.str();
927  buf.str("");
928  buf << setw(6) << right << s;
929  return buf.str();
930 }
931 
932 std::string EcalDumpRaw::ttfTag(int tccType, unsigned iSeq) const{
933  if((unsigned)iSeq > sizeof(ttId_))
934  throw cms::Exception("OutOfRange")
935  << __FILE__ << ":" << __LINE__ << ": "
936  << "parameter out of range\n";
937 
938  const int ttId = ttId_[tccType][iSeq];
939  stringstream buf;
940  buf.str("");
941  if(ttId==0){
942  buf << " '0'";
943  } else{
944  buf << "TTF# " << setw(2) << ttId;
945  }
946  return buf.str();
947 }
948 
949 std::string EcalDumpRaw::tpgTag(int tccType, unsigned iSeq) const{
950  if((unsigned)iSeq > sizeof(ttId_))
951  throw cms::Exception("OutOfRange")
952  << __FILE__ << ":" << __LINE__ << ": "
953  << "parameter out of range\n";
954 
955  const int ttId = ttId_[tccType][iSeq];
956  stringstream buf;
957  buf.str("");
958  if(ttId==0){
959  buf << " '0'";
960  } else{
961  buf << "TPG# " << setw(2) << ttId;
962  }
963  return buf.str();
964 }
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: EcalDumpRaw.cc:210
int tccBlockLen64_
Definition: EcalDumpRaw.h:168
T getUntrackedParameter(std::string const &, T const &) const
static int sideOfRu(int ru1)
Definition: EcalDumpRaw.cc:884
int i
Definition: DBlmapReader.cc:9
std::string toNth(int n)
Definition: EcalDumpRaw.cc:457
std::string tpgTag(int tccType, unsigned iSeq) const
Definition: EcalDumpRaw.cc:949
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
int end_fed_id_
Definition: EcalDumpRaw.h:92
string fill
Definition: lumiContext.py:319
unsigned iTowerWord64_
Definition: EcalDumpRaw.h:98
static const int nRu_
Definition: EcalDumpRaw.h:169
static const unsigned fedStart_
Definition: EcalDumpRaw.h:121
bool orbit0Set_
Definition: EcalDumpRaw.h:149
size_t towerBlockLength_
Definition: EcalDumpRaw.h:103
std::string ttfTag(int tccType, unsigned iSeq) const
Definition: EcalDumpRaw.cc:932
int detailedTrigType_
Definition: EcalDumpRaw.h:155
double min(const std::vector< double > &a)
Definition: EcalDumpRaw.h:59
std::vector< double > adc_
Definition: EcalDumpRaw.h:105
assert(m_qm.get())
bool l1aHistory_
Definition: EcalDumpRaw.h:111
int first_event_
Definition: EcalDumpRaw.h:93
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
double amplCut_
Definition: EcalDumpRaw.h:108
unsigned ttId(DetId const &)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
static int modOfRu(int ru1)
Definition: EcalDumpRaw.cc:893
unsigned minEventId_
Definition: EcalDumpRaw.h:145
bool writeDcc_
Definition: EcalDumpRaw.h:90
std::vector< uint32_t > lastOrbit_
Definition: EcalDumpRaw.h:119
bool decode(const uint32_t *data, int iWord32, std::ostream &out)
Definition: EcalDumpRaw.cc:481
std::vector< unsigned > eventList_
Definition: EcalDumpRaw.h:144
static int lmodOfRu(int ru1)
Definition: EcalDumpRaw.cc:902
unsigned side_
Definition: EcalDumpRaw.h:142
std::vector< int > feL1a_
Definition: EcalDumpRaw.h:170
static const char *const ttsNames[]
Definition: EcalDumpRaw.cc:103
static const int eeOuterTcc_
Definition: EcalDumpRaw.h:132
uint32_t orbit_
Definition: EcalDumpRaw.h:148
std::vector< int > feBx_
Definition: EcalDumpRaw.h:175
static const int ttId_[nTccTypes_][maxTpgsPerTcc_]
Definition: EcalDumpRaw.h:138
void endJob()
Definition: EcalDumpRaw.cc:202
static const int ebmTcc_
Definition: EcalDumpRaw.h:129
unsigned maxEventId_
Definition: EcalDumpRaw.h:146
std::ofstream dumpFile_
Definition: EcalDumpRaw.h:178
edm::InputTag fedRawDataCollectionTag_
Definition: EcalDumpRaw.h:185
unsigned iTccWord64_
Definition: EcalDumpRaw.h:100
std::string filename_
Definition: EcalDumpRaw.h:95
std::vector< int > nTpgs_
Definition: EcalDumpRaw.h:160
EcalDumpRaw(const edm::ParameterSet &)
Definition: EcalDumpRaw.cc:128
static const char *const detailedTrigNames[]
Definition: EcalDumpRaw.cc:85
T min(T a, T b)
Definition: MathUtil.h:58
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:75
unsigned iSrWord64_
Definition: EcalDumpRaw.h:99
std::vector< std::vector< int > > tpg_
Definition: EcalDumpRaw.h:159
tuple out
Definition: dbtoconf.py:99
unsigned fedId_
Definition: EcalDumpRaw.h:140
static int lastFEDId()
Definition: FEDNumbering.cc:17
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:74
std::string srRange(int offset) const
Definition: EcalDumpRaw.cc:915
static const double mgpaGainFactors[]
Definition: EcalDumpRaw.cc:126
int simpleTrigType_
Definition: EcalDumpRaw.h:154
int tccType_
type of TCC currently parsed
Definition: EcalDumpRaw.h:174
std::vector< int > dccChStatus_
Definition: EcalDumpRaw.h:161
static const char *const colorNames[]
Definition: EcalDumpRaw.cc:96
static const int eeInnerTcc_
Definition: EcalDumpRaw.h:131
std::vector< int > feRuId_
Definition: EcalDumpRaw.h:176
static const int maxTpgsPerTcc_
Definition: EcalDumpRaw.h:122
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const int feBxOffset
Definition: EcalDumpRaw.cc:33
edm::InputTag l1AcceptBunchCrossingCollectionTag_
Definition: EcalDumpRaw.h:186
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
unsigned eventId_
Definition: EcalDumpRaw.h:143
unsigned orbit0_
Definition: EcalDumpRaw.h:147
tuple cout
Definition: gather_cfg.py:121
dictionary rawdata
Definition: lumiPlot.py:393
volatile std::atomic< bool > shutdown_flag false
int beg_fed_id_
Definition: EcalDumpRaw.h:91
static const unsigned nDccs_
Definition: EcalDumpRaw.h:120
static const int maxTccsPerDcc_
Definition: EcalDumpRaw.h:123
int verbosity_
Definition: EcalDumpRaw.h:89
double max(const std::vector< double > &a, unsigned &pos)
Definition: EcalDumpRaw.h:51
unsigned dccId_
Definition: EcalDumpRaw.h:141
int last_event_
Definition: EcalDumpRaw.h:94
static const int ebpTcc_
Definition: EcalDumpRaw.h:130