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