1 #ifndef EventFilter_HcalRawToDigi_PackerHelp_h 2 #define EventFilter_HcalRawToDigi_PackerHelp_h 178 unsigned char cdfh[8];
183 OrbitNum = OrbitNum_;
184 EventNum = EventNum_;
194 for(
int is=0; is<8; is++){
195 outVec.push_back( (var64bit>> (is*8) ) & 0xFF);
245 AMCHeaders.push_back( header );
251 uhtrs.push_back(uhtr);
253 addAMCHeader( crate , slot , uhtr.size()/4 );
260 if( uhtrs.size() != AMCHeaders.size() ){
265 split64bitTo8bit(fedData, cdfHeader);
268 setNAMC(uhtrs.size());
270 split64bitTo8bit(fedData, AMC13Header);
273 for(
unsigned int iAMC = 0 ; iAMC < AMCHeaders.size() ; ++iAMC ){
277 split64bitTo8bit(fedData, AMCHeaders[iAMC]);
281 for(
unsigned int iAMC = 0 ; iAMC<uhtrs.size() ; ++iAMC ){
283 unsigned int nWords16 = uhtrs[iAMC].size();
284 for(
unsigned int amcWord = 0 ; amcWord<nWords16 ; ++amcWord ){
285 fedData.push_back((uhtrs[iAMC][amcWord]>>0 )&0xFF);
286 fedData.push_back((uhtrs[iAMC][amcWord]>>8 )&0xFF);
291 while( fedData.size()%8 != 0 )
292 fedData.push_back(0);
295 rawData.
resize(fedData.size());
296 unsigned char* words =
reinterpret_cast<unsigned char*
>(rawData.
data());
298 for(
unsigned int i = 0 ;
i < fedData.size() ; ++
i ){
317 static const int OFFSET_DATA_LENGTH = 0;
318 static const int MASK_DATA_LENGTH = 0xFFFFF;
319 static const int OFFSET_BCN = 20;
320 static const int MASK_BCN = 0xFFF;
321 static const int OFFSET_EVN = 32;
322 static const int MASK_EVN = 0xFFFFFF;
323 static const int OFFSET_FILED_BY_AMC13 = 56;
324 static const int MASK_FILED_BY_AMC13 = 0xFF;
334 static const int OFFSET_FW_FLAVOR = 32;
335 static const int MASK_FW_FLAVOR = 0xFF;
336 static const int OFFSET_EVENT_TYPE = 40;
337 static const int MASK_EVENT_TYPE = 0xF;
338 static const int OFFSET_PAYLOAD_FORMAT = 44;
339 static const int MASK_PAYLOAD_FORMAT = 0xF;
340 static const int OFFSET_FW_VERSION = 48;
341 static const int MASK_FW_VERSION = 0xFFFF;
346 return uhtrs.count(uhtrIndex) != 0 ;
355 int fiberErr = qieSample.
er();
356 int capid0 = qieSample.
capid();
376 int adc = qieSample.
adc();
377 int capid = qieSample.
capid();
378 int dv = qieSample.
dv();
379 int er = qieSample.
er();
423 int capid0 = qiedf.
samples() == 0? 0 : qiedf[0].capid();
435 uhtrData*
newUHTR(
int uhtrIndex ,
int ps = 0,
int orn = 0 ,
int bcn = 0 ,
uint64_t evt = 0 ){
438 uhtrs[uhtrIndex] = uhtrData(8);
442 uint64_t uhtrCrate = uhtrIndex&0xFF;
443 uint64_t uhtrSlot = (uhtrIndex&0xF00)>>8;
452 uhtrHeader1 |= (
uint64_t(0x0)&MASK_DATA_LENGTH)<<OFFSET_DATA_LENGTH;
453 uhtrHeader1 |= (bcn&MASK_BCN)<<OFFSET_BCN;
454 uhtrHeader1 |= (evt&MASK_EVN)<<OFFSET_EVN;
455 uhtrHeader1 |= (
uint64_t(0x0)&MASK_FILED_BY_AMC13)<<OFFSET_FILED_BY_AMC13;
461 uhtrHeader2 |= (orn&
MASK_ORN)<<OFFSET_ORN;
462 uhtrHeader2 |= (fwFlavor&MASK_FW_FLAVOR)<<OFFSET_FW_FLAVOR;
463 uhtrHeader2 |= (eventType&MASK_EVENT_TYPE)<<OFFSET_EVENT_TYPE;
464 uhtrHeader2 |= (payloadFormat&MASK_PAYLOAD_FORMAT)<<OFFSET_PAYLOAD_FORMAT;
465 uhtrHeader2 |= (fwVersion&MASK_FW_VERSION)<<OFFSET_FW_VERSION;
468 for (
unsigned int i = 0;
i< 4; ++
i){
469 uhtrs[uhtrIndex][
i] = ( uhtrHeader1>>(
i*16) )&0xFFFF ;
470 uhtrs[uhtrIndex][
i+4] = ( uhtrHeader2>>(
i*16) )&0xFFFF ;
473 return &(uhtrs[uhtrIndex]);
478 uint64_t uhtr_size = uhtr->size()-8;
481 uhtr->at(0) = uhtr_size&0xFFFF ;
482 uhtr->at(1) |= (uhtr_size>>16)&0xF ;
484 unsigned int toAdd = 4-uhtr->size()%4;
485 for(
unsigned int ia=0; ia<
toAdd; ia++){
486 uhtr->push_back(0xD07F);
490 uhtr->push_back( uhtr_size&0xFFFF );
491 uhtr->push_back( (uhtr_size>>16)&0xF );
495 uhtr->push_back( 0 );
496 uhtr->push_back( 0 );
500 if( qiedf->
size() == 0 )
return;
501 DetId detid = qiedf->id();
503 uint16_t
header = packQIE8header(qiedf->sample(0),
eid, premix ? 7 : 5);
504 uhtrs[uhtrIndex].push_back(header);
507 for(
int iTS = 0; iTS < qiedf->
size(); ++iTS){
508 uhtrs[uhtrIndex].push_back(packQIE8sample(qiedf->sample(iTS)));
512 for(
int iTS = 0; iTS < qiedf->
size(); iTS +=2 ){
514 int adc0 = qiedf->sample(iTS).adc();
515 int adc1 = qiedf->sample(iTS+1).adc();
517 cont |= (adc1&0xFF)<<8;
524 if( qiedf->
size() == 0 )
return;
525 DetId detid = qiedf->id();
527 uint16_t
header = packQIE8header(qiedf->sample(0),
eid, premix ? 7 : 5);
528 uhtrs[uhtrIndex].push_back(header);
531 for(
int iTS = 0; iTS < qiedf->
size(); ++iTS){
532 uhtrs[uhtrIndex].push_back(packQIE8sample(qiedf->sample(iTS)));
536 for(
int iTS = 0; iTS < qiedf->
size(); iTS +=2 ){
538 int adc0 = qiedf->sample(iTS).adc();
539 int adc1 = qiedf->sample(iTS+1).adc();
541 cont |= (adc1&0xFF)<<8;
548 if( qiedf->
size() ==0 )
return;
549 uint16_t
header = packTPheader(qiedf->sample(0), channelid);
550 uhtrs[uhtrIndex].push_back(header);
552 for(
int iTS = 0 ; iTS < qiedf->
size() ; iTS++ ){
554 auto raw = qiedf->sample(iTS).raw();
556 if (iTS == qiedf->presamples())
558 uhtrs[uhtrIndex].push_back(raw);
571 uint16_t
header = packQIE11header(qiedf,
eid);
572 uhtrs[uhtrIndex].push_back(header);
576 uhtrs[uhtrIndex].push_back(dfi[0]);
590 uhtrs[uhtrIndex].push_back(header);
594 uhtrs[uhtrIndex].push_back(dfi[0]);
int adc(sample_type sample)
get the ADC sample (12 bits)
DetId detid() const
Get the detector id.
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)
std::map< int, uhtrData > UHTRMap
static const int HEADER_WORDS
uhtrData * newUHTR(int uhtrIndex, int ps=0, int orn=0, int bcn=0, uint64_t evt=0)
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)
edm::DataFrame::iterator end()
void addChannel(int uhtrIndex, QIE10DataFrame qiedf, const HcalElectronicsMap *readoutMap, int verbosity=0)
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
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
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()
int samples() const
total number of samples in the digi
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_ADC