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. ) ),
19  m_tagForRunInfo( pset.getParameter<edm::ParameterSet>( "ESTransition" ).getParameter<std::string>( "tagForRunInfo" ) ),
20  m_ESGain( pset.getParameter<edm::ParameterSet>( "ESTransition" ).getParameter<std::string>( "ESGain" ) ),
21  m_tagForLowGain( pset.getParameter<edm::ParameterSet>( "ESTransition" ).getParameter<std::string>( "ESLowGainTag" ) ),
22  m_tagForHighGain( pset.getParameter<edm::ParameterSet>( "ESTransition" ).getParameter<std::string>( "ESHighGainTag" ) ),
23  m_connectionString( pset.getParameter<edm::ParameterSet>( "ESTransition" ).getParameter<std::string>( "connect" ) ),
24  m_connectionPset( pset.getParameter<edm::ParameterSet>( "ESTransition" ).getParameter<edm::ParameterSet>( "DBParameters" ) ) {
25  edm::LogInfo( "PopConESTransitionSourceHandler" ) << "[" << "PopConESTransitionSourceHandler:" << __func__ << "]: "
26  << "Initialising Connection Pool" << std::endl;
29  }
30 
32 
33  std::string id() const final { return std::string( "PopConESTransitionSourceHandler" ); }
34 
35  bool checkLowGain() {
36  //the output boolean is set to true as default
37  bool isLowGain = true;
39  //reading RunInfo from Conditions
41  edm::LogInfo( "PopConESTransitionSourceHandler" ) << "[" << "PopConESTransitionSourceHandler::" << __func__ << "]: "
42  << "Loading tag for RunInfo " << m_tagForRunInfo
43  << " and IOV valid for run number: " << m_run << std::endl;
45  cond::Iov_t currentIov = *(iov.find( m_run ));
46  LogDebug( "PopConESTransitionSourceHandler" ) << "Loaded IOV sequence from tag " << m_tagForRunInfo
47  << " with size: "<< iov.loadedSize()
48  << ", IOV valid for run number " << m_run << " starting from: " << currentIov.since
49  << ", with corresponding payload hash: " << currentIov.payloadId << std::endl;
50  /* accessing the average magnet current for the run
51  double current_default = -1;
52  double avg_current = current_default;
53  avg_current = session.fetchPayload<RunInfo>( currentIov.payloadId )->m_avg_current;
54  LogDebug( "PopConESTransitionSourceHandler" ) << "Comparing value of magnet current: " << avg_current << " A for run: " << m_run
55  << " with the corresponding threshold: "<< m_currentThreshold << " A." << std::endl;
56  comparing the magnet current with the user defined threshold
57  if( avg_current != current_default && avg_current <= m_currentThreshold ) isLowGain = false;
58  edm::LogInfo( "PopConESTransitionSourceHandler" ) << "[" << "PopConESTransitionSourceHandler::" << __func__ << "]: "
59  << "The magnet was " << ( isBOn ? "ON" : "OFF" )
60  << " during run " << m_run << std::endl; */
61  if (m_ESGain=="HIGH") {
62  isLowGain=false;}
63  else {
64  isLowGain = true;}
65  trans.close();
66  return isLowGain;
67  }
68 
69  virtual void getObjectsForESTransition( bool isLowGain ) {
70  //reading payloads for 0T and 3.8T from Conditions
73  edm::LogInfo( "PopConESTransitionSourceHandler" ) << "[" << "PopConESTransitionSourceHandler::" << __func__ << "]: "
74  << "Loading tag for ES " << ( isLowGain ? "LowGain" : "HighGain" ) << ": "
75  << ( isLowGain ? m_tagForLowGain : m_tagForHighGain )
76  << " and IOV valid for run number: " << m_run << std::endl;
77  cond::persistency::IOVProxy iov = session.readIov( isLowGain ? m_tagForLowGain : m_tagForHighGain, true );
78  cond::Iov_t currentIov = *(iov.find( m_run ));
79  LogDebug( "PopConESTransitionSourceHandler" ) << "Loaded IOV sequence from tag " << ( isLowGain ? m_tagForLowGain : m_tagForHighGain )
80  << " with size: "<< iov.loadedSize()
81  << ", IOV valid for run number " << m_run << " starting from: " << currentIov.since
82  << ", with corresponding payload hash: " << currentIov.payloadId
83  << std::endl;
84  std::string destTag = this->tagInfo().name;
85  if( currentIov.payloadId != this->tagInfo().lastPayloadToken ) {
86  std::ostringstream ss;
87  ss << "Adding iov with since "<<m_run<<" pointing to hash " << currentIov.payloadId
88  << " corresponding to the ES Gain "
89  << ( isLowGain ? "LOW" : "HIGH" );
90  edm::LogInfo( "PopConESTransitionSourceHandler" ) << "[" << "PopConESTransitionSourceHandler::" << __func__ << "]: "
91  << ss.str() << std::endl;
93  if( session.existsIov( destTag ) ){
94  editor = session.editIov( destTag );
95  } else {
96  editor = session.createIov<T>( destTag, iov.timeType() );
97  editor.setDescription( "Tag created by PopConESTransitionSourceHandler" );
98  }
99  editor.insert( m_run, currentIov.payloadId );
100  editor.flush();
101  this->m_userTextLog = ss.str();
102  } else {
103  edm::LogInfo( "PopConESTransitionSourceHandler" ) << "[" << "PopConESTransitionSourceHandler::" << __func__ << "]: "
104  << "The payload with hash " << currentIov.payloadId
105  << " corresponding to ES Gain"
106  << ( isLowGain ? "LOW" : "HIGH" )
107  << " is still valid for run " << m_run
108  << " in the destination tag " << destTag
109  << ".\nNo transfer needed." <<std::endl;
110  }
111  trans.close();
112  }
113 
114  void getNewObjects() final {
115  //check whats already inside of database
116  edm::LogInfo( "PopConESTransitionSourceHandler" ) << "[" << "PopConESTransitionSourceHandler::" << __func__ << "]: "
117  << "Destination Tag Info: name " << this->tagInfo().name
118  << ", size " << this->tagInfo().size
119  << ", last object valid since " << this->tagInfo().lastInterval.first
120  << ", hash " << this->tagInfo().lastPayloadToken << std::endl;
121  //check if a transfer is needed:
122  //if the new run number is smaller than or equal to the latest IOV, exit.
123  //This is needed as now the IOV Editor does not always protect for insertions:
124  //ANY and VALIDATION sychronizations are allowed to write in the past.
125  if( this->tagInfo().size > 0 && this->tagInfo().lastInterval.first >= m_run ) {
126  edm::LogInfo( "PopConESTransitionSourceHandler" ) << "[" << "PopConESTransitionSourceHandler::" << __func__ << "]: "
127  << "last IOV " << this->tagInfo().lastInterval.first
128  << ( this->tagInfo().lastInterval.first == m_run ? " is equal to" : " is larger than" )
129  << " the run proposed for insertion " << m_run
130  << ". No transfer needed." << std::endl;
131  return;
132  }
133  bool isLowGain = checkLowGain();
134  getObjectsForESTransition( isLowGain );
135  edm::LogInfo( "PopConESTransitionSourceHandler" ) << "[" << "PopConESTransitionSourceHandler::" << __func__ << "]: "
136  << "END." << std::endl;
137  }
138 
139  private:
140  unsigned long long m_run;
142  // for reading from CondDB the current from RunInfo
144  // for reading from CondDB the Low Gain and High Gain payloads
151  };
152 } //namespace popcon
153 
154 #endif //PopConESTransitionSourceHandler_H
#define LogDebug(id)
size
Write out results.
cond::persistency::Session & dbSession() const
Time_t since
Definition: Types.h:55
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.h:188
size_t size
Definition: Types.h:78
void setDescription(const std::string &description)
Definition: IOVEditor.cc:128
Transaction & transaction()
Definition: Session.cc:66
void setParameters(const edm::ParameterSet &connectionPset)
std::string name
Definition: Types.h:74
cond::ValidityInterval lastInterval
Definition: Types.h:76
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:81
cond::TimeType timeType() const
Definition: IOVProxy.cc:227
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:320
Hash payloadId
Definition: Types.h:57
IOVEditor editIov(const std::string &tag)
Definition: Session.cc:156
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
Definition: IOVEditor.cc:152
std::string lastPayloadToken
Definition: Types.h:77
bool existsIov(const std::string &tag)
Definition: Session.cc:97
HLT enums.
PopConESTransitionSourceHandler(edm::ParameterSet const &pset)
long double T
cond::TagInfo_t const & tagInfo() const