18 template <
class Coll,
class DetIdClass>
19 int process(
const Coll*
pt,
const DetId& did,
unsigned short*
buffer,
int& presamples,
bool& isUS,
bool& isMP) {
26 typename Coll::const_iterator
i = pt->find(DetIdClass(did));
28 isUS = i->zsUnsuppressed();
29 isMP = i->zsMarkAndPass();
30 presamples = i->presamples();
32 for (
int j = 0;
j <
size;
j++) {
33 buffer[
j] = (*i)[
j].raw();
47 bool any_nonzero =
false;
49 int presamples = i->presamples();
52 for (
int j = 0;
j <
size;
j++) {
53 buffer[
j] = (*i)[
j].raw();
54 if ((buffer[
j] & 0x1FF) != 0)
56 if (
j == presamples) {
61 return (any_nonzero) ? (
size) : (0);
79 size = process<HBHEDigiCollection, HcalDetId>(inputs.
hbhe, did,
buffer, presamples, isUS, isMP);
82 size = process<HODigiCollection, HcalDetId>(inputs.
hoCont, did,
buffer, presamples, isUS, isMP);
85 size = process<HFDigiCollection, HcalDetId>(inputs.
hfCont, did,
buffer, presamples, isUS, isMP);
88 size = process<ZDCDigiCollection, HcalZDCDetId>(inputs.
zdcCont, did,
buffer, presamples, isUS, isMP);
91 size = process<HcalCalibDigiCollection, HcalCalibDetId>(inputs.
calibCont, did,
buffer, presamples, isUS, isMP);
111 static const int HTRFormatVersion = 5;
116 for (
int spigot = 0; spigot < 15; spigot++) {
117 spigots[spigot].
allocate(HTRFormatVersion);
119 int npresent = 0, npresenttp = 0;
120 int presamples = -1, samples = -1;
121 bool haveUnsuppressed =
false;
122 for (
int fiber = 1; fiber <= 8; fiber++) {
123 for (
int fiberchan = 0; fiberchan < 3; fiberchan++) {
124 int linear = (fiber - 1) * 3 + fiberchan;
125 HcalQIESample chanSample(0, 0, fiber, fiberchan,
false,
false);
126 unsigned short chanid = chanSample.
raw() & 0xF800;
128 channelIsMP[
linear] =
false;
134 if (!emap.
lookup(partialEid, fullEid, genId)) {
140 int mypresamples = -1;
141 bool isUS =
false, isMP =
false;
142 int mysamples =
findSamples(genId, inputs, database, mypresamples, isUS, isMP);
143 haveUnsuppressed = haveUnsuppressed || isUS;
144 channelIsMP[
linear] = isMP;
149 }
else if (samples != mysamples) {
150 edm::LogError(
"HCAL") <<
"Mismatch of samples in a single HTR (unsupported) " << mysamples
151 <<
" != " << samples;
154 if (presamples < 0) {
155 presamples = mypresamples;
156 exampleEId = fullEid;
157 }
else if (mypresamples != presamples) {
158 edm::LogError(
"HCAL") <<
"Mismatch of presamples in a single HTR (unsupported) " << mypresamples
159 <<
" != " << presamples;
162 for (
int ii = 0;
ii < samples;
ii++) {
163 database[
ii] = (database[
ii] & 0x7FF) | chanid;
165 preclen[
linear] = (
unsigned char)(samples);
171 for (
int slbchan = 0; slbchan <= 3; slbchan++) {
174 unsigned short chanid = idCvt.
raw() & 0xF800;
181 if (!emap.
lookup(partialEid, fullEid, tid)) {
188 if (presamples < 0) {
189 exampleEId = fullEid;
193 if (triglen[linear]) {
198 for (
unsigned char q = 0;
q < triglen[
linear];
q++) {
199 trigbase[
q] = (trigbase[
q] & 0x7FF) | chanid;
206 spigots[spigot].
pack(&(preclen[0]), &(precdata[0]), &(triglen[0]), &(trigdata[0]),
false);
207 static const int pipeline = 0x22;
208 static const int firmwareRev = 0;
210 submodule |= (exampleEId.
htrSlot() & 0x1F) << 1;
217 if (presamples < 0) {
229 if (haveUnsuppressed) {
236 for (
int spigot = 0; spigot < 15; spigot++) {
237 theSize += spigots[spigot].
getRawLength() *
sizeof(
unsigned short);
240 theSize += (8 - (theSize % 8)) % 8;
246 dcc->
setHeader(fedid, bcn, nl1a, orbitn);
249 for (
int spigot = 0; spigot < 15; spigot++) {
250 if (spigots[spigot].getRawLength() > 0) {
static int slb(const HcalTriggerPrimitiveSample &theSample)
void packUnsuppressed(const bool *mp)
pack trailer with Mark and Pass bits
void pack(int fedid, int dccnumber, int nl1a, int orbitn, int bcn, const Collections &inputs, const HcalElectronicsMap &emap, FEDRawData &output) const
constexpr bool null() const
is this a null id ?
std::vector< T >::const_iterator const_iterator
const HcalCalibDigiCollection * calibCont
static const int CHANNELS_PER_SPIGOT
Log< level::Error, false > LogError
static const int MAXIMUM_SAMPLES_PER_CHANNEL
size_t size() const
Lenght of the data buffer in bytes.
void allocate(int version_to_create=0)
constexpr int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom), valid for VME
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
static unsigned char processTrig(const HcalTrigPrimDigiCollection *pt, const HcalTrigTowerDetId &tid, unsigned short *buffer)
int findSamples(const DetId &did, const Collections &inputs, unsigned short *buffer, int &presamples, bool &zsUS, bool &zsMP) const
void resize(size_t newsize)
constexpr int htrSlot() const
get the htr slot
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
const int getRawLength() const
Get the length of the raw data.
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
uint16_t raw() const
get the raw word
const HcalTrigPrimDigiCollection * tpCont
constexpr int readoutVMECrateId() const
get the readout VME crate number
const ZDCDigiCollection * zdcCont
const HBHEDigiCollection * hbhe
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.
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.
constexpr uint16_t raw() const
get the raw word
const HFDigiCollection * hfCont
HcalGenericSubdetector genericSubdet() const
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
constexpr Detector det() const
get the detector field from this detid