1 #ifndef EventFilter_HcalRawToDigi_PackerHelp_h 2 #define EventFilter_HcalRawToDigi_PackerHelp_h 176 unsigned char cdfh[8];
181 OrbitNum = OrbitNum_;
182 EventNum = EventNum_;
192 for(
int is=0; is<8; is++){
193 outVec.push_back( (var64bit>> (is*8) ) & 0xFF);
243 AMCHeaders.push_back( header );
249 uhtrs.push_back(uhtr);
251 addAMCHeader( crate , slot , uhtr.size()/4 );
258 if( uhtrs.size() != AMCHeaders.size() ){
263 split64bitTo8bit(fedData, cdfHeader);
266 setNAMC(uhtrs.size());
268 split64bitTo8bit(fedData, AMC13Header);
271 for(
unsigned int iAMC = 0 ; iAMC < AMCHeaders.size() ; ++iAMC ){
275 split64bitTo8bit(fedData, AMCHeaders[iAMC]);
279 for(
unsigned int iAMC = 0 ; iAMC<uhtrs.size() ; ++iAMC ){
281 unsigned int nWords16 = uhtrs[iAMC].size();
282 for(
unsigned int amcWord = 0 ; amcWord<nWords16 ; ++amcWord ){
283 fedData.push_back((uhtrs[iAMC][amcWord]>>0 )&0xFF);
284 fedData.push_back((uhtrs[iAMC][amcWord]>>8 )&0xFF);
289 while( fedData.size()%8 != 0 )
290 fedData.push_back(0);
293 rawData.
resize(fedData.size());
294 unsigned char* words =
reinterpret_cast<unsigned char*
>(rawData.
data());
296 for(
unsigned int i = 0 ;
i < fedData.size() ; ++
i ){
315 static const int OFFSET_DATA_LENGTH = 0;
316 static const int MASK_DATA_LENGTH = 0xFFFFF;
317 static const int OFFSET_BCN = 20;
318 static const int MASK_BCN = 0xFFF;
319 static const int OFFSET_EVN = 32;
320 static const int MASK_EVN = 0xFFFFFF;
321 static const int OFFSET_FILED_BY_AMC13 = 56;
322 static const int MASK_FILED_BY_AMC13 = 0xFF;
332 static const int OFFSET_FW_FLAVOR = 32;
333 static const int MASK_FW_FLAVOR = 0xFF;
334 static const int OFFSET_EVENT_TYPE = 40;
335 static const int MASK_EVENT_TYPE = 0xF;
336 static const int OFFSET_PAYLOAD_FORMAT = 44;
337 static const int MASK_PAYLOAD_FORMAT = 0xF;
338 static const int OFFSET_FW_VERSION = 48;
339 static const int MASK_FW_VERSION = 0xFFFF;
344 return uhtrs.count(uhtrIndex) != 0 ;
353 int fiberErr = qieSample.
er();
354 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 capid0 = qiedf.
samples() == 0? 0 : qiedf[0].capid();
433 uhtrData*
newUHTR(
int uhtrIndex ,
int ps = 0,
int orn = 0 ,
int bcn = 0 ,
uint64_t evt = 0 ){
436 uhtrs[uhtrIndex] = uhtrData(8);
440 uint64_t uhtrCrate = uhtrIndex&0xFF;
441 uint64_t uhtrSlot = (uhtrIndex&0xF00)>>8;
450 uhtrHeader1 |= (
uint64_t(0x0)&MASK_DATA_LENGTH)<<OFFSET_DATA_LENGTH;
451 uhtrHeader1 |= (bcn&MASK_BCN)<<OFFSET_BCN;
452 uhtrHeader1 |= (evt&MASK_EVN)<<OFFSET_EVN;
453 uhtrHeader1 |= (
uint64_t(0x0)&MASK_FILED_BY_AMC13)<<OFFSET_FILED_BY_AMC13;
459 uhtrHeader2 |= (orn&
MASK_ORN)<<OFFSET_ORN;
460 uhtrHeader2 |= (fwFlavor&MASK_FW_FLAVOR)<<OFFSET_FW_FLAVOR;
461 uhtrHeader2 |= (eventType&MASK_EVENT_TYPE)<<OFFSET_EVENT_TYPE;
462 uhtrHeader2 |= (payloadFormat&MASK_PAYLOAD_FORMAT)<<OFFSET_PAYLOAD_FORMAT;
463 uhtrHeader2 |= (fwVersion&MASK_FW_VERSION)<<OFFSET_FW_VERSION;
466 for (
unsigned int i = 0;
i< 4; ++
i){
467 uhtrs[uhtrIndex][
i] = ( uhtrHeader1>>(
i*16) )&0xFFFF ;
468 uhtrs[uhtrIndex][
i+4] = ( uhtrHeader2>>(
i*16) )&0xFFFF ;
471 return &(uhtrs[uhtrIndex]);
476 uint64_t uhtr_size = uhtr->size()-8;
479 uhtr->at(0) = uhtr_size&0xFFFF ;
480 uhtr->at(1) |= (uhtr_size>>16)&0xF ;
482 unsigned int toAdd = 4-uhtr->size()%4;
483 for(
unsigned int ia=0; ia<
toAdd; ia++){
484 uhtr->push_back(0xD07F);
488 uhtr->push_back( uhtr_size&0xFFFF );
489 uhtr->push_back( (uhtr_size>>16)&0xF );
493 uhtr->push_back( 0 );
494 uhtr->push_back( 0 );
498 if( qiedf->
size() == 0 )
return;
499 DetId detid = qiedf->id();
501 uint16_t
header = packQIE8header(qiedf->sample(0),
eid, premix ? 7 : 5);
502 uhtrs[uhtrIndex].push_back(header);
505 for(
int iTS = 0; iTS < qiedf->
size(); ++iTS){
506 uhtrs[uhtrIndex].push_back(packQIE8sample(qiedf->sample(iTS)));
510 for(
int iTS = 0; iTS < qiedf->
size(); iTS +=2 ){
512 int adc0 = qiedf->sample(iTS).adc();
513 int adc1 = qiedf->sample(iTS+1).adc();
515 cont |= (adc1&0xFF)<<8;
522 if( qiedf->
size() == 0 )
return;
523 DetId detid = qiedf->id();
525 uint16_t
header = packQIE8header(qiedf->sample(0),
eid, premix ? 7 : 5);
526 uhtrs[uhtrIndex].push_back(header);
529 for(
int iTS = 0; iTS < qiedf->
size(); ++iTS){
530 uhtrs[uhtrIndex].push_back(packQIE8sample(qiedf->sample(iTS)));
534 for(
int iTS = 0; iTS < qiedf->
size(); iTS +=2 ){
536 int adc0 = qiedf->sample(iTS).adc();
537 int adc1 = qiedf->sample(iTS+1).adc();
539 cont |= (adc1&0xFF)<<8;
546 if( qiedf->
size() ==0 )
return;
547 uint16_t
header = packTPheader(qiedf->sample(0), channelid);
548 uhtrs[uhtrIndex].push_back(header);
550 for(
int iTS = 0 ; iTS < qiedf->
size() ; iTS++ ){
552 uhtrs[uhtrIndex].push_back(qiedf->sample(iTS).raw());
565 uint16_t
header = packQIE11header(qiedf,
eid);
566 uhtrs[uhtrIndex].push_back(header);
570 uhtrs[uhtrIndex].push_back(dfi[0]);
584 uhtrs[uhtrIndex].push_back(header);
588 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
int fiberIndex() const
get the fiber index. For VME 1-8 (which of eight fibers carried by a spigot), for uTCA fibers are zer...
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
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
int adc() const
get the ADC sample
uhtrData * newUHTR(int uhtrIndex, int ps=0, int orn=0, int bcn=0, uint64_t evt=0)
std::vector< T >::const_iterator const_iterator
bool dv() const
is the Data Valid bit set?
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)
int fiberChanId() const
get the fiber channel id (which of channels on a fiber)
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)
static const int MASK_CAPID
unsigned long long uint64_t
int capid() const
get the Capacitor id
static const int FLAG_WORDS
static const int HEADER_WORDS
uint16_t packQIE8sample(const HcalQIESample &qieSample)
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)
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)
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
bool er() const
is the error bit set?
static const int MASK_ADC