CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalPacker.cc
Go to the documentation of this file.
8 
10  hbhe=0;
11  hoCont=0;
12  hfCont=0;
13  tpCont=0;
14  zdcCont=0;
15  calibCont=0;
16 }
17 
18 template <class Coll, class DetIdClass>
19 int process(const Coll* pt, const DetId& did, unsigned short* buffer, int& presamples,bool& isUS, bool& isMP) {
20  isUS=false; isMP=false;
21  if (pt==0) return 0;
22  int size=0;
23  typename Coll::const_iterator i=pt->find(DetIdClass(did));
24  if (i!=pt->end()) {
25  isUS=i->zsUnsuppressed();
26  isMP=i->zsMarkAndPass();
27  presamples=i->presamples();
28  size=i->size();
29  for (int j=0; j<size; j++)
30  buffer[j]=(*i)[j].raw();
31  }
32  return size;
33 }
34 
35 static unsigned char processTrig(const HcalTrigPrimDigiCollection* pt, const HcalTrigTowerDetId& tid, unsigned short* buffer) {
36  if (pt==0) return 0;
37  int size=0;
39  if (i!=pt->end()) {
40  int presamples=i->presamples();
41  int samples=i->size();
42 
43  for (int j=0; j<samples; j++) {
44  buffer[j]=(*i)[j].raw();
45  if (j==presamples) buffer[j]|=0x0200;
46  }
47  }
48  return size;
49 }
50 
52  unsigned short* buffer, int &presamples, bool& isUS, bool& isMP) {
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 }
78 
79 void HcalPacker::pack(int fedid, int dccnumber,
80  int nl1a, int orbitn, int bcn,
81  const Collections& inputs,
82  const HcalElectronicsMap& emap,
83  FEDRawData& output) {
85  std::vector<unsigned short> trigdata(HcalHTRData::CHANNELS_PER_SPIGOT*HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL);
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 }
int i
Definition: DBlmapReader.cc:9
void pack(int fedid, int dccnumber, int nl1a, int orbitn, int bcn, const Collections &inputs, const HcalElectronicsMap &emap, FEDRawData &output)
Definition: HcalPacker.cc:79
uint16_t raw() const
get the raw word
Definition: HcalQIESample.h:22
void packUnsuppressed(const bool *mp)
pack trailer with Mark and Pass bits
Definition: HcalHTRData.cc:310
int htrSlot() const
get the htr slot
std::vector< T >::const_iterator const_iterator
const HcalCalibDigiCollection * calibCont
Definition: HcalPacker.h:21
static const int CHANNELS_PER_SPIGOT
Definition: HcalHTRData.h:20
static const int MAXIMUM_SAMPLES_PER_CHANNEL
Definition: HcalHTRData.h:21
static void set(unsigned char *trailer, int evt_lgth, int crc, int evt_stat, int tts, bool T=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:44
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)
uint16_t raw() const
get the raw word
int j
Definition: DBlmapReader.cc:9
const HcalTrigPrimDigiCollection * tpCont
Definition: HcalPacker.h:23
const ZDCDigiCollection * zdcCont
Definition: HcalPacker.h:22
const HBHEDigiCollection * hbhe
Definition: HcalPacker.h:18
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
const_iterator end() const
Definition: DetId.h:20
static const int SubdetectorId
Definition: HcalZDCDetId.h:22
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
iterator find(key_type k)
const HODigiCollection * hoCont
Definition: HcalPacker.h:19
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
const HFDigiCollection * hfCont
Definition: HcalPacker.h:20
HcalGenericSubdetector genericSubdet() const
tuple process
Definition: LaserDQM_cfg.py:3
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
Readout chain identification for Hcal [31:26] Unused (so far) [25] Trigger-chain id flag [24:20] Read...
tuple size
Write out results.
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id