CMS 3D CMS Logo

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  simpleTrigType_(-1),
151  detailedTrigType_(-1),
152  // histo_("hist.root", "RECREATE"),
153  l1as_(36+2),
154  orbits_(36+2),
155  tpg_(maxTccsPerDcc_, std::vector<int>(maxTpgsPerTcc_)),
156  nTpgs_(maxTccsPerDcc_, 0),
157  dccChStatus_(70, 0),
158  srpL1a_(-1),
159  tccL1a_(-1),
160  nTts_(-1),
161  tccBlockLen64_(19),
162  feL1a_(nRu_,-1),
163  srpBx_(-1),
164  tccBx_(-1),
165  tccType_(0),
166  feBx_(nRu_,-1),
167  feRuId_(nRu_,-1),
168  iTow_(0),
169  pulsePerRu_(ps.getUntrackedParameter<bool>("pulsePerRu", true)),
170  pulsePerLmod_(ps.getUntrackedParameter<bool>("pulsePerLmod", true)),
171  pulsePerLme_(ps.getUntrackedParameter<bool>("pulsePerLme", true)),
172  tccId_(0),
173  fedRawDataCollectionTag_(ps.getParameter<edm::InputTag>("fedRawDataCollectionTag")),
174  l1AcceptBunchCrossingCollectionTag_(ps.getParameter<edm::InputTag>("l1AcceptBunchCrossingCollectionTag"))
175 {
176  verbosity_= ps.getUntrackedParameter<int>("verbosity",1);
177 
178  beg_fed_id_= ps.getUntrackedParameter<int>("beg_fed_id",601);
179  end_fed_id_= ps.getUntrackedParameter<int>("end_fed_id",654);
180 
181 
182  first_event_ = ps.getUntrackedParameter<int>("first_event",1);
183  last_event_ = ps.getUntrackedParameter<int>("last_event",
185 
186  writeDcc_ = ps.getUntrackedParameter<bool>("writeDCC",false);
187  filename_ = ps.getUntrackedParameter<string>("filename","dump.bin");
188 
189  fedRawDataCollectionToken_ = consumes<FEDRawDataCollection>(fedRawDataCollectionTag_);
190  l1AcceptBunchCrossingCollectionToken_ = consumes<L1AcceptBunchCrossingCollection>(l1AcceptBunchCrossingCollectionTag_);
191 
192  if(writeDcc_){
193  dumpFile_.open(filename_.c_str());
194  if(dumpFile_.bad()){
195  /*edm::LogError("EcalDumpRaw")*/ std::cout << "Failed to open file '"
196  << filename_.c_str() << "' specified by "
197  << "parameter filename for writing. DCC data "
198  " dump will be disabled.";
199  writeDcc_ = false;
200  }
201  }
202 }
203 
205 }
206 
208 }
209 
210 // ------------ method called to analyze the data ------------
211 void
213  ++iEvent_;
214  eventId_ = event.id().event();
215 
216  if(!eventList_.empty() && find(eventList_.begin(), eventList_.end(),
217  eventId_) == eventList_.end()){
218  cout << "Skipping event " << eventId_ << ".\n";
219  return;
220  }
221 
222  if ((first_event_ > 0 && iEvent_ < first_event_) ||
223  (last_event_ > 0 && last_event_ < iEvent_)) return;
224  timeval start;
225  timeval stop;
226  gettimeofday(&start, nullptr);
227 
229  event.getByToken(fedRawDataCollectionToken_, rawdata);
230 
231  if(dump_ || l1aHistory_) cout << "\n======================================================================\n"
232  << toNth(iEvent_)
233  << " read event. "
234  << "Event id: "
235  << " " << eventId_
236  << "\n----------------------------------------------------------------------\n";
237 
238  if(l1aHistory_){
240  event.getByToken(l1AcceptBunchCrossingCollectionToken_, l1aHist);
241  if(!l1aHist.isValid()) {
242  cout << "L1A history not found.\n";
243  } else if (l1aHist->empty()) {
244  cout << "L1A history is empty.\n";
245  } else{
246  cout << "L1A history: \n";
247  for(L1AcceptBunchCrossingCollection::const_iterator it = l1aHist->begin();
248  it != l1aHist->end();
249  ++it){
250  cout << "L1A offset: " << it->l1AcceptOffset() << "\t"
251  << "BX: " << it->bunchCrossing() << "\t"
252  << "Orbit ID: " << it->orbitNumber() << "\t"
253  << "Trigger type: " << it->eventType() << " ("
254  << trigNames[it->eventType()&0xF] << ")\n";
255  }
256  }
257  cout << "----------------------------------------------------------------------\n";
258  }
259 
260  if(eventId_ < minEventId_) minEventId_ = eventId_;
261  if(eventId_ > maxEventId_) maxEventId_ = eventId_;
262 
263 #if 1
264 
265  bool dccIdErr = false;
266  unsigned iFed = 0;
267  unsigned refDccId = 0;
268  // static bool recordNextPhys = false;
269  //static int bxCalib = -1;
270  //x static int nCalib = 0;
271 
272  for (int id = 0; id<=FEDNumbering::lastFEDId(); ++id){
273 
274  if (id < beg_fed_id_ || end_fed_id_ < id) continue;
275 
276  const FEDRawData& data = rawdata->FEDData(id);
277 
278  if (data.size()>4){
279  ++iFed;
280  if ((data.size() % 8) !=0){
281  cout << "***********************************************\n";
282  cout << " Fed size in bits not multiple of 64, strange.\n";
283  cout << "***********************************************\n";
284  }
285 
286 
287  size_t nWord32 = data.size()/4;
288  const uint32_t * pData = ( reinterpret_cast<uint32_t*>(const_cast<unsigned char*> ( data.data())));
289  stringstream s;
290  srpL1a_ = -1;
291  tccL1a_ = -1;
292  srpBx_ = -1;
293  tccBx_ = -1;
294  iTow_ = 0;
295  iRu_ = 0;
296  nTts_ = -1;
297  iTcc_ = 0;
298  tccType_ = 0;
299 
300  for(int i = 0; i < nRu_; ++i){
301  feL1a_[i] = -1;
302  feBx_[i] = -1;
303  feRuId_[i] = -1;
304  }
305 
306  fill(nTpgs_.begin(), nTpgs_.end(), 0);
307 
308  fill(dccChStatus_.begin(), dccChStatus_.end(), 0);
309 
310  bool rc;
311  for(size_t iWord32=0; iWord32 < nWord32; iWord32+=2){
312  s.str("");
313  if(id>=601 && id<=654){// ECAL DCC data
314  rc = decode(pData+iWord32, iWord32/2, s);
315  } else{
316  rc = true;
317  }
318  if(rc && dump_){
319  cout << setfill('0') << hex
320  << "[" << setw(8) << iWord32*4 << "] "
321  << setw(4) << (pData[iWord32+1]>>16 & 0xFFFF) << " "
322  << setw(4) << (pData[iWord32+1]>>0 & 0xFFFF) << " "
323  << setw(4) << (pData[iWord32]>>16 & 0xFFFF) << " "
324  << setw(4) << (pData[iWord32]>>0 & 0xFFFF) << " "
325  << setfill(' ') << dec
326  << s.str() << "\n";
327  }
328  }
329 
330  if(iFed==1){
331  refDccId = dccId_;
332  } else{
333  if(dccId_!=refDccId){
334  dccIdErr = true;
335  }
336  }
337 
338  if(dump_) cout << flush; //flushing cout before writing to cerr
339 
340  if(srpBx_!=-1 && srpBx_!=bx_){
341  cerr << "Bx discrepancy between SRP and DCC, Bx(SRP) = "
342  << srpBx_ << ", Bx(DCC) = " << bx_
343  << " in " << toNth(iEvent_) << " event, FED "
344  << id << endl;
345  }
346 
347  if(tccBx_!=-1 && tccBx_!=bx_){
348  cerr << "Bx discrepancy between TCC and DCC, Bx(TCC) = "
349  << srpBx_ << ", Bx(DCC) = " << bx_
350  << " in " << toNth(iEvent_) << " event, FED "
351  << id << endl;
352  }
353 
354  bool feBxErr = false;
355  for(int i=0; i < nRu_; ++i){
356  int expectedFeBx;
357  if(feBxOffset==0){
358  expectedFeBx = bx_ - 1;
359  } else{
360  expectedFeBx = (bx_==3564) ? 0 : bx_;
361  }
362  if(feBx_[i]!=-1 && feBx_[i]!=expectedFeBx){
363  cerr << "BX error for " << toNth(i+1) << " RU, RU ID "
364  << feRuId_[i];
365  if((unsigned) feRuId_[i] <= dccChStatus_.size()){
366  bool detected = (dccChStatus_[feRuId_[i]-1] == 10 || dccChStatus_[feRuId_[i]-1] == 11);
367  cerr << (detected?" ":" not ") << "detected by DCC (ch status: "
368  << dccChStatus_[feRuId_[i]-1] << ")";
369  }
370  cerr << " in " << toNth(iEvent_) << " event, FED "
371  << id << "." << endl;
372 
373  feBxErr = true;
374  }
375  }
376  if(feBxErr) cerr << "Bx discrepancy between DCC and at least one FE"
377  << " in " << toNth(iEvent_) << " event, FED "
378  << id << "\n";
379 
380 
381  int localL1a = l1a_ & 0xFFF;
382  if(srpL1a_!=-1 && srpL1a_!=localL1a){
383  cerr << "Discrepancy between SRP and DCC L1a counter, L1a(SRP) = "
384  << srpL1a_ << ", L1a(DCC) & 0xFFF = " << localL1a
385  << " in " << toNth(iEvent_) << " event, FED "
386  << id << endl;
387 
388  }
389 
390  if(tccL1a_!=-1 && tccL1a_!=localL1a){
391  cerr << "Discrepancy between TCC and DCC L1a counter, L1a(TCC) = "
392  << srpL1a_ << ", L1a(DCC) & 0xFFF = " << localL1a
393  << " in " << toNth(iEvent_) << " event, FED "
394  << id << endl;
395 
396  }
397 
398  bool feL1aErr = false;
399  for(int i=0; i < nRu_; ++i){
400  if(feL1a_[i] != -1 && feL1a_[i] != ((localL1a-1) & 0xFFF)){
401  cerr << "FE L1A error for " << toNth(i+1) << " RU, RU ID "
402  << feRuId_[i];
403  if((unsigned) feRuId_[i] <= dccChStatus_.size()){
404  bool detected = (dccChStatus_[feRuId_[i]-1] == 9 || dccChStatus_[feRuId_[i]-1] == 11);
405  cerr << (detected?" ":" not ") << "detected by DCC (ch status: "
406  << dccChStatus_[feRuId_[i]-1] << ")";
407  }
408  cerr << " in " << toNth(iEvent_) << " event, FED "
409  << id << "." << endl;
410  feL1aErr = true;
411  }
412  }
413  if(feL1aErr) cerr << "Discrepancy in L1a counter between DCC "
414  "and at least one FE (L1A(DCC) & 0xFFF = " << localL1a << ")"
415  << " in " << toNth(iEvent_) << " event, FED "
416  << id << "\n";
417 
418 
419  if(iTow_>0 && iTow_< nRu_ && feRuId_[iTow_] < feRuId_[iTow_-1]){
420  cerr << "Error in RU ID (TT/SC ID)"
421  << " in " << toNth(iEvent_) << " event, FED "
422  << id << endl;
423  }
424 
425  if (beg_fed_id_ <= id && id <= end_fed_id_ && writeDcc_){
426  dumpFile_.write( reinterpret_cast <const char *> (pData), nWord32*4);
427  }
428 
429  if(dump_) cout << "\n";
430  } else{
431  // cout << "No data for FED " << id << ". Size = "
432  // << data.size() << " byte(s).\n";
433  }
434  } //next fed
435 
436  if(dump_) cout << "Number of selected FEDs with a data block: "
437  << iFed << "\n";
438 
439  if(dccIdErr){
440  cout << flush;
441  cerr << "DCC ID discrepancy in detailed trigger type "
442  << " of " << toNth(iEvent_) << " event." << endl;
443  }
444 
445 #endif
446 
447  gettimeofday(&stop, nullptr);
448  // double dt = (stop.tv_sec-start.tv_sec)*1.e3
449  // + (stop.tv_usec-start.tv_usec)*1.e-3;
450  // histo_.fillD("hCodeTime", "Code execution time;Duration (ms);Event count",
451  // PGXAxis(100, 0, 100),
452  // dt);
453 }
454 
455 string EcalDumpRaw::toNth(int n){
456  stringstream s;
457  s << n;
458  if(n%100<10 || n%100>20){
459  switch(n%10){
460  case 1:
461  s << "st";
462  break;
463  case 2:
464  s << "nd";
465  break;
466  case 3:
467  s << "rd";
468  break;
469  default:
470  s << "th";
471  }
472  } else{
473  s << "th";
474  }
475  return s.str();
476 }
477 
478 
479 bool EcalDumpRaw::decode(const uint32_t* data, int iWord64, ostream& out){
480  bool rc = true;
481  const bool d = dump_;
482  if(iWord64==0){//start of event
483  iSrWord64_ = 0;
484  iTccWord64_ = 0;
485  iTowerWord64_ = 0;
486  }
487  int dataType = (data[1] >>28) & 0xF;
488  const int boe = 5;
489  const int eoe = 10;
490  if(dataType==boe){//Begin of Event header
491  /**********************************************************************
492  * DAQ header
493  *
494  **********************************************************************/
495  simpleTrigType_ = (data[1] >>24) & 0xF;
496  l1a_ = (data[1]>>0 ) & 0xFFffFF;
497  bx_ = (data[0] >>20) & 0xFFF;
498  fedId_ = (data[0] >>8 ) & 0xFFF;
499  if(d) out << "Trigger type: " << simpleTrigType_
500  << "(" << trigNames[(data[1]>>24) & 0xF] << ")"
501  << " L1A: " << l1a_
502  << " BX: " << bx_
503  << " FED ID: " << fedId_
504  << " FOV: " << ((data[0] >>4 ) & 0xF)
505  << " H: " << ((data[0] >>3 ) & 0x1);
506  } else if((dataType>>2)==0){//DCC header
507  /**********************************************************************
508  * ECAL DCC header
509  *
510  **********************************************************************/
511  int dccHeaderId = (data[1] >>24) & 0x3F;
512  switch(dccHeaderId){
513  case 1:
514  if(d) out << "Run #: " << ((data[1] >>0 ) & 0xFFFFFF)
515  << " DCC Err: " << ((data[0] >>24) & 0xFF)
516  << " Evt Len: " << ((data[0] >>0 ) & 0xFFFFFF);
517  break;
518  case 2:
519  side_ = (data[1] >>11) & 0x1;
520  detailedTrigType_ = (data[1] >>8 ) & 0x7;
521  dccId_ = (data[1] >>0 ) & 0x3F;
522  if(d) out << "DCC FOV: " << ((data[1] >>16) & 0xF)
523  << " Side: " << side_
524  << " Trig.: " << detailedTrigType_
525  << " (" << detailedTrigNames[(data[1]>>8)&0x7] << ")"
526  << " Color: " << ((data[1] >>6 ) & 0x3)
527  << " (" << colorNames[(data[1]>>6)&0x3] << ")"
528  << " DCC ID: " << dccId_;
529  break;
530  case 3:
531  {
532  if(d) out << "TCC Status ch<4..1>: 0x"
533  << hex << ((data[1]>>8) & 0xFFFF) << dec
534  << " SR status: " << ((data[1] >>4 ) & 0xF)
535  << " TZS: " << ((data[1] >>2 ) & 0x1)
536  << " ZS: " << ((data[1] >>1 ) & 0x1)
537  << " SR: " << ((data[1] >>0 ) & 0x1);
538  orbit_ = data[0];
539  if(d) out << " Orbit: " << orbit_;
540  if(!orbit0Set_){
541  orbit0_ = orbit_;
542  orbit0Set_ = true;
543  }
544  int iDcc0 = fedId_-fedStart_;
545  if((unsigned)iDcc0<nDccs_){
547  if(d) out << " (+" << (int)orbit_-(int)lastOrbit_[iDcc0] <<")";
548  }
549  lastOrbit_[iDcc0] = orbit_;
550  }
551  }
552  break;
553  case 4:
554  case 5:
555  case 6:
556  case 7:
557  case 8:
558  {
559  int chOffset = (dccHeaderId-4)*14;
560  dccChStatus_[13+chOffset] = ((data[1] >>20) & 0xF);
561  dccChStatus_[12+chOffset] = ((data[1] >>16) & 0xF);
562  dccChStatus_[11+chOffset] = ((data[1] >>12) & 0xF);
563  dccChStatus_[10+chOffset] = ((data[1] >>8 ) & 0xF);
564  dccChStatus_[ 9+chOffset] = ((data[1] >>4 ) & 0xF);
565  dccChStatus_[ 8+chOffset] = ((data[1] >>0) & 0xF);
566  dccChStatus_[ 7+chOffset] = ((data[0] >>28) & 0xF);
567  dccChStatus_[ 6+chOffset] = ((data[0] >>24) & 0xF);
568  dccChStatus_[ 5+chOffset] = ((data[0] >>20) & 0xF);
569  dccChStatus_[ 4+chOffset] = ((data[0] >>16) & 0xF);
570  dccChStatus_[ 3+chOffset] = ((data[0] >>12) & 0xF);
571  dccChStatus_[ 2+chOffset] = ((data[0] >>8 ) & 0xF);
572  dccChStatus_[ 1+chOffset] = ((data[0] >>4 ) & 0xF);
573  dccChStatus_[ 0+chOffset] = ((data[0] >>0 ) & 0xF);
574 
575  if(d){
576  out << "FE CH status:";
577  for(int i = chOffset; i < chOffset + 14; ++i){
578  out << " #" << (i+1) << ":" << dccChStatus_[i];
579  }
580  }
581  }
582  break;
583  default:
584  if(d) out << " bits<63..62>=0 (DCC header) bits<61..56>=" << dccHeaderId
585  << "(unknown=>ERROR?)";
586  }
587  } else if((dataType>>1)==3){//TCC block
588  /**********************************************************************
589  * TCC block
590  *
591  **********************************************************************/
592  if(iTccWord64_==0){
593  //header
594  tccL1a_ = (data[1] >>0 ) & 0xFFF;
595  tccId_ = ((data[0] >>0 ) & 0xFF);
596  nTts_ = ((data[1] >>16) & 0x7F);
598  ++iTcc_;
599  if(d) out << "LE1: " << ((data[1] >>28) & 0x1)
600  << " LE0: " << ((data[1] >>27) & 0x1)
601  << " N_samples: " << ((data[1] >>23) & 0x1F)
602  << " N_TTs: " << nTts_
603  << " E1: " << ((data[1] >>12) & 0x1)
604  << " L1A: " << tccL1a_
605  << " '3': " << ((data[0] >>29) & 0x7)
606  << " E0: " << ((data[0] >>28) & 0x1)
607  << " Bx: " << ((data[0] >>16) & 0xFFF)
608  << " TTC ID: " << tccId_;
609  if(nTts_==68){ //EB TCC (TCC68)
610  if(fedId_ < 628) tccType_ = ebmTcc_;
611  else tccType_ = ebpTcc_;
612  } else if(nTts_ == 16){//Inner EE TCC (TCC48)
614  } else if(nTts_ == 28){//Outer EE TCC (TCC48)
616  } else {
617  cout << flush;
618  cerr << "Error in #TT field of TCC block."
619  "This field is normally used to determine type of TCC "
620  "(TCC48 or TCC68). Type of TCC will be deduced from the TCC ID.\n";
621  if(tccId_ < 19) tccType_ = eeInnerTcc_;
622  else if(tccId_ < 37) tccType_ = eeOuterTcc_;
623  else if(tccId_ < 55) tccType_ = ebmTcc_;
624  else if(tccId_ < 73) tccType_ = ebpTcc_;
625  else if(tccId_ < 91) tccType_ = eeOuterTcc_;
626  else if(tccId_ < 109) tccType_ = eeInnerTcc_;
627  else{
628  cerr << "TCC ID is also invalid. EB- TCC type will be assumed.\n";
629  tccType_ = ebmTcc_;
630  }
631  cerr << flush;
632  }
633  tccBlockLen64_ = (tccType_==ebmTcc_ || tccType_==ebpTcc_) ? 18 : 9;
634  } else{// if(iTccWord64_<18){
635  int tpgOffset = (iTccWord64_-1)*4;
636  if(iTcc_ > maxTccsPerDcc_){
637  out << "Too many TCC blocks";
638  } else if(tpgOffset > (maxTpgsPerTcc_ - 4)){
639  out << "Too many TPG in one TCC block";
640  } else{
641  tpg_[iTcc_-1][3+tpgOffset] = (data[1] >>16) & 0x1FF;
642  tpg_[iTcc_-1][2+tpgOffset] = (data[1] >>0 ) & 0x1FF;
643  tpg_[iTcc_-1][1+tpgOffset] = (data[0] >>16) & 0x1FF;
644  tpg_[iTcc_-1][0+tpgOffset] = (data[0] >>0 ) & 0x1FF;
645  //int n[2][4] = {{1,2,3,4},
646  // {4,3,2,1}};
647  //int iorder = (628<=fedId_ && fedId_<=645)?1:0;
648  if(d) out << ttfTag(tccType_, 3+tpgOffset) << ":" //"TTF# " << setw(2) << ttId_[3 + tpgOffset] << ":"
649  << ((data[1] >>25) & 0x7) << " "
650  << tpgTag(tccType_, 3+tpgOffset) << ":" //" TPG# "<< setw(2) << ttId_[3 + tpgOffset] << ":"
651  << setw(3) << tpg_[iTcc_-1][3+tpgOffset] << " "
652  << ttfTag(tccType_, 2+tpgOffset) << ":" //" TTF# "<< setw(2) << ttId_[2 + tpgOffset] << ":"
653  << ((data[1] >>9 ) & 0x7) << " "
654  << tpgTag(tccType_, 2+tpgOffset) << ":" //" TPG# "<< setw(2) << ttId_[2 + tpgOffset] << ":"
655  << setw(3) << tpg_[iTcc_-1][2+tpgOffset] << " "
656  << " '3': " << ((data[0] >>29) & 0x7) << " "
657  << ttfTag(tccType_, 1+tpgOffset) << ":" //" TTF# "<< setw(2) << ttId_[1 + tpgOffset] << ":"
658  << ((data[0] >>25) & 0x7) << " "
659  << setw(3) << tpgTag(tccType_, 1+tpgOffset) << ": "//" TPG# "<< setw(2) << ttId_[1 + tpgOffset] << ":"
660  << tpg_[iTcc_-1][1+tpgOffset] << " "
661  << ttfTag(tccType_, 0+tpgOffset) << ":" //" TTF# "<< setw(2) << ttId_[0 + tpgOffset] << ":"
662  << ((data[0] >>9 ) & 0x7) << " "
663  << setw(3) << tpgTag(tccType_, 0+tpgOffset) << ":" //" TPG# "<< setw(2) << ttId_[0 + tpgOffset] << ":"
664  << tpg_[iTcc_-1][0+tpgOffset];
665  }
666  }// else{
667  // if(d) out << "ERROR";
668  //}
669  ++iTccWord64_;
670  if(iTccWord64_ >= (unsigned)tccBlockLen64_) iTccWord64_ = 0;
671  } else if((dataType>>1)==4){//SRP block
672  /**********************************************************************
673  * SRP block
674  *
675  **********************************************************************/
676  if(iSrWord64_==0){//header
677  srpL1a_ = (data[1] >>0 ) & 0xFFF;
678  srpBx_ = (data[0] >>16) & 0xFFF;
679  if(d) out << "LE1: " << ((data[1] >>28) & 0x1)
680  << " LE0: " << ((data[1] >>27) & 0x1)
681  << " N_SRFs: " << ((data[1] >>16) & 0x7F)
682  << " E1: " << ((data[1] >>12) & 0x1)
683  << " L1A: " << srpL1a_
684  << " '4': " << ((data[0] >>29) & 0x7)
685  << " E0: " << ((data[0] >>28) & 0x1)
686  << " Bx: " << srpBx_
687  << " SRP ID: " << ((data[0] >>0 ) & 0xFF);
688  } else if(iSrWord64_<6){
689  int ttfOffset = (iSrWord64_-1)*16;
690  if(d){
691  if(iSrWord64_<5){
692  out <<"SRF# " << setw(6) << right << srRange(12+ttfOffset)/*16+ttfOffset << "..#" << 13+ttfOffset*/ << ": "
693  << oct << ((data[1] >>16) & 0xFFF) << dec
694  << " SRF# " << srRange(8+ttfOffset) /*12+ttfOffset << "..#" << 9+ttfOffset*/ << ": "
695  << oct << ((data[1] >>0 ) & 0xFFF) << dec
696  << " '4':" << ((data[0] >>29) & 0x7)
697  << " SRF# " << srRange(4+ttfOffset) /*8+ttfOffset << "..#" << 5+ttfOffset*/ << ": "
698  << oct << ((data[0] >>16) & 0xFFF) << dec;
699  } else{//last 64-bit word has only 4 SRFs.
700  out << " ";
701  }
702  out << " SRF# " << srRange(ttfOffset) /*4+ttfOffset << "..#" << 1+ttfOffset*/ << ": "
703  << oct << ((data[0] >>0 ) & 0xFFF) << dec;
704  }
705  } else{
706  if(d) out << "ERROR";
707  }
708  ++iSrWord64_;
709  } else if((dataType>>2)==3){//Tower block
710  /**********************************************************************
711  * "Tower" block (crystal channel data from a RU (=1 FE cards))
712  *
713  **********************************************************************/
714  if(iTowerWord64_==0){//header
715  towerBlockLength_ = (data[1]>>16) & 0x1FF;
716  int l1a;
717  int bx;
718  l1a = (data[1] >>0 ) & 0xFFF;
719  bx = (data[0] >>16) & 0xFFF;
720  dccCh_=(data[0] >>0 ) & 0xFF;
721  if(d) out << "Block Len: " << towerBlockLength_
722  << " E1: " << ((data[1] >>12) & 0x1)
723  << " L1A: " << l1a
724  << " '3': " << ((data[0] >>30) & 0x3)
725  << " E0: " << ((data[0] >>28) & 0x1)
726  << " Bx: " << bx
727  << " N_samples: " << ((data[0] >>8 ) & 0x7F)
728  << " RU ID: " << dccCh_;
729  if(iRu_ < nRu_){
730  feL1a_[iRu_] = l1a;
731  feBx_[iRu_] = bx;
732  feRuId_[iRu_] = dccCh_;
733  ++iRu_;
734  }
735  } else if((unsigned)iTowerWord64_<towerBlockLength_){
736  if(!dumpAdc_){
737  //no output.
738  rc = false;
739  }
740  const bool da = dumpAdc_ && dump_;
741  switch((iTowerWord64_-1)%3){
742  int s[4];
743  int g[4];
744  case 0:
745  s[0]=(data[0] >>16) & 0xFFF;
746  g[0]=(data[0] >>28) & 0x3;
747  s[1]=(data[1] >>0 ) & 0xFFF;
748  g[1]=(data[1] >>12) & 0x3;
749  s[2]=(data[1] >>16) & 0xFFF;
750  g[2]=(data[1] >>28) & 0x3;
751  fill(adc_.begin(), adc_.end(), 0.);
752  if(da) out << "GMF: " << ((data[0] >>11) & 0x1)
753  << " SMF: " << ((data[0] >>9 ) & 0x1)
754  << " M: " << ((data[0] >>8 ) & 0x1)
755  << " XTAL: " << ((data[0] >>4 ) & 0x7)
756  << " STRIP: " << ((data[0] >>0 ) & 0x7)
757  << " " << setw(4) << s[0]
758  << "G" << g[0]
759  << " " << setw(4) << s[1]
760  << "G" << g[1]
761  << " " << setw(4) << s[2]
762  << "G" << g[2];
763  for(int i=0; i<3; ++i) adc_[i] = s[i]*mgpaGainFactors[g[i]];
764  break;
765  case 1:
766  s[0]=(data[0] >>0 ) & 0xFFF;
767  g[0]=(data[0] >>12) & 0x3;
768  s[1]=(data[0] >>16) & 0xFFF;
769  g[1]=(data[0] >>28) & 0x3;
770  s[2]=(data[1] >>0 ) & 0xFFF;
771  g[2]=(data[1] >>12) & 0x3;
772  s[3]=(data[1] >>16) & 0xFFF;
773  g[3]=(data[1] >>28) & 0x3;
774  if(da) out << " "
775  << " " << setw(4) << s[0]
776  << "G" << g[0]
777  << " " << setw(4) << s[1]
778  << "G" << g[1]
779  << " " << setw(4) << s[2]
780  << "G" << g[2]
781  << " " << setw(4) << s[3]
782  << "G" << g[3];
783  for(int i=0; i<4; ++i) adc_[i+3] = s[i]*mgpaGainFactors[g[i]];
784  break;
785  case 2:
786  if(da) out << "TZS: " << ((data[1] >>14) & 0x1);
787 
788  s[0]=(data[0] >>0 ) & 0xFFF;
789  g[0]=(data[0] >>12) & 0x3;
790  s[1]=(data[0] >>16) & 0xFFF;
791  g[1]=(data[0] >>28) & 0x3;
792  s[2]=(data[1] >>0 ) & 0xFFF;
793  g[2]=(data[1] >>12) & 0x3 ;
794 
795  for(int i=0; i<3; ++i) adc_[i+7] = s[i]*mgpaGainFactors[g[i]];
796  if(dccCh_<=68){
797  unsigned bom0; //Bin of Maximum, starting counting from 0
798  double ampl = max(adc_, bom0)-min(adc_);
799  if(da) out << " Ampl: " << setw(4) << ampl
800  << (ampl>amplCut_?"*":" ")
801  << " BoM:" << setw(2) << (bom0+1)
802  << " ";
803  if(fedId_ == dccId_ + 600 //block of the read-out SM
804  //if laser, only one side:
806  ){
807  }
808  } else{
809  if(da) out << setw(29) << "";
810  }
811  if(da) out << " " << setw(4) << s[0]
812  << "G" << g[0]
813  << " " << setw(4) << s[1]
814  << "G" << g[1]
815  << " " << setw(4) << s[2]
816  << "G" << g[2];
817  break;
818  default:
819  assert(false);
820  }
821  } else {
822  if(d) out << "ERROR";
823  }
824  ++iTowerWord64_;
827  ++dccCh_;
828  }
829  } else if(dataType==eoe){//End of event trailer
830  /**********************************************************************
831  * Event DAQ trailer
832  *
833  **********************************************************************/
834  int tts = (data[0] >>4) & 0xF;
835  if(d) out << "Evt Len.: " << ((data[1] >>0 ) & 0xFFFFFF)
836  << " CRC16: " << ((data[0] >>16) & 0xFFFF)
837  << " Evt Status: " << ((data[0] >>8 ) & 0xF)
838  << " TTS: " << tts
839  << " (" << ttsNames[tts] << ")"
840  << " T:" << ((data[0] >>3) & 0x1);
841  } else{
842  if(d) out << " incorrect 64-bit word type marker (see MSBs)";
843  }
844  return rc;
845 }
846 
847 // The following method was not removed due to package maintainer
848 // (Philippe Gras <philippe.gras@cern.ch>) request.
849 
850 //int EcalDumpRaw::lme(int dcc1, int side){
851 // int fedid = ((dcc1-1)%600) + 600; //to handle both FED and DCC id.
852 // vector<int> lmes;
853 // // EE -
854 // if( fedid <= 609 ) {
855 // if ( fedid <= 607 ) {
856 // lmes.push_back(fedid-601+83);
857 // } else if ( fedid == 608 ) {
858 // lmes.push_back(90);
859 // lmes.push_back(91);
860 // } else if ( fedid == 609 ) {
861 // lmes.push_back(92);
862 // }
863 // } //EB
864 // else if ( fedid >= 610 && fedid <= 645 ) {
865 // lmes.push_back(2*(fedid-610)+1);
866 // lmes.push_back(lmes[0]+1);
867 // } // EE+
868 // else if ( fedid >= 646 ) {
869 // if ( fedid <= 652 ) {
870 // lmes.push_back(fedid-646+73);
871 // } else if ( fedid == 653 ) {
872 // lmes.push_back(80);
873 // lmes.push_back(81);
874 // } else if ( fedid == 654 ) {
875 // lmes.push_back(82);
876 // }
877 // }
878 // return lmes.size()==0?-1:lmes[std::min(lmes.size(), (size_t)side)];
879 //}
880 
881 
883  if(ru1 < 5 || (ru1-5)%4 >= 2){
884  return 0;
885  } else{
886  return 1;
887  }
888 }
889 
890 
891 int EcalDumpRaw::modOfRu(int ru1){
892  int iEta0 = (ru1-1)/4;
893  if(iEta0<5){
894  return 1;
895  } else{
896  return 2 + (iEta0-5)/4;
897  }
898 }
899 
901  int iEta0 = (ru1-1)/4;
902  int iPhi0 = (ru1-1)%4;
903  int rs;
904  if(iEta0==0){
905  rs = 1;
906  } else{
907  rs = 2 + ((iEta0-1)/4)*2 + (iPhi0%4)/2;
908  }
909  // cout << "ru1 = " << ru1 << " -> lmod = " << rs << "\n";
910  return rs;
911 }
912 
914  int min = offset+1;
915  int max = offset+4;
916  stringstream buf;
917  if(628 <= fedId_ && fedId_ <= 646){//EB+
918  buf << right << min << ".."
919  << left << max;
920  } else{
921  buf << right << max << ".."
922  << left << min;
923  }
924  string s = buf.str();
925  buf.str("");
926  buf << setw(6) << right << s;
927  return buf.str();
928 }
929 
930 std::string EcalDumpRaw::ttfTag(int tccType, unsigned iSeq) const{
931  if((unsigned)iSeq > sizeof(ttId_))
932  throw cms::Exception("OutOfRange")
933  << __FILE__ << ":" << __LINE__ << ": "
934  << "parameter out of range\n";
935 
936  const int ttId = ttId_[tccType][iSeq];
937  stringstream buf;
938  buf.str("");
939  if(ttId==0){
940  buf << " '0'";
941  } else{
942  buf << "TTF# " << setw(2) << ttId;
943  }
944  return buf.str();
945 }
946 
947 std::string EcalDumpRaw::tpgTag(int tccType, unsigned iSeq) const{
948  if((unsigned)iSeq > sizeof(ttId_))
949  throw cms::Exception("OutOfRange")
950  << __FILE__ << ":" << __LINE__ << ": "
951  << "parameter out of range\n";
952 
953  const int ttId = ttId_[tccType][iSeq];
954  stringstream buf;
955  buf.str("");
956  if(ttId==0){
957  buf << " '0'";
958  } else{
959  buf << "TPG# " << setw(2) << ttId;
960  }
961  return buf.str();
962 }
int tccBlockLen64_
Definition: EcalDumpRaw.h:168
T getUntrackedParameter(std::string const &, T const &) const
static int sideOfRu(int ru1)
Definition: EcalDumpRaw.cc:882
std::string toNth(int n)
Definition: EcalDumpRaw.cc:455
std::string tpgTag(int tccType, unsigned iSeq) const
Definition: EcalDumpRaw.cc:947
edm::EDGetTokenT< FEDRawDataCollection > fedRawDataCollectionToken_
Definition: EcalDumpRaw.h:187
int end_fed_id_
Definition: EcalDumpRaw.h:94
unsigned iTowerWord64_
Definition: EcalDumpRaw.h:100
static const int nRu_
Definition: EcalDumpRaw.h:169
static const unsigned fedStart_
Definition: EcalDumpRaw.h:123
bool orbit0Set_
Definition: EcalDumpRaw.h:151
size_t towerBlockLength_
Definition: EcalDumpRaw.h:105
std::string ttfTag(int tccType, unsigned iSeq) const
Definition: EcalDumpRaw.cc:930
int detailedTrigType_
Definition: EcalDumpRaw.h:155
double min(const std::vector< double > &a)
Definition: EcalDumpRaw.h:61
std::vector< double > adc_
Definition: EcalDumpRaw.h:107
bool l1aHistory_
Definition: EcalDumpRaw.h:113
int first_event_
Definition: EcalDumpRaw.h:95
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
double amplCut_
Definition: EcalDumpRaw.h:110
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: EcalDumpRaw.cc:212
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:891
unsigned minEventId_
Definition: EcalDumpRaw.h:147
bool writeDcc_
Definition: EcalDumpRaw.h:92
std::vector< uint32_t > lastOrbit_
Definition: EcalDumpRaw.h:121
bool decode(const uint32_t *data, int iWord32, std::ostream &out)
Definition: EcalDumpRaw.cc:479
std::vector< unsigned > eventList_
Definition: EcalDumpRaw.h:146
static int lmodOfRu(int ru1)
Definition: EcalDumpRaw.cc:900
unsigned side_
Definition: EcalDumpRaw.h:144
std::vector< int > feL1a_
Definition: EcalDumpRaw.h:170
~EcalDumpRaw() override
Definition: EcalDumpRaw.cc:207
static const char *const ttsNames[]
Definition: EcalDumpRaw.cc:103
static const int eeOuterTcc_
Definition: EcalDumpRaw.h:134
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
uint32_t orbit_
Definition: EcalDumpRaw.h:150
std::vector< int > feBx_
Definition: EcalDumpRaw.h:175
static const int ttId_[nTccTypes_][maxTpgsPerTcc_]
Definition: EcalDumpRaw.h:140
void endJob()
Definition: EcalDumpRaw.cc:204
static const int ebmTcc_
Definition: EcalDumpRaw.h:131
unsigned maxEventId_
Definition: EcalDumpRaw.h:148
std::ofstream dumpFile_
Definition: EcalDumpRaw.h:178
edm::InputTag fedRawDataCollectionTag_
Definition: EcalDumpRaw.h:185
unsigned iTccWord64_
Definition: EcalDumpRaw.h:102
std::string filename_
Definition: EcalDumpRaw.h:97
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
bool isValid() const
Definition: HandleBase.h:74
constexpr size_t nSamples
unsigned iSrWord64_
Definition: EcalDumpRaw.h:101
std::vector< std::vector< int > > tpg_
Definition: EcalDumpRaw.h:159
unsigned fedId_
Definition: EcalDumpRaw.h:142
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:74
std::string srRange(int offset) const
Definition: EcalDumpRaw.cc:913
edm::EDGetTokenT< L1AcceptBunchCrossingCollection > l1AcceptBunchCrossingCollectionToken_
Definition: EcalDumpRaw.h:188
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:133
std::vector< int > feRuId_
Definition: EcalDumpRaw.h:176
static const int maxTpgsPerTcc_
Definition: EcalDumpRaw.h:124
HLT enums.
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:145
unsigned orbit0_
Definition: EcalDumpRaw.h:149
int beg_fed_id_
Definition: EcalDumpRaw.h:93
static const unsigned nDccs_
Definition: EcalDumpRaw.h:122
static constexpr int lastFEDId()
Definition: FEDNumbering.h:22
static const int maxTccsPerDcc_
Definition: EcalDumpRaw.h:125
int verbosity_
Definition: EcalDumpRaw.h:91
double max(const std::vector< double > &a, unsigned &pos)
Definition: EcalDumpRaw.h:53
Definition: event.py:1
unsigned dccId_
Definition: EcalDumpRaw.h:143
int last_event_
Definition: EcalDumpRaw.h:96
static const int ebpTcc_
Definition: EcalDumpRaw.h:132