16 template <
class DigiClass>
19 digi.setPresamples(presamples);
20 digi.setReadoutIds(eid);
22 int fiber=startPoint->
fiber();
38 while (qie_work!=limit && qie_work->
fiberAndChan()==myFiberChan) {
39 if (ncurr>=startSample && ncurr<=endSample) {
40 digi.setSample(ntaken,*qie_work);
51 template <
class DigiClass>
52 const unsigned short*
unpack_compact(
const unsigned short* startPoint,
const unsigned short*
limit, DigiClass& digi,
56 digi.setPresamples(presamples);
57 digi.setReadoutIds(eid);
58 int flavor, error_flags, capid0, channelid;
61 bool isCapRotating=!(error_flags&0x1);
62 bool fiberErr=(error_flags&0x2);
63 bool dataValid=!(error_flags&0x2);
64 int fiberchan=channelid&0x3;
65 int fiber=((channelid>>2)&0x7)+1;
79 const unsigned short* qie_work=startPoint;
83 int capidn=(isCapRotating)?((capid0+ncurr)%4):(capid0);
84 int capidn1=(isCapRotating)?((capid0+ncurr+1)%4):(capid0);
86 HcalQIESample s0((*qie_work)&0x7F,capidn,fiber,fiberchan,dataValid,fiberErr);
87 HcalQIESample s1(((*qie_work)>>8)&0x7F,capidn1,fiber,fiberchan,dataValid,fiberErr);
89 if (ncurr>=startSample && ncurr<=endSample) {
90 digi.setSample(ntaken,s0);
94 if (ncurr>=startSample && ncurr<=endSample) {
95 digi.setSample(ntaken,s1);
100 digi.setSize(ntaken);
101 }
else if (flavor==6) {
103 if (ncurr>=startSample && ncurr<=endSample) {
104 HcalQIESample sample((*qie_work)&0x7F,((*qie_work)>>8)&0x3,fiber,fiberchan,((*qie_work)>>10)&0
x1,((*qie_work)>>11)&0
x1);
105 digi.setSample(ntaken,sample);
111 digi.setSize(ntaken);
119 template <
class DigiClass>
123 digi.setPresamples(presamples-startSample);
124 digi.setReadoutIds(eid);
129 bool isCapRotating=!(error_flags&0x1);
130 bool fiberErr=(error_flags&0x2);
131 bool dataValid=!(error_flags&0x2);
138 int ncurr=0,ntaken=0;
140 for (++i; i!=iend && !i.
isHeader(); ++
i) {
141 int capidn=(isCapRotating)?((capid0+ncurr)%4):(capid0);
145 if (ncurr>=startSample && ncurr<=endSample) {
146 digi.setSample(ntaken,
s);
151 digi.setSize(ntaken);
154 for (++i; i!=iend && !i.
isHeader(); ++
i) {
155 if (ncurr>=startSample && ncurr<=endSample) {
157 digi.setSample(ntaken,
sample);
162 digi.setSize(ntaken);
170 return (s.
raw()&0x200)!=0;
194 if (!silent)
edm::LogWarning(
"Invalid Data") <<
"Empty/invalid data, size = " << raw.
size();
202 unpackVME(raw,emap,colls,report,silent);
203 else unpackUTCA(raw,emap,colls,report,silent);
206 static int slb(uint16_t theSample) {
return ((theSample>>13)&0x7); }
207 static int slbChan(uint16_t theSample) {
return (theSample>>11)&0x3; }
208 static int slbAndChan(uint16_t theSample) {
return (theSample>>11)&0x1F; }
219 int dccid=(is_VME_DCC)?(dccHeader->
getSourceId()-sourceIdOffset_):(dtcHeader->
getSourceId()-sourceIdOffset_);
225 const unsigned short* daq_first, *daq_last, *tp_first, *tp_last;
236 if (!silent)
edm::LogWarning(
"Invalid Data") <<
"Invalid HTR data (data beyond payload size) observed on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
244 edm::LogWarning(
"Invalid Data") <<
"CRC Error on HTR data observed on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
257 if (!silent)
edm::LogWarning(
"Invalid Data") <<
"Invalid uHTR data (data beyond payload size) observed on slot " << slot <<
" of DTC with source id " << dtcHeader->
getSourceId();
265 edm::LogWarning(
"Invalid Data") <<
"CRC Error on uHTR data observed on slot " << slot <<
" of DTC with source id " << dtcHeader->
getSourceId();
284 edm::LogWarning(
"Invalid Data") <<
"Invalid HTR data observed on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
289 if (!silent)
edm::LogWarning(
"Invalid Data") <<
"Histogram data passed to non-histogram unpacker on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
293 if (colls.
ttp!=
nullptr) {
298 LogDebug(
"HcalTechTrigProcessor") <<
"Skipping data on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId() <<
" which is from the TechTrigProcessor (use separate unpacker!)";
308 int nps=htr.
getNPS()-startSample_;
311 htr.
dataPointers(&daq_first,&daq_last,&tp_first,&tp_last);
314 int htr_slot=(smid>>1)&0x1F;
315 int htr_cr=(smid>>6)&0x1F;
321 int currFiberChan=0x3F;
333 for (tp_work=tp_begin; tp_work!=tp_end; tp_work++) {
334 if (tp_work->
raw()==0xFFFF)
continue;
336 if (sector>2)
continue;
338 for (
int ibit=0; ibit<8; ibit++) {
340 if (!unrolled[linear].checked) {
342 int fiber=(linear/3)+1;
346 eid.
setHTR(htr_cr,htr_slot,htr_tb);
359 if (unrolled[linear].valid) {
366 for (
int i=0;
i<24;
i++) {
367 if (unrolled[
i].valid)
373 unrolled[
i].databits));
376 for (tp_work=tp_begin; tp_work!=tp_end; tp_work++) {
377 if (tp_work->
raw()==0xFFFF)
continue;
386 if (unknownIdsTrig_.find(eid)==unknownIdsTrig_.end()) {
387 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No trigger primitive match found for electronics id :" <<
eid;
388 unknownIdsTrig_.insert(eid);
401 if (!tpgSOIbitInUse) colls.
tpCont->back().setPresamples(nps);
409 if (valid && ((tpgSOIbitInUse && ncurr<10) || (ncurr>=startSample_ && ncurr<=endSample_))) {
410 colls.
tpCont->back().setSample(colls.
tpCont->back().size(),*tp_work);
411 colls.
tpCont->back().setSize(colls.
tpCont->back().size()+1);
414 if (valid && tpgSOIbitInUse &&
isTPGSOI(*tp_work)) {
415 colls.
tpCont->back().setPresamples(ncurr);
431 for (qie_work=qie_begin; qie_work!=qie_end; ) {
432 if (qie_work->
raw()==0xFFFF) {
440 eid.setHTR(htr_cr,htr_slot,htr_tb);
446 qie_work=HcalUnpacker_impl::unpack<ZDCDataFrame>(qie_work, qie_end, colls.
zdcCont->back(), nps,
eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
452 qie_work=HcalUnpacker_impl::unpack<HBHEDataFrame>(qie_work, qie_end, colls.
hbheCont->back(), nps,
eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
456 qie_work=HcalUnpacker_impl::unpack<HODataFrame>(qie_work, qie_end, colls.
hoCont->back(), nps,
eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
460 qie_work=HcalUnpacker_impl::unpack<HFDataFrame>(qie_work, qie_end, colls.
hfCont->back(), nps,
eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
466 qie_work=HcalUnpacker_impl::unpack<HcalCalibDataFrame>(qie_work, qie_end, colls.
calibCont->back(), nps,
eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
480 if (unknownIds_.find(
eid)==unknownIds_.end()) {
481 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" <<
eid;
482 unknownIds_.insert(
eid);
491 const unsigned short* ptr_header=daq_first;
492 const unsigned short* ptr_end=daq_last+1;
493 int flavor, error_flags, capid0, channelid;
495 while (ptr_header!=ptr_end) {
496 if (*ptr_header==0xFFFF) {
507 int fiberchan=channelid&0x3;
508 int fiber=((channelid>>2)&0x7)+1;
512 eid.
setHTR(htr_cr,htr_slot,htr_tb);
518 ptr_header=HcalUnpacker_impl::unpack_compact<ZDCDataFrame>(ptr_header, ptr_end, colls.
zdcCont->back(), nps,
eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
524 ptr_header=HcalUnpacker_impl::unpack_compact<HBHEDataFrame>(ptr_header, ptr_end, colls.
hbheCont->back(), nps,
eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
528 ptr_header=HcalUnpacker_impl::unpack_compact<HODataFrame>(ptr_header, ptr_end, colls.
hoCont->back(), nps,
eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
532 ptr_header=HcalUnpacker_impl::unpack_compact<HFDataFrame>(ptr_header, ptr_end, colls.
hfCont->back(), nps,
eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
538 ptr_header=HcalUnpacker_impl::unpack_compact<HcalCalibDataFrame>(ptr_header, ptr_end, colls.
calibCont->back(), nps,
eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
552 if (unknownIds_.find(eid)==unknownIds_.end()) {
553 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" <<
eid;
554 unknownIds_.insert(eid);
572 int namc=amc13->
NAMC();
573 for (
int iamc=0; iamc<namc; iamc++) {
579 edm::LogWarning(
"Invalid Data") <<
"Missing data observed on iamc " << iamc <<
" of AMC13 with source id " << amc13->
sourceId();
585 edm::LogWarning(
"Invalid Data") <<
"CRC Error on uHTR data observed on iamc " << iamc <<
" of AMC13 with source id " << amc13->
sourceId();
592 edm::LogWarning(
"Invalid Data") <<
"Unpacker cannot handle segmented data observed on iamc " << iamc <<
" of AMC13 with source id " << amc13->
sourceId();
599 int crate=amc13->
AMCId(iamc)&0xFF;
603 if(uhtr.getFormatVersion() != 1) {
604 unpackUMNio(raw, slot, colls);
609 int nwords=uhtr.getRawLengthBytes()/2;
610 for (
int iw=0; iw<nwords; iw++)
611 printf(
"%04d %04x\n",iw,uhtr.getRawData16()[iw]);
615 int nps = uhtr.presamples();
626 std::cout <<
"its not a header" << std::endl;
637 const uint16_t* head_pos = i.
raw();
639 for (++i; i != iend && !i.
isHeader(); ++
i) {
643 if (colls.
qie11 ==
nullptr) {
663 colls.
qie11Addtl[ns]->addDataFrame( did, head_pos );
667 if (unknownIds_.find(eid)==unknownIds_.end()) {
668 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" <<
eid;
669 unknownIds_.insert(eid);
671 std::cout <<
"HcalUnpacker: No match found for electronics id :" << eid << std::endl;
675 std::cout <<
"OH NO! detector id is null!" << std::endl;
678 }
else if (i.
flavor() == 2){
687 const uint16_t* head_pos = i.
raw();
689 for (++i; i != iend && !i.
isHeader(); ++
i) {
703 else if( isLasmon ) {
710 if (colls.
qie10 ==
nullptr) {
737 colls.
qie10Addtl[ns]->addDataFrame( did, head_pos );
742 if (unknownIds_.find(eid)==unknownIds_.end()) {
743 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" <<
eid;
744 unknownIds_.insert(eid);
746 std::cout <<
"HcalUnpacker: No match found for electronics id :" << eid << std::endl;
750 std::cout <<
"OH NO! HcalUnpacker: No match found for electronics id :" << eid << std::endl;
763 HcalUnpacker_impl::unpack_compact<ZDCDataFrame>(
i,iend, colls.
zdcCont->back(), nps,
eid, startSample_, endSample_);
769 HcalUnpacker_impl::unpack_compact<HBHEDataFrame>(
i, iend, colls.
hbheCont->back(), nps,
eid, startSample_, endSample_);
773 HcalUnpacker_impl::unpack_compact<HODataFrame>(
i, iend, colls.
hoCont->back(), nps,
eid, startSample_, endSample_);
777 HcalUnpacker_impl::unpack_compact<HFDataFrame>(
i, iend, colls.
hfCont->back(), nps,
eid, startSample_, endSample_);
783 HcalUnpacker_impl::unpack_compact<HcalCalibDataFrame>(
i, iend, colls.
calibCont->back(), nps,
eid, startSample_, endSample_);
797 if (unknownIds_.find(eid)==unknownIds_.end()) {
798 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" <<
eid;
799 unknownIds_.insert(eid);
805 }
else if (i.
flavor()==0x4) {
815 if (unknownIdsTrig_.find(eid)==unknownIdsTrig_.end()) {
816 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No trigger primitive match found for electronics id :" <<
eid;
817 unknownIdsTrig_.insert(eid);
820 for (++i; i!=iend && !i.
isHeader(); ++
i);
823 for (++i; i!=iend && !i.
isHeader(); ++
i);
827 std::cout <<
"Unpacking " <<
id << std::endl;
831 for (++i; i!=iend && !i.
isHeader(); ++
i) {
833 if (i.
soi()) colls.
tpCont->back().setPresamples(j);
836 colls.
tpCont->back().setSize(j);
858 qie10Lasermon=
nullptr;
867 int dccid=dccHeader->
getSourceId()-sourceIdOffset_;
878 if (retval || !htr.
check()) {
879 edm::LogWarning(
"Invalid Data") <<
"Invalid HTR data observed on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
883 edm::LogWarning(
"Invalid Data") <<
"Non-histogram data passed to histogram unpacker on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
889 int htr_slot=(smid>>1)&0x1F;
890 int htr_cr=(smid>>6)&0x1F;
896 for (
int nf=0; nf<2; nf++) {
897 if (f[nf]<0 || (nf==1 && f[0]==f[1]))
continue;
898 for (fc=0; fc<=2; fc++) {
900 eid.
setHTR(htr_cr,htr_slot,htr_tb);
904 if (unknownIds_.find(eid)==unknownIds_.end()) {
905 edm::LogWarning(
"HCAL") <<
"HcalHistogramUnpacker: No match found for electronics id :" <<
eid;
906 unknownIds_.insert(eid);
914 for (
int capid=0; capid<4; capid++)
924 int namc=amc13->
NAMC();
926 for (
int iamc=0; iamc<namc; iamc++) {
927 if (amc13->
AMCSlot(iamc) == slot) namc = iamc;
929 if (namc==amc13->
NAMC()) {
932 const uint16_t*
data = (
const uint16_t*)(amc13->
AMCPayload(namc));
933 size_t nwords = amc13->
AMCSize(namc) * (
sizeof(
uint64_t) /
sizeof(uint16_t) );
943 if( nPrinted_ >= limit ) {
945 if( nPrinted_ == limit )
edm::LogInfo(
"Invalid Data") <<
"Suppressing further error messages";
950 std::stringstream message;
952 message <<
"The default " << coll_type <<
" Collection has " 953 << default_ns <<
" samples per digi, while the current data has " 954 << conflict_ns <<
"! This data cannot be included with the default collection.";
957 message <<
"\nIn order to store this data in the event, it must have a unique tag. " 958 <<
"To accomplish this, provide two lists to HcalRawToDigi \n" 959 <<
"1) that specifies the number of samples and " 960 <<
"2) that gives tags with which these data are saved.\n" 961 <<
"For example in this case you might add \n" 962 <<
"process.hcalDigis.save" << coll_type <<
"DataNSamples = cms.untracked.vint32( " 963 << conflict_ns <<
") \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