CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PackerHelp.h
Go to the documentation of this file.
1 #ifndef EventFilter_HcalRawToDigi_PackerHelp_h
2 #define EventFilter_HcalRawToDigi_PackerHelp_h
3 
12 
13 #include <iostream>
14 #include <cstdio>
15 #include <vector>
16 #include <map>
17 #include <cmath>
18 
19 namespace CDFHeaderSpec {
20  static const int OFFSET_H = 0;
21  static const int MASK_H = 0x8;
22  static const int OFFSET_FOV = 4;
23  static const int MASK_FOV = 0xF;
24  static const int OFFSET_SOURCE_ID = 8;
25  static const int MASK_SOURCE_ID = 0xFFF;
26  static const int OFFSET_BX_ID = 20;
27  static const int MASK_BX_ID = 0xFFF;
28  static const uint64_t OFFSET_LV1_ID = 32;
29  static const int MASK_LV1_ID = 0xFFFFFF;
30  static const int OFFSET_EVT_TY = 56;
31  static const int MASK_EVT_TY = 0xF;
32  static const int OFFSET_FIXED_MSB = 60;
33  static const int MASK_FIXED_MSB = 0xF;
34  static const uint64_t FIXED_MSB = 0x5;
35 } // namespace CDFHeaderSpec
36 
37 namespace AMC13HeaderSpec {
38  static const int OFFSET_FIXED_LSB = 0;
39  static const int MASK_FIXED_LSB = 0xF;
40  static const int FIXED_LSB = 0x0;
41  static const int OFFSET_ORN = 4;
42  static const int MASK_ORN = 0xFFFFFFFF;
43  static const int OFFSET_RESERVED = 36;
44  static const int MASK_RESERVED = 0xFFFF;
45  static const int OFFSET_NAMC = 52;
46  static const int MASK_NAMC = 0xF;
47  static const int OFFSET_RES = 56;
48  static const int MASK_RES = 0xF;
49  static const int OFFSET_UFOV = 60;
50  static const int MASK_UFOV = 0xF;
51 } // namespace AMC13HeaderSpec
52 
53 namespace AMCHeaderSpec {
54  static const int OFFSET_CRATE_ID = 0;
55  static const int MASK_CRATE_ID = 0xFF;
56  static const int OFFSET_SLOT_ID = 8;
57  static const int MASK_SLOT_ID = 0xF;
58  static const int OFFSET_PRESAMPLES = 12;
59  static const int MASK_PRESAMPLES = 0xF;
60  static const int OFFSET_AMC_NO = 16;
61  static const int MASK_AMC_NO = 0xF;
62  static const int OFFSET_BLK_NO = 20;
63  static const int MASK_BLK_NO = 0xFF;
64  static const int OFFSET_FIXED = 28;
65  static const int MASK_FIXED = 0xF;
66  static const int OFFSET_AMCN_SIZE = 32;
67  static const int MASK_AMCN_SIZE = 0xFFFFFF;
68  static const int OFFSET_C = 56;
69  static const int MASK_C = 0x1;
70  static const int OFFSET_V = 57;
71  static const int MASK_V = 0x1;
72  static const int OFFSET_P = 58;
73  static const int MASK_P = 0x1;
74  static const int OFFSET_E = 59;
75  static const int MASK_E = 0x1;
76  static const int OFFSET_S = 60;
77  static const int MASK_S = 0x1;
78  static const int OFFSET_M = 61;
79  static const int MASK_M = 0x1;
80  static const int OFFSET_L = 62;
81  static const int MASK_L = 0x1;
82 } // namespace AMCHeaderSpec
83 
84 namespace QIE8HeaderSpec {
85  static const int OFFSET_FIBERCHAN = 0;
86  static const int MASK_FIBERCHAN = 0x3;
87  static const int OFFSET_FIBER = 2;
88  static const int MASK_FIBER = 0x1F;
89  static const int OFFSET_CAPID = 8;
90  static const int MASK_CAPID = 0x3;
91  static const int OFFSET_FIBERERR = 10;
92  static const int MASK_FIBERERR = 0x3;
93  static const int OFFSET_FLAVOR = 12;
94  static const int MASK_FLAVOR = 0x7;
95  static const int OFFSET_HEADER_BIT = 15;
96  static const int MASK_HEADER_BIT = 0x1;
97  static const int OFFSET_TECHNICAL_DATA_TYPE = 8;
98  static const int MASK_TECHNICAL_DATA_TYPE = 0xF;
99 } // namespace QIE8HeaderSpec
100 
101 namespace QIE10HeaderSpec {
102  static const int OFFSET_FIBERCHAN = 0;
103  static const int MASK_FIBERCHAN = 0x7;
104  static const int OFFSET_FIBER = 3;
105  static const int MASK_FIBER = 0x1F;
106  static const int OFFSET_MP = 8; // mark-and-pass
107  static const int MASK_MP = 0x1;
108  static const int OFFSET_RESERV = 9; // reserved
109  static const int MASK_RESERV = 0x3;
110  static const int OFFSET_LE = 11; // link error
111  static const int MASK_LE = 0x1;
112  static const int OFFSET_FLAVOR = 12;
113  static const int MASK_FLAVOR = 0x7;
114  static const int OFFSET_HEADER_BIT = 15;
115  static const int MASK_HEADER_BIT = 0x1;
116 } // namespace QIE10HeaderSpec
117 
118 // QIE11 specifications for various flavors
119 
120 namespace QIE11HeaderSpec0 {
121  static const int OFFSET_FIBERCHAN = 0;
122  static const int MASK_FIBERCHAN = 0x7;
123  static const int OFFSET_FIBER = 3;
124  static const int MASK_FIBER = 0x1F;
125  static const int OFFSET_CAPID = 8;
126  static const int MASK_CAPID = 0x3;
127  static const int OFFSET_FIBERERR = 10;
128  static const int MASK_FIBERERR = 0x3;
129  static const int OFFSET_FLAVOR = 12;
130  static const int MASK_FLAVOR = 0x7;
131  static const int OFFSET_HEADER_BIT = 15;
132  static const int MASK_HEADER_BIT = 0x1;
133 } // namespace QIE11HeaderSpec0
134 
135 namespace QIE11HeaderSpec3 {
136  static const int OFFSET_FIBERCHAN = 0;
137  static const int MASK_FIBERCHAN = 0x7;
138  static const int OFFSET_FIBER = 3;
139  static const int MASK_FIBER = 0x1F;
140  static const int OFFSET_MP = 8;
141  static const int MASK_MP = 0x1;
142  static const int OFFSET_LINKERROR = 11;
143  static const int MASK_LINKERROR = 0x1;
144  static const int OFFSET_FLAVOR = 12;
145  static const int MASK_FLAVOR = 0x7;
146  static const int OFFSET_HEADER_BIT = 15;
147  static const int MASK_HEADER_BIT = 0x1;
148 } // namespace QIE11HeaderSpec3
149 
150 namespace TPHeaderSpec {
151  static const int OFFSET_TOWER = 0;
152  static const int MASK_TOWER = 0xF;
153  static const int OFFSET_LINK = 4;
154  static const int MASK_LINK = 0xF;
155  static const int OFFSET_CHANID = 0;
156  static const int MASK_CHANID = 0xFF;
157  static const int OFFSET_RESV = 8;
158  static const int MASK_RESV = 0x3;
159  static const int OFFSET_TPERR = 10;
160  static const int MASK_TPERR = 0x3;
161  static const int OFFSET_FLAVOR = 12;
162  static const int MASK_FLAVOR = 0x7;
163  static const int OFFSET_HEADER_BIT = 15;
164  static const int MASK_HEADER_BIT = 0x1;
165  static const int OFFSET_SOI_BIT = 14;
166  static const int MASK_SOI_BIT = 0x1;
167 } // namespace TPHeaderSpec
168 
169 namespace QIE8SampleSpec {
170  static const int OFFSET_ADC = 0;
171  static const int MASK_ADC = 0x7F;
172  static const int OFFSET_CAPID = 8;
173  static const int MASK_CAPID = 0x3;
174  static const int OFFSET_DV = 10;
175  static const int MASK_DV = 0x1;
176  static const int OFFSET_ER = 11;
177  static const int MASK_ER = 0x1;
178 } // namespace QIE8SampleSpec
179 
180 class HCalFED {
181 public:
182  typedef std::vector<uint16_t> uhtrData;
183 
184  std::vector<unsigned char> fedData;
185  std::vector<uint64_t> AMCHeaders;
186  std::vector<uhtrData> uhtrs;
187  int fedId;
193 
194  unsigned char cdfh[8];
196 
197  HCalFED(int fedId_, uint64_t EventNum_ = 9999, uint64_t OrbitNum_ = 999, uint64_t BxNum_ = 99) {
198  fedId = fedId_;
199  OrbitNum = OrbitNum_;
200  EventNum = EventNum_;
201  BxNum = BxNum_;
203 
204  setCDFHeader();
205  setAMC13Header();
206  };
207 
208  inline void split64bitTo8bit(std::vector<unsigned char>& outVec, const uint64_t& var64bit) {
209  for (int is = 0; is < 8; is++) { // 64/8 = 8
210  outVec.push_back((var64bit >> (is * 8)) & 0xFF);
211  }
212  }
213 
214  void setCDFHeader() {
215  cdfHeader = 0;
219  << CDFHeaderSpec::OFFSET_SOURCE_ID; // needs to be configurable
220  cdfHeader |= (BxNum & CDFHeaderSpec::MASK_BX_ID) << CDFHeaderSpec::OFFSET_BX_ID; // needs to be configurable
224  }
225 
226  void setAMC13Header() {
227  AMC13Header = 0;
234  }
235 
237 
238  void addAMCHeader(uint64_t crate, uint64_t slot, uint64_t AMCsize, uint64_t presamples = 10, uint64_t blockNum = 0) {
239  uint64_t header = 0;
242  header |= (presamples & AMCHeaderSpec::MASK_PRESAMPLES) << AMCHeaderSpec::OFFSET_PRESAMPLES; // boardId
243  header |= (slot & AMCHeaderSpec::MASK_AMC_NO) << AMCHeaderSpec::OFFSET_AMC_NO; // AMC no.
244  header |= (blockNum & AMCHeaderSpec::MASK_BLK_NO) << AMCHeaderSpec::OFFSET_BLK_NO; // Block No.
245  header |= (AMCsize & AMCHeaderSpec::MASK_AMCN_SIZE) << AMCHeaderSpec::OFFSET_AMCN_SIZE; // size
246  header |= uint64_t(0x1) << AMCHeaderSpec::OFFSET_C; // CRC is valid
247  header |= uint64_t(0x1) << AMCHeaderSpec::OFFSET_V; // EvN, BcN match
248  header |= uint64_t(0x1) << AMCHeaderSpec::OFFSET_P; // Present, header is only made if data is present
249  header |= uint64_t(0x1) << AMCHeaderSpec::OFFSET_E; // Enabled, header is only made if AMC is enabled
250  header |= uint64_t(0x0) << AMCHeaderSpec::OFFSET_S; // Segmented, always zero for unsegmented data
251  header |= uint64_t(0x0) << AMCHeaderSpec::OFFSET_M; // More data
252  header |= uint64_t(0x0) << AMCHeaderSpec::OFFSET_L; // Indicates length error
253 
254  AMCHeaders.push_back(header);
255  }
256 
257  void addUHTR(uhtrData uhtr, uint64_t crate, uint64_t slot) {
258  // push uhtr data into FED container
259  uhtrs.push_back(uhtr);
260  // create the corresponding AMC header
261  addAMCHeader(crate, slot, uhtr.size() / 4);
262  };
263 
264  // does not include HEADER and TRAILER
265  void formatFEDdata(FEDRawData& rawData) {
266  //std::vector<unsigned char> output;
267  if (uhtrs.size() != AMCHeaders.size()) {
268  return;
269  }
270 
271  // put common data format header in fed container
273 
274  // set the number of AMCs in the AMC13 header
275  setNAMC(uhtrs.size());
276  // put the AMC13 header into the fed container
278 
279  // fill fedData with AMC headers
280  for (unsigned int iAMC = 0; iAMC < AMCHeaders.size(); ++iAMC) {
281  // adjust the AMCsize bits to match uhtr header
282  //AMCHeaders[iAMC] |= uint64_t(uhtrs[iAMC][1]&0xF)<<51 ;
283  //AMCHeaders[iAMC] |= uint64_t(uhtrs[iAMC][0]&0xFFFF)<<47 ;
285  }
286 
287  // fill fedData with AMC data
288  for (unsigned int iAMC = 0; iAMC < uhtrs.size(); ++iAMC) {
289  unsigned int nWords16 = uhtrs[iAMC].size();
290  for (unsigned int amcWord = 0; amcWord < nWords16; ++amcWord) {
291  fedData.push_back((uhtrs[iAMC][amcWord] >> 0) & 0xFF); // split 16-bit words into 8-bit
292  fedData.push_back((uhtrs[iAMC][amcWord] >> 8) & 0xFF);
293  } // end loop over uhtr words
294  } // end loop over uhtrs
295 
296  // fedData should be a integer number of 64 bit words
297  while (fedData.size() % 8 != 0)
298  fedData.push_back(0);
299 
300  // convert to the correct format
301  rawData.resize(fedData.size());
302  unsigned char* words = reinterpret_cast<unsigned char*>(rawData.data());
303 
304  for (unsigned int i = 0; i < fedData.size(); ++i) {
305  *words = fedData[i];
306  words++;
307  }
308  };
309 };
310 
311 class UHTRpacker {
312 public:
313  typedef std::vector<uint16_t> uhtrData;
314  typedef std::map<int, uhtrData> UHTRMap; // the int here is intended to be the raw electronics ID
315 
317 
318  // FIRST WORD
319  static const int OFFSET_DATA_LENGTH = 0;
320  static const int MASK_DATA_LENGTH = 0xFFFFF;
321  static const int OFFSET_BCN = 20;
322  static const int MASK_BCN = 0xFFF;
323  static const int OFFSET_EVN = 32;
324  static const int MASK_EVN = 0xFFFFFF;
325  static const int OFFSET_FILED_BY_AMC13 = 56;
326  static const int MASK_FILED_BY_AMC13 = 0xFF;
327  // SECOND WORD
328  static const int OFFSET_CRATE_ID = 0;
329  static const int MASK_CRATE_ID = 0xFFFFFF;
330  static const int OFFSET_SLOT_ID = 8;
331  static const int MASK_SLOT_ID = 0xF;
332  static const int OFFSET_PRESAMPLES = 12;
333  static const int MASK_PRESAMPLES = 0xF;
334  static const int OFFSET_ORN = 16;
335  static const int MASK_ORN = 0xFFFF;
336  static const int OFFSET_FW_FLAVOR = 32;
337  static const int MASK_FW_FLAVOR = 0xFF;
338  static const int OFFSET_EVENT_TYPE = 40;
339  static const int MASK_EVENT_TYPE = 0xF;
340  static const int OFFSET_PAYLOAD_FORMAT = 44;
341  static const int MASK_PAYLOAD_FORMAT = 0xF;
342  static const int OFFSET_FW_VERSION = 48;
343  static const int MASK_FW_VERSION = 0xFFFF;
344 
346 
347  bool exist(int uhtrIndex) { return uhtrs.count(uhtrIndex) != 0; };
348 
349  // flavor should be 5, or 7 (only for premixing in sim)
350  uint16_t packQIE8header(const HcalQIESample& qieSample, const HcalElectronicsId& eid, int flavor) {
351  uint16_t header = 0;
352 
353  int fiber = eid.fiberIndex() + 1;
354  int fiberchan = eid.fiberChanId();
355 
357  header |= ((fiber - 1) & QIE8HeaderSpec::MASK_FIBER) << QIE8HeaderSpec::OFFSET_FIBER;
358  if (flavor == 7) {
360  } else {
361  int fiberErr = qieSample.er();
362  int capid0 = qieSample.capid();
365  }
366  header |= (flavor & QIE8HeaderSpec::MASK_FLAVOR) << QIE8HeaderSpec::OFFSET_FLAVOR; //flavor
368 
369  return header;
370  }
371 
372  uint16_t packQIE8sample(const HcalQIESample& qieSample) {
373  uint16_t sample = 0;
374 
375  int adc = qieSample.adc();
376  int capid = qieSample.capid();
377  int dv = qieSample.dv();
378  int er = qieSample.er();
379 
384 
385  return sample;
386  }
387 
388  uint16_t packTPheader(const HcalTriggerPrimitiveSample& tpSample, int channelid) {
389  uint16_t header = 0;
390 
391  header |= (channelid & TPHeaderSpec::MASK_CHANID) << TPHeaderSpec::OFFSET_CHANID;
394  header |= (0x4 & TPHeaderSpec::MASK_FLAVOR) << TPHeaderSpec::OFFSET_FLAVOR; //flavor
396 
397  return header;
398  }
399 
401  uint16_t header = 0;
402 
403  int fiber = eid.fiberIndex();
404  int fiberchan = eid.fiberChanId();
405 
411  header |= (0x2 & QIE10HeaderSpec::MASK_FLAVOR) << QIE10HeaderSpec::OFFSET_FLAVOR; //flavor
413 
414  return header;
415  }
416 
417  uint16_t packQIE11header(const QIE11DataFrame& qiedf, const HcalElectronicsId& eid) {
418  uint16_t header = 0;
419 
420  int fiber = eid.fiberIndex();
421  int fiberchan = eid.fiberChanId();
422  int flavor = qiedf[0].flavor();
423 
424  if (flavor == 3) {
429  header |= (flavor & QIE11HeaderSpec3::MASK_FLAVOR) << QIE11HeaderSpec3::OFFSET_FLAVOR; //flavor
431  } else {
432  int capid0 = qiedf[0].capid();
437  header |= (flavor & QIE11HeaderSpec0::MASK_FLAVOR) << QIE11HeaderSpec0::OFFSET_FLAVOR; //flavor
439  }
440 
441  return header;
442  }
443 
444  uhtrData* newUHTR(int uhtrIndex, int ps = 0, int orn = 0, int bcn = 0, uint64_t evt = 0) {
445  // initialize vector of 16-bit words
446  uhtrs[uhtrIndex] = uhtrData(8);
447  // build header -- some information will be updated at the end
448 
449  uint64_t presamples = std::max(ps, 0);
450  uint64_t uhtrCrate = uhtrIndex & 0xFF;
451  uint64_t uhtrSlot = (uhtrIndex & 0xF00) >> 8;
452  // From Jeremy:
453  // Set the firmware to zero, the firmware flavor to 0, the payload format to 1, and the event type to 1.
454  uint64_t fwFlavor = 0;
455  uint64_t eventType = 1;
456  uint64_t payloadFormat = 1;
457  uint64_t fwVersion = 0;
458 
459  uint64_t uhtrHeader1 = 0;
460  uhtrHeader1 |= (uint64_t(0x0) & MASK_DATA_LENGTH) << OFFSET_DATA_LENGTH;
461  uhtrHeader1 |= (bcn & MASK_BCN) << OFFSET_BCN;
462  uhtrHeader1 |= (evt & MASK_EVN) << OFFSET_EVN;
463  uhtrHeader1 |= (uint64_t(0x0) & MASK_FILED_BY_AMC13) << OFFSET_FILED_BY_AMC13;
464 
465  uint64_t uhtrHeader2 = 0;
466  uhtrHeader2 |= (uhtrCrate & MASK_CRATE_ID) << OFFSET_CRATE_ID;
467  uhtrHeader2 |= (uhtrSlot & MASK_SLOT_ID) << OFFSET_SLOT_ID;
468  uhtrHeader2 |= (presamples & MASK_PRESAMPLES) << OFFSET_PRESAMPLES;
469  uhtrHeader2 |= (orn & MASK_ORN) << OFFSET_ORN;
470  uhtrHeader2 |= (fwFlavor & MASK_FW_FLAVOR) << OFFSET_FW_FLAVOR;
471  uhtrHeader2 |= (eventType & MASK_EVENT_TYPE) << OFFSET_EVENT_TYPE;
472  uhtrHeader2 |= (payloadFormat & MASK_PAYLOAD_FORMAT) << OFFSET_PAYLOAD_FORMAT;
473  uhtrHeader2 |= (fwVersion & MASK_FW_VERSION) << OFFSET_FW_VERSION;
474 
475  // push header into vector of 16-bit words
476  for (unsigned int i = 0; i < 4; ++i) {
477  uhtrs[uhtrIndex][i] = (uhtrHeader1 >> (i * 16)) & 0xFFFF;
478  uhtrs[uhtrIndex][i + 4] = (uhtrHeader2 >> (i * 16)) & 0xFFFF;
479  }
480 
481  return &(uhtrs[uhtrIndex]);
482  };
483 
484  void finalizeHeadTail(uhtrData* uhtr, bool verbosity) {
485  uint64_t uhtr_size = uhtr->size() - 8;
486 
487  // adjust the size bits
488  uhtr->at(0) = uhtr_size & 0xFFFF;
489  uhtr->at(1) |= (uhtr_size >> 16) & 0xF;
490 
491  unsigned int toAdd = 4 - uhtr->size() % 4;
492  for (unsigned int ia = 0; ia < toAdd; ia++) {
493  uhtr->push_back(0xD07F);
494  }
495 
496  // add trailer
497  uhtr->push_back(uhtr_size & 0xFFFF);
498  uhtr->push_back((uhtr_size >> 16) & 0xF);
499  // this is ignoring the event number... I am not sure what this should be
500 
501  // adding some blank stuff for the CRC bits
502  uhtr->push_back(0);
503  uhtr->push_back(0);
504  };
505 
506  void addChannel(int uhtrIndex,
508  const HcalElectronicsMap* readoutMap,
509  bool premix,
510  int verbosity = 0) {
511  if (qiedf->size() == 0)
512  return;
513  DetId detid = qiedf->id();
514  HcalElectronicsId eid(readoutMap->lookup(detid));
515  uint16_t header = packQIE8header(qiedf->sample(0), eid, premix ? 7 : 5);
516  uhtrs[uhtrIndex].push_back(header);
517  // loop over words in dataframe
518  if (premix) {
519  for (int iTS = 0; iTS < qiedf->size(); ++iTS) {
520  uhtrs[uhtrIndex].push_back(packQIE8sample(qiedf->sample(iTS)));
521  }
522  } else {
523  for (int iTS = 0; iTS < qiedf->size(); iTS += 2) {
524  uint16_t cont = 0;
525  int adc0 = qiedf->sample(iTS).adc();
526  int adc1 = qiedf->sample(iTS + 1).adc();
527  cont |= adc0 & 0xFF;
528  cont |= (adc1 & 0xFF) << 8;
529  uhtrs[uhtrIndex].push_back(cont);
530  }
531  } // end loop over dataframe words
532  };
533 
534  void addChannel(int uhtrIndex,
536  const HcalElectronicsMap* readoutMap,
537  bool premix,
538  int verbosity = 0) {
539  if (qiedf->size() == 0)
540  return;
541  DetId detid = qiedf->id();
542  HcalElectronicsId eid(readoutMap->lookup(detid));
543  uint16_t header = packQIE8header(qiedf->sample(0), eid, premix ? 7 : 5);
544  uhtrs[uhtrIndex].push_back(header);
545  // loop over words in dataframe
546  if (premix) {
547  for (int iTS = 0; iTS < qiedf->size(); ++iTS) {
548  uhtrs[uhtrIndex].push_back(packQIE8sample(qiedf->sample(iTS)));
549  }
550  } else {
551  for (int iTS = 0; iTS < qiedf->size(); iTS += 2) {
552  uint16_t cont = 0;
553  int adc0 = qiedf->sample(iTS).adc();
554  int adc1 = qiedf->sample(iTS + 1).adc();
555  cont |= adc0 & 0xFF;
556  cont |= (adc1 & 0xFF) << 8;
557  uhtrs[uhtrIndex].push_back(cont);
558  }
559  } // end loop over dataframe words
560  };
561 
562  void addChannel(int uhtrIndex,
564  int channelid,
565  int verbosity = 0) {
566  if (qiedf->size() == 0)
567  return;
568  uint16_t header = packTPheader(qiedf->sample(0), channelid);
569  uhtrs[uhtrIndex].push_back(header);
570  // loop over words in dataframe
571  for (int iTS = 0; iTS < qiedf->size(); iTS++) {
572  // push data into uhtr data container
573  auto raw = qiedf->sample(iTS).raw();
574  // Add SOI information
575  if (iTS == qiedf->presamples())
577  uhtrs[uhtrIndex].push_back(raw);
578  } // end loop over dataframe words
579  };
580 
581  void addChannel(int uhtrIndex, QIE11DataFrame qiedf, const HcalElectronicsMap* readoutMap, int verbosity = 0) {
582  DetId detid = qiedf.detid();
583  HcalElectronicsId eid(readoutMap->lookup(detid));
584  // loop over words in dataframe
585  for (edm::DataFrame::iterator dfi = qiedf.begin(); dfi != qiedf.end(); ++dfi) {
586  if (dfi >= qiedf.end() - QIE11DataFrame::FLAG_WORDS) {
587  continue;
588  }
589  if (dfi == qiedf.begin() && QIE11DataFrame::HEADER_WORDS == 1) {
590  uint16_t header = packQIE11header(qiedf, eid);
591  uhtrs[uhtrIndex].push_back(header);
592  continue;
593  }
594  // push data into uhtr data container
595  uhtrs[uhtrIndex].push_back(dfi[0]);
596  } // end loop over dataframe words
597  };
598 
599  void addChannel(int uhtrIndex, QIE10DataFrame qiedf, const HcalElectronicsMap* readoutMap, int verbosity = 0) {
600  DetId detid = qiedf.detid();
601  HcalElectronicsId eid(readoutMap->lookup(detid));
602  // loop over words in dataframe
603  for (edm::DataFrame::iterator dfi = qiedf.begin(); dfi != qiedf.end(); ++dfi) {
604  if (dfi >= qiedf.end() - QIE10DataFrame::FLAG_WORDS) {
605  continue;
606  }
607  if (dfi == qiedf.begin() && QIE10DataFrame::HEADER_WORDS == 1) {
608  uint16_t header = packQIE10header(eid);
609  uhtrs[uhtrIndex].push_back(header);
610  continue;
611  }
612  // push data into uhtr data container
613  uhtrs[uhtrIndex].push_back(dfi[0]);
614  } // end loop over dataframe words
615  };
616 };
617 
618 // converts HE QIE digies to HB data format
619 
621  std::vector<int> const& tdc1,
622  std::vector<int> const& tdc2,
623  const int tdcmax) {
624  QIE11DataFrame qiehb = qiehe;
625  HcalDetId did = HcalDetId(qiehb.detid());
626  int adc, tdc;
627  bool soi;
628  int is = 0;
629  int capid = qiehe[0].capid();
630  // flavor for HB digies is hardcoded here
631  static const int hbflavor = 3;
632  // maximum HB depth
633  static const int maxHBdepth = 4;
634 
635  const int entry = (abs(did.ieta()) - 1) * maxHBdepth + did.depth() - 1;
636  const int first = tdc1.at(entry);
637  const int second = tdc2.at(entry);
638 
639  // iterator over samples
640  for (edm::DataFrame::const_iterator it = qiehe.begin(); it != qiehe.end(); ++it) {
641  if (it == qiehe.begin())
642  continue;
643  adc = qiehe[is].adc();
644  tdc = qiehe[is].tdc();
645  soi = qiehe[is].soi();
646 
647  if (tdc >= 0 && tdc <= first)
648  tdc = 0;
649  else if (tdc > first && tdc <= second)
650  tdc = 1;
651  else if (tdc > second && tdc <= tdcmax)
652  tdc = 2;
653  else
654  tdc = 3;
655 
656  qiehb.setSample(is, adc, tdc, soi);
657  is++;
658  };
659 
660  // puting flavor is safe here because flavor is stored in the same bits for all flavors
661  qiehb.setFlavor(hbflavor);
662  qiehb.setCapid0(capid);
663 
664  return qiehb;
665 }
666 
667 #endif
static const int MASK_HEADER_BIT
Definition: PackerHelp.h:132
uint64_t AMC13Header
Definition: PackerHelp.h:188
std::vector< uhtrData > uhtrs
Definition: PackerHelp.h:186
static const int OFFSET_TPERR
Definition: PackerHelp.h:159
static const int MASK_L
Definition: PackerHelp.h:81
void setCDFHeader()
Definition: PackerHelp.h:214
static const int FLAG_WORDS
static const int OFFSET_PRESAMPLES
Definition: PackerHelp.h:332
static const int MASK_H
Definition: PackerHelp.h:21
static const int OFFSET_ORN
Definition: PackerHelp.h:334
static const int OFFSET_FLAVOR
Definition: PackerHelp.h:112
static const int MASK_BLK_NO
Definition: PackerHelp.h:63
static const int OFFSET_HEADER_BIT
Definition: PackerHelp.h:146
void addChannel(int uhtrIndex, QIE11DataFrame qiedf, const HcalElectronicsMap *readoutMap, int verbosity=0)
Definition: PackerHelp.h:581
static const int MASK_MP
Definition: PackerHelp.h:141
static const int OFFSET_PAYLOAD_FORMAT
Definition: PackerHelp.h:340
static const uint64_t OFFSET_LV1_ID
Definition: PackerHelp.h:28
static const int OFFSET_CRATE_ID
Definition: PackerHelp.h:54
static const int MASK_RESERVED
Definition: PackerHelp.h:44
static const int MASK_FOV
Definition: PackerHelp.h:23
std::vector< unsigned char > fedData
Definition: PackerHelp.h:184
tuple cont
load Luminosity info ##
Definition: generateEDF.py:628
void addUHTR(uhtrData uhtr, uint64_t crate, uint64_t slot)
Definition: PackerHelp.h:257
void finalizeHeadTail(uhtrData *uhtr, bool verbosity)
Definition: PackerHelp.h:484
static const int MASK_FIXED_MSB
Definition: PackerHelp.h:33
static const int OFFSET_CAPID
Definition: PackerHelp.h:172
static const int MASK_ORN
Definition: PackerHelp.h:335
static const int MASK_SOURCE_ID
Definition: PackerHelp.h:25
constexpr bool er() const
is the error bit set?
Definition: HcalQIESample.h:51
uint16_t packQIE8header(const HcalQIESample &qieSample, const HcalElectronicsId &eid, int flavor)
Definition: PackerHelp.h:350
uint64_t cdfHeader
Definition: PackerHelp.h:188
QIE11DataFrame convertHB(QIE11DataFrame qiehe, std::vector< int > const &tdc1, std::vector< int > const &tdc2, const int tdcmax)
Definition: PackerHelp.h:620
static const int MASK_HEADER_BIT
Definition: PackerHelp.h:96
static const int MASK_RESERV
Definition: PackerHelp.h:109
static const int OFFSET_HEADER_BIT
Definition: PackerHelp.h:131
void setNAMC(uint64_t NAMC)
Definition: PackerHelp.h:236
static const int MASK_LINKERROR
Definition: PackerHelp.h:143
static const int OFFSET_BLK_NO
Definition: PackerHelp.h:62
static const int OFFSET_FIXED
Definition: PackerHelp.h:64
static const int HEADER_WORDS
static const int OFFSET_CAPID
Definition: PackerHelp.h:125
constexpr edm::DataFrame::iterator end()
static const int OFFSET_EVENT_TYPE
Definition: PackerHelp.h:338
static const int MASK_DV
Definition: PackerHelp.h:175
static const int FIXED_LSB
Definition: PackerHelp.h:40
static const int MASK_FIBER
Definition: PackerHelp.h:88
static const int OFFSET_SOURCE_ID
Definition: PackerHelp.h:24
static const int OFFSET_FLAVOR
Definition: PackerHelp.h:161
static const int MASK_TPERR
Definition: PackerHelp.h:160
uhtrData * newUHTR(int uhtrIndex, int ps=0, int orn=0, int bcn=0, uint64_t evt=0)
Definition: PackerHelp.h:444
static const int OFFSET_PRESAMPLES
Definition: PackerHelp.h:58
static const int OFFSET_CHANID
Definition: PackerHelp.h:155
std::vector< T >::const_iterator const_iterator
static const int OFFSET_HEADER_BIT
Definition: PackerHelp.h:114
static const int OFFSET_RESERVED
Definition: PackerHelp.h:43
static const int OFFSET_FOV
Definition: PackerHelp.h:22
uint64_t OrbitNum
Definition: PackerHelp.h:189
static const int MASK_MP
Definition: PackerHelp.h:107
static const int MASK_ORN
Definition: PackerHelp.h:42
constexpr edm::DataFrame::iterator begin()
iterators
static const int OFFSET_ADC
Definition: PackerHelp.h:170
static const int MASK_ER
Definition: PackerHelp.h:177
static const int MASK_SOI_BIT
Definition: PackerHelp.h:166
static const int OFFSET_MP
Definition: PackerHelp.h:140
static const int MASK_SLOT_ID
Definition: PackerHelp.h:331
static const int MASK_FIBER
Definition: PackerHelp.h:105
static const int MASK_FIBERCHAN
Definition: PackerHelp.h:137
static const int MASK_FIBERCHAN
Definition: PackerHelp.h:103
void addAMCHeader(uint64_t crate, uint64_t slot, uint64_t AMCsize, uint64_t presamples=10, uint64_t blockNum=0)
Definition: PackerHelp.h:238
static const int OFFSET_LINKERROR
Definition: PackerHelp.h:142
std::vector< uint16_t > uhtrData
Definition: PackerHelp.h:182
static const int OFFSET_FIBER
Definition: PackerHelp.h:87
static const int OFFSET_FILED_BY_AMC13
Definition: PackerHelp.h:325
static const int MASK_CRATE_ID
Definition: PackerHelp.h:55
static const int MASK_FLAVOR
Definition: PackerHelp.h:162
static const int OFFSET_RES
Definition: PackerHelp.h:47
static const int OFFSET_FIXED_MSB
Definition: PackerHelp.h:32
static const int MASK_PRESAMPLES
Definition: PackerHelp.h:59
std::vector< uint64_t > AMCHeaders
Definition: PackerHelp.h:185
static const int MASK_M
Definition: PackerHelp.h:79
static const int OFFSET_M
Definition: PackerHelp.h:78
U second(std::pair< T, U > const &p)
static const int MASK_FW_VERSION
Definition: PackerHelp.h:343
static const int MASK_FIBERERR
Definition: PackerHelp.h:128
void addChannel(int uhtrIndex, edm::SortedCollection< HcalTriggerPrimitiveDigi >::const_iterator qiedf, int channelid, int verbosity=0)
Definition: PackerHelp.h:562
uint16_t packQIE11header(const QIE11DataFrame &qiedf, const HcalElectronicsId &eid)
Definition: PackerHelp.h:417
static const int MASK_LINK
Definition: PackerHelp.h:154
constexpr void setFlavor(int flavor)
static const int OFFSET_C
Definition: PackerHelp.h:68
constexpr DetId detid() const
Get the detector id.
static const int OFFSET_CRATE_ID
Definition: PackerHelp.h:328
static const int OFFSET_DV
Definition: PackerHelp.h:174
uint16_t packQIE10header(const HcalElectronicsId &eid)
Definition: PackerHelp.h:400
static const int MASK_FIBERERR
Definition: PackerHelp.h:92
int fedId
Definition: PackerHelp.h:187
static const int MASK_CHANID
Definition: PackerHelp.h:156
static const int OFFSET_FIXED_LSB
Definition: PackerHelp.h:38
static const int MASK_V
Definition: PackerHelp.h:71
static const int MASK_CAPID
Definition: PackerHelp.h:126
static const int MASK_FIXED
Definition: PackerHelp.h:65
static const int OFFSET_FIBER
Definition: PackerHelp.h:138
static const int MASK_PRESAMPLES
Definition: PackerHelp.h:333
void resize(size_t newsize)
Definition: FEDRawData.cc:28
static const int MASK_FIXED_LSB
Definition: PackerHelp.h:39
static const int OFFSET_FIBERCHAN
Definition: PackerHelp.h:121
static const int OFFSET_E
Definition: PackerHelp.h:74
static const int MASK_FLAVOR
Definition: PackerHelp.h:94
static const int OFFSET_AMCN_SIZE
Definition: PackerHelp.h:66
static const int MASK_TECHNICAL_DATA_TYPE
Definition: PackerHelp.h:98
std::vector< uint16_t > uhtrData
Definition: PackerHelp.h:313
static const int MASK_CAPID
Definition: PackerHelp.h:90
unsigned char cdfh[8]
Definition: PackerHelp.h:194
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const int OFFSET_FLAVOR
Definition: PackerHelp.h:129
static const int OFFSET_LE
Definition: PackerHelp.h:110
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
static const int OFFSET_EVT_TY
Definition: PackerHelp.h:30
void addChannel(int uhtrIndex, edm::SortedCollection< HBHEDataFrame >::const_iterator qiedf, const HcalElectronicsMap *readoutMap, bool premix, int verbosity=0)
Definition: PackerHelp.h:534
static const int OFFSET_FW_FLAVOR
Definition: PackerHelp.h:336
constexpr edm::DataFrame::iterator end()
uint16_t packTPheader(const HcalTriggerPrimitiveSample &tpSample, int channelid)
Definition: PackerHelp.h:388
static const int MASK_C
Definition: PackerHelp.h:69
static const int MASK_PAYLOAD_FORMAT
Definition: PackerHelp.h:341
static const int MASK_FIBER
Definition: PackerHelp.h:139
static const int MASK_FIBERCHAN
Definition: PackerHelp.h:122
static const int OFFSET_RESERV
Definition: PackerHelp.h:108
static const int OFFSET_RESV
Definition: PackerHelp.h:157
static const int OFFSET_AMC_NO
Definition: PackerHelp.h:60
void addChannel(int uhtrIndex, QIE10DataFrame qiedf, const HcalElectronicsMap *readoutMap, int verbosity=0)
Definition: PackerHelp.h:599
static const int MASK_E
Definition: PackerHelp.h:75
constexpr void setSample(edm::DataFrame::size_type isample, int adc, int tdc, bool soi=false)
set the sample contents
static const int MASK_AMC_NO
Definition: PackerHelp.h:61
void split64bitTo8bit(std::vector< unsigned char > &outVec, const uint64_t &var64bit)
Definition: PackerHelp.h:208
constexpr int adc() const
get the ADC sample
Definition: HcalQIESample.h:43
static const int OFFSET_FIBERERR
Definition: PackerHelp.h:127
static const int OFFSET_LINK
Definition: PackerHelp.h:153
static const int MASK_EVN
Definition: PackerHelp.h:324
static const uint64_t FIXED_MSB
Definition: PackerHelp.h:34
static const int OFFSET_FW_VERSION
Definition: PackerHelp.h:342
UHTRMap uhtrs
Definition: PackerHelp.h:316
Definition: DetId.h:17
constexpr int fiberIndex() const
get the fiber index. For VME 1-8 (which of eight fibers carried by a spigot), for uTCA fibers are zer...
static const int MASK_HEADER_BIT
Definition: PackerHelp.h:115
static const int OFFSET_TECHNICAL_DATA_TYPE
Definition: PackerHelp.h:97
static const int MASK_CAPID
Definition: PackerHelp.h:173
static const int OFFSET_FLAVOR
Definition: PackerHelp.h:93
static const int MASK_S
Definition: PackerHelp.h:77
static const int MASK_BX_ID
Definition: PackerHelp.h:27
unsigned long long uint64_t
Definition: Time.h:13
static const int FLAG_WORDS
static const int MASK_BCN
Definition: PackerHelp.h:322
static const int MASK_RES
Definition: PackerHelp.h:48
static const int OFFSET_SLOT_ID
Definition: PackerHelp.h:330
constexpr edm::DataFrame::iterator begin()
iterators
static const int HEADER_WORDS
constexpr int flavor() const
get the flavor of the frame
static const int MASK_FILED_BY_AMC13
Definition: PackerHelp.h:326
static const int OFFSET_TOWER
Definition: PackerHelp.h:151
std::map< int, uhtrData > UHTRMap
Definition: PackerHelp.h:314
uint16_t packQIE8sample(const HcalQIESample &qieSample)
Definition: PackerHelp.h:372
static const int MASK_HEADER_BIT
Definition: PackerHelp.h:147
static const int OFFSET_HEADER_BIT
Definition: PackerHelp.h:95
constexpr bool dv() const
is the Data Valid bit set?
Definition: HcalQIESample.h:49
static const int OFFSET_FIBERCHAN
Definition: PackerHelp.h:85
static const int OFFSET_ORN
Definition: PackerHelp.h:41
static const int OFFSET_V
Definition: PackerHelp.h:70
void addChannel(int uhtrIndex, edm::SortedCollection< HFDataFrame >::const_iterator &qiedf, const HcalElectronicsMap *readoutMap, bool premix, int verbosity=0)
Definition: PackerHelp.h:506
static const int MASK_UFOV
Definition: PackerHelp.h:50
FEDHeader * rawFEDHeader
Definition: PackerHelp.h:195
static const int MASK_SLOT_ID
Definition: PackerHelp.h:57
static const int MASK_RESV
Definition: PackerHelp.h:158
static const int OFFSET_CAPID
Definition: PackerHelp.h:89
static const int OFFSET_ER
Definition: PackerHelp.h:176
static const int MASK_EVT_TY
Definition: PackerHelp.h:31
bool exist(int uhtrIndex)
Definition: PackerHelp.h:347
static const int OFFSET_FLAVOR
Definition: PackerHelp.h:144
static const int OFFSET_S
Definition: PackerHelp.h:76
constexpr int capid() const
get the Capacitor id
Definition: HcalQIESample.h:47
data_type * iterator
Definition: DataFrame.h:20
static const int OFFSET_HEADER_BIT
Definition: PackerHelp.h:163
size_type size() const
data_type const * const_iterator
Definition: DataFrame.h:21
static const int OFFSET_P
Definition: PackerHelp.h:72
uint64_t Crate
Definition: PackerHelp.h:192
static const int OFFSET_FIBERERR
Definition: PackerHelp.h:91
static const int OFFSET_EVN
Definition: PackerHelp.h:323
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
static const int OFFSET_BCN
Definition: PackerHelp.h:321
static const int MASK_FLAVOR
Definition: PackerHelp.h:130
uint64_t BxNum
Definition: PackerHelp.h:191
static const int MASK_HEADER_BIT
Definition: PackerHelp.h:164
list entry
Definition: mps_splice.py:68
void formatFEDdata(FEDRawData &rawData)
Definition: PackerHelp.h:265
static const int OFFSET_DATA_LENGTH
Definition: PackerHelp.h:319
static const int OFFSET_L
Definition: PackerHelp.h:80
constexpr int fiberChanId() const
get the fiber channel id (which of channels on a fiber)
static const int MASK_FLAVOR
Definition: PackerHelp.h:145
static const int OFFSET_SLOT_ID
Definition: PackerHelp.h:56
static const int OFFSET_NAMC
Definition: PackerHelp.h:45
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164
constexpr void setCapid0(int cap0)
static const int MASK_LV1_ID
Definition: PackerHelp.h:29
uint64_t EventNum
Definition: PackerHelp.h:190
static const int OFFSET_H
Definition: PackerHelp.h:20
static const int MASK_LE
Definition: PackerHelp.h:111
static const int MASK_P
Definition: PackerHelp.h:73
static const int OFFSET_MP
Definition: PackerHelp.h:106
static const int MASK_FLAVOR
Definition: PackerHelp.h:113
static const int MASK_FIBERCHAN
Definition: PackerHelp.h:86
static const int MASK_AMCN_SIZE
Definition: PackerHelp.h:67
HCalFED(int fedId_, uint64_t EventNum_=9999, uint64_t OrbitNum_=999, uint64_t BxNum_=99)
Definition: PackerHelp.h:197
static const int MASK_FIBER
Definition: PackerHelp.h:124
Readout chain identification for Hcal.
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
static const int OFFSET_FIBERCHAN
Definition: PackerHelp.h:102
void setAMC13Header()
Definition: PackerHelp.h:226
static const int OFFSET_BX_ID
Definition: PackerHelp.h:26
static const int OFFSET_FIBER
Definition: PackerHelp.h:123
static const int OFFSET_FIBER
Definition: PackerHelp.h:104
static const int MASK_EVENT_TYPE
Definition: PackerHelp.h:339
uint16_t *__restrict__ uint16_t const *__restrict__ adc
static const int MASK_FW_FLAVOR
Definition: PackerHelp.h:337
static const int OFFSET_FIBERCHAN
Definition: PackerHelp.h:136
static const int OFFSET_UFOV
Definition: PackerHelp.h:49
static const int MASK_NAMC
Definition: PackerHelp.h:46
static const int MASK_CRATE_ID
Definition: PackerHelp.h:329
static const int MASK_TOWER
Definition: PackerHelp.h:152
static const int MASK_DATA_LENGTH
Definition: PackerHelp.h:320
constexpr DetId detid() const
Get the detector id.
static const int MASK_ADC
Definition: PackerHelp.h:171
static const int OFFSET_SOI_BIT
Definition: PackerHelp.h:165