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  std::string id() const final { return std::string( "PopConBTransitionSourceHandler" ); }
33 
34  bool checkBOn() {
35  //the output boolean is set to true as default
36  bool isBOn = true;
38  //reading RunInfo from Conditions
40  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
41  << "Loading tag for RunInfo " << m_tagForRunInfo
42  << " and IOV valid for run number: " << m_run << std::endl;
44  cond::Iov_t currentIov = *(iov.find( m_run ));
45  LogDebug( "PopConBTransitionSourceHandler" ) << "Loaded IOV sequence from tag " << m_tagForRunInfo
46  << " with size: "<< iov.loadedSize()
47  << ", IOV valid for run number " << m_run << " starting from: " << currentIov.since
48  << ", with corresponding payload hash: " << currentIov.payloadId
49  << 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( "PopConBTransitionSourceHandler" ) << "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 ) isBOn = false;
58  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
59  << "The magnet was " << ( isBOn ? "ON" : "OFF" )
60  << " during run " << m_run << std::endl;
61  trans.close();
62  return isBOn;
63  }
64 
65  virtual void getObjectsForBTransition( bool isBOn ) {
66  //reading payloads for 0T and 3.8T from Conditions
69  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
70  << "Loading tag for B " << ( isBOn ? "ON" : "OFF" ) << ": "
71  << ( isBOn ? m_tagForBOn : m_tagForBOff )
72  << " and IOV valid for run number: " << m_run << std::endl;
73  cond::persistency::IOVProxy iov = session.readIov( isBOn ? m_tagForBOn : m_tagForBOff, true );
74  cond::Iov_t currentIov = *(iov.find( m_run ));
75  LogDebug( "PopConBTransitionSourceHandler" ) << "Loaded IOV sequence from tag " << ( isBOn ? m_tagForBOn : m_tagForBOff )
76  << " with size: "<< iov.loadedSize()
77  << ", IOV valid for run number " << m_run << " starting from: " << currentIov.since
78  << ", with corresponding payload hash: " << currentIov.payloadId
79  << std::endl;
80  std::string destTag = this->tagInfo().name;
81  if( currentIov.payloadId != this->tagInfo().lastPayloadToken ) {
82  std::ostringstream ss;
83  ss << "Adding iov with since "<<m_run<<" pointing to hash " << currentIov.payloadId
84  << " corresponding to the calibrations for magnetic field "
85  << ( isBOn ? "ON" : "OFF" );
86  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
87  << ss.str() << std::endl;
89  if( session.existsIov( destTag ) ){
90  editor = session.editIov( destTag );
91  } else {
92  editor = session.createIov<T>( destTag, iov.timeType() );
93  editor.setDescription( "Tag created by PopConBTransitionSourceHandler" );
94  }
95  editor.insert( m_run, currentIov.payloadId );
96  editor.flush();
97  this->m_userTextLog = ss.str();
98  } else {
99  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
100  << "The payload with hash " << currentIov.payloadId
101  << " corresponding to the calibrations for magnetic field "
102  << ( isBOn ? "ON" : "OFF" )
103  << " is still valid for run " << m_run
104  << " in the destination tag " << destTag
105  << ".\nNo transfer needed." <<std::endl;
106  }
107  trans.close();
108  }
109 
110  void getNewObjects() final {
111  //check whats already inside of database
112  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
113  << "Destination Tag Info: name " << this->tagInfo().name
114  << ", size " << this->tagInfo().size
115  << ", last object valid since " << this->tagInfo().lastInterval.first
116  << ", hash " << this->tagInfo().lastPayloadToken << std::endl;
117  //check if a transfer is needed:
118  //if the new run number is smaller than or equal to the latest IOV, exit.
119  //This is needed as now the IOV Editor does not always protect for insertions:
120  //ANY and VALIDATION sychronizations are allowed to write in the past.
121  if( this->tagInfo().size > 0 && this->tagInfo().lastInterval.first >= m_run ) {
122  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
123  << "last IOV " << this->tagInfo().lastInterval.first
124  << ( this->tagInfo().lastInterval.first == m_run ? " is equal to" : " is larger than" )
125  << " the run proposed for insertion " << m_run
126  << ". No transfer needed." << std::endl;
127  return;
128  }
129  bool isBOn = checkBOn();
130  getObjectsForBTransition( isBOn );
131  edm::LogInfo( "PopConBTransitionSourceHandler" ) << "[" << "PopConBTransitionSourceHandler::" << __func__ << "]: "
132  << "END." << std::endl;
133  }
134 
135  private:
136  unsigned long long m_run;
138  // for reading from CondDB the current from RunInfo
140  // for reading from CondDB the 0T and 3.8T payloads
146  };
147 } //namespace popcon
148 
149 #endif //PopConBTransitionSourceHandler_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
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:218
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
PopConBTransitionSourceHandler(edm::ParameterSet const &pset)
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.
long double T
cond::TagInfo_t const & tagInfo() const