5 #ifndef HTBDAQ_DATA_STANDALONE
29 const int needed=0x200;
33 memset(
m_ownData,0,
sizeof(
unsigned short)*needed);
92 int tp, daq, header, trailer;
94 if (tp+daq+header+trailer>
m_rawLength)
return false;
154 const unsigned short** daq_last,
155 const unsigned short** tp_first,
156 const unsigned short** tp_last)
const {
157 int tp_words_total, daq_words_total, headerLen, trailerLen;
161 *tp_last=*tp_first+(tp_words_total-1);
162 *daq_first=*tp_last+1;
163 *daq_last=*daq_first+(daq_words_total-1);
168 6, 7, 8, 99, 9,10,11, 99,
169 12,13,14,99,15,16,17, 99,
170 18,19,20,99,21,22,23, 99};
173 unsigned char* tp_lengths,
unsigned short* tp_samples)
const {
182 int tp_words_total, daq_words_total, headerLen, trailerLen;
187 const unsigned short* tpBase=
m_rawConst+headerLen;
190 for (wordPtr=0; wordPtr<tp_words_total; wordPtr++) {
192 if (ichan>=24)
continue;
198 const unsigned short* daqBase=
m_rawConst+headerLen+tp_words_total;
202 if (daq_lengths!=0) {
203 for (wordPtr=0; wordPtr<daq_words_total; wordPtr++) {
205 if (ichan>=24)
continue;
206 int capid=(daqBase[wordPtr]&0x180)>>7;
207 int erdv=(daqBase[wordPtr]&0x600)>>9;
209 (lastChan==ichan && (capid!=((lastCapid+1)%4)))) {
210 daq_lengths[ichan]|=0x80;
215 int useLength=daq_lengths[ichan]&0x1F;
218 daq_lengths[ichan]=(useLength+1)|(daq_lengths[ichan]&0xE0);
225 unsigned char* tp_lengths,
unsigned short* tp_samples,
bool do_capid) {
227 int tp_words_total=0, daq_words_total=0, headerLen, trailerLen;
236 if (tp_samples!=0 && tp_lengths!=0) {
237 for (ichan=0; ichan<24; ichan++) {
238 unsigned short chanid=((ichan%3)+((ichan/3)<<2))<<11;
240 ptr[tp_words_total]=chanid|(tp_samples[ichan*MAXIMUM_SAMPLES_PER_CHANNEL+isample]&0x3FF);
248 for (ichan=0; ichan<24; ichan++) {
249 unsigned short chanid=((ichan%3)+((ichan/3)<<2))<<11;
251 unsigned short basedata=daq_samples[ichan*MAXIMUM_SAMPLES_PER_CHANNEL+isample]&0x7FF;
252 if (do_capid) basedata=(basedata&0x7F)|(0x200)|((isample%4)<<7);
253 ptr[daq_words_total]=chanid|basedata;
257 unsigned short totalLen;
260 totalLen=headerLen+tp_words_total+daq_words_total+trailerLen;
266 totalLen=headerLen+tp_words_total+daq_words_total+trailerLen;
267 if ((totalLen%2)==1) {
276 if (trailerLen==12) {
277 for (
int i=12;
i>4;
i--)
288 m_ownData[3]=((orbitn&0xFF)<<8)|(submodule&0xFF);
294 m_ownData[3]=((orbitn&0x3F)<<10)|(submodule&0x3FF);
296 m_ownData[3]=((orbitn&0x1F)<<11)|(submodule&0x7FF);
299 m_ownData[6]=((firmwareRev&0x70000)>>3)|(firmwareRev&0x1FFF);
311 for (
int fiber=1; fiber<=8; fiber++) {
312 for (
int fiberchan=0; fiberchan<=2; fiberchan++) {
313 int linchan=(fiber-1)*3+fiberchan;
316 if (mp[linchan]) val|=1<<(linchan%8);
340 return ((smid>>1)&0x1F);
348 return ((smid>>6)&0x1F);
357 if (fiber<1 || fiber>8 || fiberchan<0 || fiberchan>2)
return false;
359 int linchan=(fiber-1)*3+fiberchan;
362 return ((val>>(linchan%8))&0x1)!=0;
365 if (slb<1 || slb>6 || slbchan<0 || slbchan>3)
return false;
367 int linchan=(slb-1)*4+slbchan;
370 return ((val>>(linchan%8))&0x100)!=0;
434 flav=(header>>12)&0x7;
435 error_flags=(header>>10)&0x3;
436 capid0=(header>>8)&0x3;
437 channelid=(header)&0xFF;
438 return (header&0x8000)!=0;
447 if (fiber1!=myfiber && fiber2!=myfiber)
return false;
450 int offset=6+mysc*4*32+capid*32;
451 if (myfiber==fiber2) offset+=3*4*32;
452 for (
int i=0;
i<32;
i++)
456 int offset=8+mysc*4*32+capid*32;
457 if (myfiber==fiber2) offset+=3*4*32;
458 for (
int i=0;
i<32;
i++)
unsigned short * m_ownData
int getNDD() const
Get the number of daq data samples per channel when not zero-suppressed.
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
unsigned int htrTopBottom() const
HcalElectronicsId-style HTR top/bottom (1=top/0=bottom)
void packUnsuppressed(const bool *mp)
pack trailer with Mark and Pass bits
bool isPatternRAMEvent() const
Is this event a pattern-ram event?
const unsigned short * m_rawConst
void determineStaticLengths(int &headerWords, int &trailerWords) const
bool wasMarkAndPassZS(int fiber, int fiberchan) const
Was this channel passed as part of Mark&Pass ZS?
bool wasHistogramError(int ifiber) const
Was there an error on the given fiber for this event (only in histogram mode!)
static const int CHANNELS_PER_SPIGOT
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)
static const int MAXIMUM_SAMPLES_PER_CHANNEL
void getHistogramFibers(int &a, int &b) const
Get the fiber numbers for the data present in this event (only in histogram mode!) ...
unsigned int getOrbitNumber() const
Get the HTR orbit number.
HcalHTRData & operator=(const HcalHTRData &)
int getNPrecisionWords() const
Get the total number of precision data 16-bit words.
bool isCalibrationStream() const
Is this event a calibration-stream event?
bool isUnsuppressed() const
Is this event an unsuppresed event?
void allocate(int version_to_create=0)
unsigned int getPipelineLength() const
Get the pipeline length used for this event.
bool isOverflowWarning() const
unsigned int htrSlot() const
HcalElectronicsId-style HTR slot.
void unpack(unsigned char *daq_lengths, unsigned short *daq_samples, unsigned char *tp_lengths, unsigned short *tp_samples) const
Unpack the HTR data into TP and DAQ data sorted by channel.
bool unpackHistogram(int fiber, int fiberchan, int capid, unsigned short *histogram) const
Unpack special histogramming mode data.
int getNTP() const
Get the number of trigger data samples when not zero-suppressed (not available after FW 4) ...
bool isEmptyEvent() const
unsigned int offset(bool)
void pack(unsigned char *daq_lengths, unsigned short *daq_samples, unsigned char *tp_lengths, unsigned short *tp_samples, bool do_capid=false)
Unpack the HTR data into TP and DAQ data sorted by channel.
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.
static const int channelDecoder[32]
int getNPS() const
Get the number of presamples in daq data.
int getFirmwareFlavor() const
Get the HTR firmware flavor.
unsigned int readoutVMECrateId() const
HcalElectronicsId-style VME crate number.
void adoptData(const unsigned short *data, int length)
char data[epos_bytes_allocation]
bool wasMarkAndPassZSTP(int slb, int slbchan) const
Was this channel passed as part of Mark&Pass ZS?
void packHeaderTrailer(int L1Anumber, int bcn, int submodule, int orbitn, int pipeline, int ndd, int nps, int firmwareRev=0)
pack header and trailer (call after pack)
uint32_t zsBunchMask() const
ZS Bunch Mask (if available)
unsigned int getSubmodule() const
Get the HTR submodule number.
unsigned int getFirmwareRevision() const
Get the HTR firmware version.
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
void determineSectionLengths(int &tpWords, int &daqWords, int &headerWords, int &trailerWords) const