CMS 3D CMS Logo

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

#include <CastorPacker.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
J. Mans - Minnesota

Definition at line 13 of file CastorPacker.h.

Member Function Documentation

◆ findSamples()

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

Definition at line 27 of file CastorPacker.cc.

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

Referenced by pack().

30  {
31  if (did.det() != DetId::Calo)
32  return 0;
33  int size = 0;
34  HcalCastorDetId genId(did);
35 
36  size = process<CastorDigiCollection, HcalCastorDetId>(inputs.castorCont, did, buffer, presamples);
37 
38  return size;
39 }
size
Write out results.
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46

◆ pack()

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

pack into HcalHTRData

Definition at line 41 of file CastorPacker.cc.

References HcalHTRData::allocate(), HcalHTRData::CHANNELS_PER_SPIGOT, HcalDCCHeader::clear(), evf::compute_crc(), HcalDCCHeader::copySpigotData(), PixelSLinkDataInputSource_cfi::fedid, findSamples(), HcalHTRData::getRawLength(), CastorElectronicsId::htrSlot(), CastorElectronicsId::htrTopBottom(), cuy::ii, PixelMapPlotter::inputs, linear(), CastorElectronicsMap::lookup(), HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL, HcalHTRData::pack(), HcalHTRData::packHeaderTrailer(), hcalTTPDigis_cfi::presamples, HcalQIESample::raw(), CastorElectronicsId::readoutVMECrateId(), EgammaValidation_cff::samples, FEDTrailer::set(), and HcalDCCHeader::setHeader().

Referenced by CastorDigiToRaw::produce().

48  {
49  std::vector<unsigned short> precdata(HcalHTRData::CHANNELS_PER_SPIGOT * HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL);
50  std::vector<unsigned short> trigdata(HcalHTRData::CHANNELS_PER_SPIGOT * HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL);
51  std::vector<unsigned char> preclen(HcalHTRData::CHANNELS_PER_SPIGOT);
52  std::vector<unsigned char> triglen(HcalHTRData::CHANNELS_PER_SPIGOT);
53  constexpr int HTRFormatVersion = 3;
54 
55  HcalHTRData spigots[15];
56  // loop over all valid channels in the given dcc, spigot by spigot.
57  for (int spigot = 0; spigot < 15; spigot++) {
58  spigots[spigot].allocate(HTRFormatVersion);
59  CastorElectronicsId exampleEId;
60  int npresent = 0;
61  int presamples = -1, samples = -1;
62  for (int fiber = 1; fiber <= 8; fiber++)
63  for (int fiberchan = 0; fiberchan < 3; fiberchan++) {
64  int linear = (fiber - 1) * 3 + fiberchan;
65  HcalQIESample chanSample(0, 0, fiber, fiberchan, false, false);
66  unsigned short chanid = chanSample.raw() & 0xF800;
67  preclen[linear] = 0;
68 
69  CastorElectronicsId partialEid(fiberchan, fiber, spigot, dccnumber);
70  // does this partial id exist?
71  CastorElectronicsId fullEid;
72  HcalGenericDetId genId;
73  if (!emap.lookup(partialEid, fullEid, genId))
74  continue;
75 
76  // next, see if there is a digi with this id
77  unsigned short* database = &(precdata[linear * HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL]);
78  int mypresamples;
79  int mysamples = findSamples(genId, inputs, database, mypresamples);
80 
81  if (mysamples > 0) {
82  if (samples < 0)
83  samples = mysamples;
84  else if (samples != mysamples) {
85  edm::LogError("CASTOR") << "Mismatch of samples in a single HTR (unsupported) " << mysamples
86  << " != " << samples;
87  continue;
88  }
89  if (presamples < 0) {
90  presamples = mypresamples;
91  exampleEId = fullEid;
92  } else if (mypresamples != presamples) {
93  edm::LogError("CASTOR") << "Mismatch of presamples in a single HTR (unsupported) " << mypresamples
94  << " != " << presamples;
95  continue;
96  }
97  for (int ii = 0; ii < samples; ii++)
98  database[ii] = (database[ii] & 0x7FF) | chanid;
99  preclen[linear] = (unsigned char)(samples);
100  npresent++;
101  }
102  }
104  if (npresent > 0) {
105  spigots[spigot].pack(&(preclen[0]), &(precdata[0]), &(triglen[0]), &(trigdata[0]), false);
106  constexpr int pipeline = 0x22;
107  constexpr int firmwareRev = 0;
108  int submodule = exampleEId.htrTopBottom() & 0x1;
109  submodule |= (exampleEId.htrSlot() & 0x1F) << 1;
110  submodule |= (exampleEId.readoutVMECrateId() & 0x1f) << 6;
111  spigots[spigot].packHeaderTrailer(nl1a, bcn, submodule, orbitn, pipeline, samples, presamples, firmwareRev);
112  }
113  }
114  // calculate the total length, and resize the FEDRawData
115  int theSize = 0;
116  for (int spigot = 0; spigot < 15; spigot++) {
117  theSize += spigots[spigot].getRawLength() * sizeof(unsigned short);
118  }
119  theSize += sizeof(HcalDCCHeader) + 8; // 8 for trailer
120  theSize += (8 - (theSize % 8)) % 8; // even number of 64-bit words.
121  output.resize(theSize);
122 
123  // construct the bare DCC Header
124  HcalDCCHeader* dcc = (HcalDCCHeader*)(output.data());
125  dcc->clear();
126  dcc->setHeader(fedid, bcn, nl1a, orbitn);
127 
128  // pack the HTR data into the FEDRawData block using HcalDCCHeader
129  for (int spigot = 0; spigot < 15; spigot++) {
130  if (spigots[spigot].getRawLength() > 0)
131  dcc->copySpigotData(spigot, spigots[spigot], true, 0);
132  }
133  // trailer
134  FEDTrailer fedTrailer(output.data() + (output.size() - 8));
135  fedTrailer.set(
136  output.data() + (output.size() - 8), output.size() / 8, evf::compute_crc(output.data(), output.size()), 0, 0);
137 }
static int findSamples(const DetId &did, const CastorCollections &inputs, unsigned short *buffer, int &presamples)
Definition: CastorPacker.cc:27
static const int CHANNELS_PER_SPIGOT
Definition: HcalHTRData.h:18
Log< level::Error, false > LogError
static const int MAXIMUM_SAMPLES_PER_CHANNEL
Definition: HcalHTRData.h:19
void allocate(int version_to_create=0)
Definition: HcalHTRData.cc:25
void copySpigotData(unsigned int spigot_id, const HcalHTRData &data, bool valid=true, unsigned char LRB_error_word=0)
Add the given HcalHTRData as the given spigot&#39;s data. This should be done in increasing spigot order!...
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
ii
Definition: cuy.py:589
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: HcalHTRData.cc:233
const DetId lookup(CastorElectronicsId fId) const
lookup the logical detid associated with the given electronics 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)
Definition: HcalHTRData.cc:294
Readout chain identification for Castor Bits for the readout chain : some names need change! [31:26] ...
Definition: output.py:1
float linear(float x)
const int getRawLength() const
Get the length of the raw data.
Definition: HcalHTRData.h:42