1 #ifndef EventFilter_HcalRawToDigi_PackerHelp_h 2 #define EventFilter_HcalRawToDigi_PackerHelp_h 193 unsigned char cdfh[8];
198 OrbitNum = OrbitNum_;
199 EventNum = EventNum_;
208 for (
int is = 0; is < 8; is++) {
209 outVec.push_back((var64bit >> (is * 8)) & 0xFF);
253 AMCHeaders.push_back(header);
258 uhtrs.push_back(uhtr);
260 addAMCHeader(crate, slot, uhtr.size() / 4);
266 if (uhtrs.size() != AMCHeaders.size()) {
271 split64bitTo8bit(fedData, cdfHeader);
274 setNAMC(uhtrs.size());
276 split64bitTo8bit(fedData, AMC13Header);
279 for (
unsigned int iAMC = 0; iAMC < AMCHeaders.size(); ++iAMC) {
283 split64bitTo8bit(fedData, AMCHeaders[iAMC]);
287 for (
unsigned int iAMC = 0; iAMC < uhtrs.size(); ++iAMC) {
288 unsigned int nWords16 = uhtrs[iAMC].size();
289 for (
unsigned int amcWord = 0; amcWord < nWords16; ++amcWord) {
290 fedData.push_back((uhtrs[iAMC][amcWord] >> 0) & 0xFF);
291 fedData.push_back((uhtrs[iAMC][amcWord] >> 8) & 0xFF);
296 while (fedData.size() % 8 != 0)
297 fedData.push_back(0);
300 rawData.
resize(fedData.size());
301 unsigned char* words =
reinterpret_cast<unsigned char*
>(rawData.
data());
303 for (
unsigned int i = 0;
i < fedData.size(); ++
i) {
318 static const int OFFSET_DATA_LENGTH = 0;
319 static const int MASK_DATA_LENGTH = 0xFFFFF;
320 static const int OFFSET_BCN = 20;
321 static const int MASK_BCN = 0xFFF;
322 static const int OFFSET_EVN = 32;
323 static const int MASK_EVN = 0xFFFFFF;
324 static const int OFFSET_FILED_BY_AMC13 = 56;
325 static const int MASK_FILED_BY_AMC13 = 0xFF;
335 static const int OFFSET_FW_FLAVOR = 32;
336 static const int MASK_FW_FLAVOR = 0xFF;
337 static const int OFFSET_EVENT_TYPE = 40;
338 static const int MASK_EVENT_TYPE = 0xF;
339 static const int OFFSET_PAYLOAD_FORMAT = 44;
340 static const int MASK_PAYLOAD_FORMAT = 0xF;
341 static const int OFFSET_FW_VERSION = 48;
342 static const int MASK_FW_VERSION = 0xFFFF;
346 bool exist(
int uhtrIndex) {
return uhtrs.count(uhtrIndex) != 0; };
360 int fiberErr = qieSample.
er();
361 int capid0 = qieSample.
capid();
374 int adc = qieSample.
adc();
375 int capid = qieSample.
capid();
376 int dv = qieSample.
dv();
377 int er = qieSample.
er();
421 int flavor = qiedf[0].
flavor();
431 int capid0 = qiedf[0].capid();
443 uhtrData*
newUHTR(
int uhtrIndex,
int ps = 0,
int orn = 0,
int bcn = 0,
uint64_t evt = 0) {
445 uhtrs[uhtrIndex] = uhtrData(8);
449 uint64_t uhtrCrate = uhtrIndex & 0xFF;
450 uint64_t uhtrSlot = (uhtrIndex & 0xF00) >> 8;
459 uhtrHeader1 |= (
uint64_t(0x0) & MASK_DATA_LENGTH) << OFFSET_DATA_LENGTH;
460 uhtrHeader1 |= (bcn & MASK_BCN) << OFFSET_BCN;
461 uhtrHeader1 |= (evt & MASK_EVN) << OFFSET_EVN;
462 uhtrHeader1 |= (
uint64_t(0x0) & MASK_FILED_BY_AMC13) << OFFSET_FILED_BY_AMC13;
465 uhtrHeader2 |= (uhtrCrate &
MASK_CRATE_ID) << OFFSET_CRATE_ID;
466 uhtrHeader2 |= (uhtrSlot &
MASK_SLOT_ID) << OFFSET_SLOT_ID;
468 uhtrHeader2 |= (orn &
MASK_ORN) << OFFSET_ORN;
469 uhtrHeader2 |= (fwFlavor & MASK_FW_FLAVOR) << OFFSET_FW_FLAVOR;
470 uhtrHeader2 |= (eventType & MASK_EVENT_TYPE) << OFFSET_EVENT_TYPE;
471 uhtrHeader2 |= (payloadFormat & MASK_PAYLOAD_FORMAT) << OFFSET_PAYLOAD_FORMAT;
472 uhtrHeader2 |= (fwVersion & MASK_FW_VERSION) << OFFSET_FW_VERSION;
475 for (
unsigned int i = 0;
i < 4; ++
i) {
476 uhtrs[uhtrIndex][
i] = (uhtrHeader1 >> (
i * 16)) & 0xFFFF;
477 uhtrs[uhtrIndex][
i + 4] = (uhtrHeader2 >> (
i * 16)) & 0xFFFF;
480 return &(uhtrs[uhtrIndex]);
484 uint64_t uhtr_size = uhtr->size() - 8;
487 uhtr->at(0) = uhtr_size & 0xFFFF;
488 uhtr->at(1) |= (uhtr_size >> 16) & 0xF;
490 unsigned int toAdd = 4 - uhtr->size() % 4;
491 for (
unsigned int ia = 0; ia <
toAdd; ia++) {
492 uhtr->push_back(0xD07F);
496 uhtr->push_back(uhtr_size & 0xFFFF);
497 uhtr->push_back((uhtr_size >> 16) & 0xF);
510 if (qiedf->
size() == 0)
512 DetId detid = qiedf->id();
514 uint16_t
header = packQIE8header(qiedf->sample(0),
eid, premix ? 7 : 5);
515 uhtrs[uhtrIndex].push_back(header);
518 for (
int iTS = 0; iTS < qiedf->
size(); ++iTS) {
519 uhtrs[uhtrIndex].push_back(packQIE8sample(qiedf->sample(iTS)));
522 for (
int iTS = 0; iTS < qiedf->
size(); iTS += 2) {
524 int adc0 = qiedf->sample(iTS).adc();
525 int adc1 = qiedf->sample(iTS + 1).adc();
527 cont |= (adc1 & 0xFF) << 8;
538 if (qiedf->
size() == 0)
540 DetId detid = qiedf->id();
542 uint16_t
header = packQIE8header(qiedf->sample(0),
eid, premix ? 7 : 5);
543 uhtrs[uhtrIndex].push_back(header);
546 for (
int iTS = 0; iTS < qiedf->
size(); ++iTS) {
547 uhtrs[uhtrIndex].push_back(packQIE8sample(qiedf->sample(iTS)));
550 for (
int iTS = 0; iTS < qiedf->
size(); iTS += 2) {
552 int adc0 = qiedf->sample(iTS).adc();
553 int adc1 = qiedf->sample(iTS + 1).adc();
555 cont |= (adc1 & 0xFF) << 8;
565 if (qiedf->
size() == 0)
567 uint16_t
header = packTPheader(qiedf->sample(0), channelid);
568 uhtrs[uhtrIndex].push_back(header);
570 for (
int iTS = 0; iTS < qiedf->
size(); iTS++) {
572 auto raw = qiedf->sample(iTS).raw();
574 if (iTS == qiedf->presamples())
576 uhtrs[uhtrIndex].push_back(raw);
589 uint16_t
header = packQIE11header(qiedf,
eid);
590 uhtrs[uhtrIndex].push_back(header);
594 uhtrs[uhtrIndex].push_back(dfi[0]);
608 uhtrs[uhtrIndex].push_back(header);
612 uhtrs[uhtrIndex].push_back(dfi[0]);
626 static const int hbflavor = 3;
630 if (it == qiehe.
begin())
632 adc = qiehe[is].adc();
633 tdc = qiehe[is].tdc();
634 soi = qiehe[is].soi();
636 if (tdc >= 0 && tdc <= tdc1)
638 else if (tdc > tdc1 && tdc <= tdc2)
640 else if (tdc > tdc2 && tdc <= tdcmax)
651 int capid = qiehe[0].capid();
DetId detid() const
Get the detector id.
void setSample(edm::DataFrame::size_type isample, int adc, int tdc, bool soi=false)
set the sample contents
std::vector< uhtrData > uhtrs
static const int FLAG_WORDS
edm::DataFrame::iterator begin()
iterators
void addChannel(int uhtrIndex, QIE11DataFrame qiedf, const HcalElectronicsMap *readoutMap, int verbosity=0)
std::vector< unsigned char > fedData
void addUHTR(uhtrData uhtr, uint64_t crate, uint64_t slot)
void finalizeHeadTail(uhtrData *uhtr, bool verbosity)
static const int OFFSET_CAPID
constexpr bool er() const
is the error bit set?
uint16_t packQIE8header(const HcalQIESample &qieSample, const HcalElectronicsId &eid, int flavor)
void setNAMC(uint64_t NAMC)
static const int HEADER_WORDS
int flavor() const
get the flavor of the frame
uhtrData * newUHTR(int uhtrIndex, int ps=0, int orn=0, int bcn=0, uint64_t evt=0)
QIE11DataFrame convertHB(QIE11DataFrame qiehe, int tdc1, int tdc2, int tdcmax)
std::vector< T >::const_iterator const_iterator
void push_back(T const &t)
static const int OFFSET_ADC
void addAMCHeader(uint64_t crate, uint64_t slot, uint64_t AMCsize, uint64_t presamples=10, uint64_t blockNum=0)
std::vector< uint16_t > uhtrData
std::vector< uint64_t > AMCHeaders
void addChannel(int uhtrIndex, edm::SortedCollection< HcalTriggerPrimitiveDigi >::const_iterator qiedf, int channelid, int verbosity=0)
uint16_t packQIE11header(const QIE11DataFrame &qiedf, const HcalElectronicsId &eid)
static const int OFFSET_DV
uint16_t packQIE10header(const HcalElectronicsId &eid)
void resize(size_t newsize)
std::vector< uint16_t > uhtrData
void addChannel(int uhtrIndex, edm::SortedCollection< HBHEDataFrame >::const_iterator qiedf, const HcalElectronicsMap *readoutMap, bool premix, int verbosity=0)
DetId detid() const
Get the detector id.
uint16_t packTPheader(const HcalTriggerPrimitiveSample &tpSample, int channelid)
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
edm::DataFrame::iterator end()
void addChannel(int uhtrIndex, QIE10DataFrame qiedf, const HcalElectronicsMap *readoutMap, int verbosity=0)
void setFlavor(int flavor)
void split64bitTo8bit(std::vector< unsigned char > &outVec, const uint64_t &var64bit)
constexpr int adc() const
get the ADC sample
constexpr int fiberIndex() const
get the fiber index. For VME 1-8 (which of eight fibers carried by a spigot), for uTCA fibers are zer...
static const int MASK_CAPID
unsigned long long uint64_t
static const int FLAG_WORDS
static const int HEADER_WORDS
std::map< int, uhtrData > UHTRMap
uint16_t packQIE8sample(const HcalQIESample &qieSample)
constexpr bool dv() const
is the Data Valid bit set?
void addChannel(int uhtrIndex, edm::SortedCollection< HFDataFrame >::const_iterator &qiedf, const HcalElectronicsMap *readoutMap, bool premix, int verbosity=0)
static const int OFFSET_ER
bool exist(int uhtrIndex)
constexpr int capid() const
get the Capacitor id
data_type const * const_iterator
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
edm::DataFrame::iterator begin()
iterators
void formatFEDdata(FEDRawData &rawData)
constexpr int fiberChanId() const
get the fiber channel id (which of channels on a fiber)
edm::DataFrame::iterator end()
HCalFED(int fedId_, uint64_t EventNum_=9999, uint64_t OrbitNum_=999, uint64_t BxNum_=99)
Readout chain identification for Hcal.
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
cont
load Luminosity info ##
static const int MASK_ADC