CMS 3D CMS Logo

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