CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)
 

Private Member Functions

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

Detailed Description

Date:
2009/11/05 21:51:15
Revision:
1.2
Author
J. Mans - Minnesota

Definition at line 14 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 
)
private

Definition at line 51 of file HcalPacker.cc.

References 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, findQualityFiles::size, HcalZDCDetId::SubdetectorId, DetId::subdetId(), and HcalPacker::Collections::zdcCont.

Referenced by pack().

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

pack into HcalHTRData

Definition at line 79 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(), HcalElectronicsMap::lookup(), HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL, DetId::null(), HcalHTRData::pack(), HcalHTRData::packHeaderTrailer(), HcalHTRData::packUnsuppressed(), processTrig(), lumiQueryAPI::q, HcalTriggerPrimitiveSample::raw(), HcalQIESample::raw(), HcalElectronicsId::readoutVMECrateId(), FEDRawData::resize(), FEDTrailer::set(), HcalDCCHeader::setHeader(), FEDRawData::size(), and HcalPacker::Collections::tpCont.

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

83  {
86  std::vector<unsigned char> preclen(HcalHTRData::CHANNELS_PER_SPIGOT);
87  std::vector<unsigned char> triglen(HcalHTRData::CHANNELS_PER_SPIGOT);
88  static const int HTRFormatVersion=5;
89  bool channelIsMP[HcalHTRData::CHANNELS_PER_SPIGOT];
90 
91  HcalHTRData spigots[15];
92  // loop over all valid channels in the given dcc, spigot by spigot.
93  for (int spigot=0; spigot<15; spigot++) {
94  spigots[spigot].allocate(HTRFormatVersion);
95  HcalElectronicsId exampleEId;
96  int npresent=0;
97  int presamples=-1, samples=-1;
98  bool haveUnsuppressed=false;
99  for (int fiber=1; fiber<=8; fiber++)
100  for (int fiberchan=0; fiberchan<3; fiberchan++) {
101  int linear=(fiber-1)*3+fiberchan;
102  HcalQIESample chanSample(0,0,fiber,fiberchan,false,false);
103  unsigned short chanid=chanSample.raw()&0xF800;
104  preclen[linear]=0;
105  channelIsMP[linear]=false;
106 
107  HcalElectronicsId partialEid(fiberchan,fiber,spigot,dccnumber);
108  // does this partial id exist?
109  HcalElectronicsId fullEid;
110  HcalGenericDetId genId;
111  if (!emap.lookup(partialEid,fullEid,genId)) continue;
112 
113 
114  // next, see if there is a digi with this id
115  unsigned short* database=&(precdata[linear*HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL]);
116  int mypresamples=-1;
117  bool isUS=false, isMP=false;
118  int mysamples=findSamples(genId,inputs,database,mypresamples,isUS,isMP);
119  haveUnsuppressed=haveUnsuppressed || isUS;
120  channelIsMP[linear]=isMP;
121 
122  if (mysamples>0) {
123  if (samples<0) samples=mysamples;
124  else if (samples!=mysamples) {
125  edm::LogError("HCAL") << "Mismatch of samples in a single HTR (unsupported) " << mysamples << " != " << samples;
126  continue;
127  }
128  if (presamples<0) {
129  presamples=mypresamples;
130  exampleEId=fullEid;
131  } else if (mypresamples!=presamples) {
132  edm::LogError("HCAL") << "Mismatch of presamples in a single HTR (unsupported) " << mypresamples << " != " << presamples;
133  continue;
134  }
135  for (int ii=0; ii<samples; ii++)
136  database[ii]=(database[ii]&0x7FF)|chanid;
137  preclen[linear]=(unsigned char)(samples);
138  npresent++;
139  }
140  }
141  for (int slb=1; slb<=6; slb++)
142  for (int slbchan=0; slbchan<=3; slbchan++) {
143  int linear=(slb-1)*4+slbchan;
144  HcalTriggerPrimitiveSample idCvt(0,0,slb,slbchan);
145  unsigned short chanid=idCvt.raw()&0xF800;
146  triglen[linear]=0;
147 
148  HcalElectronicsId partialEid(slbchan,slb,spigot,dccnumber,0,0,0);
149  // does this partial id exist?
150  HcalElectronicsId fullEid;
151  HcalTrigTowerDetId tid;
152  if (!emap.lookup(partialEid,fullEid,tid)) {
153 // std::cout << "TPGPACK : no match for " << partialEid << std::endl;
154  continue;
155  } //else std::cout << "TPGPACK : converted " << partialEid << " to " << fullEid << "/" << tid << std::endl;
156 
157  // finally, what about a trigger channel?
158  if (!tid.null()) {
159  unsigned short* trigbase=&(trigdata[linear*HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL]);
160  triglen[linear]=processTrig(inputs.tpCont,tid,trigbase);
161 
162  for (unsigned char q=0; q<triglen[linear]; q++)
163  trigbase[q]=(trigbase[q]&0x7FF)|chanid;
164  }
165  }
167  if (npresent>0) {
168  spigots[spigot].pack(&(preclen[0]),&(precdata[0]),
169  &(triglen[0]),&(trigdata[0]),
170  false);
171  static const int pipeline=0x22;
172  static const int firmwareRev=0;
173  int submodule=exampleEId.htrTopBottom()&0x1;
174  submodule|=(exampleEId.htrSlot()&0x1F)<<1;
175  submodule|=(exampleEId.readoutVMECrateId()&0x1f)<<6;
176  spigots[spigot].packHeaderTrailer(nl1a,
177  bcn,
178  submodule,
179  orbitn,
180  pipeline,
181  samples,
182  presamples,
183  firmwareRev);
184  if (haveUnsuppressed) {
185  spigots[spigot].packUnsuppressed(channelIsMP);
186  }
187 
188  }
189  }
190  // calculate the total length, and resize the FEDRawData
191  int theSize=0;
192  for (int spigot=0; spigot<15; spigot++) {
193  theSize+=spigots[spigot].getRawLength()*sizeof(unsigned short);
194  }
195  theSize+=sizeof(HcalDCCHeader)+8; // 8 for trailer
196  theSize+=(8-(theSize%8))%8; // even number of 64-bit words.
197  output.resize(theSize);
198 
199  // construct the bare DCC Header
200  HcalDCCHeader* dcc=(HcalDCCHeader*)(output.data());
201  dcc->clear();
202  dcc->setHeader(fedid,bcn,nl1a,orbitn);
203 
204  // pack the HTR data into the FEDRawData block using HcalDCCHeader
205  for (int spigot=0; spigot<15; spigot++) {
206  if (spigots[spigot].getRawLength()>0)
207  dcc->copySpigotData(spigot,spigots[spigot],true,0);
208  }
209  // trailer
210  FEDTrailer fedTrailer(output.data()+(output.size()-8));
211  fedTrailer.set(output.data()+(output.size()-8),
212  output.size()/8,
213  evf::compute_crc(output.data(),output.size()), 0, 0);
214 }
void packUnsuppressed(const bool *mp)
pack trailer with Mark and Pass bits
Definition: HcalHTRData.cc:310
int htrSlot() const
get the htr slot
static const int CHANNELS_PER_SPIGOT
Definition: HcalHTRData.h:20
static const int MAXIMUM_SAMPLES_PER_CHANNEL
Definition: HcalHTRData.h:21
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
int readoutVMECrateId() const
get the readout VME crate number
void allocate(int version_to_create=0)
Definition: HcalHTRData.cc:28
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:35
int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom)
void resize(size_t newsize)
Definition: FEDRawData.cc:33
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:41
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
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:226
bool null() const
is this a null id ?
Definition: DetId.h:47
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: HcalHTRData.cc:285
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
int findSamples(const DetId &did, const Collections &inputs, unsigned short *buffer, int &presamples, bool &zsUS, bool &zsMP)
Definition: HcalPacker.cc:51
Readout chain identification for Hcal [31:26] Unused (so far) [25] Trigger-chain id flag [24:20] Read...
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id