16 template <
class DigiClass>
27 digi.setPresamples(presamples);
28 digi.setReadoutIds(eid);
30 int fiber = startPoint->
fiber();
44 int ncurr = 0, ntaken = 0;
46 while (qie_work != limit && qie_work->
fiberAndChan() == myFiberChan) {
47 if (ncurr >= startSample && ncurr <= endSample) {
48 digi.setSample(ntaken, *qie_work);
58 template <
class DigiClass>
60 const unsigned short*
limit,
69 digi.setPresamples(presamples);
70 digi.setReadoutIds(eid);
71 int flavor, error_flags, capid0, channelid;
74 bool isCapRotating = !(error_flags & 0x1);
75 bool fiberErr = (error_flags & 0x2);
76 bool dataValid = !(error_flags & 0x2);
77 int fiberchan = channelid & 0x3;
78 int fiber = ((channelid >> 2) & 0x7) + 1;
91 int ncurr = 0, ntaken = 0;
92 const unsigned short* qie_work = startPoint;
96 int capidn = (isCapRotating) ? ((capid0 + ncurr) % 4) : (capid0);
97 int capidn1 = (isCapRotating) ? ((capid0 + ncurr + 1) % 4) : (capid0);
99 HcalQIESample s0((*qie_work) & 0x7F, capidn, fiber, fiberchan, dataValid, fiberErr);
100 HcalQIESample s1(((*qie_work) >> 8) & 0x7F, capidn1, fiber, fiberchan, dataValid, fiberErr);
102 if (ncurr >= startSample && ncurr <= endSample) {
103 digi.setSample(ntaken, s0);
107 if (ncurr >= startSample && ncurr <= endSample) {
108 digi.setSample(ntaken, s1);
113 digi.setSize(ntaken);
114 }
else if (flavor == 6) {
116 if (ncurr >= startSample && ncurr <= endSample) {
118 ((*qie_work) >> 8) & 0x3,
121 ((*qie_work) >> 10) & 0
x1,
122 ((*qie_work) >> 11) & 0
x1);
123 digi.setSample(ntaken, sample);
129 digi.setSize(ntaken);
137 template <
class DigiClass>
146 digi.setPresamples(presamples - startSample);
147 digi.setReadoutIds(eid);
152 bool isCapRotating = !(error_flags & 0x1);
153 bool fiberErr = (error_flags & 0x2);
154 bool dataValid = !(error_flags & 0x2);
156 int fiber = ((i.
channelid() >> 2) & 0x7) + 1;
161 int ncurr = 0, ntaken = 0;
163 for (++i; i != iend && !i.
isHeader(); ++
i) {
164 int capidn = (isCapRotating) ? ((capid0 + ncurr) % 4) : (capid0);
168 if (ncurr >= startSample && ncurr <= endSample) {
169 digi.setSample(ntaken,
s);
174 digi.setSize(ntaken);
175 }
else if (flavor == 7) {
176 for (++i; i != iend && !i.
isHeader(); ++
i) {
177 if (ncurr >= startSample && ncurr <= endSample) {
179 digi.setSample(ntaken,
sample);
184 digi.setSize(ntaken);
213 if (raw.
size() < 16) {
223 unpackVME(raw, emap, colls, report, silent);
225 unpackUTCA(raw, emap, colls, report, silent);
228 static int slb(uint16_t theSample) {
return ((theSample >> 13) & 0x7); }
229 static int slbChan(uint16_t theSample) {
return (theSample >> 11) & 0x3; }
230 static int slbAndChan(uint16_t theSample) {
return (theSample >> 11) & 0x1F; }
243 (is_VME_DCC) ? (dccHeader->
getSourceId() - sourceIdOffset_) : (dtcHeader->
getSourceId() - sourceIdOffset_);
249 const unsigned short *daq_first, *daq_last, *tp_first, *tp_last;
261 edm::LogWarning(
"Invalid Data") <<
"Invalid HTR data (data beyond payload size) observed on spigot " 262 << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
270 edm::LogWarning(
"Invalid Data") <<
"CRC Error on HTR data observed on spigot " << spigot
271 <<
" of DCC with source id " << dccHeader->
getSourceId();
276 int slot = spigot + 1;
287 edm::LogWarning(
"Invalid Data") <<
"Invalid uHTR data (data beyond payload size) observed on slot " << slot
288 <<
" of DTC with source id " << dtcHeader->
getSourceId();
296 edm::LogWarning(
"Invalid Data") <<
"CRC Error on uHTR data observed on slot " << slot
297 <<
" of DTC with source id " << dtcHeader->
getSourceId();
315 edm::LogWarning(
"Invalid Data") <<
"Invalid HTR data observed on spigot " << spigot <<
" of DCC with source id " 322 edm::LogWarning(
"Invalid Data") <<
"Histogram data passed to non-histogram unpacker on spigot " << spigot
323 <<
" of DCC with source id " << dccHeader->
getSourceId();
327 if (colls.
ttp !=
nullptr) {
330 ttpUnpack.
unpack(htr, colls.
ttp->back());
333 <<
"Skipping data on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId()
334 <<
" which is from the TechTrigProcessor (use separate unpacker!)";
340 edm::LogWarning(
"HcalUnpacker") <<
"Skipping data on spigot " << spigot <<
" of DCC with source id " 341 << dccHeader->
getSourceId() <<
" which is of unknown flavor " 347 int nps = htr.
getNPS() - startSample_;
350 htr.
dataPointers(&daq_first, &daq_last, &tp_first, &tp_last);
352 int htr_tb = smid & 0x1;
353 int htr_slot = (smid >> 1) & 0x1F;
354 int htr_cr = (smid >> 6) & 0x1F;
360 int currFiberChan = 0x3F;
372 for (tp_work = tp_begin; tp_work != tp_end; tp_work++) {
373 if (tp_work->
raw() == 0xFFFF)
379 for (
int ibit = 0; ibit < 8; ibit++) {
380 int linear = sector * 8 + ibit;
381 if (!unrolled[linear].checked) {
383 int fiber = (linear / 3) + 1;
384 int fc = (linear % 3);
387 eid.
setHTR(htr_cr, htr_slot, htr_tb);
400 if (unrolled[linear].valid) {
403 if (tp_work->
raw() & (1 << ibit))
409 for (
int i = 0;
i < 24;
i++) {
410 if (unrolled[
i].valid)
412 unrolled[
i].
ieta, unrolled[
i].
iphi, unrolled[
i].
samples, unrolled[
i].soi, unrolled[
i].databits));
415 for (tp_work = tp_begin; tp_work != tp_end; tp_work++) {
416 if (tp_work->
raw() == 0xFFFF)
426 if (unknownIdsTrig_.find(eid) == unknownIdsTrig_.end()) {
428 edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No trigger primitive match found for electronics id :" <<
eid;
429 unknownIdsTrig_.insert(eid);
442 colls.
tpCont->back().setPresamples(nps);
451 if (valid && ((tpgSOIbitInUse && ncurr < 10) || (ncurr >= startSample_ && ncurr <= endSample_))) {
452 colls.
tpCont->back().setSample(colls.
tpCont->back().size(), *tp_work);
453 colls.
tpCont->back().setSize(colls.
tpCont->back().size() + 1);
456 if (valid && tpgSOIbitInUse &&
isTPGSOI(*tp_work)) {
457 colls.
tpCont->back().setPresamples(ncurr);
471 for (qie_work = qie_begin; qie_work != qie_end;) {
472 if (qie_work->
raw() == 0xFFFF) {
480 eid.setHTR(htr_cr, htr_slot, htr_tb);
486 qie_work = HcalUnpacker_impl::unpack<ZDCDataFrame>(qie_work,
493 expectedOrbitMessageTime_,
500 qie_work = HcalUnpacker_impl::unpack<HBHEDataFrame>(qie_work,
507 expectedOrbitMessageTime_,
512 qie_work = HcalUnpacker_impl::unpack<HODataFrame>(qie_work,
519 expectedOrbitMessageTime_,
524 qie_work = HcalUnpacker_impl::unpack<HFDataFrame>(qie_work,
531 expectedOrbitMessageTime_,
538 qie_work = HcalUnpacker_impl::unpack<HcalCalibDataFrame>(qie_work,
545 expectedOrbitMessageTime_,
559 if (unknownIds_.find(
eid) == unknownIds_.end()) {
561 edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" <<
eid;
562 unknownIds_.insert(
eid);
571 const unsigned short* ptr_header = daq_first;
572 const unsigned short* ptr_end = daq_last + 1;
573 int flavor, error_flags, capid0, channelid;
575 while (ptr_header != ptr_end) {
576 if (*ptr_header == 0xFFFF) {
587 int fiberchan = channelid & 0x3;
588 int fiber = ((channelid >> 2) & 0x7) + 1;
592 eid.
setHTR(htr_cr, htr_slot, htr_tb);
598 ptr_header = HcalUnpacker_impl::unpack_compact<ZDCDataFrame>(ptr_header,
605 expectedOrbitMessageTime_,
612 ptr_header = HcalUnpacker_impl::unpack_compact<HBHEDataFrame>(ptr_header,
619 expectedOrbitMessageTime_,
624 ptr_header = HcalUnpacker_impl::unpack_compact<HODataFrame>(ptr_header,
631 expectedOrbitMessageTime_,
636 ptr_header = HcalUnpacker_impl::unpack_compact<HFDataFrame>(ptr_header,
643 expectedOrbitMessageTime_,
650 ptr_header = HcalUnpacker_impl::unpack_compact<HcalCalibDataFrame>(ptr_header,
657 expectedOrbitMessageTime_,
670 if (unknownIds_.find(eid) == unknownIds_.end()) {
672 edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" <<
eid;
673 unknownIds_.insert(eid);
691 int namc = amc13->
NAMC();
692 for (
int iamc = 0; iamc < namc; iamc++) {
699 edm::LogWarning(
"Invalid Data") <<
"Missing data observed on iamc " << iamc <<
" of AMC13 with source id " 706 edm::LogWarning(
"Invalid Data") <<
"CRC Error on uHTR data observed on iamc " << iamc
707 <<
" of AMC13 with source id " << amc13->
sourceId();
714 edm::LogWarning(
"Invalid Data") <<
"Unpacker cannot handle segmented data observed on iamc " << iamc
715 <<
" of AMC13 with source id " << amc13->
sourceId();
721 int slot = amc13->
AMCSlot(iamc);
722 int crate = amc13->
AMCId(iamc) & 0xFF;
726 if (uhtr.getFormatVersion() != 1) {
727 unpackUMNio(raw, slot, colls);
732 int nwords = uhtr.getRawLengthBytes() / 2;
733 for (
int iw = 0; iw < nwords; iw++)
734 printf(
"%04d %04x\n", iw, uhtr.getRawData16()[iw]);
738 int nps = uhtr.presamples();
749 std::cout <<
"its not a header" << std::endl;
755 int ifiber = ((i.
channelid() >> 3) & 0x1F);
760 const uint16_t* head_pos = i.
raw();
762 for (++i; i != iend && !i.
isHeader(); ++
i) {
766 if (colls.
qie11 ==
nullptr) {
772 printInvalidDataMessage(
"QIE11", colls.
qie11->
samples(), ns,
true);
785 colls.
qie11Addtl[ns]->addDataFrame(did, head_pos);
789 if (unknownIds_.find(eid) == unknownIds_.end()) {
791 edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" <<
eid;
792 unknownIds_.insert(eid);
794 std::cout <<
"HcalUnpacker: No match found for electronics id :" << eid << std::endl;
798 std::cout <<
"OH NO! detector id is null!" << std::endl;
801 }
else if (i.
flavor() == 2) {
804 int ifiber = ((i.
channelid() >> 3) & 0x1F);
810 const uint16_t* head_pos = i.
raw();
812 for (++i; i != iend && !i.
isHeader(); ++
i) {
824 printInvalidDataMessage(
"QIE10ZDC", colls.
qie10ZDC->
samples(), ns,
false);
826 }
else if (isLasmon) {
833 if (colls.
qie10 ==
nullptr) {
839 printInvalidDataMessage(
"QIE10", colls.
qie10->
samples(), ns,
true);
860 colls.
qie10Addtl[ns]->addDataFrame(did, head_pos);
865 if (unknownIds_.find(eid) == unknownIds_.end()) {
867 edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" <<
eid;
868 unknownIds_.insert(eid);
870 std::cout <<
"HcalUnpacker: No match found for electronics id :" << eid << std::endl;
874 std::cout <<
"OH NO! HcalUnpacker: No match found for electronics id :" << eid << std::endl;
878 int ifiber = ((i.
channelid() >> 2) & 0x1F);
886 HcalUnpacker_impl::unpack_compact<ZDCDataFrame>(
887 i, iend, colls.
zdcCont->back(), nps,
eid, startSample_, endSample_);
893 HcalUnpacker_impl::unpack_compact<HBHEDataFrame>(
894 i, iend, colls.
hbheCont->back(), nps,
eid, startSample_, endSample_);
898 HcalUnpacker_impl::unpack_compact<HODataFrame>(
899 i, iend, colls.
hoCont->back(), nps,
eid, startSample_, endSample_);
903 HcalUnpacker_impl::unpack_compact<HFDataFrame>(
904 i, iend, colls.
hfCont->back(), nps,
eid, startSample_, endSample_);
910 HcalUnpacker_impl::unpack_compact<HcalCalibDataFrame>(
911 i, iend, colls.
calibCont->back(), nps,
eid, startSample_, endSample_);
916 for (++i; i != iend && !i.
isHeader(); ++
i)
923 if (unknownIds_.find(eid) == unknownIds_.end()) {
925 edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" <<
eid;
926 unknownIds_.insert(eid);
928 for (++i; i != iend && !i.
isHeader(); ++
i)
931 }
else if (i.
flavor() == 0x4) {
932 int ilink = ((i.
channelid() >> 4) & 0xF);
941 if (unknownIdsTrig_.find(eid) == unknownIdsTrig_.end()) {
943 edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No trigger primitive match found for electronics id :" <<
eid;
944 unknownIdsTrig_.insert(eid);
947 for (++i; i != iend && !i.
isHeader(); ++
i)
950 for (++i; i != iend && !i.
isHeader(); ++
i)
955 std::cout <<
"Unpacking " <<
id << std::endl;
959 for (++i; i != iend && !i.
isHeader(); ++
i) {
962 colls.
tpCont->back().setPresamples(j);
965 colls.
tpCont->back().setSize(j);
969 for (++i; i != iend && !i.
isHeader(); ++
i)
986 qie10Lasermon =
nullptr;
993 std::vector<HcalHistogramDigi>& histoDigis) {
996 int dccid = dccHeader->
getSourceId() - sourceIdOffset_;
1008 if (retval || !htr.
check()) {
1009 edm::LogWarning(
"Invalid Data") <<
"Invalid HTR data observed on spigot " << spigot <<
" of DCC with source id " 1014 edm::LogWarning(
"Invalid Data") <<
"Non-histogram data passed to histogram unpacker on spigot " << spigot
1015 <<
" of DCC with source id " << dccHeader->
getSourceId();
1020 int htr_tb = smid & 0x1;
1021 int htr_slot = (smid >> 1) & 0x1F;
1022 int htr_cr = (smid >> 6) & 0x1F;
1028 for (
int nf = 0; nf < 2; nf++) {
1029 if (f[nf] < 0 || (nf == 1 && f[0] == f[1]))
1031 for (fc = 0; fc <= 2; fc++) {
1033 eid.
setHTR(htr_cr, htr_slot, htr_tb);
1037 if (unknownIds_.find(eid) == unknownIds_.end()) {
1038 edm::LogWarning(
"HCAL") <<
"HcalHistogramUnpacker: No match found for electronics id :" <<
eid;
1039 unknownIds_.insert(eid);
1047 for (
int capid = 0; capid < 4; capid++)
1056 int namc = amc13->
NAMC();
1058 for (
int iamc = 0; iamc < namc; iamc++) {
1059 if (amc13->
AMCSlot(iamc) == slot)
1062 if (namc == amc13->
NAMC()) {
1065 const uint16_t*
data = (
const uint16_t*)(amc13->
AMCPayload(namc));
1066 size_t nwords = amc13->
AMCSize(namc) * (
sizeof(
uint64_t) /
sizeof(uint16_t));
1077 if (nPrinted_ >= limit) {
1078 if (nPrinted_ == limit)
1079 edm::LogInfo(
"Invalid Data") <<
"Suppressing further error messages";
1084 std::stringstream message;
1086 message <<
"The default " << coll_type <<
" Collection has " << default_ns
1087 <<
" samples per digi, while the current data has " << conflict_ns
1088 <<
"! This data cannot be included with the default collection.";
1091 message <<
"\nIn order to store this data in the event, it must have a unique tag. " 1092 <<
"To accomplish this, provide two lists to HcalRawToDigi \n" 1093 <<
"1) that specifies the number of samples and " 1094 <<
"2) that gives tags with which these data are saved.\n" 1095 <<
"For example in this case you might add \n" 1096 <<
"process.hcalDigis.save" << coll_type <<
"DataNSamples = cms.untracked.vint32( " << conflict_ns
1097 <<
") \nprocess.hcalDigis.save" << coll_type <<
"DataTags = cms.untracked.vstring( \"MYDATA\" )";
constexpr void setHTR(int crate, int slot, int tb)
void countUnmappedTPDigi()
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
static int slbAndChan(uint16_t theSample)
void unpackUTCA(const FEDRawData &raw, const HcalElectronicsMap &emap, Collections &conts, HcalUnpackerReport &report, bool silent=false)
std::vector< HcalTTPDigi > * ttp
CalibDetType calibFlavor() const
get the flavor of this calibration detid
std::vector< HFDataFrame > * hfCont
constexpr bool null() const
is this a null id ?
void addDataFrame(DetId detid, const uint16_t *data)
static bool isTPGSOI(const HcalTriggerPrimitiveSample &s)
QIE10DigiCollection * qie10Lasermon
constexpr int fiberChan() const
get the fiber channel number
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)
std::vector< HBHEDataFrame > * hbheCont
std::vector< HOTriggerPrimitiveDigi > * tphoCont
bool wasMarkAndPassZS(int fiber, int fiberchan) const
Was this channel passed as part of Mark&Pass ZS?
unsigned int getFibOrbMsgBCN(int fiber) const
Get the BCN of the Fiber Orbit Messages.
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)
void getHistogramFibers(int &a, int &b) const
Get the fiber numbers for the data present in this event (only in histogram mode!) ...
std::unordered_map< int, QIE11DigiCollection * > qie11Addtl
int getFormatVersion() const
Get the version number of this event.
size_t size() const
Lenght of the data buffer in bytes.
void countSpigotFormatError()
void printInvalidDataMessage(const std::string &coll_type, int default_ns, int conflict_ns, bool extended=false)
HcalDataFrameContainer< QIE10DataFrame > QIE10DigiCollection
bool isUnsuppressed() const
Is this event an unsuppresed event?
bool isOverflowWarning() const
bool unpackHistogram(int fiber, int fiberchan, int capid, unsigned short *histogram) const
Unpack special histogramming mode data.
static bool is_channel_header(unsigned short value)
check top bit to see if this is a compact format channel header word
std::unordered_map< int, QIE10DigiCollection * > qie10Addtl
QIE10DigiCollection * qie10ZDC
bool isEmptyEvent() const
int ieta() const
get the cell ieta
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
uint16_t raw() const
get the raw word
void unpackVME(const FEDRawData &raw, const HcalElectronicsMap &emap, Collections &conts, HcalUnpackerReport &report, bool silent=false)
std::vector< HcalTriggerPrimitiveDigi > * tpCont
int technicalDataType() const
HcalDataFrameContainer< QIE11DataFrame > QIE11DigiCollection
int iphi() const
get the cell iphi
void unpack(const FEDRawData &raw, const HcalElectronicsMap &emap, std::vector< HcalHistogramDigi > &histoDigis)
static const int SubdetectorId
std::vector< HcalCalibDataFrame > * calibCont
static int slb(uint16_t theSample)
unsigned long long uint64_t
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.
bool unpack(const HcalHTRData &data, HcalTTPDigi &digi)
std::vector< HODataFrame > * hoCont
QIE11DigiCollection * qie11
int getNPS() const
Get the number of presamples in daq data.
static const HcalTrigTowerDetId Undefined
static const int FORMAT_VERSION_COMPACT_DATA
int getFirmwareFlavor() const
Get the HTR firmware flavor.
char data[epos_bytes_allocation]
bool wasMarkAndPassZSTP(int slb, int slbchan) const
Was this channel passed as part of Mark&Pass ZS?
uint16_t * getArray(int capid)
get the array for the specified capid
uint32_t zsBunchMask() const
ZS Bunch Mask (if available)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
constexpr uint16_t raw() const
get the raw word
QIE10DigiCollection * qie10
std::vector< ZDCDataFrame > * zdcCont
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.
void unpackUMNio(const FEDRawData &raw, int slot, Collections &colls)
const uint16_t * raw() const
Readout chain identification for Hcal.
void countEmptyEventSpigot()
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!!!!!)
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)
static int slbChan(uint16_t theSample)
constexpr int fiber() const
get the fiber number
constexpr Detector det() const
get the detector field from this detid
constexpr int fiberAndChan() const
get the id channel