CMS 3D CMS Logo

List of all members | Static Public Member Functions | Static Private Member Functions
CastorCtdcPacker Class Reference

#include <CastorCtdcPacker.h>

Static Public Member Functions

static void pack (int fedid, int dccnumber, int nl1a, int orbitn, int bcn, const CastorCollections &inputs, const CastorElectronicsMap &emap, FEDRawData &output)
 

Static Private Member Functions

static int findSamples (const DetId &did, const CastorCollections &inputs, unsigned short *buffer, int &presamples)
 

Detailed Description

Author
A. Campbell - DESY

Definition at line 13 of file CastorCtdcPacker.h.

Member Function Documentation

◆ findSamples()

int CastorCtdcPacker::findSamples ( const DetId did,
const CastorCollections inputs,
unsigned short *  buffer,
int &  presamples 
)
staticprivate

Definition at line 31 of file CastorCtdcPacker.cc.

34  {
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 }

References edmScanValgrind::buffer, DetId::Calo, DetId::det(), PixelMapPlotter::inputs, hcalTTPDigis_cfi::presamples, and findQualityFiles::size.

◆ pack()

void CastorCtdcPacker::pack ( int  fedid,
int  dccnumber,
int  nl1a,
int  orbitn,
int  bcn,
const CastorCollections inputs,
const CastorElectronicsMap emap,
FEDRawData output 
)
static

pack into CastorCORData

Definition at line 45 of file CastorCtdcPacker.cc.

52  {
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 }

References CastorCORData::allocate(), CastorCORData::CHANNELS_PER_SPIGOT, CastorCTDCHeader::clear(), evf::compute_crc(), CastorCTDCHeader::copyMergerData(), CastorCTDCHeader::copySpigotData(), PixelSLinkDataInputSource_cfi::fedid, CastorCORData::getRawLength(), CastorMergerData::getRawLength(), CastorElectronicsId::htrSlot(), CastorElectronicsId::htrTopBottom(), PixelMapPlotter::inputs, linear(), CastorElectronicsMap::lookup(), CastorCORData::MAXIMUM_SAMPLES_PER_CHANNEL, convertSQLitetoXML_cfg::output, CastorCORData::pack(), CastorCORData::packHeaderTrailer(), hcalTTPDigis_cfi::presamples, CastorElectronicsId::readoutVMECrateId(), EgammaValidation_cff::samples, FEDTrailer::set(), CastorCTDCHeader::setHeader(), and CastorCTDCHeader::SPIGOT_COUNT.

Referenced by CastorDigiToRaw::produce().

CastorCORData::getRawLength
const int getRawLength() const
Get the length of the raw data.
Definition: CastorCORData.h:39
CastorMergerData
Definition: CastorMergerData.h:14
CastorElectronicsId::readoutVMECrateId
int readoutVMECrateId() const
Definition: CastorElectronicsId.h:46
CastorCTDCHeader
Definition: CastorCTDCHeader.h:17
HcalGenericDetId
Definition: HcalGenericDetId.h:15
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
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
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
EgammaValidation_cff.samples
samples
Definition: EgammaValidation_cff.py:19
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
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
FEDTrailer
Definition: FEDTrailer.h:14
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
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
PixelSLinkDataInputSource_cfi.fedid
fedid
Definition: PixelSLinkDataInputSource_cfi.py:6
CastorCORData::CHANNELS_PER_SPIGOT
static const int CHANNELS_PER_SPIGOT
Definition: CastorCORData.h:16
linear
float linear(float x)
Definition: OccupancyPlotMacros.cc:26
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
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
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443