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

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

Definition at line 26 of file CastorPacker.cc.

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

Referenced by pack().

27  {
28 
29  if (did.det()!=DetId::Calo) return 0;
30  int size=0;
31  HcalCastorDetId genId(did);
32 
33  size=process<CastorDigiCollection,HcalCastorDetId>(inputs.castorCont,did,buffer,presamples);
34 
35  return size;
36 }
size
Write out results.
const CastorDigiCollection * castorCont
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39
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 38 of file CastorPacker.cc.

References HcalHTRData::allocate(), HcalHTRData::CHANNELS_PER_SPIGOT, HcalDCCHeader::clear(), evf::compute_crc(), constexpr, HcalDCCHeader::copySpigotData(), FEDRawData::data(), findSamples(), HcalHTRData::getRawLength(), CastorElectronicsId::htrSlot(), CastorElectronicsId::htrTopBottom(), cuy::ii, linear(), CastorElectronicsMap::lookup(), HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL, HcalHTRData::pack(), HcalHTRData::packHeaderTrailer(), hcalTTPDigis_cfi::presamples, HcalQIESample::raw(), CastorElectronicsId::readoutVMECrateId(), FEDRawData::resize(), hcalTTPDigis_cfi::samples, FEDTrailer::set(), HcalDCCHeader::setHeader(), and FEDRawData::size().

Referenced by pyrootRender.interactiveRender::draw(), and CastorDigiToRaw::produce().

42  {
45  std::vector<unsigned char> preclen(HcalHTRData::CHANNELS_PER_SPIGOT);
46  std::vector<unsigned char> triglen(HcalHTRData::CHANNELS_PER_SPIGOT);
47  constexpr int HTRFormatVersion=3;
48 
49  HcalHTRData spigots[15];
50  // loop over all valid channels in the given dcc, spigot by spigot.
51  for (int spigot=0; spigot<15; spigot++) {
52  spigots[spigot].allocate(HTRFormatVersion);
53  CastorElectronicsId exampleEId;
54  int npresent=0;
55  int presamples=-1, samples=-1;
56  for (int fiber=1; fiber<=8; fiber++)
57  for (int fiberchan=0; fiberchan<3; fiberchan++) {
58  int linear=(fiber-1)*3+fiberchan;
59  HcalQIESample chanSample(0,0,fiber,fiberchan,false,false);
60  unsigned short chanid=chanSample.raw()&0xF800;
61  preclen[linear]=0;
62 
63  CastorElectronicsId partialEid(fiberchan,fiber,spigot,dccnumber);
64  // does this partial id exist?
65  CastorElectronicsId fullEid;
66  HcalGenericDetId genId;
67  if (!emap.lookup(partialEid,fullEid,genId)) continue;
68 
69  // next, see if there is a digi with this id
70  unsigned short* database=&(precdata[linear*HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL]);
71  int mypresamples;
72  int mysamples=findSamples(genId,inputs,database,mypresamples);
73 
74  if (mysamples>0) {
75  if (samples<0) samples=mysamples;
76  else if (samples!=mysamples) {
77  edm::LogError("CASTOR") << "Mismatch of samples in a single HTR (unsupported) " << mysamples << " != " << samples;
78  continue;
79  }
80  if (presamples<0) {
81  presamples=mypresamples;
82  exampleEId=fullEid;
83  } else if (mypresamples!=presamples) {
84  edm::LogError("CASTOR") << "Mismatch of presamples in a single HTR (unsupported) " << mypresamples << " != " << presamples;
85  continue;
86  }
87  for (int ii=0; ii<samples; ii++)
88  database[ii]=(database[ii]&0x7FF)|chanid;
89  preclen[linear]=(unsigned char)(samples);
90  npresent++;
91  }
92  }
94  if (npresent>0) {
95  spigots[spigot].pack(&(preclen[0]),&(precdata[0]),
96  &(triglen[0]),&(trigdata[0]),
97  false);
98  constexpr int pipeline=0x22;
99  constexpr int firmwareRev=0;
100  int submodule=exampleEId.htrTopBottom()&0x1;
101  submodule|=(exampleEId.htrSlot()&0x1F)<<1;
102  submodule|=(exampleEId.readoutVMECrateId()&0x1f)<<6;
103  spigots[spigot].packHeaderTrailer(nl1a,
104  bcn,
105  submodule,
106  orbitn,
107  pipeline,
108  samples,
109  presamples,
110  firmwareRev);
111 
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(output.data()+(output.size()-8),
136  output.size()/8,
137  evf::compute_crc(output.data(),output.size()), 0, 0);
138 
139 }
int readoutVMECrateId() const
static int findSamples(const DetId &did, const CastorCollections &inputs, unsigned short *buffer, int &presamples)
Definition: CastorPacker.cc:26
static const int CHANNELS_PER_SPIGOT
Definition: HcalHTRData.h:18
static const int MAXIMUM_SAMPLES_PER_CHANNEL
Definition: HcalHTRData.h:19
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void allocate(int version_to_create=0)
Definition: HcalHTRData.cc:26
const DetId lookup(CastorElectronicsId fId) const
lookup the logical detid associated with the given electronics id
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!...
void resize(size_t newsize)
Definition: FEDRawData.cc:32
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
const int getRawLength() const
Get the length of the raw data.
Definition: HcalHTRData.h:39
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
ii
Definition: cuy.py:590
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:225
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:284
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
Readout chain identification for Castor Bits for the readout chain : some names need change! [31:26] ...
float linear(float x)
#define constexpr