CMS 3D CMS Logo

HcalDigiToRawuHTR.cc
Go to the documentation of this file.
6 
9 
12 
14 
22 
25 
26 #include "PackerHelp.h"
27 
28 #include <iostream>
29 #include <fstream>
30 #include <sstream>
31 #include <string>
32 
33 /* QUESTION: what about dual FED readout? */
34 /* QUESTION: what do I do if the number of 16-bit words
35  are not divisible by 4? -- these need to
36  fit into the 64-bit words of the FEDRawDataFormat */
37 
38 
39 using namespace std;
40 
42 public:
43  explicit HcalDigiToRawuHTR(const edm::ParameterSet&);
45 
46  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
47 
48 private:
49  virtual void produce(edm::Event&, const edm::EventSetup&) override;
50  void getData(const edm::Event&, const edm::EventSetup&);
51 
54 
65 
66  edm::InputTag qie10Tag_, qie11Tag_, hbheqie8Tag_, hfqie8Tag_, trigTag_;
67  bool premix_;
68 };
69 
71  _verbosity(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
72  electronicsMapLabel_(iConfig.getParameter<std::string>("ElectronicsMap")),
73  qie10Tag_(iConfig.getParameter<edm::InputTag>("QIE10")),
74  qie11Tag_(iConfig.getParameter<edm::InputTag>("QIE11")),
75  hbheqie8Tag_(iConfig.getParameter<edm::InputTag>("HBHEqie8")),
76  hfqie8Tag_(iConfig.getParameter<edm::InputTag>("HFqie8")),
77  trigTag_(iConfig.getParameter<edm::InputTag>("TP")),
78  premix_(iConfig.getParameter<bool>("premix"))
79 {
80  produces<FEDRawDataCollection>("");
81  tok_QIE10DigiCollection_ = consumes<HcalDataFrameContainer<QIE10DataFrame> >(qie10Tag_);
82  tok_QIE11DigiCollection_ = consumes<HcalDataFrameContainer<QIE11DataFrame> >(qie11Tag_);
83  tok_HBHEDigiCollection_ = consumes<HBHEDigiCollection >(hbheqie8Tag_);
84  tok_HFDigiCollection_ = consumes<HFDigiCollection>(hfqie8Tag_);
85  tok_TPDigiCollection_ = consumes<HcalTrigPrimDigiCollection>(trigTag_);
86 }
87 
89 
91 
92  using namespace edm;
93 
96  const HcalElectronicsMap* readoutMap = item.product();
97 
98  //collection to be inserted into event
99  std::unique_ptr<FEDRawDataCollection> fed_buffers(new FEDRawDataCollection());
100 
101  //
102  // Extracting All the Collections containing useful Info
108 
109  // first argument is the fedid (minFEDID+crateId)
110  map<int,unique_ptr<HCalFED> > fedMap;
111 
112  // - - - - - - - - - - - - - - - - - - - - - - - - - - -
113  // QIE10 precision data
114  // - - - - - - - - - - - - - - - - - - - - - - - - - - -
115  UHTRpacker uhtrs;
116  // loop over each digi and allocate memory for each
117  if( qie10DigiCollection.isValid() ){
118  const QIE10DigiCollection& qie10dc=*(qie10DigiCollection);
119  for (unsigned int j=0; j < qie10dc.size(); j++){
120  QIE10DataFrame qiedf = static_cast<QIE10DataFrame>(qie10dc[j]);
121  DetId detid = qiedf.detid();
122  HcalElectronicsId eid(readoutMap->lookup(detid));
123  int crateId = eid.crateId();
124  int slotId = eid.slot();
125  int uhtrIndex = ((slotId&0xF)<<8) | (crateId&0xFF);
126  int presamples = qiedf.presamples();
127 
128  /* Defining a custom index that will encode only
129  the information about the crate and slot of a
130  given channel: crate: bits 0-7
131  slot: bits 8-12 */
132 
133  if( ! uhtrs.exist( uhtrIndex ) ){
134  uhtrs.newUHTR( uhtrIndex , presamples );
135  }
136  uhtrs.addChannel(uhtrIndex,qiedf,readoutMap,_verbosity);
137  }
138  }
139  // - - - - - - - - - - - - - - - - - - - - - - - - - - -
140  // QIE11 precision data
141  // - - - - - - - - - - - - - - - - - - - - - - - - - - -
142  //UHTRpacker uhtrs;
143  // loop over each digi and allocate memory for each
144  if( qie11DigiCollection.isValid() ){
145  const QIE11DigiCollection& qie11dc=*(qie11DigiCollection);
146  for (unsigned int j=0; j < qie11dc.size(); j++){
147  QIE11DataFrame qiedf = static_cast<QIE11DataFrame>(qie11dc[j]);
148  DetId detid = qiedf.detid();
149  HcalElectronicsId eid(readoutMap->lookup(detid));
150  int crateId = eid.crateId();
151  int slotId = eid.slot();
152  int uhtrIndex = ((slotId&0xF)<<8) | (crateId&0xFF);
153  int presamples = qiedf.presamples();
154 
155  if( ! uhtrs.exist(uhtrIndex) ){
156  uhtrs.newUHTR( uhtrIndex , presamples );
157  }
158  uhtrs.addChannel(uhtrIndex,qiedf,readoutMap,_verbosity);
159  }
160  }
161  // - - - - - - - - - - - - - - - - - - - - - - - - - - -
162  // HF (QIE8) precision data
163  // - - - - - - - - - - - - - - - - - - - - - - - - - - -
164  // loop over each digi and allocate memory for each
165  if(hfDigiCollection.isValid()){
166  const HFDigiCollection& qie8hfdc=*(hfDigiCollection);
167  for(HFDigiCollection::const_iterator qiedf=qie8hfdc.begin();qiedf!=qie8hfdc.end();qiedf++){
168  DetId detid = qiedf->id();
169 
170  HcalElectronicsId eid(readoutMap->lookup(detid));
171  int crateId = eid.crateId();
172  int slotId = eid.slot();
173  int uhtrIndex = (crateId&0xFF) | ((slotId&0xF)<<8) ;
174  int presamples = qiedf->presamples();
175 
176  if( ! uhtrs.exist(uhtrIndex) ){
177  uhtrs.newUHTR( uhtrIndex , presamples );
178  }
179  uhtrs.addChannel(uhtrIndex,qiedf,readoutMap,premix_,_verbosity);
180  }
181  }
182  // - - - - - - - - - - - - - - - - - - - - - - - - - - -
183  // HBHE (QIE8) precision data
184  // - - - - - - - - - - - - - - - - - - - - - - - - - - -
185  // loop over each digi and allocate memory for each
186  if(hbheDigiCollection.isValid()){
187  const HBHEDigiCollection& qie8hbhedc=*(hbheDigiCollection);
188  for(HBHEDigiCollection::const_iterator qiedf=qie8hbhedc.begin();qiedf!=qie8hbhedc.end();qiedf++){
189  DetId detid = qiedf->id();
190 
191  HcalElectronicsId eid(readoutMap->lookup(detid));
192  int crateId = eid.crateId();
193  int slotId = eid.slot();
194  int uhtrIndex = (crateId&0xFF) | ((slotId&0xF)<<8) ;
195  int presamples = qiedf->presamples();
196 
197  if( ! uhtrs.exist(uhtrIndex) ){
198  uhtrs.newUHTR( uhtrIndex , presamples );
199  }
200  uhtrs.addChannel(uhtrIndex,qiedf,readoutMap,premix_,_verbosity);
201  }
202  }
203  // - - - - - - - - - - - - - - - - - - - - - - - - - - -
204  // TP data
205  // - - - - - - - - - - - - - - - - - - - - - - - - - - -
206  // loop over each digi and allocate memory for each
207  if(tpDigiCollection.isValid()){
209  for(HcalTrigPrimDigiCollection::const_iterator qiedf=qietpdc.begin();qiedf!=qietpdc.end();qiedf++){
210  DetId detid = qiedf->id();
211  HcalElectronicsId eid(readoutMap->lookupTrigger(detid));
212 
213  int crateId = eid.crateId();
214  int slotId = eid.slot();
215  int uhtrIndex = (crateId&0xFF) | ((slotId&0xF)<<8);
216  int ilink = eid.fiberIndex();
217  int itower = eid.fiberChanId();
218  int channelid = (itower&0xF) | ((ilink&0xF)<<4);
219  int presamples = qiedf->presamples();
220 
221  if( ! uhtrs.exist(uhtrIndex) ){
222  uhtrs.newUHTR( uhtrIndex , presamples );
223  }
224  uhtrs.addChannel(uhtrIndex,qiedf,channelid,_verbosity);
225  }
226  }
227  // -----------------------------------------------------
228  // -----------------------------------------------------
229  // loop over each uHTR and format data
230  // -----------------------------------------------------
231  // -----------------------------------------------------
232  // loop over each uHTR and format data
233  int idxuhtr =-1;
234  for( UHTRpacker::UHTRMap::iterator uhtr = uhtrs.uhtrs.begin() ; uhtr != uhtrs.uhtrs.end() ; ++uhtr){
235 
236  idxuhtr ++;
237 
238  uint64_t crateId = (uhtr->first)&0xFF;
239  uint64_t slotId = (uhtr->first&0xF00)>>8;
240 
241  uhtrs.finalizeHeadTail(&(uhtr->second),_verbosity);
242  int fedId = FEDNumbering::MINHCALuTCAFEDID + crateId;
243  if( fedMap.find(fedId) == fedMap.end() ){
244  /* QUESTION: where should the orbit number come from? */
245  fedMap[fedId] = std::unique_ptr<HCalFED>(new HCalFED(fedId,iEvent.id().event(),iEvent.orbitNumber(),iEvent.bunchCrossing()));
246  }
247  fedMap[fedId]->addUHTR(uhtr->second,crateId,slotId);
248  }// end loop over uhtr containers
249 
250  /* ------------------------------------------------------
251  ------------------------------------------------------
252  putting together the FEDRawDataCollection
253  ------------------------------------------------------
254  ------------------------------------------------------ */
255  for( map<int,unique_ptr<HCalFED> >::iterator fed = fedMap.begin() ; fed != fedMap.end() ; ++fed ){
256 
257  int fedId = fed->first;
258 
259  auto & rawData = fed_buffers->FEDData(fedId);
260  fed->second->formatFEDdata(rawData);
261 
262  FEDHeader hcalFEDHeader(rawData.data());
263  hcalFEDHeader.set(rawData.data(), 1, iEvent.id().event(), iEvent.bunchCrossing(), fedId);
264  FEDTrailer hcalFEDTrailer(rawData.data()+(rawData.size()-8));
265  hcalFEDTrailer.set(rawData.data()+(rawData.size()-8), rawData.size()/8, evf::compute_crc(rawData.data(),rawData.size()), 0, 0);
266 
267  }// end loop over FEDs with data
268 
269  iEvent.put(std::move(fed_buffers));
270 
271 }
272 
273 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
275  //The following says we do not know what parameters are allowed so do no validation
276  // Please change this to state exactly what you do use, even if it is no parameters
278  desc.addUntracked<int>("Verbosity", 0);
279  desc.add<std::string>("ElectronicsMap", "");
280  desc.add<edm::InputTag>("QIE10", edm::InputTag("simHcalDigis", "HFQIE10DigiCollection"));
281  desc.add<edm::InputTag>("QIE11", edm::InputTag("simHcalDigis", "HBHEQIE11DigiCollection"));
282  desc.add<edm::InputTag>("HBHEqie8", edm::InputTag("simHcalDigis"));
283  desc.add<edm::InputTag>("HFqie8", edm::InputTag("simHcalDigis"));
284  desc.add<edm::InputTag>("TP", edm::InputTag("simHcalTriggerPrimitiveDigis"));
285  desc.add<bool>("premix", false);
286  descriptions.add("hcalDigiToRawuHTR",desc);
287  descriptions.addDefault(desc);
288 }
289 
290 //define this as a plug-in
DetId detid() const
Get the detector id.
EventNumber_t event() const
Definition: EventID.h:41
edm::EDGetTokenT< HBHEDigiCollection > tok_HBHEDigiCollection_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void finalizeHeadTail(uhtrData *uhtr, bool verbosity)
Definition: PackerHelp.h:474
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int presamples() const
for backward compatibility
edm::InputTag hfqie8Tag_
uhtrData * newUHTR(int uhtrIndex, int ps=0, int orn=0, int bcn=0, uint64_t evt=0)
Definition: PackerHelp.h:433
virtual void produce(edm::Event &, const edm::EventSetup &) override
std::vector< HFDataFrame >::const_iterator const_iterator
int bunchCrossing() const
Definition: EventBase.h:66
edm::InputTag qie11Tag_
def getData(doc, options, dataset, site)
edm::InputTag qie10Tag_
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:42
edm::Handle< HcalTrigPrimDigiCollection > tpDigiCollection
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< HcalDataFrameContainer< QIE10DataFrame > > tok_QIE10DigiCollection_
std::string electronicsMapLabel_
static void set(unsigned char *header, int evt_ty, int lvl1_ID, int bx_ID, int source_ID, int version=0, bool H=false)
Set all fields in the header.
Definition: FEDHeader.cc:40
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:67
edm::EDGetTokenT< HFDigiCollection > tok_HFDigiCollection_
DetId detid() const
Get the detector id.
edm::Handle< HFDigiCollection > hfDigiCollection
int orbitNumber() const
Definition: EventBase.h:67
HcalDigiToRawuHTR(const edm::ParameterSet &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::Handle< QIE10DigiCollection > qie10DigiCollection
edm::InputTag trigTag_
const_iterator end() const
UHTRMap uhtrs
Definition: PackerHelp.h:312
Definition: DetId.h:18
unsigned long long uint64_t
Definition: Time.h:15
edm::InputTag hbheqie8Tag_
const T & get() const
Definition: EventSetup.h:56
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void addChannel(int uhtrIndex, edm::SortedCollection< HFDataFrame >::const_iterator &qiedf, const HcalElectronicsMap *readoutMap, bool premix, int verbosity=0)
Definition: PackerHelp.h:497
int presamples() const
for backward compatibility
bool exist(int uhtrIndex)
Definition: PackerHelp.h:343
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
edm::Handle< QIE11DigiCollection > qie11DigiCollection
edm::Handle< HBHEDigiCollection > hbheDigiCollection
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
T const * product() const
Definition: ESHandle.h:86
Readout chain identification for Hcal.
edm::EDGetTokenT< HcalTrigPrimDigiCollection > tok_TPDigiCollection_
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
def move(src, dest)
Definition: eostools.py:510
const_iterator begin() const
edm::EDGetTokenT< HcalDataFrameContainer< QIE11DataFrame > > tok_QIE11DigiCollection_