CMS 3D CMS Logo

PopConBTransitionSourceHandler.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>( "BTransition" ).getParameter<unsigned long long>( "runNumber" ) ),
18  m_currentThreshold( pset.getParameter<edm::ParameterSet>( "BTransition" ).getUntrackedParameter<double>( "currentThreshold", 18000. ) ),
19  m_tagForRunInfo( pset.getParameter<edm::ParameterSet>( "BTransition" ).getParameter<std::string>( "tagForRunInfo" ) ),
20  m_tagForBOff( pset.getParameter<edm::ParameterSet>( "BTransition" ).getParameter<std::string>( "tagForBOff" ) ),
21  m_tagForBOn( pset.getParameter<edm::ParameterSet>( "BTransition" ).getParameter<std::string>( "tagForBOn" ) ),
22  m_connectionString( pset.getParameter<edm::ParameterSet>( "BTransition" ).getParameter<std::string>( "connect" ) ),
23  m_connectionPset( pset.getParameter<edm::ParameterSet>( "BTransition" ).getParameter<edm::ParameterSet>( "DBParameters" ) ) {
24  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler:" << __func__ << "]: "
25  << "Initialising Connection Pool" << std::endl;
28  }
29 
31 
32  virtual std::string id() const override final { return std::string( "PopConBTransitionSourceHandler" ); }
33 
34  bool checkBOn() {
35  //the output boolean is set to true as default
36  bool isBOn = true;
37  //reading RunInfo from Conditions
38  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
39  << "Initialising CondDB read-only session to " << m_connectionString << std::endl;
41  session.transaction().start();
42  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
43  << "Loading tag for RunInfo " << m_tagForRunInfo
44  << " and IOV valid for run number: " << m_run << std::endl;
46  cond::Iov_t currentIov = *(iov.find( m_run ));
47  LogDebug( "PopConBTransitionSourceHandler" ) << "Loaded IOV sequence from tag " << m_tagForRunInfo
48  << " with size: "<< iov.loadedSize()
49  << ", IOV valid for run number " << m_run << " starting from: " << currentIov.since
50  << ", with corresponding payload hash: " << currentIov.payloadId
51  << std::endl;
52  //accessing the average magnet current for the run
53  double current_default = -1;
54  double avg_current = current_default;
55  avg_current = session.fetchPayload<RunInfo>( currentIov.payloadId )->m_avg_current;
56  LogDebug( "PopConBTransitionSourceHandler" ) << "Comparing value of magnet current: " << avg_current << " A for run: " << m_run
57  << " with the corresponding threshold: "<< m_currentThreshold << " A." << std::endl;
58  //comparing the magnet current with the user defined threshold
59  if( avg_current != current_default && avg_current <= m_currentThreshold ) isBOn = false;
60  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
61  << "The magnet was " << ( isBOn ? "ON" : "OFF" )
62  << " during run " << m_run << std::endl;
63  session.transaction().commit();
64  return isBOn;
65  }
66 
67  virtual void getObjectsForBTransition( bool isBOn ) {
68  //reading payloads for 0T and 3.8T from Conditions
69  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
70  << "Initialising CondDB session to " << m_connectionString << std::endl;
73  trans.start( false );
74  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
75  << "Loading tag for B " << ( isBOn ? "ON" : "OFF" ) << ": "
76  << ( isBOn ? m_tagForBOn : m_tagForBOff )
77  << " and IOV valid for run number: " << m_run << std::endl;
78  cond::persistency::IOVProxy iov = session.readIov( isBOn ? m_tagForBOn : m_tagForBOff, true );
79  cond::Iov_t currentIov = *(iov.find( m_run ));
80  LogDebug( "PopConBTransitionSourceHandler" ) << "Loaded IOV sequence from tag " << ( isBOn ? m_tagForBOn : m_tagForBOff )
81  << " with size: "<< iov.loadedSize()
82  << ", IOV valid for run number " << m_run << " starting from: " << currentIov.since
83  << ", with corresponding payload hash: " << currentIov.payloadId
84  << std::endl;
85  std::string destTag = this->tagInfo().name;
86  if( currentIov.payloadId != this->tagInfo().lastPayloadToken ) {
87  std::ostringstream ss;
88  ss << "Adding iov with since "<<m_run<<" pointing to hash " << currentIov.payloadId
89  << " corresponding to the calibrations for magnetic field "
90  << ( isBOn ? "ON" : "OFF" );
91  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
92  << ss.str() << std::endl;
93  cond::persistency::IOVEditor editor = session.editIov( destTag );
94  editor.insert( m_run, currentIov.payloadId );
95  editor.flush();
96  this->m_userTextLog = ss.str();
97  } else {
98  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
99  << "The payload with hash " << currentIov.payloadId
100  << " corresponding to the calibrations for magnetic field "
101  << ( isBOn ? "ON" : "OFF" )
102  << " is still valid for run " << m_run
103  << " in the destination tag " << destTag
104  << ".\nNo transfer needed." <<std::endl;
105  }
106  trans.commit();
107  }
108 
109  virtual void getNewObjects() override final {
110  //check whats already inside of database
111  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
112  << "Destination Tag Info: name " << this->tagInfo().name
113  << ", size " << this->tagInfo().size
114  << ", last object valid since " << this->tagInfo().lastInterval.first
115  << ", hash " << this->tagInfo().lastPayloadToken << std::endl;
116  //check if a transfer is needed:
117  //if the new run number is smaller than or equal to the latest IOV, exit.
118  //This is needed as now the IOV Editor does not always protect for insertions:
119  //ANY and VALIDATION sychronizations are allowed to write in the past.
120  if( this->tagInfo().size > 0 && this->tagInfo().lastInterval.first >= m_run ) {
121  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
122  << "last IOV " << this->tagInfo().lastInterval.first
123  << ( this->tagInfo().lastInterval.first == m_run ? " is equal to" : " is larger than" )
124  << " the run proposed for insertion " << m_run
125  << ". No transfer needed." << std::endl;
126  return;
127  }
128  bool isBOn = checkBOn();
129  getObjectsForBTransition( isBOn );
130  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
131  << "END." << std::endl;
132  }
133 
134  private:
135  unsigned long long m_run;
137  // for reading from CondDB the current from RunInfo
139  // for reading from CondDB the 0T and 3.8T payloads
145  };
146 } //namespace popcon
147 
148 #endif //PopConBTransitionSourceHandler_H
#define LogDebug(id)
size
Write out results.
void start(bool readOnly=true)
Definition: Session.cc:22
Time_t since
Definition: Types.h:55
size_t size
Definition: Types.h:76
Transaction & transaction()
Definition: Session.cc:66
void setParameters(const edm::ParameterSet &connectionPset)
std::string name
Definition: Types.h:72
cond::ValidityInterval lastInterval
Definition: Types.h:74
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:81
virtual std::string id() const override final
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:320
Hash payloadId
Definition: Types.h:57
void start(bool readOnly=true)
Definition: Session.cc:248
Session createSession(const std::string &connectionString, bool writeCapable=false)
PopConBTransitionSourceHandler(edm::ParameterSet const &pset)
IOVEditor editIov(const std::string &tag)
Definition: Session.cc:148
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
Definition: IOVEditor.cc:152
std::string lastPayloadToken
Definition: Types.h:75
HLT enums.
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
cond::TagInfo_t const & tagInfo() const
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:215