CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions
HcalPacker Class Reference

#include <HcalPacker.h>

Classes

struct  Collections
 

Public Member Functions

void pack (int fedid, int dccnumber, int nl1a, int orbitn, int bcn, const Collections &inputs, const HcalElectronicsMap &emap, FEDRawData &output) const
 

Private Member Functions

int findSamples (const DetId &did, const Collections &inputs, unsigned short *buffer, int &presamples, bool &zsUS, bool &zsMP) const
 

Detailed Description

Author
J. Mans - Minnesota

Definition at line 12 of file HcalPacker.h.

Member Function Documentation

int HcalPacker::findSamples ( const DetId did,
const Collections inputs,
unsigned short *  buffer,
int &  presamples,
bool &  zsUS,
bool &  zsMP 
) const
private

Definition at line 54 of file HcalPacker.cc.

References edmScanValgrind::buffer, HcalPacker::Collections::calibCont, DetId::Calo, DetId::det(), HcalGenericDetId::genericSubdet(), HcalPacker::Collections::hbhe, DetId::Hcal, HcalGenericDetId::HcalGenBarrel, HcalGenericDetId::HcalGenCalibration, HcalGenericDetId::HcalGenEndcap, HcalGenericDetId::HcalGenForward, HcalGenericDetId::HcalGenOuter, HcalGenericDetId::HcalGenZDC, HcalPacker::Collections::hfCont, HcalPacker::Collections::hoCont, hcalTTPDigis_cfi::presamples, findQualityFiles::size, HcalZDCDetId::SubdetectorId, DetId::subdetId(), and HcalPacker::Collections::zdcCont.

Referenced by pack().

55  {
56  if (!(did.det()==DetId::Hcal || (did.det()== DetId::Calo && did.subdetId()==HcalZDCDetId::SubdetectorId)) ) { return 0; }
57  int size=0;
58  HcalGenericDetId genId(did);
59 
60  switch (genId.genericSubdet()) {
63  size=process<HBHEDigiCollection,HcalDetId>(inputs.hbhe,did,buffer,presamples,isUS,isMP);
64  break;
66  size=process<HODigiCollection,HcalDetId>(inputs.hoCont,did,buffer,presamples,isUS,isMP);
67  break;
69  size=process<HFDigiCollection,HcalDetId>(inputs.hfCont,did,buffer,presamples,isUS,isMP);
70  break;
72  size=process<ZDCDigiCollection,HcalZDCDetId>(inputs.zdcCont,did,buffer,presamples,isUS,isMP);
73  break;
75  size=process<HcalCalibDigiCollection,HcalCalibDetId>(inputs.calibCont,did,buffer,presamples,isUS,isMP);
76  break;
77  default: size=0;
78  }
79  return size;
80 }
size
Write out results.
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
static const int SubdetectorId
Definition: HcalZDCDetId.h:25
Detector det() const
get the detector field from this detid
Definition: DetId.h:36
void HcalPacker::pack ( int  fedid,
int  dccnumber,
int  nl1a,
int  orbitn,
int  bcn,
const Collections inputs,
const HcalElectronicsMap emap,
FEDRawData output 
) const

pack into HcalHTRData

Definition at line 82 of file HcalPacker.cc.

References HcalHTRData::allocate(), HcalHTRData::CHANNELS_PER_SPIGOT, HcalDCCHeader::clear(), evf::compute_crc(), HcalDCCHeader::copySpigotData(), FEDRawData::data(), findSamples(), HcalHTRData::getRawLength(), HcalElectronicsId::htrSlot(), HcalElectronicsId::htrTopBottom(), cuy::ii, linear(), HcalElectronicsMap::lookup(), HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL, DetId::null(), HcalHTRData::pack(), HcalHTRData::packHeaderTrailer(), HcalHTRData::packUnsuppressed(), hcalTTPDigis_cfi::presamples, processTrig(), lumiQueryAPI::q, HcalTriggerPrimitiveSample::raw(), HcalQIESample::raw(), HcalElectronicsId::readoutVMECrateId(), FEDRawData::resize(), hcalTTPDigis_cfi::samples, FEDTrailer::set(), HcalDCCHeader::setHeader(), FEDRawData::size(), slb(), and HcalPacker::Collections::tpCont.

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

