1 #ifndef EventFilter_HcalRawToDigi_PackerHelp_h
2 #define EventFilter_HcalRawToDigi_PackerHelp_h
19 namespace CDFHeaderSpec {
37 namespace AMC13HeaderSpec {
53 namespace AMCHeaderSpec {
84 namespace QIE8HeaderSpec {
101 namespace QIE10HeaderSpec {
120 namespace QIE11HeaderSpec0 {
135 namespace QIE11HeaderSpec3 {
150 namespace TPHeaderSpec {
169 namespace QIE8SampleSpec {
209 for (
int is = 0; is < 8; is++) {
210 outVec.push_back((var64bit >> (is * 8)) & 0xFF);
259 uhtrs.push_back(uhtr);
280 for (
unsigned int iAMC = 0; iAMC <
AMCHeaders.size(); ++iAMC) {
288 for (
unsigned int iAMC = 0; iAMC <
uhtrs.size(); ++iAMC) {
289 unsigned int nWords16 =
uhtrs[iAMC].size();
290 for (
unsigned int amcWord = 0; amcWord < nWords16; ++amcWord) {
297 while (
fedData.size() % 8 != 0)
302 unsigned char* words =
reinterpret_cast<unsigned char*
>(rawData.
data());
304 for (
unsigned int i = 0;
i <
fedData.size(); ++
i) {
347 bool exist(
int uhtrIndex) {
return uhtrs.count(uhtrIndex) != 0; };
361 int fiberErr = qieSample.
er();
362 int capid0 = qieSample.
capid();
375 int adc = qieSample.
adc();
376 int capid = qieSample.
capid();
377 int dv = qieSample.
dv();
378 int er = qieSample.
er();
422 int flavor = qiedf[0].
flavor();
432 int capid0 = qiedf[0].capid();
450 uint64_t uhtrCrate = uhtrIndex & 0xFF;
451 uint64_t uhtrSlot = (uhtrIndex & 0xF00) >> 8;
476 for (
unsigned int i = 0;
i < 4; ++
i) {
477 uhtrs[uhtrIndex][
i] = (uhtrHeader1 >> (
i * 16)) & 0xFFFF;
478 uhtrs[uhtrIndex][
i + 4] = (uhtrHeader2 >> (
i * 16)) & 0xFFFF;
481 return &(
uhtrs[uhtrIndex]);
485 uint64_t uhtr_size = uhtr->size() - 8;
488 uhtr->at(0) = uhtr_size & 0xFFFF;
489 uhtr->at(1) |= (uhtr_size >> 16) & 0xF;
491 unsigned int toAdd = 4 - uhtr->size() % 4;
492 for (
unsigned int ia = 0; ia <
toAdd; ia++) {
493 uhtr->push_back(0xD07F);
497 uhtr->push_back(uhtr_size & 0xFFFF);
498 uhtr->push_back((uhtr_size >> 16) & 0xF);
511 if (qiedf->
size() == 0)
513 DetId detid = qiedf->id();
516 uhtrs[uhtrIndex].push_back(header);
519 for (
int iTS = 0; iTS < qiedf->
size(); ++iTS) {
523 for (
int iTS = 0; iTS < qiedf->
size(); iTS += 2) {
525 int adc0 = qiedf->sample(iTS).adc();
526 int adc1 = qiedf->sample(iTS + 1).adc();
528 cont |= (adc1 & 0xFF) << 8;
529 uhtrs[uhtrIndex].push_back(cont);
539 if (qiedf->
size() == 0)
541 DetId detid = qiedf->id();
544 uhtrs[uhtrIndex].push_back(header);
547 for (
int iTS = 0; iTS < qiedf->
size(); ++iTS) {
551 for (
int iTS = 0; iTS < qiedf->
size(); iTS += 2) {
553 int adc0 = qiedf->sample(iTS).adc();
554 int adc1 = qiedf->sample(iTS + 1).adc();
556 cont |= (adc1 & 0xFF) << 8;
557 uhtrs[uhtrIndex].push_back(cont);
566 if (qiedf->
size() == 0)
568 uint16_t header =
packTPheader(qiedf->sample(0), channelid);
569 uhtrs[uhtrIndex].push_back(header);
571 for (
int iTS = 0; iTS < qiedf->
size(); iTS++) {
573 auto raw = qiedf->sample(iTS).raw();
575 if (iTS == qiedf->presamples())
577 uhtrs[uhtrIndex].push_back(raw);
591 uhtrs[uhtrIndex].push_back(header);
595 uhtrs[uhtrIndex].push_back(dfi[0]);
609 uhtrs[uhtrIndex].push_back(header);
613 uhtrs[uhtrIndex].push_back(dfi[0]);
621 std::vector<int>
const& tdc1,
622 std::vector<int>
const& tdc2,
629 int capid = qiehe[0].capid();
631 static const int hbflavor = 3;
633 static const int maxHBdepth = 4;
636 const int first = tdc1.at(entry);
637 const int second = tdc2.at(entry);
641 if (it == qiehe.
begin())
643 adc = qiehe[is].adc();
644 tdc = qiehe[is].tdc();
645 soi = qiehe[is].soi();
647 if (tdc >= 0 && tdc <= first)
649 else if (tdc > first && tdc <= second)
651 else if (tdc > second && tdc <= tdcmax)
std::vector< uhtrData > uhtrs
static const int FLAG_WORDS
static const int OFFSET_PRESAMPLES
static const int OFFSET_ORN
void addChannel(int uhtrIndex, QIE11DataFrame qiedf, const HcalElectronicsMap *readoutMap, int verbosity=0)
static const int OFFSET_PAYLOAD_FORMAT
std::vector< unsigned char > fedData
tuple cont
load Luminosity info ##
void addUHTR(uhtrData uhtr, uint64_t crate, uint64_t slot)
void finalizeHeadTail(uhtrData *uhtr, bool verbosity)
static const int OFFSET_CAPID
static const int MASK_ORN
constexpr bool er() const
is the error bit set?
uint16_t packQIE8header(const HcalQIESample &qieSample, const HcalElectronicsId &eid, int flavor)
QIE11DataFrame convertHB(QIE11DataFrame qiehe, std::vector< int > const &tdc1, std::vector< int > const &tdc2, const int tdcmax)
void setNAMC(uint64_t NAMC)
static const int HEADER_WORDS
constexpr edm::DataFrame::iterator end()
static const int OFFSET_EVENT_TYPE
uhtrData * newUHTR(int uhtrIndex, int ps=0, int orn=0, int bcn=0, uint64_t evt=0)
std::vector< T >::const_iterator const_iterator
constexpr edm::DataFrame::iterator begin()
iterators
static const int OFFSET_ADC
static const int MASK_SLOT_ID
void addAMCHeader(uint64_t crate, uint64_t slot, uint64_t AMCsize, uint64_t presamples=10, uint64_t blockNum=0)
std::vector< uint16_t > uhtrData
static const int OFFSET_FILED_BY_AMC13
std::vector< uint64_t > AMCHeaders
U second(std::pair< T, U > const &p)
static const int MASK_FW_VERSION
void addChannel(int uhtrIndex, edm::SortedCollection< HcalTriggerPrimitiveDigi >::const_iterator qiedf, int channelid, int verbosity=0)
uint16_t packQIE11header(const QIE11DataFrame &qiedf, const HcalElectronicsId &eid)
constexpr void setFlavor(int flavor)
constexpr DetId detid() const
Get the detector id.
static const int OFFSET_CRATE_ID
static const int OFFSET_DV
uint16_t packQIE10header(const HcalElectronicsId &eid)
static const int MASK_PRESAMPLES
void resize(size_t newsize)
std::vector< uint16_t > uhtrData
Abs< T >::type abs(const T &t)
constexpr int ieta() const
get the cell ieta
void addChannel(int uhtrIndex, edm::SortedCollection< HBHEDataFrame >::const_iterator qiedf, const HcalElectronicsMap *readoutMap, bool premix, int verbosity=0)
static const int OFFSET_FW_FLAVOR
constexpr edm::DataFrame::iterator end()
uint16_t packTPheader(const HcalTriggerPrimitiveSample &tpSample, int channelid)
static const int MASK_PAYLOAD_FORMAT
void addChannel(int uhtrIndex, QIE10DataFrame qiedf, const HcalElectronicsMap *readoutMap, int verbosity=0)
constexpr void setSample(edm::DataFrame::size_type isample, int adc, int tdc, bool soi=false)
set the sample contents
void split64bitTo8bit(std::vector< unsigned char > &outVec, const uint64_t &var64bit)
constexpr int adc() const
get the ADC sample
static const int MASK_EVN
static const int OFFSET_FW_VERSION
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 MASK_BCN
static const int OFFSET_SLOT_ID
constexpr edm::DataFrame::iterator begin()
iterators
static const int HEADER_WORDS
constexpr int flavor() const
get the flavor of the frame
static const int MASK_FILED_BY_AMC13
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
static const int OFFSET_EVN
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
static const int OFFSET_BCN
void formatFEDdata(FEDRawData &rawData)
static const int OFFSET_DATA_LENGTH
constexpr int fiberChanId() const
get the fiber channel id (which of channels on a fiber)
constexpr int depth() const
get the tower depth
constexpr void setCapid0(int cap0)
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
static const int MASK_EVENT_TYPE
uint16_t *__restrict__ uint16_t const *__restrict__ adc
static const int MASK_FW_FLAVOR
static const int MASK_CRATE_ID
static const int MASK_DATA_LENGTH
constexpr DetId detid() const
Get the detector id.
static const int MASK_ADC