1 #ifndef EventFilter_HcalRawToDigi_PackerHelp_h 2 #define EventFilter_HcalRawToDigi_PackerHelp_h 163 unsigned char cdfh[8];
168 OrbitNum = OrbitNum_;
169 EventNum = EventNum_;
179 for(
int is=0; is<8; is++){
180 outVec.push_back( (var64bit>> (is*8) ) & 0xFF);
230 AMCHeaders.push_back( header );
236 uhtrs.push_back(uhtr);
238 addAMCHeader( crate , slot , uhtr.size()/4 );
245 if( uhtrs.size() != AMCHeaders.size() ){
250 split64bitTo8bit(fedData, cdfHeader);
253 setNAMC(uhtrs.size());
255 split64bitTo8bit(fedData, AMC13Header);
258 for(
unsigned int iAMC = 0 ; iAMC < AMCHeaders.size() ; ++iAMC ){
262 split64bitTo8bit(fedData, AMCHeaders[iAMC]);
266 for(
unsigned int iAMC = 0 ; iAMC<uhtrs.size() ; ++iAMC ){
268 unsigned int nWords16 = uhtrs[iAMC].size();
269 for(
unsigned int amcWord = 0 ; amcWord<nWords16 ; ++amcWord ){
270 fedData.push_back((uhtrs[iAMC][amcWord]>>0 )&0xFF);
271 fedData.push_back((uhtrs[iAMC][amcWord]>>8 )&0xFF);
276 while( fedData.size()%8 != 0 )
277 fedData.push_back(0);
280 rawData.
resize(fedData.size());
281 unsigned char* words =
reinterpret_cast<unsigned char*
>(rawData.
data());
283 for(
unsigned int i = 0 ;
i < fedData.size() ; ++
i ){
302 static const int OFFSET_DATA_LENGTH = 0;
303 static const int MASK_DATA_LENGTH = 0xFFFFF;
304 static const int OFFSET_BCN = 20;
305 static const int MASK_BCN = 0xFFF;
306 static const int OFFSET_EVN = 32;
307 static const int MASK_EVN = 0xFFFFFF;
308 static const int OFFSET_FILED_BY_AMC13 = 56;
309 static const int MASK_FILED_BY_AMC13 = 0xFF;
319 static const int OFFSET_FW_FLAVOR = 32;
320 static const int MASK_FW_FLAVOR = 0xFF;
321 static const int OFFSET_EVENT_TYPE = 40;
322 static const int MASK_EVENT_TYPE = 0xF;
323 static const int OFFSET_PAYLOAD_FORMAT = 44;
324 static const int MASK_PAYLOAD_FORMAT = 0xF;
325 static const int OFFSET_FW_VERSION = 48;
326 static const int MASK_FW_VERSION = 0xFFFF;
331 return uhtrs.count(uhtrIndex) != 0 ;
339 int fiberErr = qieSample.
er();
340 int capid0 = qieSample.
capid();
386 int capid0 = qiedf.
samples() == 0? 0 : qiedf[0].capid();
398 uhtrData*
newUHTR(
int uhtrIndex ,
int ps = 0,
int orn = 0 ,
int bcn = 0 ,
uint64_t evt = 0 ){
401 uhtrs[uhtrIndex] = uhtrData(8);
405 uint64_t uhtrCrate = uhtrIndex&0xFF;
406 uint64_t uhtrSlot = (uhtrIndex&0xF00)>>8;
415 uhtrHeader1 |= (
uint64_t(0x0)&MASK_DATA_LENGTH)<<OFFSET_DATA_LENGTH;
416 uhtrHeader1 |= (bcn&MASK_BCN)<<OFFSET_BCN;
417 uhtrHeader1 |= (evt&MASK_EVN)<<OFFSET_EVN;
418 uhtrHeader1 |= (
uint64_t(0x0)&MASK_FILED_BY_AMC13)<<OFFSET_FILED_BY_AMC13;
424 uhtrHeader2 |= (orn&
MASK_ORN)<<OFFSET_ORN;
425 uhtrHeader2 |= (fwFlavor&MASK_FW_FLAVOR)<<OFFSET_FW_FLAVOR;
426 uhtrHeader2 |= (eventType&MASK_EVENT_TYPE)<<OFFSET_EVENT_TYPE;
427 uhtrHeader2 |= (payloadFormat&MASK_PAYLOAD_FORMAT)<<OFFSET_PAYLOAD_FORMAT;
428 uhtrHeader2 |= (fwVersion&MASK_FW_VERSION)<<OFFSET_FW_VERSION;
431 for (
unsigned int i = 0;
i< 4; ++
i){
432 uhtrs[uhtrIndex][
i] = ( uhtrHeader1>>(
i*16) )&0xFFFF ;
433 uhtrs[uhtrIndex][
i+4] = ( uhtrHeader2>>(
i*16) )&0xFFFF ;
436 return &(uhtrs[uhtrIndex]);
441 uint64_t uhtr_size = uhtr->size()-8;
444 uhtr->at(0) = uhtr_size&0xFFFF ;
445 uhtr->at(1) |= (uhtr_size>>16)&0xF ;
447 unsigned int toAdd = 4-uhtr->size()%4;
448 for(
unsigned int ia=0; ia<
toAdd; ia++){
449 uhtr->push_back(0xD07F);
453 uhtr->push_back( uhtr_size&0xFFFF );
454 uhtr->push_back( (uhtr_size>>16)&0xF );
458 uhtr->push_back( 0 );
459 uhtr->push_back( 0 );
463 if( qiedf->
size() == 0 )
return;
464 DetId detid = qiedf->id();
466 uint16_t
header = packQIE8header(qiedf->sample(0),
eid);
467 uhtrs[uhtrIndex].push_back(header);
469 for(
int iTS = 0; iTS < qiedf->
size(); iTS +=2 ){
471 int adc0 = qiedf->sample(iTS).adc();
472 int adc1 = qiedf->sample(iTS+1).adc();
474 cont |= (adc1&0xFF)<<8;
480 if( qiedf->
size() == 0 )
return;
481 DetId detid = qiedf->id();
483 uint16_t
header = packQIE8header(qiedf->sample(0),
eid);
484 uhtrs[uhtrIndex].push_back(header);
486 for(
int iTS = 0; iTS < qiedf->
size(); iTS +=2 ){
488 int adc0 = qiedf->sample(iTS).adc();
489 int adc1 = qiedf->sample(iTS+1).adc();
491 cont |= (adc1&0xFF)<<8;
497 if( qiedf->
size() ==0 )
return;
498 uint16_t
header = packTPheader(qiedf->sample(0), channelid);
499 uhtrs[uhtrIndex].push_back(header);
501 for(
int iTS = 0 ; iTS < qiedf->
size() ; iTS++ ){
503 uhtrs[uhtrIndex].push_back(qiedf->sample(iTS).raw());
516 uint16_t
header = packQIE11header(qiedf,
eid);
517 uhtrs[uhtrIndex].push_back(header);
521 uhtrs[uhtrIndex].push_back(dfi[0]);
535 uhtrs[uhtrIndex].push_back(header);
539 uhtrs[uhtrIndex].push_back(dfi[0]);
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)
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)
uint16_t packQIE8header(const HcalQIESample &qieSample, const HcalElectronicsId &eid)
void addChannel(int uhtrIndex, edm::SortedCollection< HBHEDataFrame >::const_iterator qiedf, const HcalElectronicsMap *readoutMap, int verbosity=0)
void addAMCHeader(uint64_t crate, uint64_t slot, uint64_t AMCsize, uint64_t presamples=10, uint64_t blockNum=0)
std::vector< uint16_t > uhtrData
void addChannel(int uhtrIndex, edm::SortedCollection< HFDataFrame >::const_iterator &qiedf, const HcalElectronicsMap *readoutMap, int verbosity=0)
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)
uint16_t packQIE10header(const HcalElectronicsId &eid)
void resize(size_t newsize)
std::vector< uint16_t > uhtrData
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)
unsigned long long uint64_t
int capid() const
get the Capacitor id
static const int FLAG_WORDS
static const int HEADER_WORDS
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?