15 oracle::occi::Connection* conn) {
22 std::map<int, LMFCorrCoefDatComponent*>::iterator
i =
m_data.begin();
23 std::map<int, LMFCorrCoefDatComponent*>::iterator
e =
m_data.end();
29 std::map<int, LMFLmrSubIOV*>::iterator si =
m_subiov.begin();
30 std::map<int, LMFLmrSubIOV*>::iterator se =
m_subiov.end();
47 oracle::occi::Connection* conn) {
50 std::map<int, LMFCorrCoefDatComponent*>::iterator
i =
m_data.begin();
51 std::map<int, LMFCorrCoefDatComponent*>::iterator
e =
m_data.end();
66 float p1,
float p2,
float p3,
67 float p1e,
float p2e,
float p3e) {
118 std::cout <<
"##################### LMF_CORR_COEF_DAT ########################" << std::endl;
119 std::cout <<
"This structure contains " <<
m_data.size() <<
" LMR_SUB_IOV_ID" << std::endl;
120 std::map<int, LMFCorrCoefDatComponent*>::const_iterator
i =
m_data.begin();
121 std::map<int, LMFCorrCoefDatComponent*>::const_iterator
e =
m_data.end();
124 std::cout <<
"### SUB IOV ID: " << i->second->getLMFLmrSubIOVID() << std::endl;
125 std::list<int> logic_ids = i->second->getLogicIds();
126 std::cout <<
" Contains data for " << logic_ids.size() <<
" xtals" << std::endl;
127 count += logic_ids.size();
130 std::cout <<
"Total no. of xtals for which data are stored: " << count << std::endl;
131 std::cout <<
"##################### LMF_CORR_COEF_DAT ########################" << std::endl;
135 std::map<int, LMFCorrCoefDatComponent*>::iterator
i =
m_data.begin();
136 std::map<int, LMFCorrCoefDatComponent*>::iterator
e =
m_data.end();
139 std::cout <<
"Writing data for LMR_SUB_IOV_ID " << i->first << std::endl;
141 i->second->writeDB();
147 std::cout <<
"Set debug" << std::endl << std::flush;
158 throw std::runtime_error(
"[LMFCorrCoefDat::fetchLastInsertedRun] ERROR: " 159 "Connection not set");
162 std::string sql =
"SELECT IOV_ID FROM CMS_ECAL_COND.RUN_IOV WHERE " 163 "IOV_ID = (SELECT RUN_IOV_ID FROM LMF_SEQ_DAT WHERE SEQ_ID = " 164 "(SELECT MAX(SEQ_ID) FROM LMF_CORR_COEF_DAT))";
165 oracle::occi::Statement * stmt;
167 stmt =
m_conn->createStatement();
170 catch (oracle::occi::SQLException &
e) {
171 throw(std::runtime_error(
"[LMFCorrCoefDat::fetchLastInsertedRun]: " +
175 std::cout <<
"[LMFCorrCoefDat::fetchLastInsertedRun] executing query" 176 << std::endl << sql << std::endl << std::flush;
178 oracle::occi::ResultSet *rset = stmt->executeQuery();
181 << std::endl << std::flush;
185 while (rset->next()) {
187 iov_id = rset->getInt(1);
190 catch (oracle::occi::SQLException &e) {
191 throw(std::runtime_error(
"[LMFCorrCoefDat::fetchLastInsertedRun]: " +
217 int maxNumberOfIOVs) {
222 std::cout <<
"Searching for data collected after " << tmin.
str();
227 << maxNumberOfIOVs <<
" records" << std::endl;
232 std::cout <<
"Now we are going to fetch details about " 233 <<
"data collected within the above mentioned " 234 <<
"LMR_SUB_IOV's" << std::endl;
239 << std::endl << std::flush;
244 std::list<int>::const_iterator
i = subiov_ids.begin();
245 std::list<int>::const_iterator
e = subiov_ids.end();
249 std::cout <<
"[LMFCorrCoefDat] Fetching data taken " 250 <<
"during LMR_SUB_IOV no. " << ++c << std::endl;
256 std::cout <<
"[LMFCorrCoefDat] fetch done for all sub iovs" 257 << std::endl << std::flush;
265 std::cout <<
"[LMFCorrCoefDat] Looking for LMR_SUB_IOV with ID " 266 << iov.
getID() << std::endl
274 std::cout <<
"[LMFCorrCoefDat] Latest LMR_SUB_IOV data follows" 277 std::cout <<
"[LMFCorrCoefDat] Fetching data taken " 278 <<
"during LMR_SUB_IOV ID " << subiov_id << std::endl
289 std::cout <<
" Data collected in LMR_SUB_IOV " 291 <<
" not found in private data. " 292 <<
"Getting it from DB " << std::endl
303 std::cout <<
"====== DEBUGGING: Data collected during this LMR_SUB_IOV" 306 std::cout <<
"====== DEBUGGING: ======================================" 307 << std::endl << std::endl;
312 std::cout <<
" Data collected in LMR_SUB_IOV " 314 <<
" found in private data. " 315 << std::endl << std::flush;
318 std::cout <<
"[LMFCorrCoefDat] Fetch done" << std::endl << std::endl << std::flush;
326 std::map<int, std::map<int, LMFSextuple> >
332 const std::map<int, LMFSextuple> &lastMap)
336 if (lastMap.find(logic_id) != lastMap.end()) {
337 const LMFSextuple sold = lastMap.find(logic_id)->second;
355 std::map<int, std::map<int, LMFSextuple> >
360 std::map<int, std::map<int, LMFSextuple> >
371 throw std::runtime_error(
"[LMFCorrCoefDat::getCorrections] ERROR: " 372 "Connection not set");
377 std::cout <<
" Required to fetch " << max <<
" sequences from OMDS. " 384 std::map<int, std::map<int, LMFSextuple> > ret;
385 std::string sql =
"SELECT * FROM (SELECT LOGIC_ID, T1, T2, T3, P1, P2, P3, " 386 "SEQ_ID, D.LMR_SUB_IOV_ID FROM LMF_LMR_SUB_IOV JOIN LMF_CORR_COEF_DAT D ON " 387 "D.LMR_SUB_IOV_ID = LMF_LMR_SUB_IOV.LMR_SUB_IOV_ID " 388 "WHERE T1 > TO_DATE(:1, 'YYYY-MM-DD HH24:MI:SS') AND " 389 "T1 <= TO_DATE(:2, 'YYYY-MM-DD HH24:MI:SS') ORDER BY T1) WHERE ROWNUM <= :3";
392 const int PREFETCH = 10000;
393 oracle::occi::Statement * stmt =
m_conn->createStatement();
395 int toFetch = (max * (61200 + 14648));
396 stmt->setString(1, t.
str());
397 stmt->setString(2, t2.
str());
398 stmt->setInt(3, toFetch);
399 stmt->setPrefetchRowCount(PREFETCH);
401 std::cout <<
"[LMFCorrCoefDat::getCorrections] executing query" 402 << std::endl << sql << std::endl
403 <<
"Parameters 1 = " << t.
str() <<
" 2 = " 404 << t2.
str() <<
" 3 = " << toFetch << std::endl
405 <<
"Prefetching " << PREFETCH <<
" rows " 406 << std::endl << std::flush;
408 oracle::occi::ResultSet *rset = stmt->executeQuery();
411 << std::endl << std::flush;
414 std::map<int, LMFSextuple> theMap;
416 int previousSeqId = 0;
417 int startingSeqId = -1;
420 while (rset->next()) {
421 int logic_id = rset->getInt(1);
422 int seq_id = rset->getInt(8);
423 if (startingSeqId < 0) {
424 startingSeqId = seq_id;
426 if ((seq_id == 0) && (startingSeqId == 0)) {
430 std::cout <<
"[LMFCorrCoefDat::getCorrections] Using fixed-time IOV" 433 seq_id = rset->getInt(9);
434 }
else if ((startingSeqId == 0) && (proceed =
true)) {
435 std::cout <<
"[LMFCorrCoefDat::getCorrections] Switch to normal (sequence based) mode. " 436 <<
"Exiting..." << std::endl;
438 }
else if ((seq_id == 0) && (proceed =
true)) {
439 std::cout <<
"[LMFCorrCoefDat::getCorrections] Switch to fixed-time IOV mode. " 440 <<
"Exiting..." << std::endl;
444 if (seq_id != lastSeqId) {
446 if (lastSeqId != 0) {
447 std::cout <<
" Triplets in sequences: " << c
450 <<
" T3: " << s.
t[2].
str() << std::endl;
453 std::cout <<
" Found new sequence: " << seq_id
458 for (
int i = 0;
i < 3;
i++) {
459 oracle::occi::Date
d = rset->getDate(
i + 2);
463 ret[lastSeqId] = theMap;
466 previousSeqId = lastSeqId;
469 for (
int i = 0;
i <3;
i++) {
470 s.
p[
i] = rset->getDouble(
i + 5);
472 theMap[logic_id] =
s;
481 ret[lastSeqId] = theMap;
483 std::cout <<
" Triplets in sequences: " << c
486 <<
" T3: " << s.
t[2].
str() << std::endl;
490 catch (oracle::occi::SQLException &
e) {
491 throw(std::runtime_error(
"LMFCorrCoefDat::getCorrections: " +
495 std::cout <<
"[LMFCorrCoefDat::getCorrections] Map built" << std::endl
496 <<
" Contains " << ret.size()
497 <<
" sequences. These are the size of all sequences" 499 std::map<int, std::map<int, LMFSextuple> >::const_iterator
i = ret.begin();
500 std::map<int, std::map<int, LMFSextuple> >::const_iterator e = ret.end();
503 <<
" Size " << i->second.size() << std::endl;
517 std::map<int, LMFCorrCoefDatComponent *>::const_iterator
i =
m_data.begin();
518 std::map<int, LMFCorrCoefDatComponent *>::const_iterator
e =
m_data.end();
519 std::list<std::vector<float> > ret;
521 std::list<int> logic_ids = i->second->getLogicIds();
522 std::list<int>::iterator
p =
524 if (p != logic_ids.end()) {
526 std::vector<float> ppar;
527 std::vector<Tm> tpar;
529 i->second->getData(
id, ppar);
530 tpar =
m_subiov[i->first]->getTimes();
532 std::vector<float> par(6);
533 for (
int k = 0;
k < 3;
k++) {
534 par[
k + 3] = ppar[
k];
535 par[
k] = tpar[
k].microsTime();
546 std::vector<float>
x(3);
558 std::vector<float>
x;
599 std::map<int, LMFCorrCoefDatComponent *>::const_iterator
i =
m_data.begin();
600 std::map<int, LMFCorrCoefDatComponent *>::const_iterator
e =
m_data.end();
602 c += i->second->size();
610 std::map<int, LMFCorrCoefDatComponent *>::const_iterator
i =
m_data.begin();
611 std::map<int, LMFCorrCoefDatComponent *>::const_iterator
e =
m_data.end();
613 ret.push_back(i->first);
std::map< int, LMFLmrSubIOV * > m_subiov
void setByID(int id) noexcept(false) override
std::list< int > getIOVIDsLaterThan(const Tm &t) noexcept(false)
std::map< int, std::map< int, LMFSextuple > > getCorrections(const Tm &t)
std::list< std::vector< float > > getParameters(int id)
std::vector< float > getParameterErrors(const LMFLmrSubIOV &iov, const EcalLogicID &id)
int getFlag(const LMFLmrSubIOV &iov, const EcalLogicID &id)
void dump() const override
oracle::occi::Connection * m_conn
virtual void dump() const
oracle::occi::Environment * getEnv() const
RunIOV fetchLastInsertedRun()
void fetch(std::list< int > subiov_ids)
static const int MAX_NUMBER_OF_SEQUENCES_TO_FETCH
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
oracle::occi::Connection * getConn() const
void setByID(int id) noexcept(false) override
LMFCorrCoefDatComponent & setP123Errors(const EcalLogicID &id, float p1e, float p2e, float p3e)
U second(std::pair< T, U > const &p)
LMFCorrCoefDatComponent & setSequence(const EcalLogicID &id, int seq_id)
LMFCorrCoefDat & setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
void fetchBetween(const Tm &tmin, const Tm &tmax)
LMFSeqDat getSequence(const LMFLmrSubIOV &iov, const EcalLogicID &id)
void fetch() noexcept(false)
std::map< int, LMFCorrCoefDatComponent * > m_data
void getTimes(Tm *t1, Tm *t2, Tm *t3) const
oracle::occi::Environment * m_env
int getSeqID(const LMFLmrSubIOV &iov, const EcalLogicID &id)
void fetchAfter(const Tm &t)
static const double tmax[3]
void setToString(const std::string s) noexcept(false)
LMFCorrCoefDatComponent & setP123(const EcalLogicID &id, float p1, float p2, float p3)
std::vector< Tm > getTimes(const LMFLmrSubIOV &iov)
void checkTriplets(int logic_id, const LMFSextuple &s, const std::map< int, LMFSextuple > &lastMap)
LMFCorrCoefDat & setP123Errors(const LMFLmrSubIOV &iov, const EcalLogicID &id, float p1e, float p2e, float p3e)
LMFCorrCoefDat & setSequence(const LMFLmrSubIOV &iov, const EcalLogicID &id, int seq_id)
LMFCorrCoefDat & setFlag(const LMFLmrSubIOV &iov, const EcalLogicID &id, int flag)
LMFCorrCoefDatComponent & setFlag(const EcalLogicID &id, int flag)
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
LMFCorrCoefDatComponent & setLMFLmrSubIOV(const LMFLmrSubIOV &iov)
std::list< int > getSubIOVIDs()
Tm dateToTm(oracle::occi::Date &date) const
LMFCorrCoefDatComponent * find(const LMFLmrSubIOV &iov)
LMFCorrCoefDat & setP123(const LMFLmrSubIOV &iov, const EcalLogicID &id, float p1, float p2, float p3)