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.
8 
9 namespace HcalUnpacker_impl {
10  template <class DigiClass>
11  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) {
12  // set parameters
13  digi.setPresamples(presamples);
14  digi.setReadoutIds(eid);
15  int fiber=startPoint->fiber();
16  int fiberchan=startPoint->fiberChan();
17  uint32_t zsmask=hhd.zsBunchMask()>>startSample;
18  digi.setZSInfo(hhd.isUnsuppressed(),hhd.wasMarkAndPassZS(fiber,fiberchan),zsmask);
19 
20  if (expectedTime>=0 && !hhd.isUnsuppressed()) {
21  // std::cout << hhd.getFibOrbMsgBCN(fiber) << " " << expectedTime << std::endl;
22  digi.setFiberIdleOffset(hhd.getFibOrbMsgBCN(fiber)-expectedTime);
23  }
24 
25  // what is my sample number?
26  int myFiberChan=startPoint->fiberAndChan();
27  int ncurr=0,ntaken=0;
28  const HcalQIESample* qie_work=startPoint;
29  while (qie_work!=limit && qie_work->fiberAndChan()==myFiberChan) {
30  if (ncurr>=startSample && ncurr<=endSample) {
31  digi.setSample(ntaken,*qie_work);
32  ++ntaken;
33  }
34  ncurr++;
35  qie_work++;
36  }
37  digi.setSize(ntaken);
38  return qie_work;
39  }
40 }
41 
42 static inline bool isTPGSOI(const HcalTriggerPrimitiveSample& s) {
43  return (s.raw()&0x200)!=0;
44 }
45 
46 
47 struct HOUnrolledTP { // parts of an HO trigger primitive, unpacked
48  bool valid, checked;
49  int ieta, iphi, samples, soi;
50  unsigned int databits;
52  valid=false;
53  checked=false;
54  ieta=0;
55  iphi=0;
56  samples=0;
57  soi=0;
58  databits=0;
59  }
60  void setbit(int i) { databits|=(1<<i); }
61 };
62 
63 void HcalUnpacker::unpack(const FEDRawData& raw, const HcalElectronicsMap& emap,
65 
66  if (raw.size()<16) {
67  if (!silent) edm::LogWarning("Invalid Data") << "Empty/invalid DCC data, size = " << raw.size();
68  return;
69  }
70 
71  // get the DCC header
72  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
73  int dccid=dccHeader->getSourceId()-sourceIdOffset_;
74 
75  // check the summary status
76 
77  // walk through the HTR data...
78  HcalHTRData htr;
79  const unsigned short* daq_first, *daq_last, *tp_first, *tp_last;
80  const HcalQIESample* qie_begin, *qie_end, *qie_work;
81  const HcalTriggerPrimitiveSample *tp_begin, *tp_end, *tp_work;
82  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
83  if (!dccHeader->getSpigotPresent(spigot)) continue;
84 
85  int retval=dccHeader->getSpigotData(spigot,htr,raw.size());
86  if (retval!=0) {
87  if (retval==-1) {
88  if (!silent) edm::LogWarning("Invalid Data") << "Invalid HTR data (data beyond payload size) observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
89  report.countSpigotFormatError();
90  }
91  continue;
92  }
93  // check
94  if (dccHeader->getSpigotCRCError(spigot)) {
95  if (!silent)
96  edm::LogWarning("Invalid Data") << "CRC Error on HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
97  report.countSpigotFormatError();
98  continue;
99  }
100  if (!htr.check()) {
101  if (!silent)
102  edm::LogWarning("Invalid Data") << "Invalid HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
103  report.countSpigotFormatError();
104  continue;
105  }
106  if (htr.isHistogramEvent()) {
107  if (!silent) edm::LogWarning("Invalid Data") << "Histogram data passed to non-histogram unpacker on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
108  continue;
109  }
110  if ((htr.getFirmwareFlavor()&0xE0)==0x80) { // some kind of TTP data
111  if (colls.ttp!=0) {
112  HcalTTPUnpacker ttpUnpack;
113  colls.ttp->push_back(HcalTTPDigi());
114  ttpUnpack.unpack(htr,colls.ttp->back());
115  } else {
116  LogDebug("HcalTechTrigProcessor") << "Skipping data on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId() << " which is from the TechTrigProcessor (use separate unpacker!)";
117  }
118  continue;
119  }
120  if (htr.getFirmwareFlavor()>=0x80) {
121  if (!silent) edm::LogWarning("HcalUnpacker") << "Skipping data on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId() << " which is of unknown flavor " << htr.getFirmwareFlavor();
122  continue;
123  }
124 
125  // calculate "real" number of presamples
126  int nps=htr.getNPS()-startSample_;
127 
128  // get pointers
129  htr.dataPointers(&daq_first,&daq_last,&tp_first,&tp_last);
130  unsigned int smid=htr.getSubmodule();
131  int htr_tb=smid&0x1;
132  int htr_slot=(smid>>1)&0x1F;
133  int htr_cr=(smid>>6)&0x1F;
134 
135  tp_begin=(HcalTriggerPrimitiveSample*)tp_first;
136  tp_end=(HcalTriggerPrimitiveSample*)(tp_last+1); // one beyond last..
137 
139  int currFiberChan=0x3F; // invalid fiber+channel...
140  int ncurr=0;
141  bool valid=false;
142 
143  bool tpgSOIbitInUse=htr.getFormatVersion()>=3; // version 3 and later
144  bool isHOtpg=htr.getFormatVersion()>=3 && htr.getFirmwareFlavor()==0; // HO is flavor zero
145  int npre=0;
146  /*
147  Unpack the trigger primitives
148  */
149  if (isHOtpg) {
150  HOUnrolledTP unrolled[24];
151  for (tp_work=tp_begin; tp_work!=tp_end; tp_work++) {
152  if (tp_work->raw()==0xFFFF) continue; // filler word
153  int sector=tp_work->slbChan();
154  if (sector>2) continue;
155 
156  for (int ibit=0; ibit<8; ibit++) {
157  int linear=sector*8+ibit;
158  if (!unrolled[linear].checked) {
159  unrolled[linear].checked=true;
160  int fiber=(linear/3)+1;
161  int fc=(linear%3);
162  // electronics id (use precision match for HO TP)
163  HcalElectronicsId eid(fc,fiber,spigot,dccid);
164  eid.setHTR(htr_cr,htr_slot,htr_tb);
165  DetId did=emap.lookup(eid);
166  if (!did.null()) {
167  if (did.det()==DetId::Hcal && ((HcalSubdetector)did.subdetId())==HcalOuter ) {
168  HcalDetId hid(did);
169  unrolled[linear].valid=true;
170  unrolled[linear].ieta=hid.ieta();
171  unrolled[linear].iphi=hid.iphi();
172  }
173  } else {
174  report.countUnmappedTPDigi(eid);
175  }
176  }
177  if (unrolled[linear].valid) {
178  if (isTPGSOI(*tp_work)) unrolled[linear].soi=unrolled[linear].samples;
179  if (tp_work->raw()&(1<<ibit)) unrolled[linear].setbit(unrolled[linear].samples);
180  unrolled[linear].samples++;
181  }
182  }
183  }
184  for (int i=0; i<24; i++) {
185  if (unrolled[i].valid)
186  colls.tphoCont->push_back(HOTriggerPrimitiveDigi(
187  unrolled[i].ieta,
188  unrolled[i].iphi,
189  unrolled[i].samples,
190  unrolled[i].soi,
191  unrolled[i].databits));
192  }
193  } else { // regular TPs (not HO)
194  for (tp_work=tp_begin; tp_work!=tp_end; tp_work++) {
195  if (tp_work->raw()==0xFFFF) continue; // filler word
196  if (tp_work->slbAndChan()!=currFiberChan) { // start new set
197  npre=0;
198  currFiberChan=tp_work->slbAndChan();
199  // lookup the right channel
200  HcalElectronicsId eid(tp_work->slbChan(),tp_work->slb(),spigot,dccid,htr_cr,htr_slot,htr_tb);
201  DetId did=emap.lookupTrigger(eid);
202  if (did.null()) {
203  report.countUnmappedTPDigi(eid);
204  if (unknownIdsTrig_.find(eid)==unknownIdsTrig_.end()) {
205  if (!silent) edm::LogWarning("HCAL") << "HcalUnpacker: No trigger primitive match found for electronics id :" << eid;
206  unknownIdsTrig_.insert(eid);
207  }
208  valid=false;
209  continue;
210  } else if (did==HcalTrigTowerDetId::Undefined ||
211  (did.det()==DetId::Hcal && did.subdetId()==0)) {
212  // known to be unmapped
213  valid=false;
214  continue;
215  }
216  HcalTrigTowerDetId id(did);
217  colls.tpCont->push_back(HcalTriggerPrimitiveDigi(id));
218  // set the various bits
219  if (!tpgSOIbitInUse) colls.tpCont->back().setPresamples(nps);
220  colls.tpCont->back().setZSInfo(htr.isUnsuppressed(),htr.wasMarkAndPassZSTP(tp_work->slb(),tp_work->slbChan()));
221 
222  // no hits recorded for current
223  ncurr=0;
224  valid=true;
225  }
226  // add the word (if within settings or recent firmware [recent firmware ignores startSample/endSample])
227  if (valid && ((tpgSOIbitInUse && ncurr<10) || (ncurr>=startSample_ && ncurr<=endSample_))) {
228  colls.tpCont->back().setSample(colls.tpCont->back().size(),*tp_work);
229  colls.tpCont->back().setSize(colls.tpCont->back().size()+1);
230  }
231  // set presamples,if SOI
232  if (valid && tpgSOIbitInUse && isTPGSOI(*tp_work)) {
233  colls.tpCont->back().setPresamples(ncurr);
234  }
235  ncurr++;
236  npre++;
237  }
238  }
239 
240 
241  qie_begin=(HcalQIESample*)daq_first;
242  qie_end=(HcalQIESample*)(daq_last+1); // one beyond last..
243 
245  currFiberChan=0x3F; // invalid fiber+channel...
246  ncurr=0;
247  valid=false;
248 
249 
250  for (qie_work=qie_begin; qie_work!=qie_end; ) {
251  if (qie_work->raw()==0xFFFF) {
252  qie_work++;
253  continue; // filler word
254  }
255  // always at the beginning ...
256  currFiberChan=qie_work->fiberAndChan();
257 
258  // lookup the right channel
259  HcalElectronicsId eid(qie_work->fiberChan(),qie_work->fiber(),spigot,dccid);
260  eid.setHTR(htr_cr,htr_slot,htr_tb);
261  DetId did=emap.lookup(eid);
262 
263  if (!did.null()) {
264  if (did.det()==DetId::Calo && did.subdetId()==HcalZDCDetId::SubdetectorId) {
265  colls.zdcCont->push_back(ZDCDataFrame(HcalZDCDetId(did)));
266  qie_work=HcalUnpacker_impl::unpack<ZDCDataFrame>(qie_work, qie_end, colls.zdcCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
267  } else if (did.det()==DetId::Hcal) {
268  switch (((HcalSubdetector)did.subdetId())) {
269  case (HcalBarrel):
270  case (HcalEndcap): {
271  colls.hbheCont->push_back(HBHEDataFrame(HcalDetId(did)));
272  qie_work=HcalUnpacker_impl::unpack<HBHEDataFrame>(qie_work, qie_end, colls.hbheCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
273  } break;
274  case (HcalOuter): {
275  colls.hoCont->push_back(HODataFrame(HcalDetId(did)));
276  qie_work=HcalUnpacker_impl::unpack<HODataFrame>(qie_work, qie_end, colls.hoCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
277  } break;
278  case (HcalForward): {
279  colls.hfCont->push_back(HFDataFrame(HcalDetId(did)));
280  qie_work=HcalUnpacker_impl::unpack<HFDataFrame>(qie_work, qie_end, colls.hfCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
281  } break;
282  case (HcalOther) : {
283  HcalOtherDetId odid(did);
284  if (odid.subdet()==HcalCalibration) {
285  colls.calibCont->push_back(HcalCalibDataFrame(HcalCalibDetId(did)));
286  qie_work=HcalUnpacker_impl::unpack<HcalCalibDataFrame>(qie_work, qie_end, colls.calibCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
287  }
288  } break;
289  case (HcalEmpty):
290  default: {
291  for (int fiberC=qie_work->fiberAndChan();
292  qie_work!=qie_end && qie_work->fiberAndChan()==fiberC;
293  qie_work++);
294  }
295  break;
296  }
297  }
298  } else {
299  report.countUnmappedDigi(eid);
300  if (unknownIds_.find(eid)==unknownIds_.end()) {
301  if (!silent) edm::LogWarning("HCAL") << "HcalUnpacker: No match found for electronics id :" << eid;
302  unknownIds_.insert(eid);
303  }
304  for (int fiberC=qie_work->fiberAndChan();
305  qie_work!=qie_end && qie_work->fiberAndChan()==fiberC;
306  qie_work++);
307  }
308  }
309  }
310 }
311 
313  hbheCont=0;
314  hoCont=0;
315  hfCont=0;
316  tpCont=0;
317  zdcCont=0;
318  calibCont=0;
319  ttp=0;
320 }
321 
322 void HcalUnpacker::unpack(const FEDRawData& raw, const HcalElectronicsMap& emap, std::vector<HBHEDataFrame>& container, std::vector<HcalTriggerPrimitiveDigi>& tp) {
323  Collections c;
324  c.hbheCont=&container;
325  c.tpCont=&tp;
327  unpack(raw,emap,c,r);
328 }
329 
330 void HcalUnpacker::unpack(const FEDRawData& raw, const HcalElectronicsMap& emap, std::vector<HODataFrame>& container, std::vector<HcalTriggerPrimitiveDigi>& tp) {
331  Collections c;
332  c.hoCont=&container;
333  c.tpCont=&tp;
335  unpack(raw,emap,c,r);
336 }
337 
338 void HcalUnpacker::unpack(const FEDRawData& raw, const HcalElectronicsMap& emap, std::vector<HFDataFrame>& container, std::vector<HcalTriggerPrimitiveDigi>& tp) {
339  Collections c;
340  c.hfCont=&container;
341  c.tpCont=&tp;
343  unpack(raw,emap,c,r);
344 }
345 
346 void HcalUnpacker::unpack(const FEDRawData& raw, const HcalElectronicsMap& emap, std::vector<HcalHistogramDigi>& histoDigis) {
347 
348  // get the DCC header
349  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
350  int dccid=dccHeader->getSourceId()-sourceIdOffset_;
351 
352  // check the summary status
353 
354  // walk through the HTR data...
355  HcalHTRData htr;
356  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
357  if (!dccHeader->getSpigotPresent(spigot)) continue;
358 
359  int retval=dccHeader->getSpigotData(spigot,htr,raw.size());
360  // check
361  if (retval || !htr.check()) {
362  edm::LogWarning("Invalid Data") << "Invalid HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
363  continue;
364  }
365  if (!htr.isHistogramEvent()) {
366  edm::LogWarning("Invalid Data") << "Non-histogram data passed to histogram unpacker on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
367  continue;
368  }
369 
370  unsigned int smid=htr.getSubmodule();
371  int htr_tb=smid&0x1;
372  int htr_slot=(smid>>1)&0x1F;
373  int htr_cr=(smid>>6)&0x1F;
374 
375  // find out the fibers
376  int f[2],fc;
377  htr.getHistogramFibers(f[0],f[1]);
378 
379  for (int nf=0; nf<2; nf++) {
380  if (f[nf]<0 || (nf==1 && f[0]==f[1])) continue; // skip if invalid or the same
381  for (fc=0; fc<=2; fc++) {
382  HcalElectronicsId eid(fc,f[nf],spigot,dccid);
383  eid.setHTR(htr_cr,htr_slot,htr_tb);
384  DetId did=emap.lookup(eid);
385 
386  if (did.null() || did.det()!=DetId::Hcal || did.subdetId()==0) {
387  if (unknownIds_.find(eid)==unknownIds_.end()) {
388  edm::LogWarning("HCAL") << "HcalHistogramUnpacker: No match found for electronics id :" << eid;
389  unknownIds_.insert(eid);
390  }
391  continue;
392  }
393  histoDigis.push_back(HcalHistogramDigi(HcalDetId(did))); // add it!
394  HcalHistogramDigi& digi=histoDigis.back();
395 
396  // unpack the four capids
397  for (int capid=0; capid<4; capid++)
398  htr.unpackHistogram(f[nf],fc,capid,digi.getArray(capid));
399 
400  }
401  }
402  }
403 }
404 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
std::set< HcalElectronicsId > unknownIds_
Definition: HcalUnpacker.h:52
int sourceIdOffset_
number to subtract from the source id to get the dcc id
Definition: HcalUnpacker.h:48
int endSample_
last sample from fed raw data to copy (if present)
Definition: HcalUnpacker.h:50
int startSample_
first sample from fed raw data to copy
Definition: HcalUnpacker.h:49
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:62
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)
Definition: HcalUnpacker.cc:42
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:331
unsigned int getFibOrbMsgBCN(int fiber) const
Get the BCN of the Fiber Orbit Messages.
Definition: HcalHTRData.h:165
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:388
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:34
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
bool isUnsuppressed() const
Is this event an unsuppresed event?
Definition: HcalHTRData.cc:328
tuple report
Definition: zeeHLT_cff.py:9
bool unpackHistogram(int fiber, int fiberchan, int capid, unsigned short *histogram) const
Unpack special histogramming mode data.
Definition: HcalHTRData.cc:408
int slbAndChan() const
get the id channel
int expectedOrbitMessageTime_
Expected orbit bunch time (needed to evaluate time differences)
Definition: HcalUnpacker.h:51
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
std::set< HcalElectronicsId > unknownIdsTrig_
Recorded to limit number of times a log message is generated.
Definition: HcalUnpacker.h:52
int getSourceId() const
Definition: HcalDCCHeader.h:34
int iphi() const
get the cell iphi
Definition: HcalDetId.h:40
unsigned int databits
Definition: HcalUnpacker.cc:50
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:128
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)
Definition: HcalUnpacker.cc:60
int getNPS() const
Get the number of presamples in daq data.
Definition: HcalHTRData.cc:375
static const HcalTrigTowerDetId Undefined
int getFirmwareFlavor() const
Get the HTR firmware flavor.
Definition: HcalHTRData.cc:384
int slb() const
get the slb site number
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:21
bool wasMarkAndPassZSTP(int slb, int slbchan) const
Was this channel passed as part of Mark&amp;Pass ZS?
Definition: HcalHTRData.cc:339
uint16_t * getArray(int capid)
get the array for the specified capid
uint32_t zsBunchMask() const
ZS Bunch Mask (if available)
Definition: HcalHTRData.cc:348
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
unsigned int getSubmodule() const
Get the HTR submodule number.
Definition: HcalHTRData.cc:306
string s
Definition: asciidump.py:422
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:360
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:11