CMS 3D CMS Logo

CastorCtdcPacker.cc
Go to the documentation of this file.
10 #include <iostream>
11 
12 using namespace std;
13 
14 namespace {
15  template <class Coll, class DetIdClass>
16  int process(const Coll* pt, const DetId& did, unsigned short* buffer, int& presamples) {
17  if (pt == nullptr)
18  return 0;
19  int size = 0;
20  typename Coll::const_iterator i = pt->find(DetIdClass(did));
21  if (i != pt->end()) {
22  presamples = i->presamples();
23  size = i->size();
24  for (int j = 0; j < size; j++)
25  buffer[j] = (*i)[j].raw();
26  }
27  return size;
28  }
29 } // namespace
30 
33  unsigned short* buffer,
34  int& presamples) {
35  if (did.det() != DetId::Calo)
36  return 0;
37  int size = 0;
38  HcalCastorDetId genId(did);
39 
40  size = process<CastorDigiCollection, HcalCastorDetId>(inputs.castorCont, did, buffer, presamples);
41 
42  return size;
43 }
44 
46  int dccnumber,
47  int nl1a,
48  int orbitn,
49  int bcn,
51  const CastorElectronicsMap& emap,
52  FEDRawData& output) {
55  std::vector<unsigned char> preclen(CastorCORData::CHANNELS_PER_SPIGOT);
56  std::vector<unsigned char> triglen(CastorCORData::CHANNELS_PER_SPIGOT);
57  constexpr int CORFormatVersion = 1;
58 
59  // CastorCORData spigots[CastorCTDCHeader::SPIGOT_COUNT];
60  CastorCORData spigots[2];
61  // loop over all valid channels in the given ctdc, spigot by spigot.
62  for (int spigot = 0; spigot < CastorCTDCHeader::SPIGOT_COUNT; spigot++) {
63  spigots[spigot].allocate(CORFormatVersion);
64  CastorElectronicsId exampleEId;
65  int npresent = 0;
66  int presamples = -1, samples = -1;
67  for (int fiber = 1; fiber <= 12; fiber++)
68  for (int fiberchan = 0; fiberchan < 3; fiberchan++) {
69  int linear = (fiber - 1) * 3 + fiberchan;
70  // HcalQIESample chanSample(0,0,fiber,fiberchan,false,false);
71  // unsigned short chanid=chanSample.raw()&0xF800;
72  preclen[linear] = 0;
73  CastorElectronicsId partialEid(fiberchan, fiber, spigot, dccnumber);
74  // does this partial id exist?
75  CastorElectronicsId fullEid;
76  HcalGenericDetId genId;
77  if (!emap.lookup(partialEid, fullEid, genId))
78  continue;
79 
80  // next, see if there is a digi with this id
81  unsigned short* database = &(precdata[linear * CastorCORData::MAXIMUM_SAMPLES_PER_CHANNEL]);
82  int mypresamples;
83  int mysamples = findSamples(genId, inputs, database, mypresamples);
84  if (mysamples > 0) {
85  if (samples < 0)
86  samples = mysamples;
87  else if (samples != mysamples) {
88  edm::LogError("CASTOR") << "Mismatch of samples in a single COR (unsupported) " << mysamples
89  << " != " << samples;
90  continue;
91  }
92  if (presamples < 0) {
93  presamples = mypresamples;
94  exampleEId = fullEid;
95  } else if (mypresamples != presamples) {
96  edm::LogError("CASTOR") << "Mismatch of presamples in a single COR (unsupported) " << mypresamples
97  << " != " << presamples;
98  continue;
99  }
100  preclen[linear] = (unsigned char)(samples);
101  npresent++;
102  }
103  }
105  if (npresent > 0) {
106  spigots[spigot].pack(&(preclen[0]), &(precdata[0]), &(triglen[0]), &(trigdata[0]), true);
107  constexpr int pipeline = 0x22;
108  constexpr int firmwareRev = 0;
109  int submodule = exampleEId.htrTopBottom() & 0x1;
110  submodule |= (exampleEId.htrSlot() & 0x1F) << 1;
111  submodule |= (exampleEId.readoutVMECrateId() & 0x1f) << 6;
112  spigots[spigot].packHeaderTrailer(nl1a, bcn, submodule, orbitn, pipeline, samples, presamples, firmwareRev);
113  }
114  }
115  // calculate the total length, and resize the FEDRawData
116  int theSize = 0;
117  for (int spigot = 0; spigot < 2; spigot++) {
118  theSize += spigots[spigot].getRawLength() * sizeof(unsigned short);
119  }
120  // the merger payload - not yet defined
121  CastorMergerData mergerdata;
122  // would need to fill mergdata here
123  theSize += mergerdata.getRawLength() * sizeof(unsigned short);
124 
125  theSize += sizeof(CastorCTDCHeader) + 8; // 8 for trailer
126  theSize += (8 - (theSize % 8)) % 8; // even number of 64-bit words.
127  output.resize(theSize);
128 
129  // construct the bare CTDC Header
130  CastorCTDCHeader* dcc = (CastorCTDCHeader*)(output.data());
131  dcc->clear();
132  dcc->setHeader(fedid, bcn, nl1a, orbitn);
133 
134  // pack the HTR data into the FEDRawData block using CastorCTDCHeader
135  for (int spigot = 0; spigot < 2; spigot++) {
136  if (spigots[spigot].getRawLength() > 0)
137  dcc->copySpigotData(spigot, spigots[spigot], true, 0);
138  }
139  if (mergerdata.getRawLength() > 0)
140  dcc->copyMergerData(mergerdata, true);
141  // trailer
142  FEDTrailer fedTrailer(output.data() + (output.size() - 8));
143  fedTrailer.set(
144  output.data() + (output.size() - 8), output.size() / 8, evf::compute_crc(output.data(), output.size()), 0, 0);
145 }
mps_fire.i
i
Definition: mps_fire.py:355
CastorCORData::getRawLength
const int getRawLength() const
Get the length of the raw data.
Definition: CastorCORData.h:39
CastorMergerData
Definition: CastorMergerData.h:14
CastorCtdcPacker::pack
static void pack(int fedid, int dccnumber, int nl1a, int orbitn, int bcn, const CastorCollections &inputs, const CastorElectronicsMap &emap, FEDRawData &output)
Definition: CastorCtdcPacker.cc:45
MessageLogger.h
CastorElectronicsId::readoutVMECrateId
int readoutVMECrateId() const
Definition: CastorElectronicsId.h:46
CastorCTDCHeader
Definition: CastorCTDCHeader.h:17
HcalGenericDetId
Definition: HcalGenericDetId.h:15
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
CastorCTDCHeader::clear
void clear()
Definition: CastorCTDCHeader.cc:37
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
CastorCtdcPacker::findSamples
static int findSamples(const DetId &did, const CastorCollections &inputs, unsigned short *buffer, int &presamples)
Definition: CastorCtdcPacker.cc:31
HcalGenericDetId.h
CastorMergerData::getRawLength
const int getRawLength() const
Get the length of the raw data.
Definition: CastorMergerData.h:41
CastorElectronicsId
Readout chain identification for Castor Bits for the readout chain : some names need change!...
Definition: CastorElectronicsId.h:20
DetId::Calo
Definition: DetId.h:29
FEDRawData
Definition: FEDRawData.h:19
CastorCollections.h
EgammaValidation_cff.samples
samples
Definition: EgammaValidation_cff.py:19
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
std::size
constexpr auto size(const C &c) -> decltype(c.size())
Definition: cuda_cxx17.h:13
DetId
Definition: DetId.h:17
CastorElectronicsId::htrTopBottom
int htrTopBottom() const
Definition: CastorElectronicsId.h:45
hcalTTPDigis_cfi.presamples
presamples
Definition: hcalTTPDigis_cfi.py:9
CastorCORData::allocate
void allocate(int version_to_create=0)
Definition: CastorCORData.cc:32
CastorCORData
Definition: CastorCORData.h:14
evf::compute_crc
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
HcalCastorDetId
Definition: HcalCastorDetId.h:23
edm::LogError
Definition: MessageLogger.h:183
FEDTrailer
Definition: FEDTrailer.h:14
CastorCTDCHeader.h
CastorCollections
Definition: CastorCollections.h:16
LaserDQM_cfg.process
process
Definition: LaserDQM_cfg.py:3
PixelMapPlotter.inputs
inputs
Definition: PixelMapPlotter.py:490
CastorElectronicsId::htrSlot
int htrSlot() const
Definition: CastorElectronicsId.h:44
CastorCTDCHeader::SPIGOT_COUNT
static const int SPIGOT_COUNT
Definition: CastorCTDCHeader.h:19
FEDTrailer::set
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.
Definition: FEDTrailer.cc:31
PixelSLinkDataInputSource_cfi.fedid
fedid
Definition: PixelSLinkDataInputSource_cfi.py:6
CastorMergerData.h
CastorCORData::CHANNELS_PER_SPIGOT
static const int CHANNELS_PER_SPIGOT
Definition: CastorCORData.h:16
linear
float linear(float x)
Definition: OccupancyPlotMacros.cc:26
std
Definition: JetResolutionObject.h:76
CastorCORData::pack
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.
Definition: CastorCORData.cc:163
CastorCORData::packHeaderTrailer
void packHeaderTrailer(int L1Anumber, int bcn, int submodule, int orbitn, int pipeline, int ndd, int nps, int firmwareRev=0)
pack header and trailer (call after pack)
Definition: CastorCORData.cc:249
CastorCORData::MAXIMUM_SAMPLES_PER_CHANNEL
static const int MAXIMUM_SAMPLES_PER_CHANNEL
Definition: CastorCORData.h:17
CastorElectronicsMap::lookup
const DetId lookup(CastorElectronicsId fId) const
lookup the logical detid associated with the given electronics id
Definition: CastorElectronicsMap.cc:105
CastorCTDCHeader::copyMergerData
void copyMergerData(const CastorMergerData &data, bool valid)
Definition: CastorCTDCHeader.cc:83
CastorCTDCHeader::setHeader
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
Definition: CastorCTDCHeader.cc:49
CastorElectronicsMap
Definition: CastorElectronicsMap.h:30
CastorCTDCHeader::copySpigotData
void copySpigotData(unsigned int spigot_id, const CastorCORData &data, bool valid=true, unsigned char LRB_error_word=0)
Add the given CastorCORData as the given spigot's data. This should be done in increasing spigot orde...
Definition: CastorCTDCHeader.cc:54
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
CastorCtdcPacker.h
CastorCORData.h
CRC16.h
FEDTrailer.h