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.

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

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 }
size
Write out results.
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46

◆ 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.

References CastorCORData::allocate(), CastorCORData::CHANNELS_PER_SPIGOT, evf::compute_crc(), ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), ALPAKA_ACCELERATOR_NAMESPACE::ecal::reconstruction::internal::barrel::dcc(), PixelSLinkDataInputSource_cfi::fedid, FCDTask_cfi::fiber, CastorCORData::getRawLength(), CastorMergerData::getRawLength(), CastorElectronicsId::htrSlot(), CastorElectronicsId::htrTopBottom(), PixelMapPlotter::inputs, linear(), CastorElectronicsMap::lookup(), CastorCORData::MAXIMUM_SAMPLES_PER_CHANNEL, CastorCORData::pack(), CastorCORData::packHeaderTrailer(), hcalTTPDigis_cfi::presamples, CastorElectronicsId::readoutVMECrateId(), EgammaValidation_cff::samples, FEDTrailer::set(), and CastorCTDCHeader::SPIGOT_COUNT.

Referenced by CastorDigiToRaw::produce().

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
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 }
static const int CHANNELS_PER_SPIGOT
Definition: CastorCORData.h:16
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)
pack header and trailer (call after pack)
Log< level::Error, false > LogError
static const int SPIGOT_COUNT
static const int MAXIMUM_SAMPLES_PER_CHANNEL
Definition: CastorCORData.h:17
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
void allocate(int version_to_create=0)
const DetId lookup(CastorElectronicsId fId) const
lookup the logical detid associated with the given electronics id
static int findSamples(const DetId &did, const CastorCollections &inputs, unsigned short *buffer, int &presamples)
const int getRawLength() const
Get the length of the raw data.
Definition: CastorCORData.h:39
Readout chain identification for Castor Bits for the readout chain : some names need change! [31:26] ...
Definition: output.py:1
const int getRawLength() const
Get the length of the raw data.
float linear(float x)