86  {
89  std::vector<unsigned char> preclen(HcalHTRData::CHANNELS_PER_SPIGOT);
90  std::vector<unsigned char> triglen(HcalHTRData::CHANNELS_PER_SPIGOT);
91  static const int HTRFormatVersion=5;
92  bool channelIsMP[HcalHTRData::CHANNELS_PER_SPIGOT];
93 
94  HcalHTRData spigots[15];
95  // loop over all valid channels in the given dcc, spigot by spigot.
96  for (int spigot=0; spigot<15; spigot++) {
97  spigots[spigot].allocate(HTRFormatVersion);
98  HcalElectronicsId exampleEId;
99  int npresent=0, npresenttp=0;
100  int presamples=-1, samples=-1;
101  bool haveUnsuppressed=false;
102  for (int fiber=1; fiber<=8; fiber++) {
103  for (int fiberchan=0; fiberchan<3; fiberchan++) {
104  int linear=(fiber-1)*3+fiberchan;
105  HcalQIESample chanSample(0,0,fiber,fiberchan,false,false);
106  unsigned short chanid=chanSample.raw()&0xF800;
107  preclen[linear]=0;
108  channelIsMP[linear]=false;
109 
110  HcalElectronicsId partialEid(fiberchan,fiber,spigot,dccnumber);
111  // does this partial id exist?
112  HcalElectronicsId fullEid;
113  HcalGenericDetId genId;
114  if (!emap.lookup(partialEid,fullEid,genId)) { continue; }
115 
116 
117  // next, see if there is a digi with this id
118  unsigned short* database=&(precdata[linear*HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL]);
119  int mypresamples=-1;
120  bool isUS=false, isMP=false;
121  int mysamples=findSamples(genId,inputs,database,mypresamples,isUS,isMP);
122  haveUnsuppressed=haveUnsuppressed || isUS;
123  channelIsMP[linear]=isMP;
124 
125  if (mysamples>0) {
126  if (samples<0) { samples=mysamples; }
127  else if (samples!=mysamples) {
128  edm::LogError("HCAL") << "Mismatch of samples in a single HTR (unsupported) " << mysamples << " != " << samples;
129  continue;
130  }
131  if (presamples<0) {
132  presamples=mypresamples;
133  exampleEId=fullEid;
134  } else if (mypresamples!=presamples) {
135  edm::LogError("HCAL") << "Mismatch of presamples in a single HTR (unsupported) " << mypresamples << " != " << presamples;
136  continue;
137  }
138  for (int ii=0; ii<samples; ii++) {
139  database[ii]=(database[ii]&0x7FF)|chanid;
140  }
141  preclen[linear]=(unsigned char)(samples);
142  npresent++;
143  }
144  }
145  }
146  for (int slb=1; slb<=6; slb++) {
147  for (int slbchan=0; slbchan<=3; slbchan++) {
148  int linear=(slb-1)*4+slbchan;
149  HcalTriggerPrimitiveSample idCvt(0,false,slb,slbchan);
150  unsigned short chanid=idCvt.raw()&0xF800;
151  triglen[linear]=0;
152 
153  HcalElectronicsId partialEid(slbchan,slb,spigot,dccnumber,0,0,0);
154  // does this partial id exist?
155  HcalElectronicsId fullEid;
156  HcalTrigTowerDetId tid;
157  if (!emap.lookup(partialEid,fullEid,tid)) {
158 // std::cout << "TPGPACK : no match for " << partialEid << std::endl;
159  continue;
160  } //else std::cout << "TPGPACK : converted " << partialEid << " to " << fullEid << "/" << tid << std::endl;
161 
162  // finally, what about a trigger channel?
163  if (!tid.null()) {
164  if (presamples < 0) {
165  exampleEId = fullEid;
166  }
167  unsigned short* trigbase=&(trigdata[linear*HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL]);
168  triglen[linear]=processTrig(inputs.tpCont,tid,trigbase);
169  if (triglen[linear]) {
170  npresent++;
171  npresenttp++;
172  }
173 
174  for (unsigned char q=0; q<triglen[linear]; q++) {
175  trigbase[q]=(trigbase[q]&0x7FF)|chanid;
176  }
177 
178  }
179  }
180  }
182  if (npresent>0) {
183  spigots[spigot].pack(&(preclen[0]),&(precdata[0]),
184  &(triglen[0]),&(trigdata[0]),
185  false);
186  static const int pipeline=0x22;
187  static const int firmwareRev=0;
188  int submodule=exampleEId.htrTopBottom()&0x1;
189  submodule|=(exampleEId.htrSlot()&0x1F)<<1;
190  submodule|=(exampleEId.readoutVMECrateId()&0x1f)<<6;
191  // Samples and Presamples can't be negative, or the HeaderTrailer will
192  // generate a large large number using them (unsigned int roll over)
193  if (samples < 0) {
194  samples = 0;
195  }
196  if (presamples < 0) {
197  presamples = 0;
198  }
199  spigots[spigot].packHeaderTrailer(nl1a,
200  bcn,
201  submodule,
202  orbitn,
203  pipeline,
204  samples,
205  presamples,
206  firmwareRev,
207  1); // need non-zero falvor
208  if (haveUnsuppressed) {
209  spigots[spigot].packUnsuppressed(channelIsMP);
210  }
211 
212  }
213  }
214  // calculate the total length, and resize the FEDRawData
215  int theSize=0;
216  for (int spigot=0; spigot<15; spigot++) {
217  theSize+=spigots[spigot].getRawLength()*sizeof(unsigned short);
218  }
219  theSize+=sizeof(HcalDCCHeader)+8; // 8 for trailer
220  theSize+=(8-(theSize%8))%8; // even number of 64-bit words.
221  output.resize(theSize);
222 
223  // construct the bare DCC Header
224  HcalDCCHeader* dcc=(HcalDCCHeader*)(output.data());
225  dcc->clear();
226  dcc->setHeader(fedid,bcn,nl1a,orbitn);
227 
228  // pack the HTR data into the FEDRawData block using HcalDCCHeader
229  for (int spigot=0; spigot<15; spigot++) {
230  if (spigots[spigot].getRawLength()>0) {
231  dcc->copySpigotData(spigot,spigots[spigot],true,0);
232  }
233  }
234  // trailer
235  FEDTrailer fedTrailer(output.data()+(output.size()-8));
236  fedTrailer.set(output.data()+(output.size()-8),
237  output.size()/8,
238  evf::compute_crc(output.data(),output.size()), 0, 0);
239 }
static int slb(const HcalTriggerPrimitiveSample &theSample)
void packUnsuppressed(const bool *mp)
pack trailer with Mark and Pass bits
Definition: HcalHTRData.cc:309
int htrSlot() const
get the htr slot
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
int readoutVMECrateId() const
get the readout VME crate number
void allocate(int version_to_create=0)
Definition: HcalHTRData.cc:26
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!...
static unsigned char processTrig(const HcalTrigPrimDigiCollection *pt, const HcalTrigTowerDetId &tid, unsigned short *buffer)
Definition: HcalPacker.cc:36
int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom), valid for VME
int findSamples(const DetId &did, const Collections &inputs, unsigned short *buffer, int &presamples, bool &zsUS, bool &zsMP) const
Definition: HcalPacker.cc:54
void resize(size_t newsize)
Definition: FEDRawData.cc:32
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:67
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:588
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
bool null() const
is this a null id ?
Definition: DetId.h:46
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
float linear(float x)
Readout chain identification for Hcal.
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id