CMS 3D CMS Logo

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