CMS 3D CMS Logo

PopConESTransitionSourceHandler.h
Go to the documentation of this file.
1 #ifndef PopConBTransitionSourceHandler_H
2 #define PopConBTransitionSourceHandler_H
3 
10 #include <string>
11 
12 namespace popcon {
13  template <class T>
15  public:
17  : m_run(pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<unsigned long long>("runNumber")),
18  // m_currentThreshold( pset.getParameter<edm::ParameterSet>( "ESTransition" ).getUntrackedParameter<double>( "currentThreshold", 18000. ) ),
20  pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<std::string>("tagForRunInfo")),
21  m_ESGain(pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<std::string>("ESGain")),
23  pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<std::string>("ESLowGainTag")),
25  pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<std::string>("ESHighGainTag")),
26  m_connectionString(pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<std::string>("connect")),
28  pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<edm::ParameterSet>("DBParameters")) {
29  edm::LogInfo("PopConESTransitionSourceHandler") << "["
30  << "PopConESTransitionSourceHandler:" << __func__ << "]: "
31  << "Initialising Connection Pool" << std::endl;
34  }
35 
37 
38  std::string id() const final { return std::string("PopConESTransitionSourceHandler"); }
39 
40  bool checkLowGain() {
41  //the output boolean is set to true as default
42  bool isLowGain = true;
44  //reading RunInfo from Conditions
46  edm::LogInfo("PopConESTransitionSourceHandler")
47  << "["
48  << "PopConESTransitionSourceHandler::" << __func__ << "]: "
49  << "Loading tag for RunInfo " << m_tagForRunInfo << " and IOV valid for run number: " << m_run << std::endl;
51  cond::Iov_t currentIov = iov.getInterval(m_run);
52  LogDebug("PopConESTransitionSourceHandler")
53  << "Loaded IOV sequence from tag " << m_tagForRunInfo << " with size: " << iov.loadedSize()
54  << ", IOV valid for run number " << m_run << " starting from: " << currentIov.since
55  << ", with corresponding payload hash: " << currentIov.payloadId << std::endl;
56  /* accessing the average magnet current for the run
57  double current_default = -1;
58  double avg_current = current_default;
59  avg_current = session.fetchPayload<RunInfo>( currentIov.payloadId )->m_avg_current;
60  LogDebug( "PopConESTransitionSourceHandler" ) << "Comparing value of magnet current: " << avg_current << " A for run: " << m_run
61  << " with the corresponding threshold: "<< m_currentThreshold << " A." << std::endl;
62  comparing the magnet current with the user defined threshold
63  if( avg_current != current_default && avg_current <= m_currentThreshold ) isLowGain = false;
64  edm::LogInfo( "PopConESTransitionSourceHandler" ) << "[" << "PopConESTransitionSourceHandler::" << __func__ << "]: "
65  << "The magnet was " << ( isBOn ? "ON" : "OFF" )
66  << " during run " << m_run << std::endl; */
67  if (m_ESGain == "HIGH") {
68  isLowGain = false;
69  } else {
70  isLowGain = true;
71  }
72  trans.close();
73  return isLowGain;
74  }
75 
76  virtual void getObjectsForESTransition(bool isLowGain) {
77  //reading payloads for 0T and 3.8T from Conditions
80  edm::LogInfo("PopConESTransitionSourceHandler") << "["
81  << "PopConESTransitionSourceHandler::" << __func__ << "]: "
82  << "Loading tag for ES " << (isLowGain ? "LowGain" : "HighGain")
83  << ": " << (isLowGain ? m_tagForLowGain : m_tagForHighGain)
84  << " and IOV valid for run number: " << m_run << std::endl;
86  cond::Iov_t currentIov = iov.getInterval(m_run);
87  LogDebug("PopConESTransitionSourceHandler")
88  << "Loaded IOV sequence from tag " << (isLowGain ? m_tagForLowGain : m_tagForHighGain)
89  << " with size: " << iov.loadedSize() << ", IOV valid for run number " << m_run
90  << " starting from: " << currentIov.since << ", with corresponding payload hash: " << currentIov.payloadId
91  << std::endl;
92  std::string destTag = this->tagInfo().name;
93  if (currentIov.payloadId != this->tagInfo().lastInterval.payloadId) {
94  std::ostringstream ss;
95  ss << "Adding iov with since " << m_run << " pointing to hash " << currentIov.payloadId
96  << " corresponding to the ES Gain " << (isLowGain ? "LOW" : "HIGH");
97  edm::LogInfo("PopConESTransitionSourceHandler")
98  << "["
99  << "PopConESTransitionSourceHandler::" << __func__ << "]: " << ss.str() << std::endl;
101  if (session.existsIov(destTag)) {
102  editor = session.editIov(destTag);
103  } else {
104  editor = session.createIov<T>(destTag, iov.tagInfo().timeType);
105  editor.setDescription("Tag created by PopConESTransitionSourceHandler");
106  }
107  editor.insert(m_run, currentIov.payloadId);
108  editor.flush();
109  this->m_userTextLog = ss.str();
110  } else {
111  edm::LogInfo("PopConESTransitionSourceHandler")
112  << "["
113  << "PopConESTransitionSourceHandler::" << __func__ << "]: "
114  << "The payload with hash " << currentIov.payloadId << " corresponding to ES Gain"
115  << (isLowGain ? "LOW" : "HIGH") << " is still valid for run " << m_run << " in the destination tag "
116  << destTag << ".\nNo transfer needed." << std::endl;
117  }
118  trans.close();
119  }
120 
121  void getNewObjects() final {
122  //check whats already inside of database
123  edm::LogInfo("PopConESTransitionSourceHandler")
124  << "["
125  << "PopConESTransitionSourceHandler::" << __func__ << "]: "
126  << "Destination Tag Info: name " << this->tagInfo().name << ", size " << this->tagInfo().size
127  << ", last object valid since " << this->tagInfo().lastInterval.since << ", hash "
128  << this->tagInfo().lastInterval.payloadId << std::endl;
129  //check if a transfer is needed:
130  //if the new run number is smaller than or equal to the latest IOV, exit.
131  //This is needed as now the IOV Editor does not always protect for insertions:
132  //ANY and VALIDATION sychronizations are allowed to write in the past.
133  if (this->tagInfo().size > 0 && this->tagInfo().lastInterval.since >= m_run) {
134  edm::LogInfo("PopConESTransitionSourceHandler")
135  << "["
136  << "PopConESTransitionSourceHandler::" << __func__ << "]: "
137  << "last IOV " << this->tagInfo().lastInterval.since
138  << (this->tagInfo().lastInterval.since == m_run ? " is equal to" : " is larger than")
139  << " the run proposed for insertion " << m_run << ". No transfer needed." << std::endl;
140  return;
141  }
142  bool isLowGain = checkLowGain();
143  getObjectsForESTransition(isLowGain);
144  edm::LogInfo("PopConESTransitionSourceHandler") << "["
145  << "PopConESTransitionSourceHandler::" << __func__ << "]: "
146  << "END." << std::endl;
147  }
148 
149  private:
150  unsigned long long m_run;
152  // for reading from CondDB the current from RunInfo
154  // for reading from CondDB the Low Gain and High Gain payloads
161  };
162 } //namespace popcon
163 
164 #endif //PopConESTransitionSourceHandler_H
cond::persistency::TransactionScope
Definition: Session.h:231
PopConSourceHandler.h
cond::persistency::IOVEditor::insert
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
Definition: IOVEditor.cc:160
ConnectionPool.h
MessageLogger.h
popcon::PopConESTransitionSourceHandler::m_tagForHighGain
std::string m_tagForHighGain
Definition: PopConESTransitionSourceHandler.h:157
cond::persistency::Session::existsIov
bool existsIov(const std::string &tag)
Definition: Session.cc:77
popcon::PopConSourceHandler::dbSession
cond::persistency::Session & dbSession() const
Definition: PopConSourceHandler.h:144
cond::persistency::IOVProxy::getInterval
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:321
popcon::PopConESTransitionSourceHandler::m_currentThreshold
double m_currentThreshold
Definition: PopConESTransitionSourceHandler.h:151
edm
HLT enums.
Definition: AlignableModifier.h:19
cond::persistency::IOVProxy::loadedSize
int loadedSize() const
Definition: IOVProxy.cc:401
cond::persistency::IOVEditor
Definition: IOVEditor.h:28
popcon::PopConESTransitionSourceHandler::m_connection
cond::persistency::ConnectionPool m_connection
Definition: PopConESTransitionSourceHandler.h:160
popcon::PopConESTransitionSourceHandler::m_ESGain
std::string m_ESGain
Definition: PopConESTransitionSourceHandler.h:155
popcon::PopConESTransitionSourceHandler::checkLowGain
bool checkLowGain()
Definition: PopConESTransitionSourceHandler.h:40
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
popcon::PopConESTransitionSourceHandler::PopConESTransitionSourceHandler
PopConESTransitionSourceHandler(edm::ParameterSet const &pset)
Definition: PopConESTransitionSourceHandler.h:16
watchdog.const
const
Definition: watchdog.py:83
popcon::PopConESTransitionSourceHandler::m_connectionString
std::string m_connectionString
Definition: PopConESTransitionSourceHandler.h:158
cond::TagInfo_t::name
std::string name
Definition: Types.h:72
popcon::PopConESTransitionSourceHandler::id
std::string id() const final
Definition: PopConESTransitionSourceHandler.h:38
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
popcon::PopConESTransitionSourceHandler::m_tagForLowGain
std::string m_tagForLowGain
Definition: PopConESTransitionSourceHandler.h:156
IOVProxy.h
cond::persistency::ConnectionPool
Definition: ConnectionPool.h:35
popcon::PopConESTransitionSourceHandler::m_tagForRunInfo
std::string m_tagForRunInfo
Definition: PopConESTransitionSourceHandler.h:153
popcon::PopConESTransitionSourceHandler::~PopConESTransitionSourceHandler
~PopConESTransitionSourceHandler() override
Definition: PopConESTransitionSourceHandler.h:36
cond::persistency::Session::readIov
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
cond::persistency::IOVEditor::setDescription
void setDescription(const std::string &description)
Definition: IOVEditor.cc:140
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
popcon::PopConESTransitionSourceHandler::m_run
unsigned long long m_run
Definition: PopConESTransitionSourceHandler.h:150
cond::persistency::IOVProxy
Definition: IOVProxy.h:92
cond::persistency::Session::editIov
IOVEditor editIov(const std::string &tag)
Definition: Session.cc:130
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
popcon::PopConSourceHandler::tagInfo
cond::TagInfo_t const & tagInfo() const
Definition: PopConSourceHandler.h:78
cond::Iov_t::payloadId
Hash payloadId
Definition: Types.h:55
ParameterSet
Definition: Functions.h:16
cond::persistency::Session
Definition: Session.h:63
cond::Iov_t::since
Time_t since
Definition: Types.h:53
popcon::PopConESTransitionSourceHandler
Definition: PopConESTransitionSourceHandler.h:14
cond::persistency::ConnectionPool::setParameters
void setParameters(const edm::ParameterSet &connectionPset)
Definition: ConnectionPool.cc:43
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:127
popcon::PopConSourceHandler
Definition: PopConSourceHandler.h:30
cond::TagInfo_t::lastInterval
Iov_t lastInterval
Definition: Types.h:73
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
RunInfo.h
std
Definition: JetResolutionObject.h:76
popcon
Definition: Exception.h:6
T
long double T
Definition: Basic3DVectorLD.h:48
cond::persistency::Session::createIov
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.h:179
cond::Iov_t
Definition: Types.h:47
popcon::PopConESTransitionSourceHandler::getObjectsForESTransition
virtual void getObjectsForESTransition(bool isLowGain)
Definition: PopConESTransitionSourceHandler.h:76
ParameterSet.h
cond::persistency::IOVEditor::flush
bool flush()
Definition: IOVEditor.cc:316
popcon::PopConESTransitionSourceHandler::getNewObjects
void getNewObjects() final
Definition: PopConESTransitionSourceHandler.h:121
cond::persistency::IOVProxy::tagInfo
cond::Tag_t tagInfo() const
Definition: IOVProxy.cc:247
popcon::PopConSourceHandler::m_userTextLog
std::string m_userTextLog
Definition: PopConSourceHandler.h:168
cond::Tag_t::timeType
TimeType timeType
Definition: Types.h:63
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
cond::TagInfo_t::size
size_t size
Definition: Types.h:74
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
popcon::PopConESTransitionSourceHandler::m_connectionPset
edm::ParameterSet m_connectionPset
Definition: PopConESTransitionSourceHandler.h:159