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
Iov_t lastInterval
Definition: Types.h:73
Time_t since
Definition: Types.h:53
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.h:179
size_t size
Definition: Types.h:74
void setDescription(const std::string &description)
Definition: IOVEditor.cc:139
Transaction & transaction()
Definition: Session.cc:52
void setParameters(const edm::ParameterSet &connectionPset)
std::string name
Definition: Types.h:72
cond::TagInfo_t const & tagInfo() const
Hash payloadId
Definition: Types.h:55
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:320
cond::Tag_t tagInfo() const
Definition: IOVProxy.cc:246
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
IOVEditor editIov(const std::string &tag)
Definition: Session.cc:130
Log< level::Info, false > LogInfo
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
Definition: IOVEditor.cc:159
TimeType timeType
Definition: Types.h:63
bool existsIov(const std::string &tag)
Definition: Session.cc:77
cond::persistency::Session & dbSession() const
HLT enums.
PopConESTransitionSourceHandler(edm::ParameterSet const &pset)
long double T
#define LogDebug(id)