CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalUnpacker.cc
Go to the documentation of this file.
9 
10 namespace HcalUnpacker_impl {
11  template <class DigiClass>
12  const HcalQIESample* unpack(const HcalQIESample* startPoint, const HcalQIESample* limit, DigiClass& digi, int presamples, const HcalElectronicsId& eid, int startSample, int endSample, int expectedTime, const HcalHTRData& hhd) {
13  // set parameters
14  digi.setPresamples(presamples);
15  digi.setReadoutIds(eid);
16 
17  int fiber=startPoint->fiber();
18  int fiberchan=startPoint->fiberChan();
19  uint32_t zsmask=hhd.zsBunchMask()>>startSample;
20  digi.setZSInfo(hhd.isUnsuppressed(),hhd.wasMarkAndPassZS(fiber,fiberchan),zsmask);
21 
22  if (expectedTime>=0 && !hhd.isUnsuppressed()) {
23  // std::cout << hhd.getFibOrbMsgBCN(fiber) << " " << expectedTime << std::endl;
24  digi.setFiberIdleOffset(hhd.getFibOrbMsgBCN(fiber)-expectedTime);
25  }
26 
27  // what is my sample number?
28  int myFiberChan=startPoint->fiberAndChan();
29  int ncurr=0,ntaken=0;
30  const HcalQIESample* qie_work=startPoint;
31  while (qie_work!=limit && qie_work->fiberAndChan()==myFiberChan) {
32  if (ncurr>=startSample && ncurr<=endSample) {
33  digi.setSample(ntaken,*qie_work);
34  ++ntaken;
35  }
36  ncurr++;
37  qie_work++;
38  }
39  digi.setSize(ntaken);
40  return qie_work;
41  }
42 
43 
44  template <class DigiClass>
45  const unsigned short* unpack_compact(const unsigned short* startPoint, const unsigned short* limit, DigiClass& digi,
46  int presamples, const HcalElectronicsId& eid, int startSample, int endSample,
47  int expectedTime, const HcalHTRData& hhd) {
48  // set parameters
49  digi.setPresamples(presamples);
50  digi.setReadoutIds(eid);
51  int flavor, error_flags, capid0, channelid;
52 
53  HcalHTRData::unpack_per_channel_header(*startPoint,flavor,error_flags,capid0,channelid);
54  bool isCapRotating=!(error_flags&0x1);
55  bool fiberErr=(error_flags&0x2);
56  bool dataValid=!(error_flags&0x2);
57  int fiberchan=channelid&0x3;
58  int fiber=((channelid>>2)&0x7)+1;
59 
60  uint32_t zsmask=hhd.zsBunchMask()>>startSample;
61  digi.setZSInfo(hhd.isUnsuppressed(),hhd.wasMarkAndPassZS(fiber,fiberchan),zsmask);
62 
63  if (expectedTime>=0 && !hhd.isUnsuppressed()) {
64  // std::cout << hhd.getFibOrbMsgBCN(fiber) << " " << expectedTime << std::endl;
65  digi.setFiberIdleOffset(hhd.getFibOrbMsgBCN(fiber)-expectedTime);
66  }
67 
68  // what is my sample number?
69  int ncurr=0,ntaken=0;
70  const unsigned short* qie_work=startPoint;
71  // we branch here between normal (flavor=5) and error mode (flavor=6)
72  if (flavor==5) {
73  for (qie_work++; qie_work!=limit && !HcalHTRData::is_channel_header(*qie_work); qie_work++) {
74  int capidn=(isCapRotating)?((capid0+ncurr)%4):(capid0);
75  int capidn1=(isCapRotating)?((capid0+ncurr+1)%4):(capid0);
76  // two samples in one...
77  HcalQIESample s0((*qie_work)&0x7F,capidn,fiber,fiberchan,dataValid,fiberErr);
78  HcalQIESample s1(((*qie_work)>>8)&0x7F,capidn1,fiber,fiberchan,dataValid,fiberErr);
79 
80  if (ncurr>=startSample && ncurr<=endSample) {
81  digi.setSample(ntaken,s0);
82  ++ntaken;
83  }
84  ncurr++;
85  if (ncurr>=startSample && ncurr<=endSample) {
86  digi.setSample(ntaken,s1);
87  ++ntaken;
88  }
89  ncurr++;
90  }
91  digi.setSize(ntaken);
92  } else if (flavor==6) {
93  for (qie_work++; qie_work!=limit && !HcalHTRData::is_channel_header(*qie_work); qie_work++) {
94  if (ncurr>=startSample && ncurr<=endSample) {
95  HcalQIESample sample((*qie_work)&0x7F,((*qie_work)>>8)&0x3,fiber,fiberchan,((*qie_work)>>10)&0x1,((*qie_work)>>11)&0x1);
96  digi.setSample(ntaken,sample);
97  ++ntaken;
98  }
99  ncurr++;
100  }
101  digi.setSize(ntaken);
102  }
103  return qie_work;
104  }
105 
106 }
107 
108 static inline bool isTPGSOI(const HcalTriggerPrimitiveSample& s) {
109  return (s.raw()&0x200)!=0;
110 }
111 
112 
113 struct HOUnrolledTP { // parts of an HO trigger primitive, unpacked
114  bool valid, checked;
116  unsigned int databits;
118  valid=false;
119  checked=false;
120  ieta=0;
121  iphi=0;
122  samples=0;
123  soi=0;
124  databits=0;
125  }
126  void setbit(int i) { databits|=(1<<i); }
127 };
128 
130  Collections& colls, HcalUnpackerReport& report, bool silent) {
131 
132  if (raw.size()<16) {
133  if (!silent) edm::LogWarning("Invalid Data") << "Empty/invalid DCC data, size = " << raw.size();
134  return;
135  }
136 
137  // get the DCC header
138  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
139  const HcalDTCHeader* dtcHeader=(const HcalDTCHeader*)(raw.data());
140  bool is_VME_DCC=(dccHeader->getDCCDataFormatVersion()<0x10) || ((mode_&0x1)==0);
141 
142  int dccid=(is_VME_DCC)?(dccHeader->getSourceId()-sourceIdOffset_):(dtcHeader->getSourceId()-sourceIdOffset_);
143 
144  // check the summary status
145 
146  // walk through the HTR data. For the uTCA, use spigot=slot+1
147  HcalHTRData htr;
148  const unsigned short* daq_first, *daq_last, *tp_first, *tp_last;
149  const HcalQIESample* qie_begin, *qie_end, *qie_work;
150  const HcalTriggerPrimitiveSample *tp_begin, *tp_end, *tp_work;
151  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
152 
153  if (is_VME_DCC) {
154  if (!dccHeader->getSpigotPresent(spigot)) continue;
155 
156  int retval=dccHeader->getSpigotData(spigot,htr,raw.size());
157  if (retval!=0) {
158  if (retval==-1) {
159  if (!silent) edm::LogWarning("Invalid Data") << "Invalid HTR data (data beyond payload size) observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
160  report.countSpigotFormatError();
161  }
162  continue;
163  }
164  // check
165  if (dccHeader->getSpigotCRCError(spigot)) {
166  if (!silent)
167  edm::LogWarning("Invalid Data") << "CRC Error on HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
168  report.countSpigotFormatError();
169  continue;
170  }
171  } else { // is_uTCA (!is_VME_DCC)
172  int slot=spigot+1;
173  if (slot>HcalDTCHeader::MAXIMUM_SLOT) continue;
174 
175  if (!dtcHeader->getSlotPresent(slot)) continue;
176 
177  int retval=dtcHeader->getSlotData(slot,htr,raw.size());
178  if (retval!=0) {
179  if (retval==-1) {
180  if (!silent) edm::LogWarning("Invalid Data") << "Invalid uHTR data (data beyond payload size) observed on slot " << slot << " of DTC with source id " << dtcHeader->getSourceId();
181  report.countSpigotFormatError();
182  }
183  continue;
184  }
185  // check
186  if (dtcHeader->getSlotCRCError(slot)) {
187  if (!silent)
188  edm::LogWarning("Invalid Data") << "CRC Error on uHTR data observed on slot " << slot << " of DTC with source id " << dtcHeader->getSourceId();
189  report.countSpigotFormatError();
190  continue;
191  }
192  }
193 
194 
195  // check for EE
196  if (htr.isEmptyEvent()) {
197  report.countEmptyEventSpigot();
198  }
199  if (htr.isOverflowWarning()) {
200  report.countOFWSpigot();
201  }
202  if (htr.isBusy()) {
203  report.countBusySpigot();
204  }
205  if (!htr.check()) {
206  if (!silent)
207  edm::LogWarning("Invalid Data") << "Invalid HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
208  report.countSpigotFormatError();
209  continue;
210  }
211  if (htr.isHistogramEvent()) {
212  if (!silent) edm::LogWarning("Invalid Data") << "Histogram data passed to non-histogram unpacker on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
213  continue;
214  }
215  if ((htr.getFirmwareFlavor()&0xE0)==0x80) { // some kind of TTP data
216  if (colls.ttp!=0) {
217  HcalTTPUnpacker ttpUnpack;
218  colls.ttp->push_back(HcalTTPDigi());
219  ttpUnpack.unpack(htr,colls.ttp->back());
220  } else {
221  LogDebug("HcalTechTrigProcessor") << "Skipping data on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId() << " which is from the TechTrigProcessor (use separate unpacker!)";
222  }
223  continue;
224  }
225  if (htr.getFirmwareFlavor()>=0x80) {
226  if (!silent) edm::LogWarning("HcalUnpacker") << "Skipping data on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId() << " which is of unknown flavor " << htr.getFirmwareFlavor();
227  continue;
228  }
229 
230  // calculate "real" number of presamples
231  int nps=htr.getNPS()-startSample_;
232 
233  // get pointers
234  htr.dataPointers(&daq_first,&daq_last,&tp_first,&tp_last);
235  unsigned int smid=htr.getSubmodule();
236  int htr_tb=smid&0x1;
237  int htr_slot=(smid>>1)&0x1F;
238  int htr_cr=(smid>>6)&0x1F;
239 
240  tp_begin=(HcalTriggerPrimitiveSample*)tp_first;
241  tp_end=(HcalTriggerPrimitiveSample*)(tp_last+1); // one beyond last..
242 
244  int currFiberChan=0x3F; // invalid fiber+channel...
245  int ncurr=0;
246  bool valid=false;
247 
248  bool tpgSOIbitInUse=htr.getFormatVersion()>=3; // version 3 and later
249  bool isHOtpg=htr.getFormatVersion()>=3 && htr.getFirmwareFlavor()==0; // HO is flavor zero
250  int npre=0;
251  /*
252  Unpack the trigger primitives
253  */
254  if (isHOtpg) {
255  HOUnrolledTP unrolled[24];
256  for (tp_work=tp_begin; tp_work!=tp_end; tp_work++) {
257  if (tp_work->raw()==0xFFFF) continue; // filler word
258  int sector=tp_work->slbChan();
259  if (sector>2) continue;
260 
261  for (int ibit=0; ibit<8; ibit++) {
262  int linear=sector*8+ibit;
263  if (!unrolled[linear].checked) {
264  unrolled[linear].checked=true;
265  int fiber=(linear/3)+1;
266  int fc=(linear%3);
267  // electronics id (use precision match for HO TP)
268  HcalElectronicsId eid(fc,fiber,spigot,dccid);
269  eid.setHTR(htr_cr,htr_slot,htr_tb);
270  DetId did=emap.lookup(eid);
271  if (!did.null()) {
272  if (did.det()==DetId::Hcal && ((HcalSubdetector)did.subdetId())==HcalOuter ) {
273  HcalDetId hid(did);
274  unrolled[linear].valid=true;
275  unrolled[linear].ieta=hid.ieta();
276  unrolled[linear].iphi=hid.iphi();
277  }
278  } else {
279  report.countUnmappedTPDigi(eid);
280  }
281  }
282  if (unrolled[linear].valid) {
283  if (isTPGSOI(*tp_work)) unrolled[linear].soi=unrolled[linear].samples;
284  if (tp_work->raw()&(1<<ibit)) unrolled[linear].setbit(unrolled[linear].samples);
285  unrolled[linear].samples++;
286  }
287  }
288  }
289  for (int i=0; i<24; i++) {
290  if (unrolled[i].valid)
291  colls.tphoCont->push_back(HOTriggerPrimitiveDigi(
292  unrolled[i].ieta,
293  unrolled[i].iphi,
294  unrolled[i].samples,
295  unrolled[i].soi,
296  unrolled[i].databits));
297  }
298  } else { // regular TPs (not HO)
299  for (tp_work=tp_begin; tp_work!=tp_end; tp_work++) {
300  if (tp_work->raw()==0xFFFF) continue; // filler word
301  if (tp_work->slbAndChan()!=currFiberChan) { // start new set
302  npre=0;
303  currFiberChan=tp_work->slbAndChan();
304  // lookup the right channel
305  HcalElectronicsId eid(tp_work->slbChan(),tp_work->slb(),spigot,dccid,htr_cr,htr_slot,htr_tb);
306  DetId did=emap.lookupTrigger(eid);
307  if (did.null()) {
308  report.countUnmappedTPDigi(eid);
309  if (unknownIdsTrig_.find(eid)==unknownIdsTrig_.end()) {
310  if (!silent) edm::LogWarning("HCAL") << "HcalUnpacker: No trigger primitive match found for electronics id :" << eid;
311  unknownIdsTrig_.insert(eid);
312  }
313  valid=false;
314  continue;
315  } else if (did==HcalTrigTowerDetId::Undefined ||
316  (did.det()==DetId::Hcal && did.subdetId()==0)) {
317  // known to be unmapped
318  valid=false;
319  continue;
320  }
321  HcalTrigTowerDetId id(did);
322  colls.tpCont->push_back(HcalTriggerPrimitiveDigi(id));
323  // set the various bits
324  if (!tpgSOIbitInUse) colls.tpCont->back().setPresamples(nps);
325  colls.tpCont->back().setZSInfo(htr.isUnsuppressed(),htr.wasMarkAndPassZSTP(tp_work->slb(),tp_work->slbChan()));
326 
327  // no hits recorded for current
328  ncurr=0;
329  valid=true;
330  }
331  // add the word (if within settings or recent firmware [recent firmware ignores startSample/endSample])
332  if (valid && ((tpgSOIbitInUse && ncurr<10) || (ncurr>=startSample_ && ncurr<=endSample_))) {
333  colls.tpCont->back().setSample(colls.tpCont->back().size(),*tp_work);
334  colls.tpCont->back().setSize(colls.tpCont->back().size()+1);
335  }
336  // set presamples,if SOI
337  if (valid && tpgSOIbitInUse && isTPGSOI(*tp_work)) {
338  colls.tpCont->back().setPresamples(ncurr);
339  }
340  ncurr++;
341  npre++;
342  }
343  }
344 
347 
348  qie_begin=(HcalQIESample*)daq_first;
349  qie_end=(HcalQIESample*)(daq_last+1); // one beyond last..
350 
352  currFiberChan=0x3F; // invalid fiber+channel...
353  ncurr=0;
354  valid=false;
355 
356 
357  for (qie_work=qie_begin; qie_work!=qie_end; ) {
358  if (qie_work->raw()==0xFFFF) {
359  qie_work++;
360  continue; // filler word
361  }
362  // always at the beginning ...
363  currFiberChan=qie_work->fiberAndChan();
364 
365  // lookup the right channel
366  HcalElectronicsId eid(qie_work->fiberChan(),qie_work->fiber(),spigot,dccid);
367  eid.setHTR(htr_cr,htr_slot,htr_tb);
368  DetId did=emap.lookup(eid);
369 
370  if (!did.null()) {
371  if (did.det()==DetId::Calo && did.subdetId()==HcalZDCDetId::SubdetectorId) {
372  colls.zdcCont->push_back(ZDCDataFrame(HcalZDCDetId(did)));
373  qie_work=HcalUnpacker_impl::unpack<ZDCDataFrame>(qie_work, qie_end, colls.zdcCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
374  } else if (did.det()==DetId::Hcal) {
375  switch (((HcalSubdetector)did.subdetId())) {
376  case (HcalBarrel):
377  case (HcalEndcap): {
378  colls.hbheCont->push_back(HBHEDataFrame(HcalDetId(did)));
379  qie_work=HcalUnpacker_impl::unpack<HBHEDataFrame>(qie_work, qie_end, colls.hbheCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
380  } break;
381  case (HcalOuter): {
382  colls.hoCont->push_back(HODataFrame(HcalDetId(did)));
383  qie_work=HcalUnpacker_impl::unpack<HODataFrame>(qie_work, qie_end, colls.hoCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
384  } break;
385  case (HcalForward): {
386  colls.hfCont->push_back(HFDataFrame(HcalDetId(did)));
387  qie_work=HcalUnpacker_impl::unpack<HFDataFrame>(qie_work, qie_end, colls.hfCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
388  } break;
389  case (HcalOther) : {
390  HcalOtherDetId odid(did);
391  if (odid.subdet()==HcalCalibration) {
392  colls.calibCont->push_back(HcalCalibDataFrame(HcalCalibDetId(did)));
393  qie_work=HcalUnpacker_impl::unpack<HcalCalibDataFrame>(qie_work, qie_end, colls.calibCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
394  }
395  } break;
396  case (HcalEmpty):
397  default: {
398  for (int fiberC=qie_work->fiberAndChan();
399  qie_work!=qie_end && qie_work->fiberAndChan()==fiberC;
400  qie_work++);
401  }
402  break;
403  }
404  }
405  } else {
406  report.countUnmappedDigi(eid);
407  if (unknownIds_.find(eid)==unknownIds_.end()) {
408  if (!silent) edm::LogWarning("HCAL") << "HcalUnpacker: No match found for electronics id :" << eid;
409  unknownIds_.insert(eid);
410  }
411  for (int fiberC=qie_work->fiberAndChan();
412  qie_work!=qie_end && qie_work->fiberAndChan()==fiberC;
413  qie_work++);
414  }
415  }
416  } else {
417  // this is the branch for unpacking the compact data format with per-channel headers
418  const unsigned short* ptr_header=daq_first;
419  const unsigned short* ptr_end=daq_last+1;
420  int flavor, error_flags, capid0, channelid;
421 
422  while (ptr_header!=ptr_end) {
423  if (*ptr_header==0xFFFF) { // impossible filler word
424  ptr_header++;
425  continue;
426  }
427  // unpack the header word
428  bool isheader=HcalHTRData::unpack_per_channel_header(*ptr_header,flavor,error_flags,capid0,channelid);
429  if (!isheader) {
430  ptr_header++;
431  continue;
432  }
433 
434  int fiberchan=channelid&0x3;
435  int fiber=((channelid>>2)&0x7)+1;
436 
437  // lookup the right channel
438  HcalElectronicsId eid(fiberchan,fiber,spigot,dccid);
439  eid.setHTR(htr_cr,htr_slot,htr_tb);
440  DetId did=emap.lookup(eid);
441 
442  if (!did.null()) {
443  if (did.det()==DetId::Calo && did.subdetId()==HcalZDCDetId::SubdetectorId) {
444  colls.zdcCont->push_back(ZDCDataFrame(HcalZDCDetId(did)));
445  ptr_header=HcalUnpacker_impl::unpack_compact<ZDCDataFrame>(ptr_header, ptr_end, colls.zdcCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
446  } else if (did.det()==DetId::Hcal) {
447  switch (((HcalSubdetector)did.subdetId())) {
448  case (HcalBarrel):
449  case (HcalEndcap): {
450  colls.hbheCont->push_back(HBHEDataFrame(HcalDetId(did)));
451  ptr_header=HcalUnpacker_impl::unpack_compact<HBHEDataFrame>(ptr_header, ptr_end, colls.hbheCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
452  } break;
453  case (HcalOuter): {
454  colls.hoCont->push_back(HODataFrame(HcalDetId(did)));
455  ptr_header=HcalUnpacker_impl::unpack_compact<HODataFrame>(ptr_header, ptr_end, colls.hoCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
456  } break;
457  case (HcalForward): {
458  colls.hfCont->push_back(HFDataFrame(HcalDetId(did)));
459  ptr_header=HcalUnpacker_impl::unpack_compact<HFDataFrame>(ptr_header, ptr_end, colls.hfCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
460  } break;
461  case (HcalOther) : {
462  HcalOtherDetId odid(did);
463  if (odid.subdet()==HcalCalibration) {
464  colls.calibCont->push_back(HcalCalibDataFrame(HcalCalibDetId(did)));
465  ptr_header=HcalUnpacker_impl::unpack_compact<HcalCalibDataFrame>(ptr_header, ptr_end, colls.calibCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
466  }
467  } break;
468  case (HcalEmpty):
469  default: {
470  for (ptr_header++;
471  ptr_header!=ptr_end && !HcalHTRData::is_channel_header(*ptr_header);
472  ptr_header++);
473  }
474  break;
475  }
476  }
477  } else {
478  report.countUnmappedDigi(eid);
479  if (unknownIds_.find(eid)==unknownIds_.end()) {
480  if (!silent) edm::LogWarning("HCAL") << "HcalUnpacker: No match found for electronics id :" << eid;
481  unknownIds_.insert(eid);
482  }
483  for (ptr_header++;
484  ptr_header!=ptr_end && !HcalHTRData::is_channel_header(*ptr_header);
485  ptr_header++);
486  }
487  }
488 
489  }
490  }
491 }
492 
494  hbheCont=0;
495  hoCont=0;
496  hfCont=0;
497  tpCont=0;
498  zdcCont=0;
499  calibCont=0;
500  ttp=0;
501 }
502 
503 void HcalUnpacker::unpack(const FEDRawData& raw, const HcalElectronicsMap& emap, std::vector<HBHEDataFrame>& container, std::vector<HcalTriggerPrimitiveDigi>& tp) {
504  Collections c;
505  c.hbheCont=&container;
506  c.tpCont=&tp;
508  unpack(raw,emap,c,r);
509 }
510 
511 void HcalUnpacker::unpack(const FEDRawData& raw, const HcalElectronicsMap& emap, std::vector<HODataFrame>& container, std::vector<HcalTriggerPrimitiveDigi>& tp) {
512  Collections c;
513  c.hoCont=&container;
514  c.tpCont=&tp;
516  unpack(raw,emap,c,r);
517 }
518 
519 void HcalUnpacker::unpack(const FEDRawData& raw, const HcalElectronicsMap& emap, std::vector<HFDataFrame>& container, std::vector<HcalTriggerPrimitiveDigi>& tp) {
520  Collections c;
521  c.hfCont=&container;
522  c.tpCont=&tp;
524  unpack(raw,emap,c,r);
525 }
526 
527 void HcalUnpacker::unpack(const FEDRawData& raw, const HcalElectronicsMap& emap, std::vector<HcalHistogramDigi>& histoDigis) {
528 
529  // get the DCC header
530  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
531  int dccid=dccHeader->getSourceId()-sourceIdOffset_;
532 
533  // check the summary status
534 
535  // walk through the HTR data...
536  HcalHTRData htr;
537  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
538  if (!dccHeader->getSpigotPresent(spigot)) continue;
539 
540  int retval=dccHeader->getSpigotData(spigot,htr,raw.size());
541  // check
542  if (retval || !htr.check()) {
543  edm::LogWarning("Invalid Data") << "Invalid HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
544  continue;
545  }
546  if (!htr.isHistogramEvent()) {
547  edm::LogWarning("Invalid Data") << "Non-histogram data passed to histogram unpacker on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
548  continue;
549  }
550 
551  unsigned int smid=htr.getSubmodule();
552  int htr_tb=smid&0x1;
553  int htr_slot=(smid>>1)&0x1F;
554  int htr_cr=(smid>>6)&0x1F;
555 
556  // find out the fibers
557  int f[2],fc;
558  htr.getHistogramFibers(f[0],f[1]);
559 
560  for (int nf=0; nf<2; nf++) {
561  if (f[nf]<0 || (nf==1 && f[0]==f[1])) continue; // skip if invalid or the same
562  for (fc=0; fc<=2; fc++) {
563  HcalElectronicsId eid(fc,f[nf],spigot,dccid);
564  eid.setHTR(htr_cr,htr_slot,htr_tb);
565  DetId did=emap.lookup(eid);
566 
567  if (did.null() || did.det()!=DetId::Hcal || did.subdetId()==0) {
568  if (unknownIds_.find(eid)==unknownIds_.end()) {
569  edm::LogWarning("HCAL") << "HcalHistogramUnpacker: No match found for electronics id :" << eid;
570  unknownIds_.insert(eid);
571  }
572  continue;
573  }
574  histoDigis.push_back(HcalHistogramDigi(HcalDetId(did))); // add it!
575  HcalHistogramDigi& digi=histoDigis.back();
576 
577  // unpack the four capids
578  for (int capid=0; capid<4; capid++)
579  htr.unpackHistogram(f[nf],fc,capid,digi.getArray(capid));
580 
581  }
582  }
583  }
584 }
585 
#define LogDebug(id)
int getSourceId() const
Definition: HcalDTCHeader.h:37
int i
Definition: DBlmapReader.cc:9
std::set< HcalElectronicsId > unknownIds_
Definition: HcalUnpacker.h:54
int sourceIdOffset_
number to subtract from the source id to get the dcc id
Definition: HcalUnpacker.h:49
int endSample_
last sample from fed raw data to copy (if present)
Definition: HcalUnpacker.h:51
int startSample_
first sample from fed raw data to copy
Definition: HcalUnpacker.h:50
uint16_t raw() const
get the raw word
Definition: HcalQIESample.h:22
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
Definition: HcalHTRData.cc:64
std::vector< HcalTTPDigi > * ttp
Definition: HcalUnpacker.h:31
std::vector< HFDataFrame > * hfCont
Definition: HcalUnpacker.h:26
int fiberAndChan() const
get the id channel
Definition: HcalQIESample.h:38
int fiberChan() const
get the fiber channel number
Definition: HcalQIESample.h:36
bool getSpigotCRCError(unsigned int nspigot) const
Read the &quot;CRC-Mismatch&quot; bit for this spigot.
static bool isTPGSOI(const HcalTriggerPrimitiveSample &s)
const unsigned short * unpack_compact(const unsigned short *startPoint, const unsigned short *limit, DigiClass &digi, int presamples, const HcalElectronicsId &eid, int startSample, int endSample, int expectedTime, const HcalHTRData &hhd)
Definition: HcalUnpacker.cc:45
std::vector< HBHEDataFrame > * hbheCont
Definition: HcalUnpacker.h:24
std::vector< HOTriggerPrimitiveDigi > * tphoCont
Definition: HcalUnpacker.h:30
bool wasMarkAndPassZS(int fiber, int fiberchan) const
Was this channel passed as part of Mark&amp;Pass ZS?
Definition: HcalHTRData.cc:358
unsigned int getFibOrbMsgBCN(int fiber) const
Get the BCN of the Fiber Orbit Messages.
Definition: HcalHTRData.h:179
static bool unpack_per_channel_header(unsigned short, int &flav, int &error_flags, int &capid0, int &channelid)
Unpack a per-channel header word (compact format)
Definition: HcalHTRData.cc:435
void getHistogramFibers(int &a, int &b) const
Get the fiber numbers for the data present in this event (only in histogram mode!) ...
Definition: HcalHTRData.cc:415
int getSpigotData(int nspigot, HcalHTRData &decodeTool, int validSize) const
int slbChan() const
get the slb channel number
int getFormatVersion() const
Get the version number of this event.
Definition: HcalHTRData.h:35
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
bool isUnsuppressed() const
Is this event an unsuppresed event?
Definition: HcalHTRData.cc:355
tuple report
Definition: zeeHLT_cff.py:9
bool isOverflowWarning() const
Definition: HcalHTRData.cc:111
bool unpackHistogram(int fiber, int fiberchan, int capid, unsigned short *histogram) const
Unpack special histogramming mode data.
Definition: HcalHTRData.cc:443
static bool is_channel_header(unsigned short value)
check top bit to see if this is a compact format channel header word
Definition: HcalHTRData.h:92
int slbAndChan() const
get the id channel
int expectedOrbitMessageTime_
Expected orbit bunch time (needed to evaluate time differences)
Definition: HcalUnpacker.h:52
bool isEmptyEvent() const
Definition: HcalHTRData.cc:102
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
HcalSubdetector
Definition: HcalAssistant.h:32
uint16_t raw() const
get the raw word
double f[11][100]
std::vector< HcalTriggerPrimitiveDigi > * tpCont
Definition: HcalUnpacker.h:29
int fiber() const
get the fiber number
Definition: HcalQIESample.h:34
bool getSpigotPresent(unsigned int nspigot) const
Read the &quot;PRESENT&quot; bit for this spigot.
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool getSlotPresent(unsigned int nslot) const
Read the &quot;PRESENT&quot; bit for this slot.
Definition: HcalDTCHeader.h:82
std::set< HcalElectronicsId > unknownIdsTrig_
Recorded to limit number of times a log message is generated.
Definition: HcalUnpacker.h:54
int getSourceId() const
Definition: HcalDCCHeader.h:34
int iphi() const
get the cell iphi
Definition: HcalDetId.h:40
unsigned int databits
Definition: DetId.h:20
void setHTR(int crate, int slot, int tb)
void unpack(const FEDRawData &raw, const HcalElectronicsMap &emap, std::vector< HcalHistogramDigi > &histoDigis)
static const int SubdetectorId
Definition: HcalZDCDetId.h:22
std::vector< HcalCalibDataFrame > * calibCont
Definition: HcalUnpacker.h:27
HcalOtherSubdetector subdet() const
get the category
void dataPointers(const unsigned short **daq_first, const unsigned short **daq_last, const unsigned short **tp_first, const unsigned short **tp_last) const
Obtain the starting and ending pointers for external unpacking of the data.
Definition: HcalHTRData.cc:155
bool unpack(const HcalHTRData &data, HcalTTPDigi &digi)
bool null() const
is this a null id ?
Definition: DetId.h:47
std::vector< HODataFrame > * hoCont
Definition: HcalUnpacker.h:25
void setbit(int i)
int getNPS() const
Get the number of presamples in daq data.
Definition: HcalHTRData.cc:402
static const HcalTrigTowerDetId Undefined
static const int FORMAT_VERSION_COMPACT_DATA
Definition: HcalHTRData.h:22
int getFirmwareFlavor() const
Get the HTR firmware flavor.
Definition: HcalHTRData.cc:411
int slb() const
get the slb site number
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:21
int getSlotData(int nslot, HcalHTRData &decodeTool, int validSize) const
bool wasMarkAndPassZSTP(int slb, int slbchan) const
Was this channel passed as part of Mark&amp;Pass ZS?
Definition: HcalHTRData.cc:366
uint16_t * getArray(int capid)
get the array for the specified capid
uint32_t zsBunchMask() const
ZS Bunch Mask (if available)
Definition: HcalHTRData.cc:375
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
std::vector< ZDCDataFrame > * zdcCont
Definition: HcalUnpacker.h:28
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
short getDCCDataFormatVersion() const
Definition: HcalDCCHeader.h:59
unsigned int getSubmodule() const
Get the HTR submodule number.
Definition: HcalHTRData.cc:333
bool isBusy() const
Definition: HcalHTRData.cc:119
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
Readout chain identification for Hcal [31:26] Unused (so far) [25] Trigger-chain id flag [24:20] Read...
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:387
static const int MAXIMUM_SLOT
Definition: HcalDTCHeader.h:24
const HcalQIESample * unpack(const HcalQIESample *startPoint, const HcalQIESample *limit, DigiClass &digi, int presamples, const HcalElectronicsId &eid, int startSample, int endSample, int expectedTime, const HcalHTRData &hhd)
Definition: HcalUnpacker.cc:12
bool getSlotCRCError(unsigned int nslot) const
Read the &quot;CRC-Mismatch&quot; bit for this slot.
Definition: HcalDTCHeader.h:86