CMS 3D CMS Logo

EcalLaserHandler.cc
Go to the documentation of this file.
8 
9 #include <iostream>
10 #include <iomanip>
11 #include <sstream>
12 
14  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalLaserHandler")) {
15  std::cout << "EcalLaser Source handler constructor\n" << std::endl;
16 
17  m_sequences = 1;
18  m_fake = true;
19 
20  m_sid = ps.getParameter<std::string>("OnlineDBSID");
21  m_user = ps.getParameter<std::string>("OnlineDBUser");
22  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
23  m_debug = ps.getParameter<bool>("debug");
24  m_fake = ps.getParameter<bool>("fake");
25  m_sequences = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("sequences").c_str()));
26  m_maxtime = ps.getParameter<std::string>("maxtime");
27  std::cout << "Starting O2O process on DB: " << m_sid << " User: " << m_user << std::endl;
28  if (m_fake) {
29  std::cout << "*******************************************" << std::endl;
30  std::cout << "This is a fake run. No change to offline DB" << std::endl;
31  std::cout << "*******************************************" << std::endl;
32  }
33 }
34 
36  // do nothing
37 }
38 
39 double popcon::EcalLaserHandler::diff(float a, float b) { return std::abs(b - a) / a; }
40 
43  int hashedIndex,
44  const std::string &reason) {
45  std::cout << "===== " << reason << " =====" << std::endl;
46  if (hashedIndex < 0) {
47  EEDetId ee;
48  std::cout << "Triplets for " << ee.unhashIndex(-hashedIndex) << " bad: [" << old.p1 << ", " << old.p2 << ", "
49  << old.p3 << "] ==> [" << current.p1 << ", " << current.p2 << ", " << current.p3 << "]" << std::endl;
50  } else {
51  EBDetId eb;
52  std::cout << "Triplets for " << eb.unhashIndex(hashedIndex) << " bad: [" << old.p1 << ", " << old.p2 << ", "
53  << old.p3 << "] ==> [" << current.p1 << ", " << current.p2 << ", " << current.p3 << "]" << std::endl;
54  }
55 }
56 
59  int hashedIndex) {
60  bool ret = true;
61  if ((current.p1 < 0) || (current.p2 < 0) || (current.p3 < 0)) {
62  ret = false;
63  notifyProblems(old, current, hashedIndex, "Negative values");
64  } else if ((current.p1 > 10) || (current.p2 > 10) || (current.p3 > 10)) {
65  ret = false;
66  notifyProblems(old, current, hashedIndex, "Values too large");
67  } else if (((diff(old.p1, current.p1) > 0.2) && (old.p1 != 0) && (old.p1 != 1)) ||
68  ((diff(old.p2, current.p2) > 0.2) && (old.p2 != 0) && (old.p1 != 2)) ||
69  ((diff(old.p3, current.p3) > 0.2) && (old.p3 != 0) && (old.p1 != 3))) {
70  ret = false;
71  notifyProblems(old, current, hashedIndex, "Difference w.r.t. previous too large");
72  }
73  return ret;
74 }
75 
77  const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap &apdpns_popcon) {
78  bool ret = true;
79  for (int hashedIndex = 0; hashedIndex < 61200; hashedIndex++) {
82  ret = checkAPDPN(old, current, hashedIndex);
83  }
84  for (int hashedIndex = 0; hashedIndex < 14648; hashedIndex++) {
87  ret = checkAPDPN(old, current, -hashedIndex);
88  }
89  return ret;
90 }
91 
93  int c = 0;
96  EBDetId eb;
97  try {
98  EcalCondDBInterface *econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
99  while (i != e) {
100  if (c % 1000 == 0) {
101  std::cout << std::setw(5) << c << ": " << eb.unhashIndex(c) << " "
102  << econn
103  ->getEcalLogicID("EB_crystal_angle",
104  eb.unhashIndex(c).ieta(),
105  eb.unhashIndex(c).iphi(),
107  "EB_crystal_number")
108  .getLogicID()
109  << " " << std::setiosflags(std::ios::fixed) << std::setprecision(9) << i->p1 << " " << i->p2 << " "
110  << i->p3 << std::endl;
111  }
112  i++;
113  c++;
114  }
115  delete econn;
116  } catch (std::runtime_error &e) {
117  std::cerr << e.what() << std::endl;
118  delete econn;
119  throw cms::Exception("OMDS not available");
120  }
121 }
122 
124  int c = 0;
127  EEDetId ee;
128  try {
129  EcalCondDBInterface *econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
130  while (i != e) {
131  if (c % 1000 == 0) {
132  std::cout << std::setw(5) << c << ": " << ee.unhashIndex(c) << " "
133  << econn
134  ->getEcalLogicID("EE_crystal_number",
135  ee.unhashIndex(c).zside(),
136  ee.unhashIndex(c).ix(),
137  ee.unhashIndex(c).iy(),
138  "EE_crystal_number")
139  .getLogicID()
140  << " " << std::setiosflags(std::ios::fixed) << std::setprecision(9) << i->p1 << " " << i->p2 << " "
141  << i->p3 << std::endl;
142  }
143  i++;
144  c++;
145  }
146  delete econn;
147  } catch (std::runtime_error &e) {
148  std::cerr << e.what() << std::endl;
149  delete econn;
150  throw cms::Exception("OMDS not available");
151  }
152 }
153 
155  std::cerr << "------- " << m_name << " ---> getNewObjects" << std::endl;
156 
157  std::cout << "------- Ecal -> getNewObjects\n";
158 
159  unsigned long long max_since = 1;
160  Ref payload = lastPayload();
161 
162  // here popcon tells us which is the last since of the last object in the
163  // offline DB
164  max_since = tagInfo().lastInterval.since;
165  // Tm max_since_tm((max_since >> 32)*1000000);
166  Tm max_since_tm(max_since);
167  // get the last object in the orcoff
168  edm::Timestamp t_min = edm::Timestamp(18446744073709551615ULL);
169 
170  const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap &laserRatiosMap = payload->getLaserMap();
171  std::cout << "payload->getLaserMap(): OK " << std::endl;
172  std::cout << "Its size is " << laserRatiosMap.size() << std::endl;
173  const EcalLaserAPDPNRatios::EcalLaserTimeStampMap &laserTimeMap = payload->getTimeMap();
174  std::cout << "payload->getTimeMap(): OK " << std::endl;
175  std::cout << "Last Object in Offline DB has SINCE = " << max_since << " -> " << max_since_tm.cmsNanoSeconds() << " ("
176  << max_since_tm << ")"
177  << " and SIZE = " << tagInfo().size << std::endl;
178  // loop through light modules and determine the minimum date among the
179  // available channels
180  if (m_debug) {
181  dumpBarrelPayload(laserRatiosMap);
182  dumpEndcapPayload(laserRatiosMap);
183  }
184  for (int i = 0; i < 92; i++) {
186  if (t_min > timestamp.t1) {
187  t_min = timestamp.t1;
188  }
189  }
190 
191  std::cout << "WOW: we just retrieved the last valid record from DB " << std::endl;
192  //std::cout <<"Its tmin is "<< Tm((t_min.value() >> 32)*1000000)
193  std::cout << "Its tmin is " << Tm(t_min.value()) << std::endl;
194 
195  // connect to the database
196  try {
197  std::cout << "Making connection..." << std::flush;
198  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
199  std::cout << "Done." << std::endl;
200  } catch (std::runtime_error &e) {
201  std::cout << " connection parameters " << m_sid << "/" << m_user;
202  if (m_debug) {
203  std::cout << "/" << m_pass << std::endl;
204  } else {
205  std::cout << "/**********" << std::endl;
206  }
207  std::cerr << e.what() << std::endl;
208  throw cms::Exception("OMDS not available");
209  }
210 
211  // retrieve the lists of logic_ids, to build the detids
212  std::vector<EcalLogicID> crystals_EB = econn->getEcalLogicIDSetOrdered(
213  "EB_crystal_angle", -85, 85, 1, 360, EcalLogicID::NULLID, EcalLogicID::NULLID, "EB_crystal_number", 4);
214  std::vector<EcalLogicID> crystals_EE =
215  econn->getEcalLogicIDSetOrdered("EE_crystal_number", -1, 1, 1, 100, 1, 100, "EE_crystal_number", 4);
216 
217  std::vector<EcalLogicID>::const_iterator ieb = crystals_EB.begin();
218  std::vector<EcalLogicID>::const_iterator eeb = crystals_EB.end();
219 
220  std::cout << "Got list of " << crystals_EB.size() << " crystals in EB" << std::endl;
221  std::cout << "Got list of " << crystals_EE.size() << " crystals in EE" << std::endl;
222  // loop through barrel
223  int count = 0;
224  // prepare a map to associate EB logic id's to detids
225  std::map<int, int> detids;
226  while (ieb != eeb) {
227  int iEta = ieb->getID1();
228  int iPhi = ieb->getID2();
229  count++;
230  EBDetId ebdetid(iEta, iPhi);
231  // unsigned int hieb = ebdetid.hashedIndex();
232  detids[ieb->getLogicID()] = ebdetid;
233  ieb++;
234  }
235  std::cout << "Validated " << count << " logic ID's for EB" << std::endl;
236 
237  // do the same for EE
238 
239  std::vector<EcalLogicID>::const_iterator iee = crystals_EE.begin();
240  std::vector<EcalLogicID>::const_iterator eee = crystals_EE.end();
241 
242  count = 0;
243  while (iee != eee) {
244  int iSide = iee->getID1();
245  int iX = iee->getID2();
246  int iY = iee->getID3();
247  EEDetId eedetidpos(iX, iY, iSide);
248  // int hi = eedetidpos.hashedIndex();
249  detids[iee->getLogicID()] = eedetidpos;
250  count++;
251  iee++;
252  }
253  std::cout << "Validated " << count << " logic ID's for EE" << std::endl;
254 
255  // get association between ecal logic id and LMR
256  std::map<int, int> logicId2Lmr = econn->getEcalLogicID2LmrMap();
257 
258  std::cout << "Retrieving corrections from ONLINE DB ... " << std::endl;
259 
261  if (m_debug) {
262  data.debug();
263  }
264  // get all data in the database taken after the last available time in ORCOFF
265  // we associate another map, whose key is the crystal ID and whose value is a
266  // sextuple (p1, p2, p3, t1, t2, t3)
267  Tm tmax;
268  if (m_maxtime[0] == '-') {
269  // this is a time relative to now
270  tmax.setToCurrentLocalTime();
271  if (m_debug) {
272  std::cout << "Subtracting " << m_maxtime.substr(1) << " hours "
273  << "to " << tmax.str() << std::endl;
274  std::cout << "tmax was " << tmax.microsTime() << " ns" << std::endl;
275  }
276  tmax -= atoi(m_maxtime.substr(1).c_str()) * 3600; //
277  if (m_debug) {
278  std::cout << "tmax is " << tmax.microsTime() << " ns" << std::endl;
279  }
280  } else {
281  if (m_debug) {
282  std::cout << "Setting t_max to " << m_maxtime << std::endl;
283  }
284  tmax.setToString(m_maxtime);
285  }
286  // Tm tmin = Tm((t_min.value() >> 32)*1000000);
287  Tm tmin = Tm(t_min.value());
288  /*
289  Tm strunz;
290  strunz.setToString("2011-04-11 20:50:08");
291  if (tmin < strunz) {
292  tmin = strunz;
293  }
294  */
295 
296  if (m_debug) {
297  std::cout << "Tmin: " << tmin << std::endl;
298  std::cout << "Tmax: " << tmax << std::endl;
299  }
300 
301  std::map<int, std::map<int, LMFSextuple> > d = data.getCorrections(tmin, tmax, m_sequences);
302  // sice must be equal to the number of different SEQ_ID's found
303  std::cout << "Data organized into " << d.size() << " sequences" << std::endl;
304  // iterate over sequences
305  std::map<int, std::map<int, LMFSextuple> >::const_iterator iseq = d.begin();
306  std::map<int, std::map<int, LMFSextuple> >::const_iterator eseq = d.end();
307  std::cout << "===== Looping on Sequences" << std::endl;
308  while (iseq != eseq) {
309  std::cout << "==== SEQ_ID: " << iseq->first << " contains " << iseq->second.size() << " crystals" << std::endl
310  << std::flush;
311  // iterate over crystals, but skip those sequences with wrong number of crystals
312  if (iseq->second.size() == (61200 + 14648)) {
313  std::map<int, LMFSextuple>::const_iterator is = iseq->second.begin();
314  std::map<int, LMFSextuple>::const_iterator es = iseq->second.end();
315  EcalLaserAPDPNRatios *apdpns_popcon = new EcalLaserAPDPNRatios();
316  Time_t t_last = 18446744073709551615ULL;
317  while (is != es) {
319  apdpnpair_temp.p1 = is->second.p[0];
320  apdpnpair_temp.p2 = is->second.p[1];
321  apdpnpair_temp.p3 = is->second.p[2];
323  timestamp_temp.t1 = edm::Timestamp(is->second.t[0].cmsNanoSeconds());
324  timestamp_temp.t2 = edm::Timestamp(is->second.t[1].cmsNanoSeconds());
325  timestamp_temp.t3 = edm::Timestamp(is->second.t[2].cmsNanoSeconds());
326  apdpns_popcon->setValue(detids[is->first], apdpnpair_temp);
327  if (logicId2Lmr.find(is->first) != logicId2Lmr.end()) {
328  int hashedIndex = logicId2Lmr[is->first] - 1;
329  if ((hashedIndex >= 0) && (hashedIndex <= 91)) {
330  apdpns_popcon->setTime(hashedIndex, timestamp_temp);
331  if (t_last > timestamp_temp.t1.value()) {
332  t_last = timestamp_temp.t1.value();
333  }
334  } else {
335  std::stringstream ss;
336  ss << "LOGIC_ID: " << is->first << " LMR: " << hashedIndex + 1 << " Out of range";
337  throw(std::runtime_error("[EcalLaserHandler::getNewObjects]" + ss.str()));
338  }
339  } else {
340  std::stringstream ss;
341  ss << "LOGIC_ID: " << is->first << " Cannot determine LMR";
342  throw(std::runtime_error("[EcalLaserHandler::getNewObjects]" + ss.str()));
343  }
344  is++;
345  }
346  if (m_fake) {
347  delete apdpns_popcon;
348  }
349  if ((!iseq->second.empty()) && (!m_fake)) {
350  m_to_transfer.push_back(std::make_pair(apdpns_popcon, Tm(t_last).cmsNanoSeconds()));
351  }
352  } else {
353  // Here we should put a warning
354  }
355  iseq++;
356  }
357  std::cout << "==== END OF LOOP ON SEQUENCES" << std::endl << std::flush;
358  delete econn;
359  std::cout << "Ecal -> end of getNewObjects -----------\n";
360 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
change_name.diff
diff
Definition: change_name.py:13
EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p1
float p1
Definition: EcalLaserAPDPNRatios.h:18
EcalCondDBInterface
Definition: EcalCondDBInterface.h:37
alignBH_cfg.fixed
fixed
Definition: alignBH_cfg.py:54
popcon::EcalLaserHandler::diff
double diff(float x, float old_x)
Definition: EcalLaserHandler.cc:39
EBDetId::ieta
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
mps_fire.i
i
Definition: mps_fire.py:428
EcalCondObjectContainer::endcapItems
const Items & endcapItems() const
Definition: EcalCondObjectContainer.h:32
LMFCorrCoefDat
Definition: LMFCorrCoefDat.h:16
popcon::EcalLaserHandler::m_fake
bool m_fake
Definition: EcalLaserHandler.h:82
muonTiming_cfi.tmin
tmin
Definition: muonTiming_cfi.py:24
popcon::EcalLaserHandler::m_pass
std::string m_pass
Definition: EcalLaserHandler.h:78
EBDetId
Definition: EBDetId.h:17
popcon::EcalLaserHandler::m_debug
bool m_debug
Definition: EcalLaserHandler.h:81
EcalLaserAPDPNRatios::EcalLaserTimeStamp::t3
edm::Timestamp t3
Definition: EcalLaserAPDPNRatios.h:28
EEDetId::unhashIndex
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
gather_cfg.cout
cout
Definition: gather_cfg.py:144
popcon::EcalLaserHandler::EcalLaserHandler
EcalLaserHandler(edm::ParameterSet const &)
Definition: EcalLaserHandler.cc:13
EBDetId::unhashIndex
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
test_db_connect.econn
econn
Definition: test_db_connect.py:10
popcon::PopConSourceHandler< EcalLaserAPDPNRatios >::Time_t
cond::Time_t Time_t
Definition: PopConSourceHandler.h:34
edm::Timestamp::value
TimeValue_t value() const
Definition: Timestamp.h:45
EcalCondObjectContainer::size
size_t size() const
Definition: EcalCondObjectContainer.h:82
EcalCondObjectContainer::barrel
const Item & barrel(size_t hashedIndex) const
Definition: EcalCondObjectContainer.h:34
EcalCondObjectContainer::endcap
const Item & endcap(size_t hashedIndex) const
Definition: EcalCondObjectContainer.h:36
popcon::EcalLaserHandler::m_user
std::string m_user
Definition: EcalLaserHandler.h:77
EcalCondObjectContainer< EcalLaserAPDPNpair >
EEDetId::ix
int ix() const
Definition: EEDetId.h:77
EcalLaserHandler.h
tmax
static const double tmax[3]
Definition: CastorTimeSlew.cc:7
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
cond::timestamp
Definition: Time.h:19
popcon::EcalLaserHandler::dumpEndcapPayload
void dumpEndcapPayload(EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap const &laserMap)
Definition: EcalLaserHandler.cc:123
popcon::EcalLaserHandler::getNewObjects
void getNewObjects() override
Definition: EcalLaserHandler.cc:154
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
popcon::EcalLaserHandler::~EcalLaserHandler
~EcalLaserHandler() override
Definition: EcalLaserHandler.cc:35
popcon::EcalLaserHandler::checkAPDPNs
bool checkAPDPNs(const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap &laserMap, const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap &apdpns_popcon)
Definition: EcalLaserHandler.cc:76
jets_cff.payload
payload
Definition: jets_cff.py:32
EEDetId::zside
int zside() const
Definition: EEDetId.h:71
b
double b
Definition: hdecay.h:118
EcalCondObjectContainer::barrelItems
const Items & barrelItems() const
Definition: EcalCondObjectContainer.h:30
Tm
Definition: Tm.h:13
EEDetId
Definition: EEDetId.h:14
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
popcon::EcalLaserHandler::m_sequences
unsigned long m_sequences
Definition: EcalLaserHandler.h:75
Time.h
EcalLaserAPDPNRatios::EcalLaserAPDPNpair
Definition: EcalLaserAPDPNRatios.h:16
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
Timestamp.h
EcalLaserAPDPNRatios::EcalLaserTimeStamp::t1
edm::Timestamp t1
Definition: EcalLaserAPDPNRatios.h:26
Tm.h
EcalLaserAPDPNRatios::setValue
void setValue(uint32_t rawId, const EcalLaserAPDPNpair &value)
Definition: EcalLaserAPDPNRatios.h:39
popcon::EcalLaserHandler::notifyProblems
void notifyProblems(const EcalLaserAPDPNRatios::EcalLaserAPDPNpair &old, const EcalLaserAPDPNRatios::EcalLaserAPDPNpair &current, int hashedIndex, const std::string &reason)
Definition: EcalLaserHandler.cc:41
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
EcalLaserAPDPNRatios::EcalLaserTimeStampMap
std::vector< EcalLaserTimeStamp > EcalLaserTimeStampMap
Definition: EcalLaserAPDPNRatios.h:34
popcon::EcalLaserHandler::m_maxtime
std::string m_maxtime
Definition: EcalLaserHandler.h:80
EEDetId::iy
int iy() const
Definition: EEDetId.h:83
PixelMapPlotter.reason
reason
Definition: PixelMapPlotter.py:509
EcalLogicID.h
EcalLogicID::NULLID
static const int NULLID
Definition: EcalLogicID.h:35
std
Definition: JetResolutionObject.h:76
reco::JetExtendedAssociation::Ref
edm::Ref< Container > Ref
Definition: JetExtendedAssociation.h:32
Exception
Definition: hltDiff.cc:246
ParameterSetfwd.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dumpRecoGeometry_cfg.tagInfo
tagInfo
Definition: dumpRecoGeometry_cfg.py:194
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
popcon::EcalLaserHandler::checkAPDPN
bool checkAPDPN(const EcalLaserAPDPNRatios::EcalLaserAPDPNpair &old, const EcalLaserAPDPNRatios::EcalLaserAPDPNpair &current, int hashedIndex)
Definition: EcalLaserHandler.cc:57
L1TowerCalibrationProducer_cfi.iEta
iEta
Definition: L1TowerCalibrationProducer_cfi.py:60
EcalCondObjectContainer< EcalLaserAPDPNpair >::const_iterator
std::vector< Item >::const_iterator const_iterator
Definition: EcalCondObjectContainer.h:19
EBDetId::iphi
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
ztail.d
d
Definition: ztail.py:151
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
popcon::EcalLaserHandler::m_sid
std::string m_sid
Definition: EcalLaserHandler.h:76
EcalLaserAPDPNRatios
Definition: EcalLaserAPDPNRatios.h:14
Tm::cmsNanoSeconds
uint64_t cmsNanoSeconds() const
Definition: Tm.cc:92
popcon::EcalLaserHandler::dumpBarrelPayload
void dumpBarrelPayload(EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap const &laserMap)
Definition: EcalLaserHandler.cc:92
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
EcalLaserAPDPNRatios::setTime
void setTime(int hashedIndex, const EcalLaserTimeStamp &value)
Definition: EcalLaserAPDPNRatios.h:42
ecalpyutils::hashedIndex
int hashedIndex(int ieta, int iphi)
Definition: EcalPyUtils.cc:38
EcalLaserAPDPNRatios::EcalLaserTimeStamp
Definition: EcalLaserAPDPNRatios.h:24
EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p2
float p2
Definition: EcalLaserAPDPNRatios.h:19
LMFSextuple.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p3
float p3
Definition: EcalLaserAPDPNRatios.h:20
EcalLaserAPDPNRatios::EcalLaserTimeStamp::t2
edm::Timestamp t2
Definition: EcalLaserAPDPNRatios.h:27
edm::Timestamp
Definition: Timestamp.h:30