CMS 3D CMS Logo

EcalGetLaserData.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Ecal
4 // Class: GetLaserData
5 //
11 //
12 // Original Author: Vladlen Timciuc
13 // Created: Wed Jul 4 13:55:56 CEST 2007
14 // $Id: EcalGetLaserData.cc,v 1.5 2009/12/21 14:22:03 ebecheva Exp $
15 //
16 //
17 
18 // system include files
19 #include <memory>
20 
21 // user include files
31 
33 
38 
42 
45 
47 
48 //
49 // constants, enums and typedefs
50 //
51 
52 //
53 // static data member definitions
54 //
55 
56 //
57 // constructors and destructor
58 //
60  : // m_timetype(iConfig.getParameter<std::string>("timetype")),
61  m_cacheIDs(),
62  m_records(),
63  ecalLaserAPDPNRatiosToken_(esConsumes()),
64  ecalLaserAPDPNRatiosRefToken_(esConsumes()),
65  ecalLaserAlphasToken_(esConsumes()) {
66  //m_firstRun=(unsigned long long)atoi( iConfig.getParameter<std::string>("firstRun").c_str());
67  //m_lastRun=(unsigned long long)atoi( iConfig.getParameter<std::string>("lastRun").c_str());
68  std::string container;
70  typedef std::vector<edm::ParameterSet> Parameters;
71  Parameters toGet = iConfig.getParameter<Parameters>("toGet");
72  for (const auto& iparam : toGet) {
73  container = iparam.getParameter<std::string>("container");
74  record = iparam.getParameter<std::string>("record");
75  m_cacheIDs.emplace(container, 0);
76  m_records.emplace(container, record);
77 
78  } //now do what ever initialization is needed
79 }
80 
82  // do anything here that needs to be done at desctruction time
83  // (e.g. close files, deallocate resources etc.)
84 }
85 
86 //
87 // member functions
88 //
89 
90 // ------------ method called to for each event ------------
91 void EcalGetLaserData::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
92  using namespace edm;
93 
94  // loop on offline DB conditions to be transferred as from config file
95  for (const auto& irec : m_records) {
96  const std::string& container = irec.first;
97  //record = irec.second;
98 
99  if (container == "EcalLaserAPDPNRatios") {
100  // get from offline DB the last valid laser set
101  const EcalLaserAPDPNRatios* laserapdpnrRatios = &evtSetup.getData(ecalLaserAPDPNRatiosToken_);
102  // this is the offline object
105 
106  const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& laserRatiosMap = laserapdpnrRatios->getLaserMap();
107  const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& laserTimeMap = laserapdpnrRatios->getTimeMap();
108 
109  // loop through ecal barrel
110  for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
111  if (iEta == 0)
112  continue;
113  for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
114  EBDetId ebdetid(iEta, iPhi);
115  int hi = ebdetid.hashedIndex();
116 
117  if (hi < static_cast<int>(laserRatiosMap.size())) {
118  apdpnpair = laserRatiosMap[hi];
119  edm::LogInfo("EcalGetLaserData") << "A sample value of APDPN pair EB : " << hi << " : " << apdpnpair.p1
120  << " , " << apdpnpair.p2 << std::endl;
121  } else {
122  edm::LogError("EcalGetLaserData") << "error with laserRatiosMap!" << std::endl;
123  }
124  }
125  }
126 
127  // loop through ecal endcap
128  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
129  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
130  if (!EEDetId::validDetId(iX, iY, 1))
131  continue;
132 
133  EEDetId eedetidpos(iX, iY, 1);
134  int hi = eedetidpos.hashedIndex();
135 
136  if (hi < static_cast<int>(laserRatiosMap.size())) {
137  apdpnpair = laserRatiosMap[hi];
138  edm::LogInfo("EcalGetLaserData") << "A sample value of APDPN pair EE+ : " << hi << " : " << apdpnpair.p1
139  << " , " << apdpnpair.p2 << std::endl;
140  } else {
141  edm::LogError("EcalGetLaserData") << "error with laserRatiosMap!" << std::endl;
142  }
143 
144  if (!EEDetId::validDetId(iX, iY, -1))
145  continue;
146  EEDetId eedetidneg(iX, iY, 1);
147  hi = eedetidneg.hashedIndex();
148 
149  if (hi < static_cast<int>(laserRatiosMap.size())) {
150  apdpnpair = laserRatiosMap[hi];
151  edm::LogInfo("EcalGetLaserData") << "A sample value of APDPN pair EE- : " << hi << " : " << apdpnpair.p1
152  << " , " << apdpnpair.p2 << std::endl;
153  } else {
154  edm::LogError("EcalGetLaserData") << "error with laserRatiosMap!" << std::endl;
155  }
156  }
157  }
158 
159  for (int i = 0; i < 92; i++) {
160  timestamp = laserTimeMap[i];
161  edm::LogInfo("EcalGetLaserData") << "A value of timestamp pair : " << i << " " << timestamp.t1.value() << " , "
162  << timestamp.t2.value() << std::endl;
163  }
164 
165  edm::LogInfo("EcalGetLaserData") << ".. just retrieved the last valid record from DB " << std::endl;
166 
167  } else if (container == "EcalLaserAPDPNRatiosRef") {
168  // get from offline DB the last valid laser set
169  EcalLaserAPDPNref apdpnref;
170  const EcalLaserAPDPNRatiosRefMap& laserRefMap = (&evtSetup.getData(ecalLaserAPDPNRatiosRefToken_))->getMap();
171 
172  // first barrel
173  for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
174  if (iEta == 0)
175  continue;
176  for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
177  EBDetId ebdetid(iEta, iPhi);
178  int hi = ebdetid.hashedIndex();
179 
180  if (hi < static_cast<int>(laserRefMap.size())) {
181  apdpnref = laserRefMap[hi];
182  edm::LogInfo("EcalGetLaserData")
183  << "A sample value of APDPN Reference value EB : " << hi << " : " << apdpnref << std::endl;
184  } else {
185  edm::LogError("EcalGetLaserData") << "error with laserRefMap!" << std::endl;
186  }
187  }
188  }
189 
190  // now for endcap
191  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
192  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
193  if (!EEDetId::validDetId(iX, iY, 1))
194  continue;
195 
196  EEDetId eedetidpos(iX, iY, 1);
197  int hi = eedetidpos.hashedIndex();
198 
199  if (hi < static_cast<int>(laserRefMap.size())) {
200  apdpnref = laserRefMap[hi];
201  edm::LogInfo("EcalGetLaserData")
202  << "A sample value of APDPN Reference value EE+ : " << hi << " : " << apdpnref << std::endl;
203 
204  } else {
205  edm::LogError("EcalGetLaserData") << "error with laserRefMap!" << std::endl;
206  }
207 
208  if (!EEDetId::validDetId(iX, iY, -1))
209  continue;
210  EEDetId eedetidneg(iX, iY, -1);
211  hi = eedetidneg.hashedIndex();
212 
213  if (hi < static_cast<int>(laserRefMap.size())) {
214  apdpnref = laserRefMap[hi];
215  edm::LogInfo("EcalGetLaserData")
216  << "A sample value of APDPN Reference value EE- : " << hi << " : " << apdpnref << std::endl;
217  } else {
218  edm::LogError("EcalGetLaserData") << "error with laserRefMap!" << std::endl;
219  }
220  }
221  }
222 
223  edm::LogInfo("EcalGetLaserData") << "... just retrieved the last valid record from DB " << std::endl;
224 
225  } else if (container == "EcalLaserAlphas") {
226  // get from offline DB the last valid laser set
227  // this is the offline object
229  const EcalLaserAlphaMap& laserAlphaMap = (&evtSetup.getData(ecalLaserAlphasToken_))->getMap(); // map of apdpns
230 
231  // first barrel
232  for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
233  if (iEta == 0)
234  continue;
235  for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
236  EBDetId ebdetid(iEta, iPhi);
237  int hi = ebdetid.hashedIndex();
238 
239  if (hi < static_cast<int>(laserAlphaMap.size())) {
240  alpha = laserAlphaMap[hi];
241  edm::LogInfo("EcalGetLaserData")
242  << " A sample value of Alpha value EB : " << hi << " : " << alpha << std::endl;
243  } else {
244  edm::LogError("EcalGetLaserData") << "error with laserAlphaMap!" << std::endl;
245  }
246  }
247  }
248 
249  // next endcap
250  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
251  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
252  if (!EEDetId::validDetId(iX, iY, 1))
253  continue;
254 
255  EEDetId eedetidpos(iX, iY, 1);
256  int hi = eedetidpos.hashedIndex();
257 
258  if (hi < static_cast<int>(laserAlphaMap.size())) {
259  alpha = laserAlphaMap[hi];
260  edm::LogInfo("EcalGetLaserData")
261  << " A sample value of Alpha value EE+ : " << hi << " : " << alpha << std::endl;
262  } else {
263  edm::LogError("EcalGetLaserData") << "error with laserAlphaMap!" << std::endl;
264  }
265 
266  if (!EEDetId::validDetId(iX, iY, -1))
267  continue;
268  EEDetId eedetidneg(iX, iY, -1);
269  hi = eedetidneg.hashedIndex();
270 
271  if (hi < static_cast<int>(laserAlphaMap.size())) {
272  alpha = laserAlphaMap[hi];
273  edm::LogInfo("EcalGetLaserData")
274  << " A sample value of Alpha value EE- : " << hi << " : " << alpha << std::endl;
275  } else {
276  edm::LogError("EcalGetLaserData") << "error with laserAlphaMap!" << std::endl;
277  }
278  }
279  }
280 
281  edm::LogInfo("EcalGetLaserData") << "... just retrieved the last valid record from DB " << std::endl;
282 
283  } else {
284  edm::LogError("EcalGetLaserData") << "Cannot retrieve for container: " << container << std::endl;
285  }
286  }
287 }
288 
289 // ------------ method called once each job just before starting event loop ------------
291 
292 // ------------ method called once each job just after ending the event loop ------------
const EcalLaserAPDPNRatiosMap & getLaserMap() const
~EcalGetLaserData() override
float EcalLaserAlpha
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
float alpha
Definition: AMPTWrapper.h:105
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static const int MIN_IPHI
Definition: EBDetId.h:135
std::map< std::string, std::string > m_records
EcalGetLaserData(const edm::ParameterSet &iConfig)
void endJob() override
Log< level::Error, false > LogError
static const int IX_MIN
Definition: EEDetId.h:290
float EcalLaserAPDPNref
static const int IY_MIN
Definition: EEDetId.h:294
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
vector< ParameterSet > Parameters
Definition: EPCuts.h:4
const EcalLaserTimeStampMap & getTimeMap() const
bool getData(T &iHolder) const
Definition: EventSetup.h:122
std::map< std::string, unsigned long long > m_cacheIDs
void beginJob() override
static const int IX_MAX
Definition: EEDetId.h:298
Log< level::Info, false > LogInfo
edm::ESGetToken< EcalLaserAlphas, EcalLaserAlphasRcd > ecalLaserAlphasToken_
static const int MAX_IPHI
Definition: EBDetId.h:137
std::vector< EcalLaserTimeStamp > EcalLaserTimeStampMap
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int MAX_IETA
Definition: EBDetId.h:136
HLT enums.
edm::ESGetToken< EcalLaserAPDPNRatios, EcalLaserAPDPNRatiosRcd > ecalLaserAPDPNRatiosToken_
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:82
static const int IY_MAX
Definition: EEDetId.h:302
int hashedIndex() const
Definition: EEDetId.h:183
edm::ESGetToken< EcalLaserAPDPNRatiosRef, EcalLaserAPDPNRatiosRefRcd > ecalLaserAPDPNRatiosRefToken_