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 
20 // system include files
21 #include <memory>
22 #include <iostream>
23 #include <string>
24 
25 
26 // user include files
29 
32 
34 
39 
42 
44 
48 
49 
53 
56 
58  public:
60 
61  void produce(edm::StreamID, edm::Event& e, const edm::EventSetup& c) const override;
62 
63  typedef long long Word64;
64  typedef unsigned int Word32;
65 
66  static const int BXMAX = 2808;
67 
68 
69  private:
70 
71 
72  // ----------member data ---------------------------
73 
80 
81  const std::vector<int32_t> listDCCId_;
82 
83 
85 
86 };
87 
88 using namespace edm;
89 using namespace std;
90 
92  listDCCId_{iConfig.getUntrackedParameter< std::vector<int32_t> >("listDCCId")},
93  config_{
94  &listDCCId_,
95  iConfig.getUntrackedParameter<bool>("debug"),
96  iConfig.getUntrackedParameter<bool>("DoBarrel"),
97  iConfig.getUntrackedParameter<bool>("DoEndCap"),
98  iConfig.getUntrackedParameter<bool>("WriteTCCBlock"),
99  iConfig.getUntrackedParameter<bool>("WriteSRFlags"),
100  iConfig.getUntrackedParameter<bool>("WriteTowerBlock") }
101 {
102  auto label= iConfig.getParameter<string>("Label");
103  auto instanceNameEB = iConfig.getParameter<string>("InstanceEB");
104  auto instanceNameEE = iConfig.getParameter<string>("InstanceEE");
105 
106  edm::InputTag EBlabel = edm::InputTag(label,instanceNameEB);
107  edm::InputTag EElabel = edm::InputTag(label,instanceNameEE);
108 
109  EBDigiToken_ = consumes<EBDigiCollection>(EBlabel);
110  EEDigiToken_ = consumes<EEDigiCollection>(EElabel);
111 
112  labelTT_ = consumes<EcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("labelTT"));
113 
114  labelEBSR_ = consumes<EBSrFlagCollection>(iConfig.getParameter<edm::InputTag>("labelEBSRFlags"));
115  labelEESR_ = consumes<EESrFlagCollection>(iConfig.getParameter<edm::InputTag>("labelEESRFlags"));
116 
117  putToken_ = produces<FEDRawDataCollection>();
118 }
119 
120 
121 //
122 // member functions
123 //
124 
125 // ------------ method called to for each event ------------
126 void
128 {
129 
130  if (config_.debug_) cout << "Enter in EcalDigiToRaw::produce ... " << endl;
131 
133  iSetup.get< EcalMappingRcd >().get(ecalmapping);
134  const EcalElectronicsMapping* TheMapping = ecalmapping.product();
135 
136  FEDRawDataCollection productRawData;
137 
138  BlockFormatter::Params params;
139  int counter = iEvent.id().event();
140  params.counter_ = counter;
141  params.orbit_number_ = iEvent.orbitNumber();
142  params.bx_ = iEvent.bunchCrossing();
143  params.lv1_ = counter % (0x1<<24);
144  params.runnumber_ = iEvent.id().run();
145 
146  BlockFormatter Headerblockformatter(config_,params);
147  TCCBlockFormatter TCCblockformatter(config_,params);
148  TowerBlockFormatter Towerblockformatter(config_,params);
149  SRBlockFormatter SRblockformatter(config_,params);
150 
151 
152  Headerblockformatter.DigiToRaw(&productRawData);
153 
154 
155 // --------- Now the Trigger Block part
156 
158 
159  Handle<EBSrFlagCollection> ebSrFlags;
160  Handle<EESrFlagCollection> eeSrFlags;
161 
162 
163  if (config_.doTCC_) {
164 
165  if (config_.debug_) cout << "Creation of the TCC block " << endl;
166  // iEvent.getByType(ecalTrigPrim);
167  iEvent.getByToken(labelTT_, ecalTrigPrim);
168 
169  // loop on TP's and add one by one to the block
170  for (EcalTrigPrimDigiCollection::const_iterator it = ecalTrigPrim -> begin();
171  it != ecalTrigPrim -> end(); it++) {
172 
173  const EcalTriggerPrimitiveDigi& trigprim = *it;
174  const EcalTrigTowerDetId& detid = it -> id();
175 
176  if ( (detid.subDet() == EcalBarrel) && (! config_.doBarrel_) ) continue;
177  if ( (detid.subDet() == EcalEndcap) && (! config_.doEndCap_) ) continue;
178 
179  int iDCC = TheMapping -> DCCid(detid);
180  int FEDid = FEDNumbering::MINECALFEDID + iDCC;
181 
182  FEDRawData& rawdata = productRawData.FEDData(FEDid);
183 
184  // adding the primitive to the block
185  TCCblockformatter.DigiToRaw(trigprim, rawdata, TheMapping);
186 
187  } // end loop on ecalTrigPrim
188 
189  } // endif doTCC
190 
191 
192  if (config_.doSR_) {
193  if (config_.debug_) cout << " Process the SR flags " << endl;
194 
195  if (config_.doBarrel_) {
196 
197  // iEvent.getByType(ebSrFlags);
198  iEvent.getByToken(labelEBSR_, ebSrFlags);
199 
200  for (EBSrFlagCollection::const_iterator it = ebSrFlags -> begin();
201  it != ebSrFlags -> end(); it++) {
202  const EcalSrFlag& srflag = *it;
203  int flag = srflag.value();
204 
205  EcalTrigTowerDetId id = srflag.id();
206  int Dccid = TheMapping -> DCCid(id);
207  int DCC_Channel = TheMapping -> iTT(id);
208  int FEDid = FEDNumbering::MINECALFEDID + Dccid;
209  // if (Dccid == 10) cout << "Dcc " << Dccid << " DCC_Channel " << DCC_Channel << " flag " << flag << endl;
210  if (config_.debug_) cout << "will process SRblockformatter_ for FEDid " << dec << FEDid << endl;
211  FEDRawData& rawdata = productRawData.FEDData(FEDid);
212  if (config_.debug_) Headerblockformatter.print(rawdata);
213  SRblockformatter.DigiToRaw(Dccid,DCC_Channel,flag, rawdata);
214 
215  }
216  } // end DoBarrel
217 
218 
219  if (config_.doEndCap_) {
220  // iEvent.getByType(eeSrFlags);
221  iEvent.getByToken(labelEESR_, eeSrFlags);
222 
223  for (EESrFlagCollection::const_iterator it = eeSrFlags -> begin();
224  it != eeSrFlags -> end(); it++) {
225  const EcalSrFlag& srflag = *it;
226  int flag = srflag.value();
227  EcalScDetId id = srflag.id();
228  pair<int, int> ind = TheMapping -> getDCCandSC(id);
229  int Dccid = ind.first;
230  int DCC_Channel = ind.second;
231 
232  int FEDid = FEDNumbering::MINECALFEDID + Dccid;
233  FEDRawData& rawdata = productRawData.FEDData(FEDid);
234  SRblockformatter.DigiToRaw(Dccid,DCC_Channel,flag, rawdata);
235  }
236  } // end doEndCap
237 
238  } // endif doSR
239 
240 
241 // --------- Now the Tower Block part
242 
243  Handle<EBDigiCollection> ebDigis;
244  Handle<EEDigiCollection> eeDigis;
245 
246  if (config_.doTower_) {
247 
248  if (config_.doBarrel_) {
249  if (config_.debug_) cout << "Creation of the TowerBlock ... Barrel case " << endl;
250  iEvent.getByToken(EBDigiToken_,ebDigis);
251  for (EBDigiCollection::const_iterator it=ebDigis -> begin();
252  it != ebDigis->end(); it++) {
253  const EBDataFrame& dataframe = *it;
254  const EBDetId& ebdetid = it -> id();
255  int DCCid = TheMapping -> DCCid(ebdetid);
256  int FEDid = FEDNumbering::MINECALFEDID + DCCid ;
257  FEDRawData& rawdata = productRawData.FEDData(FEDid);
258  Towerblockformatter.DigiToRaw(dataframe, rawdata, TheMapping);
259  }
260 
261  }
262 
263  if (config_.doEndCap_) {
264  if (config_.debug_) cout << "Creation of the TowerBlock ... EndCap case " << endl;
265  iEvent.getByToken(EEDigiToken_,eeDigis);
266  for (EEDigiCollection::const_iterator it=eeDigis -> begin();
267  it != eeDigis->end(); it++) {
268  const EEDataFrame& dataframe = *it;
269  const EEDetId& eedetid = it -> id();
270  EcalElectronicsId elid = TheMapping -> getElectronicsId(eedetid);
271  int DCCid = elid.dccId() ;
272  int FEDid = FEDNumbering::MINECALFEDID + DCCid;
273  FEDRawData& rawdata = productRawData.FEDData(FEDid);
274  Towerblockformatter.DigiToRaw(dataframe, rawdata, TheMapping);
275  }
276  }
277 
278  } // endif config_.doTower_
279 
280 
281 
282 // -------- Clean up things ...
283 
284  map<int, map<int,int> >& FEDorder = Towerblockformatter.GetFEDorder();
285 
286  Headerblockformatter.CleanUp(&productRawData, &FEDorder);
287 
288 
289 /*
290  cout << "For FED 633 " << endl;
291  FEDRawData& rawdata = productRawData -> FEDData(633);
292  Headerblockformatter_ -> print(rawdata);
293 */
294 
295  // Headerblockformatter_ -> PrintSizes(productRawData.get());
296 
297 
298 
299  Towerblockformatter.EndEvent(&productRawData);
300 
301  iEvent.emplace(putToken_, std::move(productRawData));
302 
303 
304  return;
305 
306 }
307 
308 
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< EESrFlagCollection > labelEESR_
int value() const
Definition: EcalSrFlag.h:44
void DigiToRaw(FEDRawDataCollection *productRawData)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
edm::EDGetTokenT< EBDigiCollection > EBDigiToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
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
unsigned int Word32
std::map< int, std::map< int, int > > & GetFEDorder()
void print(FEDRawData &rawdata)
void DigiToRaw(int dccid, int dcc_channel, int flag, FEDRawData &rawdata)
char const * label
void CleanUp(FEDRawDataCollection *productRawData, std::map< int, std::map< int, int > > *FEDorder)
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)
#define end
Definition: vmac.h:39
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
edm::EDPutTokenT< FEDRawDataCollection > putToken_
edm::EDGetTokenT< EcalTrigPrimDigiCollection > labelTT_
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:413
edm::EDGetTokenT< EEDigiCollection > EEDigiToken_
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
#define begin
Definition: vmac.h:32
HLT enums.
static std::atomic< unsigned int > counter
T get() const
Definition: EventSetup.h:71
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
static const int BXMAX