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