CMS 3D CMS Logo

EcalDigiToRaw.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalDigiToRaw
4 // Class: EcalDigiToRaw
5 //
13 //
14 // Original Author: Emmanuelle Perez
15 // Created: Sat Nov 25 13:59:51 CET 2006
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <iostream>
22 #include <string>
23 
24 // user include files
27 
30 
33 
38 
41 
43 
47 
51 
54 
56 public:
58 
59  void produce(edm::StreamID, edm::Event& e, const edm::EventSetup& c) const override;
60 
61  typedef long long Word64;
62  typedef unsigned int Word32;
63 
64  static const int BXMAX = 2808;
65 
66 private:
67  // ----------member data ---------------------------
68 
76 
77  const std::vector<int32_t> listDCCId_;
78 
80 };
81 
82 using namespace edm;
83 using namespace std;
84 
86  : listDCCId_{iConfig.getUntrackedParameter<std::vector<int32_t> >("listDCCId")},
87  config_{&listDCCId_,
88  iConfig.getUntrackedParameter<bool>("debug"),
89  iConfig.getUntrackedParameter<bool>("DoBarrel"),
90  iConfig.getUntrackedParameter<bool>("DoEndCap"),
91  iConfig.getUntrackedParameter<bool>("WriteTCCBlock"),
92  iConfig.getUntrackedParameter<bool>("WriteSRFlags"),
93  iConfig.getUntrackedParameter<bool>("WriteTowerBlock")} {
94  auto label = iConfig.getParameter<string>("Label");
95  auto instanceNameEB = iConfig.getParameter<string>("InstanceEB");
96  auto instanceNameEE = iConfig.getParameter<string>("InstanceEE");
97 
98  edm::InputTag EBlabel = edm::InputTag(label, instanceNameEB);
99  edm::InputTag EElabel = edm::InputTag(label, instanceNameEE);
100 
101  EBDigiToken_ = consumes<EBDigiCollection>(EBlabel);
102  EEDigiToken_ = consumes<EEDigiCollection>(EElabel);
103 
104  labelTT_ = consumes<EcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("labelTT"));
105 
106  labelEBSR_ = consumes<EBSrFlagCollection>(iConfig.getParameter<edm::InputTag>("labelEBSRFlags"));
107  labelEESR_ = consumes<EESrFlagCollection>(iConfig.getParameter<edm::InputTag>("labelEESRFlags"));
108  ecalmappingToken_ = esConsumes<EcalElectronicsMapping, EcalMappingRcd>();
109 
110  putToken_ = produces<FEDRawDataCollection>();
111 }
112 
113 //
114 // member functions
115 //
116 
117 // ------------ method called to for each event ------------
119  if (config_.debug_)
120  cout << "Enter in EcalDigiToRaw::produce ... " << endl;
121 
123  const EcalElectronicsMapping* TheMapping = ecalmapping.product();
124 
125  FEDRawDataCollection productRawData;
126 
128  int counter = iEvent.id().event();
129  params.counter_ = counter;
130  params.orbit_number_ = iEvent.orbitNumber();
131  params.bx_ = iEvent.bunchCrossing();
132  params.lv1_ = counter % (0x1 << 24);
133  params.runnumber_ = iEvent.id().run();
134 
135  BlockFormatter Headerblockformatter(config_, params);
136  TCCBlockFormatter TCCblockformatter(config_, params);
137  TowerBlockFormatter Towerblockformatter(config_, params);
138  SRBlockFormatter SRblockformatter(config_, params);
139 
140  Headerblockformatter.DigiToRaw(&productRawData);
141 
142  // --------- Now the Trigger Block part
143 
145 
146  Handle<EBSrFlagCollection> ebSrFlags;
147  Handle<EESrFlagCollection> eeSrFlags;
148 
149  if (config_.doTCC_) {
150  if (config_.debug_)
151  cout << "Creation of the TCC block " << endl;
152  // iEvent.getByType(ecalTrigPrim);
153  iEvent.getByToken(labelTT_, ecalTrigPrim);
154 
155  // loop on TP's and add one by one to the block
156  for (EcalTrigPrimDigiCollection::const_iterator it = ecalTrigPrim->begin(); it != ecalTrigPrim->end(); it++) {
157  const EcalTriggerPrimitiveDigi& trigprim = *it;
158  const EcalTrigTowerDetId& detid = it->id();
159 
160  if ((detid.subDet() == EcalBarrel) && (!config_.doBarrel_))
161  continue;
162  if ((detid.subDet() == EcalEndcap) && (!config_.doEndCap_))
163  continue;
164 
165  int iDCC = TheMapping->DCCid(detid);
166  int FEDid = FEDNumbering::MINECALFEDID + iDCC;
167 
168  FEDRawData& rawdata = productRawData.FEDData(FEDid);
169 
170  // adding the primitive to the block
171  TCCblockformatter.DigiToRaw(trigprim, rawdata, TheMapping);
172 
173  } // end loop on ecalTrigPrim
174 
175  } // endif doTCC
176 
177  if (config_.doSR_) {
178  if (config_.debug_)
179  cout << " Process the SR flags " << endl;
180 
181  if (config_.doBarrel_) {
182  // iEvent.getByType(ebSrFlags);
183  iEvent.getByToken(labelEBSR_, ebSrFlags);
184 
185  for (EBSrFlagCollection::const_iterator it = ebSrFlags->begin(); it != ebSrFlags->end(); it++) {
186  const EcalSrFlag& srflag = *it;
187  int flag = srflag.value();
188 
189  EcalTrigTowerDetId id = srflag.id();
190  int Dccid = TheMapping->DCCid(id);
191  int DCC_Channel = TheMapping->iTT(id);
192  int FEDid = FEDNumbering::MINECALFEDID + Dccid;
193  // if (Dccid == 10) cout << "Dcc " << Dccid << " DCC_Channel " << DCC_Channel << " flag " << flag << endl;
194  if (config_.debug_)
195  cout << "will process SRblockformatter_ for FEDid " << dec << FEDid << endl;
196  FEDRawData& rawdata = productRawData.FEDData(FEDid);
197  if (config_.debug_)
198  Headerblockformatter.print(rawdata);
199  SRblockformatter.DigiToRaw(Dccid, DCC_Channel, flag, rawdata);
200  }
201  } // end DoBarrel
202 
203  if (config_.doEndCap_) {
204  // iEvent.getByType(eeSrFlags);
205  iEvent.getByToken(labelEESR_, eeSrFlags);
206 
207  for (EESrFlagCollection::const_iterator it = eeSrFlags->begin(); it != eeSrFlags->end(); it++) {
208  const EcalSrFlag& srflag = *it;
209  int flag = srflag.value();
210  EcalScDetId id = srflag.id();
211  pair<int, int> ind = TheMapping->getDCCandSC(id);
212  int Dccid = ind.first;
213  int DCC_Channel = ind.second;
214 
215  int FEDid = FEDNumbering::MINECALFEDID + Dccid;
216  FEDRawData& rawdata = productRawData.FEDData(FEDid);
217  SRblockformatter.DigiToRaw(Dccid, DCC_Channel, flag, rawdata);
218  }
219  } // end doEndCap
220 
221  } // endif doSR
222 
223  // --------- Now the Tower Block part
224 
225  Handle<EBDigiCollection> ebDigis;
227 
228  if (config_.doTower_) {
229  if (config_.doBarrel_) {
230  if (config_.debug_)
231  cout << "Creation of the TowerBlock ... Barrel case " << endl;
232  iEvent.getByToken(EBDigiToken_, ebDigis);
233  for (EBDigiCollection::const_iterator it = ebDigis->begin(); it != ebDigis->end(); it++) {
234  const EBDataFrame& dataframe = *it;
235  const EBDetId& ebdetid = it->id();
236  int DCCid = TheMapping->DCCid(ebdetid);
237  int FEDid = FEDNumbering::MINECALFEDID + DCCid;
238  FEDRawData& rawdata = productRawData.FEDData(FEDid);
239  Towerblockformatter.DigiToRaw(dataframe, rawdata, TheMapping);
240  }
241  }
242 
243  if (config_.doEndCap_) {
244  if (config_.debug_)
245  cout << "Creation of the TowerBlock ... EndCap case " << endl;
246  iEvent.getByToken(EEDigiToken_, eeDigis);
247  for (EEDigiCollection::const_iterator it = eeDigis->begin(); it != eeDigis->end(); it++) {
248  const EEDataFrame& dataframe = *it;
249  const EEDetId& eedetid = it->id();
250  EcalElectronicsId elid = TheMapping->getElectronicsId(eedetid);
251  int DCCid = elid.dccId();
252  int FEDid = FEDNumbering::MINECALFEDID + DCCid;
253  FEDRawData& rawdata = productRawData.FEDData(FEDid);
254  Towerblockformatter.DigiToRaw(dataframe, rawdata, TheMapping);
255  }
256  }
257 
258  } // endif config_.doTower_
259 
260  // -------- Clean up things ...
261 
262  map<int, map<int, int> >& FEDorder = Towerblockformatter.GetFEDorder();
263 
264  Headerblockformatter.CleanUp(&productRawData, &FEDorder);
265 
266  /*
267  cout << "For FED 633 " << endl;
268  FEDRawData& rawdata = productRawData -> FEDData(633);
269  Headerblockformatter_ -> print(rawdata);
270 */
271 
272  // Headerblockformatter_ -> PrintSizes(productRawData.get());
273 
274  Towerblockformatter.EndEvent(&productRawData);
275 
276  iEvent.emplace(putToken_, std::move(productRawData));
277 
278  return;
279 }
280 
edm::EDGetTokenT< EESrFlagCollection > labelEESR_
std::pair< int, int > getDCCandSC(EcalScDetId id) const
void DigiToRaw(FEDRawDataCollection *productRawData)
edm::EDGetTokenT< EBDigiCollection > EBDigiToken_
EcalSubdetector subDet() const
get the subDetector associated to the Trigger Tower
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
int DCCid(const EBDetId &id) const
returns the DCC of an EBDetId
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > ecalmappingToken_
std::vector< T >::const_iterator const_iterator
virtual const DetId & id() const =0
unsigned int Word32
void print(FEDRawData &rawdata)
void DigiToRaw(int dccid, int dcc_channel, int flag, FEDRawData &rawdata)
T getUntrackedParameter(std::string const &, T const &) const
std::map< int, std::map< int, int > > & GetFEDorder()
char const * label
void CleanUp(FEDRawDataCollection *productRawData, std::map< int, std::map< int, int > > *FEDorder)
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
int value() const
Definition: EcalSrFlag.h:44
void DigiToRaw(const EcalTriggerPrimitiveDigi &trigprim, FEDRawData &rawdata, const EcalElectronicsMapping *TheMapping)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
const std::vector< int32_t > listDCCId_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
const_iterator end() const
const_iterator end() const
edm::EDPutTokenT< FEDRawDataCollection > putToken_
edm::EDGetTokenT< EcalTrigPrimDigiCollection > labelTT_
const_iterator begin() const
The iterator returned can not safely be used across threads.
edm::EDGetTokenT< EEDigiCollection > EEDigiToken_
void produce(edm::StreamID, edm::Event &e, const edm::EventSetup &c) const override
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
int iTT(const EcalTrigTowerDetId &id) const
returns the index of a Trigger Tower within its TCC.
long long Word64
HLT enums.
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
static std::atomic< unsigned int > counter
void EndEvent(FEDRawDataCollection *productRawData)
void DigiToRaw(const EBDataFrame &dataframe, FEDRawData &rawdata, const EcalElectronicsMapping *TheMapping)
edm::EDGetTokenT< EBSrFlagCollection > labelEBSR_
EcalDigiToRaw(const edm::ParameterSet &pset)
const BlockFormatter::Config config_
def move(src, dest)
Definition: eostools.py:511
static const int BXMAX