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