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  * $Id: EcalDumpRaw.cc,v 1.11 2012/09/11 20:47:03 wdd Exp $
4  *
5  * Author: Ph Gras. CEA/IRFU - Saclay
6  *
7  */
8 
10 
11 #include <iostream>
12 #include <fstream>
13 #include <iomanip>
14 #include <limits>
15 #include <algorithm>
16 #include <sys/time.h>
17 
21 
26 
27 // FE BX counter starts at 0, while OD BX starts at 1.
28 // For some reason, I do not understand myself,
29 // Bx offset is often set such that:
30 // BX_FE = BX_OD for BX_OD < 3564
31 // and BX_FE = BX_OD - 3564 for BX_OD = 3564
32 // set feBxOffset to 1 if this FE BX shift is operated, 0 otherwise
33 //Ph. Gras.
34 const int feBxOffset = 1;
35 
36 const int EcalDumpRaw::ttId_[nTccTypes_][maxTpgsPerTcc_] = {
37  //EB-
38  { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
39  17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
40  33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
41  49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
42  65, 66, 67, 68
43  },
44 
45  //EB+
46  { 4, 3, 2, 1, 8, 7, 6, 5, 12, 11, 10, 9, 16, 15, 14, 13,
47  20, 19, 18, 17, 24, 23, 22, 21, 28, 27, 26, 25, 32, 31, 30, 29,
48  36, 35, 34, 33, 40, 39, 38, 37, 44, 43, 42, 41, 48, 47, 46, 45,
49  52, 51, 50, 49, 56, 55, 54, 53, 60, 59, 58, 57, 64, 63, 62, 61,
50  68, 67, 66, 65
51  },
52 
53  //inner EE
54  { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
55  17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58  0, 0, 0, 0
59  },
60 
61  //outer EE
62  { 1, 2, 3, 4, 5, 6, 7, 8, 9,
63  0, 0, 0, 0, 0, 0, 0, 0, 0,
64  10, 11, 12, 13, 14, 15, 16, 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, 0, 0, 0, 0,
69  0, 0, 0, 0, 0
70  }
71 };
72 
73 using namespace std;
74 
75 static const char* const trigNames[] = {
76  "Unknown",
77  "Phys",
78  "Calib",
79  "Test",
80  "Ext",
81  "Simu",
82  "Trace",
83  "Err"
84 };
85 
86 static const char* const detailedTrigNames[] = {
87  "?", //000
88  "?", //001
89  "?", //010
90  "?", //011
91  "Las", //100
92  "Led", //101
93  "TP", //110
94  "Ped" //111
95 };
96 
97 static const char* const colorNames[] = {
98  "Blue",
99  "Green",
100  "Red",
101  "IR"
102 };
103 
104 static const char* const ttsNames[] = {
105  "Discon'd", //0000
106  "OvFWarn", //0001
107  "OoS", //0010
108  "Forb", //0011
109  "Busy", //0100
110  "Forb", //0101
111  "Forb", //0110
112  "Forb", //0111
113  "Ready", //1000
114  "Forb", //1001
115  "Idle", //1010
116  "Forb", //1011
117  "Err", //1100
118  "Forb", //1101
119  "Forb", //1110
120  "Discon'd" //1111
121 };
122 
123 //double mgpaGainFactors[] = {12., 1., 12./6., 12.}; //index 0->saturation
124 // gain setting: sat 12 6 1 //index 0->saturation
125 // gain setting: 1(sat) 12 6 1
126 //index 0->saturation
127 double mgpaGainFactors[] = {10.63, 1., 10.63/5.43, 10.63};
128 double fppaGainFactors[] = {0, 1., 16./1., 0.};
129 
131  iEvent_(0),
132  adc_(nSamples, 0.),
133  amplCut_(ps.getUntrackedParameter<double>("amplCut", 5.)),
134  dump_(ps.getUntrackedParameter<bool>("dump", true)),
135  dumpAdc_(ps.getUntrackedParameter<bool>("dumpAdc", true)),
136  l1aHistory_(ps.getUntrackedParameter<bool>("l1aHistory", true)),
137  // doHisto_(ps.getUntrackedParameter<bool>("doHisto", true)),
138  maxEvt_(ps.getUntrackedParameter<int>("maxEvt", 10000)),
139  profileFedId_(ps.getUntrackedParameter<int>("profileFedId", 0)),
140  profileRuId_(ps.getUntrackedParameter<int>("profileRuId", 1)),
141  l1aMinX_(ps.getUntrackedParameter<int>("l1aMinX", 1)),
142  l1aMaxX_(ps.getUntrackedParameter<int>("l1aMaxX", 601)),
143  lastOrbit_(nDccs_, numeric_limits<uint32_t>::max()),
144  eventId_(numeric_limits<unsigned>::max()),
145  eventList_(ps.getUntrackedParameter<vector<unsigned> >("eventList", vector<unsigned>())),
146  minEventId_(999999),
147  maxEventId_(0),
148  orbit0_(0),
149  orbit0Set_(false),
150  bx_(-1),
151  l1a_(-1),
152  l1amin_(numeric_limits<int>::max()),
153  l1amax_(-numeric_limits<int>::min()),
154  simpleTrigType_(-1),
155  detailedTrigType_(-1),
156  // histo_("hist.root", "RECREATE"),
157  l1as_(36+2),
158  orbits_(36+2),
159  tpg_(maxTccsPerDcc_, std::vector<int>(maxTpgsPerTcc_)),
160  nTpgs_(maxTccsPerDcc_, 0),
161  dccChStatus_(70, 0),
162  srpL1a_(-1),
163  tccL1a_(-1),
164  nTts_(-1),
165  tccBlockLen64_(19),
166  feL1a_(nRu_,-1),
167  srpBx_(-1),
168  tccBx_(-1),
169  tccType_(0),
170  feBx_(nRu_,-1),
171  feRuId_(nRu_,-1),
172  iTow_(0),
173  pulsePerRu_(ps.getUntrackedParameter<bool>("pulsePerRu", true)),
174  pulsePerLmod_(ps.getUntrackedParameter<bool>("pulsePerLmod", true)),
175  pulsePerLme_(ps.getUntrackedParameter<bool>("pulsePerLme", true)),
176  tccId_(0),
177  fedRawDataCollectionTag_(ps.getParameter<edm::InputTag>("fedRawDataCollectionTag")),
178  l1AcceptBunchCrossingCollectionTag_(ps.getParameter<edm::InputTag>("l1AcceptBunchCrossingCollectionTag"))
179 {
180  verbosity_= ps.getUntrackedParameter<int>("verbosity",1);
181 
182  beg_fed_id_= ps.getUntrackedParameter<int>("beg_fed_id",601);
183  end_fed_id_= ps.getUntrackedParameter<int>("end_fed_id",654);
184 
185 
186  first_event_ = ps.getUntrackedParameter<int>("first_event",1);
187  last_event_ = ps.getUntrackedParameter<int>("last_event",
189 
190  writeDcc_ = ps.getUntrackedParameter<bool>("writeDCC",false);
191  filename_ = ps.getUntrackedParameter<string>("filename","dump.bin");
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_.size()!=0 && 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, 0);
227 
229  event.getByLabel(fedRawDataCollectionTag_, 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.getByLabel(l1AcceptBunchCrossingCollectionTag_, l1aHist);
241  if(!l1aHist.isValid()) {
242  cout << "L1A history not found.\n";
243  } else if (l1aHist->size() == 0) {
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  if(l1a_>0 && l1a_< l1amin_) l1amin_ = l1a_;
446  if(l1a_>l1amax_) l1amax_ = l1a_;
447 
448 
449 #endif
450 
451  gettimeofday(&stop, 0);
452  // double dt = (stop.tv_sec-start.tv_sec)*1.e3
453  // + (stop.tv_usec-start.tv_usec)*1.e-3;
454  // histo_.fillD("hCodeTime", "Code execution time;Duration (ms);Event count",
455  // PGXAxis(100, 0, 100),
456  // dt);
457 }
458 
459 string EcalDumpRaw::toNth(int n){
460  stringstream s;
461  s << n;
462  if(n%100<10 || n%100>20){
463  switch(n%10){
464  case 1:
465  s << "st";
466  break;
467  case 2:
468  s << "nd";
469  break;
470  case 3:
471  s << "rd";
472  break;
473  default:
474  s << "th";
475  }
476  } else{
477  s << "th";
478  }
479  return s.str();
480 }
481 
482 
483 bool EcalDumpRaw::decode(const uint32_t* data, int iWord64, ostream& out){
484  bool rc = true;
485  const bool d = dump_;
486  if(iWord64==0){//start of event
487  iSrWord64_ = 0;
488  iTccWord64_ = 0;
489  iTowerWord64_ = 0;
490  }
491  int dataType = (data[1] >>28) & 0xF;
492  const int boe = 5;
493  const int eoe = 10;
494  if(dataType==boe){//Begin of Event header
495  /**********************************************************************
496  * DAQ header
497  *
498  **********************************************************************/
499  simpleTrigType_ = (data[1] >>24) & 0xF;
500  l1a_ = (data[1]>>0 ) & 0xFFffFF;
501  bx_ = (data[0] >>20) & 0xFFF;
502  fedId_ = (data[0] >>8 ) & 0xFFF;
503  if(d) out << "Trigger type: " << simpleTrigType_
504  << "(" << trigNames[(data[1]>>24) & 0xF] << ")"
505  << " L1A: " << l1a_
506  << " BX: " << bx_
507  << " FED ID: " << fedId_
508  << " FOV: " << ((data[0] >>4 ) & 0xF)
509  << " H: " << ((data[0] >>3 ) & 0x1);
510  } else if((dataType>>2)==0){//DCC header
511  /**********************************************************************
512  * ECAL DCC header
513  *
514  **********************************************************************/
515  int dccHeaderId = (data[1] >>24) & 0x3F;
516  switch(dccHeaderId){
517  case 1:
518  if(d) out << "Run #: " << ((data[1] >>0 ) & 0xFFFFFF)
519  << " DCC Err: " << ((data[0] >>24) & 0xFF)
520  << " Evt Len: " << ((data[0] >>0 ) & 0xFFFFFF);
521  break;
522  case 2:
523  side_ = (data[1] >>11) & 0x1;
524  detailedTrigType_ = (data[1] >>8 ) & 0x7;
525  dccId_ = (data[1] >>0 ) & 0x3F;
526  if(d) out << "DCC FOV: " << ((data[1] >>16) & 0xF)
527  << " Side: " << side_
528  << " Trig.: " << detailedTrigType_
529  << " (" << detailedTrigNames[(data[1]>>8)&0x7] << ")"
530  << " Color: " << ((data[1] >>6 ) & 0x3)
531  << " (" << colorNames[(data[1]>>6)&0x3] << ")"
532  << " DCC ID: " << dccId_;
533  break;
534  case 3:
535  {
536  if(d) out << "TCC Status ch<4..1>: 0x"
537  << hex << ((data[1]>>8) & 0xFFFF) << dec
538  << " SR status: " << ((data[1] >>4 ) & 0xF)
539  << " TZS: " << ((data[1] >>2 ) & 0x1)
540  << " ZS: " << ((data[1] >>1 ) & 0x1)
541  << " SR: " << ((data[1] >>0 ) & 0x1);
542  orbit_ = data[0];
543  if(d) out << " Orbit: " << orbit_;
544  if(!orbit0Set_){
545  orbit0_ = orbit_;
546  orbit0Set_ = true;
547  }
548  int iDcc0 = fedId_-fedStart_;
549  if((unsigned)iDcc0<nDccs_){
551  if(d) out << " (+" << (int)orbit_-(int)lastOrbit_[iDcc0] <<")";
552  }
553  lastOrbit_[iDcc0] = orbit_;
554  }
555  }
556  break;
557  case 4:
558  case 5:
559  case 6:
560  case 7:
561  case 8:
562  {
563  int chOffset = (dccHeaderId-4)*14;
564  dccChStatus_[13+chOffset] = ((data[1] >>20) & 0xF);
565  dccChStatus_[12+chOffset] = ((data[1] >>16) & 0xF);
566  dccChStatus_[11+chOffset] = ((data[1] >>12) & 0xF);
567  dccChStatus_[10+chOffset] = ((data[1] >>8 ) & 0xF);
568  dccChStatus_[ 9+chOffset] = ((data[1] >>4 ) & 0xF);
569  dccChStatus_[ 8+chOffset] = ((data[1] >>0) & 0xF);
570  dccChStatus_[ 7+chOffset] = ((data[0] >>28) & 0xF);
571  dccChStatus_[ 6+chOffset] = ((data[0] >>24) & 0xF);
572  dccChStatus_[ 5+chOffset] = ((data[0] >>20) & 0xF);
573  dccChStatus_[ 4+chOffset] = ((data[0] >>16) & 0xF);
574  dccChStatus_[ 3+chOffset] = ((data[0] >>12) & 0xF);
575  dccChStatus_[ 2+chOffset] = ((data[0] >>8 ) & 0xF);
576  dccChStatus_[ 1+chOffset] = ((data[0] >>4 ) & 0xF);
577  dccChStatus_[ 0+chOffset] = ((data[0] >>0 ) & 0xF);
578 
579  if(d){
580  out << "FE CH status:";
581  for(int i = chOffset; i < chOffset + 14; ++i){
582  out << " #" << (i+1) << ":" << dccChStatus_[i];
583  }
584  }
585  }
586  break;
587  default:
588  if(d) out << " bits<63..62>=0 (DCC header) bits<61..56>=" << dccHeaderId
589  << "(unknown=>ERROR?)";
590  }
591  } else if((dataType>>1)==3){//TCC block
592  /**********************************************************************
593  * TCC block
594  *
595  **********************************************************************/
596  if(iTccWord64_==0){
597  //header
598  tccL1a_ = (data[1] >>0 ) & 0xFFF;
599  tccId_ = ((data[0] >>0 ) & 0xFF);
600  nTts_ = ((data[1] >>16) & 0x7F);
602  ++iTcc_;
603  if(d) out << "LE1: " << ((data[1] >>28) & 0x1)
604  << " LE0: " << ((data[1] >>27) & 0x1)
605  << " N_samples: " << ((data[1] >>23) & 0x1F)
606  << " N_TTs: " << nTts_
607  << " E1: " << ((data[1] >>12) & 0x1)
608  << " L1A: " << tccL1a_
609  << " '3': " << ((data[0] >>29) & 0x7)
610  << " E0: " << ((data[0] >>28) & 0x1)
611  << " Bx: " << ((data[0] >>16) & 0xFFF)
612  << " TTC ID: " << tccId_;
613  if(nTts_==68){ //EB TCC (TCC68)
614  if(fedId_ < 628) tccType_ = ebmTcc_;
615  else tccType_ = ebpTcc_;
616  } else if(nTts_ == 16){//Inner EE TCC (TCC48)
618  } else if(nTts_ == 28){//Outer EE TCC (TCC48)
620  } else {
621  cout << flush;
622  cerr << "Error in #TT field of TCC block."
623  "This field is normally used to determine type of TCC "
624  "(TCC48 or TCC68). Type of TCC will be deduced from the TCC ID.\n";
625  if(tccId_ < 19) tccType_ = eeInnerTcc_;
626  else if(tccId_ < 37) tccType_ = eeOuterTcc_;
627  else if(tccId_ < 55) tccType_ = ebmTcc_;
628  else if(tccId_ < 73) tccType_ = ebpTcc_;
629  else if(tccId_ < 91) tccType_ = eeOuterTcc_;
630  else if(tccId_ < 109) tccType_ = eeInnerTcc_;
631  else{
632  cerr << "TCC ID is also invalid. EB- TCC type will be assumed.\n";
633  tccType_ = ebmTcc_;
634  }
635  cerr << flush;
636  }
637  tccBlockLen64_ = (tccType_==ebmTcc_ || tccType_==ebpTcc_) ? 18 : 9;
638  } else{// if(iTccWord64_<18){
639  int tpgOffset = (iTccWord64_-1)*4;
640  if(iTcc_ > maxTccsPerDcc_){
641  out << "Too many TCC blocks";
642  } else if(tpgOffset > (maxTpgsPerTcc_ - 4)){
643  out << "Too many TPG in one TCC block";
644  } else{
645  tpg_[iTcc_-1][3+tpgOffset] = (data[1] >>16) & 0x1FF;
646  tpg_[iTcc_-1][2+tpgOffset] = (data[1] >>0 ) & 0x1FF;
647  tpg_[iTcc_-1][1+tpgOffset] = (data[0] >>16) & 0x1FF;
648  tpg_[iTcc_-1][0+tpgOffset] = (data[0] >>0 ) & 0x1FF;
649  //int n[2][4] = {{1,2,3,4},
650  // {4,3,2,1}};
651  //int iorder = (628<=fedId_ && fedId_<=645)?1:0;
652  if(d) out << ttfTag(tccType_, 3+tpgOffset) << ":" //"TTF# " << setw(2) << ttId_[3 + tpgOffset] << ":"
653  << ((data[1] >>25) & 0x7) << " "
654  << tpgTag(tccType_, 3+tpgOffset) << ":" //" TPG# "<< setw(2) << ttId_[3 + tpgOffset] << ":"
655  << setw(3) << tpg_[iTcc_-1][3+tpgOffset] << " "
656  << ttfTag(tccType_, 2+tpgOffset) << ":" //" TTF# "<< setw(2) << ttId_[2 + tpgOffset] << ":"
657  << ((data[1] >>9 ) & 0x7) << " "
658  << tpgTag(tccType_, 2+tpgOffset) << ":" //" TPG# "<< setw(2) << ttId_[2 + tpgOffset] << ":"
659  << setw(3) << tpg_[iTcc_-1][2+tpgOffset] << " "
660  << " '3': " << ((data[0] >>29) & 0x7) << " "
661  << ttfTag(tccType_, 1+tpgOffset) << ":" //" TTF# "<< setw(2) << ttId_[1 + tpgOffset] << ":"
662  << ((data[0] >>25) & 0x7) << " "
663  << setw(3) << tpgTag(tccType_, 1+tpgOffset) << ": "//" TPG# "<< setw(2) << ttId_[1 + tpgOffset] << ":"
664  << tpg_[iTcc_-1][1+tpgOffset] << " "
665  << ttfTag(tccType_, 0+tpgOffset) << ":" //" TTF# "<< setw(2) << ttId_[0 + tpgOffset] << ":"
666  << ((data[0] >>9 ) & 0x7) << " "
667  << setw(3) << tpgTag(tccType_, 0+tpgOffset) << ":" //" TPG# "<< setw(2) << ttId_[0 + tpgOffset] << ":"
668  << tpg_[iTcc_-1][0+tpgOffset];
669  }
670  }// else{
671  // if(d) out << "ERROR";
672  //}
673  ++iTccWord64_;
674  if(iTccWord64_ >= (unsigned)tccBlockLen64_) iTccWord64_ = 0;
675  } else if((dataType>>1)==4){//SRP block
676  /**********************************************************************
677  * SRP block
678  *
679  **********************************************************************/
680  if(iSrWord64_==0){//header
681  srpL1a_ = (data[1] >>0 ) & 0xFFF;
682  srpBx_ = (data[0] >>16) & 0xFFF;
683  if(d) out << "LE1: " << ((data[1] >>28) & 0x1)
684  << " LE0: " << ((data[1] >>27) & 0x1)
685  << " N_SRFs: " << ((data[1] >>16) & 0x7F)
686  << " E1: " << ((data[1] >>12) & 0x1)
687  << " L1A: " << srpL1a_
688  << " '4': " << ((data[0] >>29) & 0x7)
689  << " E0: " << ((data[0] >>28) & 0x1)
690  << " Bx: " << srpBx_
691  << " SRP ID: " << ((data[0] >>0 ) & 0xFF);
692  } else if(iSrWord64_<6){
693  int ttfOffset = (iSrWord64_-1)*16;
694  if(d){
695  if(iSrWord64_<5){
696  out <<"SRF# " << setw(6) << right << srRange(12+ttfOffset)/*16+ttfOffset << "..#" << 13+ttfOffset*/ << ": "
697  << oct << ((data[1] >>16) & 0xFFF) << dec
698  << " SRF# " << srRange(8+ttfOffset) /*12+ttfOffset << "..#" << 9+ttfOffset*/ << ": "
699  << oct << ((data[1] >>0 ) & 0xFFF) << dec
700  << " '4':" << ((data[0] >>29) & 0x7)
701  << " SRF# " << srRange(4+ttfOffset) /*8+ttfOffset << "..#" << 5+ttfOffset*/ << ": "
702  << oct << ((data[0] >>16) & 0xFFF) << dec;
703  } else{//last 64-bit word has only 4 SRFs.
704  out << " ";
705  }
706  out << " SRF# " << srRange(ttfOffset) /*4+ttfOffset << "..#" << 1+ttfOffset*/ << ": "
707  << oct << ((data[0] >>0 ) & 0xFFF) << dec;
708  }
709  } else{
710  if(d) out << "ERROR";
711  }
712  ++iSrWord64_;
713  } else if((dataType>>2)==3){//Tower block
714  /**********************************************************************
715  * "Tower" block (crystal channel data from a RU (=1 FE cards))
716  *
717  **********************************************************************/
718  if(iTowerWord64_==0){//header
719  towerBlockLength_ = (data[1]>>16) & 0x1FF;
720  int l1a;
721  int bx;
722  l1a = (data[1] >>0 ) & 0xFFF;
723  bx = (data[0] >>16) & 0xFFF;
724  dccCh_=(data[0] >>0 ) & 0xFF;
725  if(d) out << "Block Len: " << towerBlockLength_
726  << " E1: " << ((data[1] >>12) & 0x1)
727  << " L1A: " << l1a
728  << " '3': " << ((data[0] >>30) & 0x3)
729  << " E0: " << ((data[0] >>28) & 0x1)
730  << " Bx: " << bx
731  << " N_samples: " << ((data[0] >>8 ) & 0x7F)
732  << " RU ID: " << dccCh_;
733  if(iRu_ < nRu_){
734  feL1a_[iRu_] = l1a;
735  feBx_[iRu_] = bx;
736  feRuId_[iRu_] = dccCh_;
737  ++iRu_;
738  }
739  } else if((unsigned)iTowerWord64_<towerBlockLength_){
740  if(!dumpAdc_){
741  //no output.
742  rc = false;
743  }
744  const bool da = dumpAdc_ && dump_;
745  switch((iTowerWord64_-1)%3){
746  int s[4];
747  int g[4];
748  case 0:
749  s[0]=(data[0] >>16) & 0xFFF;
750  g[0]=(data[0] >>28) & 0x3;
751  s[1]=(data[1] >>0 ) & 0xFFF;
752  g[1]=(data[1] >>12) & 0x3;
753  s[2]=(data[1] >>16) & 0xFFF;
754  g[2]=(data[1] >>28) & 0x3;
755  fill(adc_.begin(), adc_.end(), 0.);
756  if(da) out << "GMF: " << ((data[0] >>11) & 0x1)
757  << " SMF: " << ((data[0] >>9 ) & 0x1)
758  << " M: " << ((data[0] >>8 ) & 0x1)
759  << " XTAL: " << ((data[0] >>4 ) & 0x7)
760  << " STRIP: " << ((data[0] >>0 ) & 0x7)
761  << " " << setw(4) << s[0]
762  << "G" << g[0]
763  << " " << setw(4) << s[1]
764  << "G" << g[1]
765  << " " << setw(4) << s[2]
766  << "G" << g[2];
767  for(int i=0; i<3; ++i) adc_[i] = s[i]*mgpaGainFactors[g[i]];
768  break;
769  case 1:
770  s[0]=(data[0] >>0 ) & 0xFFF;
771  g[0]=(data[0] >>12) & 0x3;
772  s[1]=(data[0] >>16) & 0xFFF;
773  g[1]=(data[0] >>28) & 0x3;
774  s[2]=(data[1] >>0 ) & 0xFFF;
775  g[2]=(data[1] >>12) & 0x3;
776  s[3]=(data[1] >>16) & 0xFFF;
777  g[3]=(data[1] >>28) & 0x3;
778  if(da) out << " "
779  << " " << setw(4) << s[0]
780  << "G" << g[0]
781  << " " << setw(4) << s[1]
782  << "G" << g[1]
783  << " " << setw(4) << s[2]
784  << "G" << g[2]
785  << " " << setw(4) << s[3]
786  << "G" << g[3];
787  for(int i=0; i<4; ++i) adc_[i+3] = s[i]*mgpaGainFactors[g[i]];
788  break;
789  case 2:
790  if(da) out << "TZS: " << ((data[1] >>14) & 0x1);
791 
792  s[0]=(data[0] >>0 ) & 0xFFF;
793  g[0]=(data[0] >>12) & 0x3;
794  s[1]=(data[0] >>16) & 0xFFF;
795  g[1]=(data[0] >>28) & 0x3;
796  s[2]=(data[1] >>0 ) & 0xFFF;
797  g[2]=(data[1] >>12) & 0x3 ;
798 
799  for(int i=0; i<3; ++i) adc_[i+7] = s[i]*mgpaGainFactors[g[i]];
800  if(dccCh_<=68){
801  unsigned bom0; //Bin of Maximum, starting counting from 0
802  double ampl = max(adc_, bom0)-min(adc_);
803  if(da) out << " Ampl: " << setw(4) << ampl
804  << (ampl>amplCut_?"*":" ")
805  << " BoM:" << setw(2) << (bom0+1)
806  << " ";
807  if(fedId_ == dccId_ + 600 //block of the read-out SM
808  //if laser, only one side:
809  && (detailedTrigType_!=4 || sideOfRu(dccCh_)==(int)side_)
810  ){
811  }
812  } else{
813  if(da) out << setw(29) << "";
814  }
815  if(da) out << " " << setw(4) << s[0]
816  << "G" << g[0]
817  << " " << setw(4) << s[1]
818  << "G" << g[1]
819  << " " << setw(4) << s[2]
820  << "G" << g[2];
821  break;
822  default:
823  assert(false);
824  }
825  } else {
826  if(d) out << "ERROR";
827  }
828  ++iTowerWord64_;
831  ++dccCh_;
832  }
833  } else if(dataType==eoe){//End of event trailer
834  /**********************************************************************
835  * Event DAQ trailer
836  *
837  **********************************************************************/
838  int tts = (data[0] >>4) & 0xF;
839  if(d) out << "Evt Len.: " << ((data[1] >>0 ) & 0xFFFFFF)
840  << " CRC16: " << ((data[0] >>16) & 0xFFFF)
841  << " Evt Status: " << ((data[0] >>8 ) & 0xF)
842  << " TTS: " << tts
843  << " (" << ttsNames[tts] << ")"
844  << " T:" << ((data[0] >>3) & 0x1);
845  } else{
846  if(d) out << " incorrect 64-bit word type marker (see MSBs)";
847  }
848  return rc;
849 }
850 
851 // The following method was not removed due to package maintainer
852 // (Philippe Gras <philippe.gras@cern.ch>) request.
853 
854 //int EcalDumpRaw::lme(int dcc1, int side){
855 // int fedid = ((dcc1-1)%600) + 600; //to handle both FED and DCC id.
856 // vector<int> lmes;
857 // // EE -
858 // if( fedid <= 609 ) {
859 // if ( fedid <= 607 ) {
860 // lmes.push_back(fedid-601+83);
861 // } else if ( fedid == 608 ) {
862 // lmes.push_back(90);
863 // lmes.push_back(91);
864 // } else if ( fedid == 609 ) {
865 // lmes.push_back(92);
866 // }
867 // } //EB
868 // else if ( fedid >= 610 && fedid <= 645 ) {
869 // lmes.push_back(2*(fedid-610)+1);
870 // lmes.push_back(lmes[0]+1);
871 // } // EE+
872 // else if ( fedid >= 646 ) {
873 // if ( fedid <= 652 ) {
874 // lmes.push_back(fedid-646+73);
875 // } else if ( fedid == 653 ) {
876 // lmes.push_back(80);
877 // lmes.push_back(81);
878 // } else if ( fedid == 654 ) {
879 // lmes.push_back(82);
880 // }
881 // }
882 // return lmes.size()==0?-1:lmes[std::min(lmes.size(), (size_t)side)];
883 //}
884 
885 
887  if(ru1 < 5 || (ru1-5)%4 >= 2){
888  return 0;
889  } else{
890  return 1;
891  }
892 }
893 
894 
895 int EcalDumpRaw::modOfRu(int ru1){
896  int iEta0 = (ru1-1)/4;
897  if(iEta0<5){
898  return 1;
899  } else{
900  return 2 + (iEta0-5)/4;
901  }
902 }
903 
905  int iEta0 = (ru1-1)/4;
906  int iPhi0 = (ru1-1)%4;
907  int rs;
908  if(iEta0==0){
909  rs = 1;
910  } else{
911  rs = 2 + ((iEta0-1)/4)*2 + (iPhi0%4)/2;
912  }
913  // cout << "ru1 = " << ru1 << " -> lmod = " << rs << "\n";
914  return rs;
915 }
916 
918  int min = offset+1;
919  int max = offset+4;
920  stringstream buf;
921  if(628 <= fedId_ && fedId_ <= 646){//EB+
922  buf << right << min << ".."
923  << left << max;
924  } else{
925  buf << right << max << ".."
926  << left << min;
927  }
928  string s = buf.str();
929  buf.str("");
930  buf << setw(6) << right << s;
931  return buf.str();
932 }
933 
934 std::string EcalDumpRaw::ttfTag(int tccType, unsigned iSeq) const{
935  if((unsigned)iSeq > sizeof(ttId_))
936  throw cms::Exception("OutOfRange")
937  << __FILE__ << ":" << __LINE__ << ": "
938  << "parameter out of range\n";
939 
940  const int ttId = ttId_[tccType][iSeq];
941  stringstream buf;
942  buf.str("");
943  if(ttId==0){
944  buf << " '0'";
945  } else{
946  buf << "TTF# " << setw(2) << ttId;
947  }
948  return buf.str();
949 }
950 
951 std::string EcalDumpRaw::tpgTag(int tccType, unsigned iSeq) const{
952  if((unsigned)iSeq > sizeof(ttId_))
953  throw cms::Exception("OutOfRange")
954  << __FILE__ << ":" << __LINE__ << ": "
955  << "parameter out of range\n";
956 
957  const int ttId = ttId_[tccType][iSeq];
958  stringstream buf;
959  buf.str("");
960  if(ttId==0){
961  buf << " '0'";
962  } else{
963  buf << "TPG# " << setw(2) << ttId;
964  }
965  return buf.str();
966 }
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: EcalDumpRaw.cc:212
int tccBlockLen64_
Definition: EcalDumpRaw.h:169
T getUntrackedParameter(std::string const &, T const &) const
static int sideOfRu(int ru1)
Definition: EcalDumpRaw.cc:886
int i
Definition: DBlmapReader.cc:9
std::string toNth(int n)
Definition: EcalDumpRaw.cc:459
std::string tpgTag(int tccType, unsigned iSeq) const
Definition: EcalDumpRaw.cc:951
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
int end_fed_id_
Definition: EcalDumpRaw.h:93
string fill
Definition: lumiContext.py:319
unsigned iTowerWord64_
Definition: EcalDumpRaw.h:99
static const int nRu_
Definition: EcalDumpRaw.h:170
static const unsigned fedStart_
Definition: EcalDumpRaw.h:122
bool orbit0Set_
Definition: EcalDumpRaw.h:150
size_t towerBlockLength_
Definition: EcalDumpRaw.h:104
std::string ttfTag(int tccType, unsigned iSeq) const
Definition: EcalDumpRaw.cc:934
int detailedTrigType_
Definition: EcalDumpRaw.h:156
double min(const std::vector< double > &a)
Definition: EcalDumpRaw.h:60
std::vector< double > adc_
Definition: EcalDumpRaw.h:106
#define min(a, b)
Definition: mlp_lapack.h:161
bool l1aHistory_
Definition: EcalDumpRaw.h:112
int first_event_
Definition: EcalDumpRaw.h:94
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:109
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:49
static int modOfRu(int ru1)
Definition: EcalDumpRaw.cc:895
unsigned minEventId_
Definition: EcalDumpRaw.h:146
bool writeDcc_
Definition: EcalDumpRaw.h:91
std::vector< uint32_t > lastOrbit_
Definition: EcalDumpRaw.h:120
bool decode(const uint32_t *data, int iWord32, std::ostream &out)
Definition: EcalDumpRaw.cc:483
std::vector< unsigned > eventList_
Definition: EcalDumpRaw.h:145
static int lmodOfRu(int ru1)
Definition: EcalDumpRaw.cc:904
unsigned side_
Definition: EcalDumpRaw.h:143
std::vector< int > feL1a_
Definition: EcalDumpRaw.h:171
static const char *const ttsNames[]
Definition: EcalDumpRaw.cc:104
static const int eeOuterTcc_
Definition: EcalDumpRaw.h:133
uint32_t orbit_
Definition: EcalDumpRaw.h:149
std::vector< int > feBx_
Definition: EcalDumpRaw.h:176
static const int ttId_[nTccTypes_][maxTpgsPerTcc_]
Definition: EcalDumpRaw.h:139
const T & max(const T &a, const T &b)
void endJob()
Definition: EcalDumpRaw.cc:204
static const int ebmTcc_
Definition: EcalDumpRaw.h:130
unsigned maxEventId_
Definition: EcalDumpRaw.h:147
std::ofstream dumpFile_
Definition: EcalDumpRaw.h:179
edm::InputTag fedRawDataCollectionTag_
Definition: EcalDumpRaw.h:186
unsigned iTccWord64_
Definition: EcalDumpRaw.h:101
std::string filename_
Definition: EcalDumpRaw.h:96
std::vector< int > nTpgs_
Definition: EcalDumpRaw.h:161
EcalDumpRaw(const edm::ParameterSet &)
Definition: EcalDumpRaw.cc:130
static const char *const detailedTrigNames[]
Definition: EcalDumpRaw.cc:86
unsigned int offset(bool)
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:76
double fppaGainFactors[]
Definition: EcalDumpRaw.cc:128
unsigned iSrWord64_
Definition: EcalDumpRaw.h:100
std::vector< std::vector< int > > tpg_
Definition: EcalDumpRaw.h:160
tuple out
Definition: dbtoconf.py:99
unsigned fedId_
Definition: EcalDumpRaw.h:141
static int lastFEDId()
Definition: FEDNumbering.cc:19
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:75
std::string srRange(int offset) const
Definition: EcalDumpRaw.cc:917
int simpleTrigType_
Definition: EcalDumpRaw.h:155
int tccType_
type of TCC currently parsed
Definition: EcalDumpRaw.h:175
std::vector< int > dccChStatus_
Definition: EcalDumpRaw.h:162
static const char *const colorNames[]
Definition: EcalDumpRaw.cc:97
static const int eeInnerTcc_
Definition: EcalDumpRaw.h:132
std::vector< int > feRuId_
Definition: EcalDumpRaw.h:177
unsigned ttId(const DetId &)
static const int maxTpgsPerTcc_
Definition: EcalDumpRaw.h:123
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const int feBxOffset
Definition: EcalDumpRaw.cc:34
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:29
unsigned eventId_
Definition: EcalDumpRaw.h:144
unsigned orbit0_
Definition: EcalDumpRaw.h:148
tuple cout
Definition: gather_cfg.py:121
dictionary rawdata
Definition: lumiPlot.py:393
int beg_fed_id_
Definition: EcalDumpRaw.h:92
static const unsigned nDccs_
Definition: EcalDumpRaw.h:121
static const int maxTccsPerDcc_
Definition: EcalDumpRaw.h:124
int verbosity_
Definition: EcalDumpRaw.h:90
double mgpaGainFactors[]
Definition: EcalDumpRaw.cc:127
double max(const std::vector< double > &a, unsigned &pos)
Definition: EcalDumpRaw.h:52
unsigned dccId_
Definition: EcalDumpRaw.h:142
int last_event_
Definition: EcalDumpRaw.h:95
static const int ebpTcc_
Definition: EcalDumpRaw.h:131