CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
22 
23 // user include files
25 
27 
31 
32 
33 // #include "DataFormats/Common/interface/Handle.h"
37 
40 
41 
42 
43 
44 using namespace edm;
45 using namespace std;
46 
48 {
49 
50  doTCC_ = iConfig.getUntrackedParameter<bool>("WriteTCCBlock");
51  doSR_ = iConfig.getUntrackedParameter<bool>("WriteSRFlags");
52  doTower_ = iConfig.getUntrackedParameter<bool>("WriteTowerBlock");
53 
54  doBarrel_ = iConfig.getUntrackedParameter<bool>("DoBarrel");
55  doEndCap_ = iConfig.getUntrackedParameter<bool>("DoEndCap");
56 
57  listDCCId_ = iConfig.getUntrackedParameter< std::vector<int32_t> >("listDCCId");
58  label_= iConfig.getParameter<string>("Label");
59  instanceNameEB_ = iConfig.getParameter<string>("InstanceEB");
60  instanceNameEE_ = iConfig.getParameter<string>("InstanceEE");
61 
62  edm::InputTag EBlabel = edm::InputTag(label_,instanceNameEB_);
63  edm::InputTag EElabel = edm::InputTag(label_,instanceNameEE_);
64 
65  EBDigiToken_ = consumes<EBDigiCollection>(EBlabel);
66  EEDigiToken_ = consumes<EEDigiCollection>(EElabel);
67 
68  labelTT_ = consumes<EcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("labelTT"));
69 
70  labelEBSR_ = consumes<EBSrFlagCollection>(iConfig.getParameter<edm::InputTag>("labelEBSRFlags"));
71  labelEESR_ = consumes<EESrFlagCollection>(iConfig.getParameter<edm::InputTag>("labelEESRFlags"));
72 
73  counter_ = 0;
74  debug_ = iConfig.getUntrackedParameter<bool>("debug");
75 
76 
77  Towerblockformatter_ = new TowerBlockFormatter;
78  TCCblockformatter_ = new TCCBlockFormatter();
79  SRblockformatter_ = new SRBlockFormatter();
80  Headerblockformatter_= new BlockFormatter;
81 
82  produces<FEDRawDataCollection>();
83 
84 
85 }
86 
87 
89 {
90 
91  // do anything here that needs to be done at desctruction time
92  // (e.g. close files, deallocate resources etc.)
93 
94  delete Towerblockformatter_;
95  delete TCCblockformatter_;
96  delete SRblockformatter_;
97  delete Headerblockformatter_;
98 
99 }
100 
101 
102 //
103 // member functions
104 //
105 
106 // ------------ method called to for each event ------------
107 void
109 {
110 
111  if (debug_) cout << "Enter in EcalDigiToRaw::produce ... " << endl;
112 
114  iSetup.get< EcalMappingRcd >().get(ecalmapping);
115  const EcalElectronicsMapping* TheMapping = ecalmapping.product();
116 
117  Towerblockformatter_ -> StartEvent();
118  SRblockformatter_ -> StartEvent();
119 
120  runnumber_ = iEvent.id().run();
121 
122  // bx_ = (counter_ % BXMAX);
123  // orbit_number_ = counter_ / BXMAX;
124  // counter_ ++;
125 
126  counter_ = iEvent.id().event();
127  bx_ = iEvent.bunchCrossing();
128  orbit_number_ = iEvent.orbitNumber();
129 
130  lv1_ = counter_ % (0x1<<24);
131 
132  auto_ptr<FEDRawDataCollection> productRawData(new FEDRawDataCollection);
133 
134 
135  Headerblockformatter_ -> DigiToRaw(productRawData.get());
136 
137 
138 // --------- Now the Trigger Block part
139 
141 
142  Handle<EBSrFlagCollection> ebSrFlags;
143  Handle<EESrFlagCollection> eeSrFlags;
144 
145 
146  if (doTCC_) {
147 
148  if (debug_) cout << "Creation of the TCC block " << endl;
149  // iEvent.getByType(ecalTrigPrim);
150  iEvent.getByToken(labelTT_, ecalTrigPrim);
151 
152  // loop on TP's and add one by one to the block
153  for (EcalTrigPrimDigiCollection::const_iterator it = ecalTrigPrim -> begin();
154  it != ecalTrigPrim -> end(); it++) {
155 
156  const EcalTriggerPrimitiveDigi& trigprim = *it;
157  const EcalTrigTowerDetId& detid = it -> id();
158 
159  if ( (detid.subDet() == EcalBarrel) && (! doBarrel_) ) continue;
160  if ( (detid.subDet() == EcalEndcap) && (! doEndCap_) ) continue;
161 
162  int iDCC = TheMapping -> DCCid(detid);
163  int FEDid = FEDNumbering::MINECALFEDID + iDCC;
164 
165  FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
166 
167  // adding the primitive to the block
168  TCCblockformatter_ -> DigiToRaw(trigprim, rawdata, TheMapping);
169 
170  } // end loop on ecalTrigPrim
171 
172  } // endif doTCC
173 
174 
175  if (doSR_) {
176  if (debug_) cout << " Process the SR flags " << endl;
177 
178  if (doBarrel_) {
179 
180  // iEvent.getByType(ebSrFlags);
181  iEvent.getByToken(labelEBSR_, ebSrFlags);
182 
183  for (EBSrFlagCollection::const_iterator it = ebSrFlags -> begin();
184  it != ebSrFlags -> end(); it++) {
185  const EcalSrFlag& srflag = *it;
186  int flag = srflag.value();
187 
188  EcalTrigTowerDetId id = srflag.id();
189  int Dccid = TheMapping -> DCCid(id);
190  int DCC_Channel = TheMapping -> iTT(id);
191  int FEDid = FEDNumbering::MINECALFEDID + Dccid;
192  // if (Dccid == 10) cout << "Dcc " << Dccid << " DCC_Channel " << DCC_Channel << " flag " << flag << endl;
193  if (debug_) cout << "will process SRblockformatter_ for FEDid " << dec << FEDid << endl;
194  FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
195  if (debug_) Headerblockformatter_ -> print(rawdata);
196  SRblockformatter_ -> DigiToRaw(Dccid,DCC_Channel,flag, rawdata);
197 
198  }
199  } // end DoBarrel
200 
201 
202  if (doEndCap_) {
203  // iEvent.getByType(eeSrFlags);
204  iEvent.getByToken(labelEESR_, eeSrFlags);
205 
206  for (EESrFlagCollection::const_iterator it = eeSrFlags -> begin();
207  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.get() -> FEDData(FEDid);
217  SRblockformatter_ -> DigiToRaw(Dccid,DCC_Channel,flag, rawdata);
218  }
219  } // end doEndCap
220 
221  } // endif doSR
222 
223 
224 // --------- Now the Tower Block part
225 
226  Handle<EBDigiCollection> ebDigis;
227  Handle<EEDigiCollection> eeDigis;
228 
229  if (doTower_) {
230 
231  if (doBarrel_) {
232  if (debug_) cout << "Creation of the TowerBlock ... Barrel case " << endl;
233  iEvent.getByToken(EBDigiToken_,ebDigis);
234  for (EBDigiCollection::const_iterator it=ebDigis -> begin();
235  it != ebDigis->end(); it++) {
236  const EBDataFrame& dataframe = *it;
237  const EBDetId& ebdetid = it -> id();
238  int DCCid = TheMapping -> DCCid(ebdetid);
239  int FEDid = FEDNumbering::MINECALFEDID + DCCid ;
240  FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
241  Towerblockformatter_ -> DigiToRaw(dataframe, rawdata, TheMapping);
242  }
243 
244  }
245 
246  if (doEndCap_) {
247  if (debug_) cout << "Creation of the TowerBlock ... EndCap case " << endl;
248  iEvent.getByToken(EEDigiToken_,eeDigis);
249  for (EEDigiCollection::const_iterator it=eeDigis -> begin();
250  it != eeDigis->end(); it++) {
251  const EEDataFrame& dataframe = *it;
252  const EEDetId& eedetid = it -> id();
253  EcalElectronicsId elid = TheMapping -> getElectronicsId(eedetid);
254  int DCCid = elid.dccId() ;
255  int FEDid = FEDNumbering::MINECALFEDID + DCCid;
256  FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
257  Towerblockformatter_ -> DigiToRaw(dataframe, rawdata, TheMapping);
258  }
259  }
260 
261  } // endif doTower_
262 
263 
264 
265 // -------- Clean up things ...
266 
267  map<int, map<int,int> >* FEDorder = Towerblockformatter_ -> GetFEDorder();
268 
269  Headerblockformatter_ -> CleanUp(productRawData.get(), FEDorder);
270 
271 
272 /*
273  cout << "For FED 633 " << endl;
274  FEDRawData& rawdata = productRawData -> FEDData(633);
275  Headerblockformatter_ -> print(rawdata);
276 */
277 
278  // Headerblockformatter_ -> PrintSizes(productRawData.get());
279 
280 
281 
282  Towerblockformatter_ -> EndEvent(productRawData.get());
283 
284  iEvent.put(productRawData);
285 
286 
287  return;
288 
289 }
290 
291 
292 // ------------ method called once each job just before starting event loop ------------
293 void
295 {
296  Headerblockformatter_ -> SetParam(this);
297  Towerblockformatter_ -> SetParam(this);
298  TCCblockformatter_ -> SetParam(this);
299  SRblockformatter_ -> SetParam(this);
300 }
301 
302 // ------------ method called once each job just after ending the event loop ------------
303 void
305 }
306 
307 
308 
309 
310 
311 
312 
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int value() const
Definition: EcalSrFlag.h:44
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
std::vector< EcalTriggerPrimitiveDigi >::const_iterator const_iterator
int bunchCrossing() const
Definition: EventBase.h:66
virtual const DetId & id() const =0
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
#define end
Definition: vmac.h:37
int orbitNumber() const
Definition: EventBase.h:67
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
void produce(edm::Event &e, const edm::EventSetup &c)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
virtual ~EcalDigiToRaw()
EcalSubdetector subDet() const
get the subDetector associated to the Trigger Tower
edm::EventID id() const
Definition: EventBase.h:60
#define begin
Definition: vmac.h:30
tuple cout
Definition: gather_cfg.py:121
dictionary rawdata
Definition: lumiPlot.py:393
EcalDigiToRaw(const edm::ParameterSet &pset)