14 namespace HcalUnpacker_impl {
15 template <
class DigiClass>
18 digi.setPresamples(presamples);
19 digi.setReadoutIds(eid);
21 int fiber=startPoint->
fiber();
37 while (qie_work!=limit && qie_work->
fiberAndChan()==myFiberChan) {
38 if (ncurr>=startSample && ncurr<=endSample) {
39 digi.setSample(ntaken,*qie_work);
50 template <
class DigiClass>
51 const unsigned short*
unpack_compact(
const unsigned short* startPoint,
const unsigned short*
limit, DigiClass& digi,
55 digi.setPresamples(presamples);
56 digi.setReadoutIds(eid);
57 int flavor, error_flags, capid0, channelid;
60 bool isCapRotating=!(error_flags&0x1);
61 bool fiberErr=(error_flags&0x2);
62 bool dataValid=!(error_flags&0x2);
63 int fiberchan=channelid&0x3;
64 int fiber=((channelid>>2)&0x7)+1;
78 const unsigned short* qie_work=startPoint;
82 int capidn=(isCapRotating)?((capid0+ncurr)%4):(capid0);
83 int capidn1=(isCapRotating)?((capid0+ncurr+1)%4):(capid0);
85 HcalQIESample s0((*qie_work)&0x7F,capidn,fiber,fiberchan,dataValid,fiberErr);
86 HcalQIESample s1(((*qie_work)>>8)&0x7F,capidn1,fiber,fiberchan,dataValid,fiberErr);
88 if (ncurr>=startSample && ncurr<=endSample) {
89 digi.setSample(ntaken,s0);
93 if (ncurr>=startSample && ncurr<=endSample) {
94 digi.setSample(ntaken,s1);
100 }
else if (flavor==6) {
102 if (ncurr>=startSample && ncurr<=endSample) {
103 HcalQIESample sample((*qie_work)&0x7F,((*qie_work)>>8)&0x3,fiber,fiberchan,((*qie_work)>>10)&0x1,((*qie_work)>>11)&0x1);
104 digi.setSample(ntaken,sample);
109 digi.setSize(ntaken);
117 template <
class DigiClass>
121 digi.setPresamples(presamples-startSample);
122 digi.setReadoutIds(eid);
126 bool isCapRotating=!(error_flags&0x1);
127 bool fiberErr=(error_flags&0x2);
128 bool dataValid=!(error_flags&0x2);
135 int ncurr=0,ntaken=0;
136 for (++i; i!=iend && !i.
isHeader(); ++
i) {
137 int capidn=(isCapRotating)?((capid0+ncurr)%4):(capid0);
141 if (ncurr>=startSample && ncurr<=endSample) {
142 digi.setSample(ntaken,
s);
147 digi.setSize(ntaken);
153 return (s.
raw()&0x200)!=0;
177 if (!silent)
edm::LogWarning(
"Invalid Data") <<
"Empty/invalid data, size = " << raw.
size();
186 else unpackUTCA(raw,emap,colls,report,silent);
189 static int slb(uint16_t theSample) {
return ((theSample>>13)&0x7); }
190 static int slbChan(uint16_t theSample) {
return (theSample>>11)&0x3; }
191 static int slbAndChan(uint16_t theSample) {
return (theSample>>11)&0x1F; }
208 const unsigned short* daq_first, *daq_last, *tp_first, *tp_last;
219 if (!silent)
edm::LogWarning(
"Invalid Data") <<
"Invalid HTR data (data beyond payload size) observed on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
227 edm::LogWarning(
"Invalid Data") <<
"CRC Error on HTR data observed on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
240 if (!silent)
edm::LogWarning(
"Invalid Data") <<
"Invalid uHTR data (data beyond payload size) observed on slot " << slot <<
" of DTC with source id " << dtcHeader->
getSourceId();
248 edm::LogWarning(
"Invalid Data") <<
"CRC Error on uHTR data observed on slot " << slot <<
" of DTC with source id " << dtcHeader->
getSourceId();
267 edm::LogWarning(
"Invalid Data") <<
"Invalid HTR data observed on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
272 if (!silent)
edm::LogWarning(
"Invalid Data") <<
"Histogram data passed to non-histogram unpacker on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
281 LogDebug(
"HcalTechTrigProcessor") <<
"Skipping data on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId() <<
" which is from the TechTrigProcessor (use separate unpacker!)";
294 htr.
dataPointers(&daq_first,&daq_last,&tp_first,&tp_last);
297 int htr_slot=(smid>>1)&0x1F;
298 int htr_cr=(smid>>6)&0x1F;
304 int currFiberChan=0x3F;
316 for (tp_work=tp_begin; tp_work!=tp_end; tp_work++) {
317 if (tp_work->
raw()==0xFFFF)
continue;
319 if (sector>2)
continue;
321 for (
int ibit=0; ibit<8; ibit++) {
323 if (!unrolled[linear].checked) {
325 int fiber=(linear/3)+1;
329 eid.
setHTR(htr_cr,htr_slot,htr_tb);
342 if (unrolled[linear].valid) {
344 if (tp_work->
raw()&(1<<ibit)) unrolled[
linear].
setbit(unrolled[linear].samples);
349 for (
int i=0;
i<24;
i++) {
350 if (unrolled[
i].valid)
356 unrolled[
i].databits));
359 for (tp_work=tp_begin; tp_work!=tp_end; tp_work++) {
360 if (tp_work->
raw()==0xFFFF)
continue;
370 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No trigger primitive match found for electronics id :" << eid;
384 if (!tpgSOIbitInUse) colls.
tpCont->back().setPresamples(nps);
393 colls.
tpCont->back().setSample(colls.
tpCont->back().size(),*tp_work);
394 colls.
tpCont->back().setSize(colls.
tpCont->back().size()+1);
397 if (valid && tpgSOIbitInUse &&
isTPGSOI(*tp_work)) {
398 colls.
tpCont->back().setPresamples(ncurr);
417 for (qie_work=qie_begin; qie_work!=qie_end; ) {
418 if (qie_work->
raw()==0xFFFF) {
427 eid.
setHTR(htr_cr,htr_slot,htr_tb);
468 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" << eid;
478 const unsigned short* ptr_header=daq_first;
479 const unsigned short* ptr_end=daq_last+1;
480 int flavor, error_flags, capid0, channelid;
482 while (ptr_header!=ptr_end) {
483 if (*ptr_header==0xFFFF) {
494 int fiberchan=channelid&0x3;
495 int fiber=((channelid>>2)&0x7)+1;
499 eid.
setHTR(htr_cr,htr_slot,htr_tb);
540 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" << eid;
559 int namc=amc13->
NAMC();
560 for (
int iamc=0; iamc<namc; iamc++) {
566 edm::LogWarning(
"Invalid Data") <<
"Missing data observed on iamc " << iamc <<
" of AMC13 with source id " << amc13->
sourceId();
572 edm::LogWarning(
"Invalid Data") <<
"CRC Error on uHTR data observed on iamc " << iamc <<
" of AMC13 with source id " << amc13->
sourceId();
579 edm::LogWarning(
"Invalid Data") <<
"Unpacker cannot handle segmented data observed on iamc " << iamc <<
" of AMC13 with source id " << amc13->
sourceId();
586 int crate=amc13->
AMCId(iamc)&0xFF;
588 int nps=(amc13->
AMCId(iamc)>>12)&0xF;
592 if(uhtr.getFormatVersion() != 1)
continue;
596 for (
int iw=0; iw<nwords; iw++)
597 printf(
"%04d %04x\n",iw,uhtr.getRawData16()[iw]);
609 std::cout <<
"its not a header" << std::endl;
620 const uint16_t* head_pos = i.
raw();
622 for (++i; i != iend && !i.
isHeader(); ++
i) {
626 if (colls.
qie11 == 0) {
631 edm::LogError(
"Invalid Data") <<
"Collection has " << colls.
qie11->
samples() <<
" samples per digi, raw data has " << ns <<
"!";
642 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" << eid;
645 std::cout <<
"HcalUnpacker: No match found for electronics id :" << eid << std::endl;
649 std::cout <<
"OH NO! detector id is null!" << std::endl;
652 }
else if (i.
flavor() == 2){
661 const uint16_t* head_pos = i.
raw();
663 for (++i; i != iend && !i.
isHeader(); ++
i) {
668 if (colls.
qie10 == 0) {
673 edm::LogError(
"Invalid Data") <<
"Collection has " << colls.
qie10->
samples() <<
" samples per digi, raw data has " << ns <<
"!";
684 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" << eid;
687 std::cout <<
"HcalUnpacker: No match found for electronics id :" << eid << std::endl;
691 std::cout <<
"OH NO! HcalUnpacker: No match found for electronics id :" << eid << std::endl;
695 else if (i.
flavor()==0x5) {
739 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No match found for electronics id :" << eid;
746 }
else if (i.
flavor()==0x4) {
757 if (!silent)
edm::LogWarning(
"HCAL") <<
"HcalUnpacker: No trigger primitive match found for electronics id :" << eid;
761 for (++i; i!=iend && !i.
isHeader(); ++
i);
764 for (++i; i!=iend && !i.
isHeader(); ++
i);
768 std::cout <<
"Unpacking " <<
id << std::endl;
772 for (++i; i!=iend && !i.
isHeader(); ++
i) {
774 if (i.
soi()) colls.
tpCont->back().setPresamples(j);
777 colls.
tpCont->back().setSize(j);
816 if (retval || !htr.
check()) {
817 edm::LogWarning(
"Invalid Data") <<
"Invalid HTR data observed on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
821 edm::LogWarning(
"Invalid Data") <<
"Non-histogram data passed to histogram unpacker on spigot " << spigot <<
" of DCC with source id " << dccHeader->
getSourceId();
827 int htr_slot=(smid>>1)&0x1F;
828 int htr_cr=(smid>>6)&0x1F;
834 for (
int nf=0; nf<2; nf++) {
835 if (f[nf]<0 || (nf==1 && f[0]==f[1]))
continue;
836 for (fc=0; fc<=2; fc++) {
838 eid.
setHTR(htr_cr,htr_slot,htr_tb);
843 edm::LogWarning(
"HCAL") <<
"HcalHistogramUnpacker: No match found for electronics id :" << eid;
852 for (
int capid=0; capid<4; capid++)
862 int namc=amc13->
NAMC();
864 for (
int iamc=0; iamc<namc; iamc++) {
865 if (amc13->
AMCSlot(iamc) == slot) namc = iamc;
867 if (namc==amc13->
NAMC())
return;
869 const uint16_t*
data = (
const uint16_t*)(amc13->
AMCPayload(namc));
870 size_t nwords = amc13->
AMCSize(namc) * (
sizeof(
uint64_t) /
sizeof(uint16_t) );
std::set< HcalElectronicsId > unknownIds_
int sourceIdOffset_
number to subtract from the source id to get the dcc id
int endSample_
last sample from fed raw data to copy (if present)
int startSample_
first sample from fed raw data to copy
void countUnmappedTPDigi()
uint16_t raw() const
get the raw word
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
std::vector< HFDataFrame > * hfCont
int fiberAndChan() const
get the id channel
int fiberChan() const
get the fiber channel number
void addDataFrame(DetId detid, const uint16_t *data)
static bool isTPGSOI(const HcalTriggerPrimitiveSample &s)
void unpackUMNio(const FEDRawData &raw, int slot, HcalUMNioDigi &umnio)
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!) ...
int getFormatVersion() const
Get the version number of this event.
size_t size() const
Lenght of the data buffer in bytes.
void countSpigotFormatError()
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
int expectedOrbitMessageTime_
Expected orbit bunch time (needed to evaluate time differences)
bool isEmptyEvent() const
int ieta() const
get the cell ieta
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 fiber() const
get the fiber number
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::set< HcalElectronicsId > unknownIdsTrig_
Recorded to limit number of times a log message is generated.
HcalDataFrameContainer< QIE11DataFrame > QIE11DigiCollection
int iphi() const
get the cell iphi
void setHTR(int crate, int slot, int tb)
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)
bool null() const
is this a null id ?
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.
const int getRawLengthBytes() const
Get the length of the raw data.
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.
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.
Detector det() const
get the detector field from this detid
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)