18 template <
class Coll,
class DetIdClass>
19 int process(
const Coll*
pt,
const DetId& did,
unsigned short* buffer,
int& presamples,
bool& isUS,
bool& isMP) {
20 isUS=
false; isMP=
false;
21 if (pt==0) {
return 0; }
23 typename Coll::const_iterator
i=pt->find(DetIdClass(did));
25 isUS=i->zsUnsuppressed();
26 isMP=i->zsMarkAndPass();
27 presamples=i->presamples();
30 buffer[
j]=(*i)[
j].raw();
37 if (pt==0) {
return 0; }
40 bool any_nonzero=
false;
42 int presamples=i->presamples();
46 buffer[
j]=(*i)[
j].raw();
47 if ((buffer[
j]&0x1FF)!=0) any_nonzero=
true;
48 if (
j==presamples) { buffer[
j]|=0x0200; }
51 return (any_nonzero)?(
size):(0);
55 unsigned short* buffer,
int &presamples,
bool& isUS,
bool& isMP) {
63 size=process<HBHEDigiCollection,HcalDetId>(inputs.
hbhe,did,buffer,presamples,isUS,isMP);
66 size=process<HODigiCollection,HcalDetId>(inputs.
hoCont,did,buffer,presamples,isUS,isMP);
69 size=process<HFDigiCollection,HcalDetId>(inputs.
hfCont,did,buffer,presamples,isUS,isMP);
72 size=process<ZDCDigiCollection,HcalZDCDetId>(inputs.
zdcCont,did,buffer,presamples,isUS,isMP);
75 size=process<HcalCalibDigiCollection,HcalCalibDetId>(inputs.
calibCont,did,buffer,presamples,isUS,isMP);
83 int nl1a,
int orbitn,
int bcn,
91 static const int HTRFormatVersion=5;
96 for (
int spigot=0; spigot<15; spigot++) {
97 spigots[spigot].
allocate(HTRFormatVersion);
99 int npresent=0, npresenttp=0;
100 int presamples=-1, samples=-1;
101 bool haveUnsuppressed=
false;
102 for (
int fiber=1; fiber<=8; fiber++) {
103 for (
int fiberchan=0; fiberchan<3; fiberchan++) {
104 int linear=(fiber-1)*3+fiberchan;
106 unsigned short chanid=chanSample.
raw()&0xF800;
108 channelIsMP[
linear]=
false;
114 if (!emap.
lookup(partialEid,fullEid,genId)) {
continue; }
120 bool isUS=
false, isMP=
false;
121 int mysamples=
findSamples(genId,inputs,database,mypresamples,isUS,isMP);
122 haveUnsuppressed=haveUnsuppressed || isUS;
126 if (samples<0) { samples=mysamples; }
127 else if (samples!=mysamples) {
128 edm::LogError(
"HCAL") <<
"Mismatch of samples in a single HTR (unsupported) " << mysamples <<
" != " << samples;
132 presamples=mypresamples;
134 }
else if (mypresamples!=presamples) {
135 edm::LogError(
"HCAL") <<
"Mismatch of presamples in a single HTR (unsupported) " << mypresamples <<
" != " << presamples;
138 for (
int ii=0;
ii<samples;
ii++) {
139 database[
ii]=(database[
ii]&0x7FF)|chanid;
147 for (
int slbchan=0; slbchan<=3; slbchan++) {
150 unsigned short chanid=idCvt.
raw()&0xF800;
157 if (!emap.
lookup(partialEid,fullEid,tid)) {
164 if (presamples < 0) {
165 exampleEId = fullEid;
169 if (triglen[linear]) {
174 for (
unsigned char q=0;
q<triglen[
linear];
q++) {
175 trigbase[
q]=(trigbase[
q]&0x7FF)|chanid;
183 spigots[spigot].
pack(&(preclen[0]),&(precdata[0]),
184 &(triglen[0]),&(trigdata[0]),
186 static const int pipeline=0x22;
187 static const int firmwareRev=0;
189 submodule|=(exampleEId.
htrSlot()&0x1F)<<1;
196 if (presamples < 0) {
208 if (haveUnsuppressed) {
216 for (
int spigot=0; spigot<15; spigot++) {
217 theSize+=spigots[spigot].
getRawLength()*
sizeof(
unsigned short);
220 theSize+=(8-(theSize%8))%8;
229 for (
int spigot=0; spigot<15; spigot++) {
230 if (spigots[spigot].getRawLength()>0) {
void pack(int fedid, int dccnumber, int nl1a, int orbitn, int bcn, const Collections &inputs, const HcalElectronicsMap &emap, FEDRawData &output)
uint16_t raw() const
get the raw word
static int slb(const HcalTriggerPrimitiveSample &theSample)
void packUnsuppressed(const bool *mp)
pack trailer with Mark and Pass bits
int htrSlot() const
get the htr slot
std::vector< HcalTriggerPrimitiveDigi >::const_iterator const_iterator
const HcalCalibDigiCollection * calibCont
static const int CHANNELS_PER_SPIGOT
static const int MAXIMUM_SAMPLES_PER_CHANNEL
static void set(unsigned char *trailer, int evt_lgth, int crc, int evt_stat, int tts, bool T=false)
Set all fields in the trailer.
size_t size() const
Lenght of the data buffer in bytes.
int readoutVMECrateId() const
get the readout VME crate number
void allocate(int version_to_create=0)
static unsigned char processTrig(const HcalTrigPrimDigiCollection *pt, const HcalTrigTowerDetId &tid, unsigned short *buffer)
int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom), valid for VME
void resize(size_t newsize)
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
const int getRawLength() const
Get the length of the raw data.
uint16_t raw() const
get the raw word
const HcalTrigPrimDigiCollection * tpCont
const ZDCDigiCollection * zdcCont
const HBHEDigiCollection * hbhe
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
const_iterator end() const
static const int SubdetectorId
void pack(unsigned char *daq_lengths, unsigned short *daq_samples, unsigned char *tp_lengths, unsigned short *tp_samples, bool do_capid=false)
Unpack the HTR data into TP and DAQ data sorted by channel.
bool null() const
is this a null id ?
void packHeaderTrailer(int L1Anumber, int bcn, int submodule, int orbitn, int pipeline, int ndd, int nps, int firmwareRev=0, int firmwareFlav=0)
pack header and trailer (call after pack)
iterator find(key_type k)
const HODigiCollection * hoCont
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
int findSamples(const DetId &did, const Collections &inputs, unsigned short *buffer, int &presamples, bool &zsUS, bool &zsMP)
const HFDigiCollection * hfCont
HcalGenericSubdetector genericSubdet() const
Detector det() const
get the detector field from this detid
Readout chain identification for Hcal.
tuple size
Write out results.
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id