CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions
HcalO2OManager Class Reference

#include <CaloOnlineTools/HcalOnlineDb/interface/HcalO2OManager.h>

Public Member Functions

int getListOfNewIovs (std::vector< uint32_t > &iovs, const std::vector< uint32_t > &omds_iovs, const std::vector< uint32_t > &orcon_iovs)
 
void getListOfNewIovs_test (void)
 
int getListOfOmdsIovs (std::vector< uint32_t > &out, std::string tagname)
 
std::vector< std::string > getListOfOmdsTags ()
 
int getListOfPoolIovs (std::vector< uint32_t > &out, std::string tagname, std::string connect, std::string auth_path)
 
std::vector< std::string > getListOfPoolTags (std::string connect, std::string auth_path)
 
int getListOfUpdateIovs (std::vector< uint32_t > &_iovs, std::string _tag, std::string pool_connect_string, std::string pool_auth_path)
 
 HcalO2OManager ()
 
virtual ~HcalO2OManager ()
 

Detailed Description

Description: Defines all logic of HCAL O2O transfers

Usage: <usage>

Definition at line 25 of file HcalO2OManager.h.

Constructor & Destructor Documentation

HcalO2OManager::HcalO2OManager ( )

Definition at line 44 of file HcalO2OManager.cc.

References edmplugin::standard::config(), and edmplugin::PluginManager::configure().

45 {
47 }
static PluginManager & configure(const Config &)
PluginManager::Config config()
Definition: standard.cc:21
HcalO2OManager::~HcalO2OManager ( )
virtual

Definition at line 50 of file HcalO2OManager.cc.

51 {
52 }

Member Function Documentation

int HcalO2OManager::getListOfNewIovs ( std::vector< uint32_t > &  iovs,
const std::vector< uint32_t > &  omds_iovs,
const std::vector< uint32_t > &  orcon_iovs 
)

Definition at line 243 of file HcalO2OManager.cc.

References Reconstruction_AftMix_cff::_index, gather_cfg::cout, and query::result.

245  {
246  int result = -1; // default fail
247  iovs.clear();
248 
249  // OMDS tag may not have the first IOV=1
250  int _orcon_index_offset = 0;
251  if (omds_iovs.size() > 0 &&
252  orcon_iovs.size() > 0 &&
253  orcon_iovs[0] == 1 &&
254  omds_iovs[0] != 1){
255  std::cout << std::endl << "HcalO2OManager: First IOV in the OMDS tag is not 1," << std::endl;
256  std::cout << "HcalO2OManager: while it must be 1 in the offline tag." << std::endl;
257  std::cout << "HcalO2OManager: O2O will assume that IOV=1 in the offline tag" << std::endl;
258  std::cout << "HcalO2OManager: is filled with some safe default." << std::endl;
259  std::cout << "HcalO2OManager: IOV=1 will be ignored, and O2O will proceeed" << std::endl;
260  std::cout << "HcalO2OManager: as long as other inconsistencies are not detected." << std::endl << std::endl;
261  _orcon_index_offset = 1; // skip the first IOV in ORCON because it
262  // // is 1 while OMDS doesn't have IOV=1
263  }
264  if (omds_iovs.size()+_orcon_index_offset < orcon_iovs.size()){
265  std::cout << "HcalO2OManager: too many IOVs in the Pool tag, cannot sync, exiting..." << std::endl;
266  return result;
267  }
268 
269  // loop over all OMDS IOVs
270  unsigned int _index = 0;
271 
272  bool enforce_strict_matching = false; // set to true if the strict IOV matching is desired, see description in the comments below
273 
274  for (std::vector<uint32_t>::const_iterator _iov = orcon_iovs.begin();
275  _iov != orcon_iovs.end();
276  ++_iov){
277  _index = (int)(_iov - orcon_iovs.begin());
278 
279  // special case when the first Pool IOV = 1 (must always be true)
280  // but OMDS IOVs do not start with IOV = 1
281  // This can be a ligitimate mismatch when the OMDS tag is created for
282  // current conditions without regard to the history
283  // In such cases, when creating a copy of this tag in offline,
284  // O2O copies the first IOV from OMDS and assigns it as IOV=1.
285  // With later sync passes, O2O must skip the first offline IOV = 1
286  if (_orcon_index_offset == 1 && _index == 0) continue;
287 
288  // current pair of OMDS-offline IOVs does not match
289  // There are several options in such case:
290  //
291  // - with strict matching, the program should quit, as it is not possible
292  // to keep the tag in sync between OMDS and offline because
293  // offline tags do not allow fixes, only updates
294  //
295  // - intermediate solution is to find the latest IOV in the offline tag
296  // and append any IOVs from the OMDS tag that come after it
297  //
298 
299  if (omds_iovs[_index-_orcon_index_offset] != orcon_iovs[_index]){
300 
301  std::cout << std::endl;
302  std::cout << "HcalO2OManager: existing IOVs do not match, cannot sync in the strict sense." << std::endl;
303  std::cout << "HcalO2OManager: mismatched pair is (OMDS/offline): " << omds_iovs[_index-_orcon_index_offset] << "/" << orcon_iovs[_index] << std::endl;
304  std::cout << "HcalO2OManager: In the strict sense, the SYNCHRONIZATION OF THIS TAG HAS FAILED!" << std::endl;
305  std::cout << "HcalO2OManager: As an interim solution, I will still copy to the offline tag" << std::endl;
306  std::cout << "HcalO2OManager: those IOV from the OMDS tag that are newer than the last IOV" << std::endl;
307  std::cout << "HcalO2OManager: currently in the offline tag. " << std::endl;
308 
309  // existing IOVs do not match
310 
311  if (enforce_strict_matching){
312  return result;
313  }
314  else{
315  break; // _index now contains the last "valid" OMDS IOV
316  }
317 
318  }
319  ++_index;
320  }
321 
322 
323  //
324  //_____ loop over remaining OMDS IOVs
325  //
326  //std::cout << "HcalO2OManager: DEBUG: " << std::endl;
327  int _counter = 0; // count output IOVs
328  uint32_t _lastOrconIov = orcon_iovs[orcon_iovs.size()-1];
329 
330  for (;_index < omds_iovs.size();++_index){
331 
332  uint32_t _aIov = omds_iovs[_index];
333 
334  if (_index == 0 && _aIov > _lastOrconIov){ // can only copy later IOVs
335  iovs.push_back(_aIov);
336  ++_counter;
337  }
338  else if (omds_iovs[_index]>omds_iovs[_index-1] &&
339  _aIov > _lastOrconIov){ // can only copy later IOVs
340  iovs.push_back(omds_iovs[_index]);
341  ++_counter;
342  }
343  else{
344  if (enforce_strict_matching){
345  return result;
346  }
347  else{
348  continue;
349  }
350  }
351  }
352  //if (_counter != 0) result = _counter;
353  result = _counter;
354  return result;
355 }
tuple result
Definition: query.py:137
int _index
the final reconstruction sequence
tuple cout
Definition: gather_cfg.py:121
void HcalO2OManager::getListOfNewIovs_test ( void  )

Definition at line 206 of file HcalO2OManager.cc.

References filterCSVwithJSON::copy, gather_cfg::cout, and dbtoconf::out.

206  {
207  std::vector<uint32_t> omds, orcon, out;
208  orcon.push_back(1);
209  orcon.push_back(100);
210  //orcon.push_back(80000);
211  //orcon.push_back(90000);
212  //orcon.push_back(100000);
213  //orcon.push_back(199000);
214  //orcon.push_back(199001);
215  //orcon.push_back(199002);
216  //orcon.push_back(199003);
217  omds.push_back(1);
218  omds.push_back(100);
219  //omds.push_back(80000);
220  //omds.push_back(90000);
221  //omds.push_back(100000);
222  //omds.push_back(199000);
223  //omds.push_back(199001);
224  //omds.push_back(199002);
225  //omds.push_back(199004);
226  if (getListOfNewIovs(out, omds, orcon) == -1){
227  std::cout << "HcalO2OManager::getListOfNewIovs_test(): O2O is not possible" << std::endl;
228  }
229  else if (getListOfNewIovs(out, omds, orcon) == 0){
230  std::cout << "HcalO2OManager::getListOfNewIovs_test(): O2O is not needed, the tag is up to date" << std::endl;
231  }
232  else{
233  std::cout << "HcalO2OManager::getListOfNewIovs_test(): O2O is possible" << std::endl;
234  std::cout << "HcalO2OManager::getListOfNewIovs_test(): " << out.size() << " IOVs to be copied to ORCON" << std::endl;
235  std::copy (out.begin(),
236  out.end(),
237  std::ostream_iterator<uint32_t>(std::cout,"\n")
238  );
239  }
240 }
int getListOfNewIovs(std::vector< uint32_t > &iovs, const std::vector< uint32_t > &omds_iovs, const std::vector< uint32_t > &orcon_iovs)
tuple out
Definition: dbtoconf.py:99
tuple cout
Definition: gather_cfg.py:121
int HcalO2OManager::getListOfOmdsIovs ( std::vector< uint32_t > &  out,
std::string  tagname 
)

Definition at line 163 of file HcalO2OManager.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, results_mgr::conn, ConnectionManager::connect(), ConnectionManager::disconnect(), alignCSCRings::e, ConnectionManager::getStatement(), o2o::query, AlCaHLTBitMon_QueryRunRegistry::string, and toolbox::toString().

163  {
164  out.clear();
165  static ConnectionManager conn;
166  conn.connect();
167  std::string query = " ";
168  //query += "select iov, ";
169  //query += " i.cond_iov_record_id, ";
170  //query += " time ";
171  //query += "from ( ";
172  query += " select iovs.interval_of_validity_begin as iov, ";
173  query += " min(iovs.record_insertion_time) time ";
174  query += " from cms_hcl_core_iov_mgmnt.cond_tags tags ";
175  query += " inner join cms_hcl_core_iov_mgmnt.cond_iov2tag_maps i2t ";
176  query += " on tags.cond_tag_id=i2t.cond_tag_id ";
177  query += " inner join cms_hcl_core_iov_mgmnt.cond_iovs iovs ";
178  query += " on i2t.cond_iov_record_id=iovs.cond_iov_record_id ";
179  query += "where ";
180  query += " tags.tag_name=:1 ";
181  query += "group by iovs.interval_of_validity_begin ";
182  //query += " ) ";
183  //query += "inner join cms_hcl_core_iov_mgmnt.cond_iovs i ";
184  //query += "on time=i.record_insertion_time ";
185  query += "order by time asc ";
186  int _n_iovs = 0;
187  try {
188  oracle::occi::Statement* stmt = conn.getStatement(query);
189  //_____ set bind variables
190  stmt->setString(1,tagname);
191  oracle::occi::ResultSet *rs = stmt->executeQuery();
192  while (rs->next()) {
193  _n_iovs++;
194  out.push_back(rs->getInt(1));
195  }
196  }
197  catch (SQLException& e) {
198  std::cerr << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
199  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()));
200  }
201  conn.disconnect();
202  return out.size();
203 }
oracle::occi::Statement * getStatement(const std::string &query)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4
tuple out
Definition: dbtoconf.py:99
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
tuple query
Definition: o2o.py:269
tuple conn
Definition: results_mgr.py:53
std::vector< std::string > HcalO2OManager::getListOfOmdsTags ( )

Definition at line 134 of file HcalO2OManager.cc.

References lumiTag::alltags, ecal_dqm_sourceclient-live_cfg::cerr, results_mgr::conn, ConnectionManager::connect(), ConnectionManager::disconnect(), alignCSCRings::e, ConnectionManager::getStatement(), o2o::query, AlCaHLTBitMon_QueryRunRegistry::string, and toolbox::toString().

134  {
135  std::vector<std::string> alltags;
136  static ConnectionManager conn;
137  conn.connect();
138  std::string query = "select ";
139  query += " channel_map_id,subdet,ieta,iphi,depth ";
140  query += "from ";
141  query += " cms_hcl_hcal_cond.hcal_channels ";
142  query += "where ";
143  query += " subdet='HB' or subdet='HE' or subdet='HF' or subdet='HO' ";
144  int _n_tags = 0;
145  try {
146  oracle::occi::Statement* stmt = conn.getStatement(query);
147  oracle::occi::ResultSet *rs = stmt->executeQuery();
148  while (rs->next()) {
149  _n_tags++;
150  //alltags.push_back(rs->getString(1));
151  }
152  }
153  catch (SQLException& e) {
154  std::cerr << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
155  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()));
156  }
157  conn.disconnect();
158  return alltags;
159 }
oracle::occi::Statement * getStatement(const std::string &query)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
tuple alltags
Definition: lumiTag.py:77
tuple query
Definition: o2o.py:269
tuple conn
Definition: results_mgr.py:53
int HcalO2OManager::getListOfPoolIovs ( std::vector< uint32_t > &  out,
std::string  tagname,
std::string  connect,
std::string  auth_path 
)

Definition at line 89 of file HcalO2OManager.cc.

References cond::IOVProxy::begin(), cond::DbScopedTransaction::commit(), cond::DbConnection::configuration(), cond::DbConnection::configure(), results_mgr::conn, counter, gather_cfg::cout, cond::DbConnection::createSession(), cond::IOVProxy::end(), cppFunctionSkipper::exception, cond::MetaData::getToken(), cond::MetaData::hasTag(), o2o::iov, cond::DbSession::open(), python.CommonUtils::session, cond::DbConnectionConfiguration::setAuthenticationPath(), cond::DbScopedTransaction::start(), AlCaHLTBitMon_QueryRunRegistry::string, and cms::Exception::what().

92  {
93  //edmplugin::PluginManager::configure(edmplugin::standard::config()); // in the constructor for now
94  // FIXME: how to add auth_path authentication to this? See v1.25 for the functionality using old API
95  std::cout << "===> WARNING! auth_path is specified as " << auth_path;
96  std::cout << " but is not used explicitely. Is it being used at all?" << std::endl;
98  //conn.configure( cond::CmsDefaults );
99  conn.configuration().setAuthenticationPath(auth_path);
100  //conn.configuration().setMessageLevel( coral::Debug );
101  conn.configure();
103  session.open(connect);
104  out.clear();
105  try{
106  cond::MetaData metadata_svc(session);
107  cond::DbScopedTransaction tr(session);
108  tr.start(true);
109  std::string token;
110  if(!metadata_svc.hasTag(tag)){
111  //std::cout << "no such tag in the Pool database!" << std::endl;
112  return -1;
113  }
114  token=metadata_svc.getToken(tag);
115  cond::IOVProxy iov(session, token);
116  unsigned int counter=0;
117 
118  for (cond::IOVProxy::const_iterator ioviterator=iov.begin(); ioviterator!=iov.end(); ioviterator++) {
119  out.push_back(ioviterator->since());
120  ++counter;
121  }
122  tr.commit();
123  }
124  catch(cond::Exception& er){
125  std::cout<<er.what()<<std::endl;
126  }catch(std::exception& er){
127  std::cout<<er.what()<<std::endl;
128  }
129  return out.size();
130 }
virtual char const * what() const
Definition: Exception.cc:141
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:159
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:83
tuple iov
Definition: o2o.py:307
tuple out
Definition: dbtoconf.py:99
DbSession createSession() const
Definition: DbConnection.cc:66
void setAuthenticationPath(const std::string &p)
static std::atomic< unsigned int > counter
tuple cout
Definition: gather_cfg.py:121
tuple conn
Definition: results_mgr.py:53
iov_range_iterator const_iterator
Definition: IOVProxy.h:160
std::vector< std::string > HcalO2OManager::getListOfPoolTags ( std::string  connect,
std::string  auth_path 
)

Definition at line 57 of file HcalO2OManager.cc.

References lumiTag::alltags, cond::DbScopedTransaction::commit(), cond::DbConnection::configuration(), cond::DbConnection::configure(), results_mgr::conn, gather_cfg::cout, cond::DbConnection::createSession(), cppFunctionSkipper::exception, cond::MetaData::listAllTags(), cond::DbSession::open(), python.CommonUtils::session, cond::DbConnectionConfiguration::setAuthenticationPath(), cond::DbScopedTransaction::start(), and cms::Exception::what().

57  {
58  //edmplugin::PluginManager::configure(edmplugin::standard::config()); // in the constructor for now
59  //
60  // FIXME: how to add auth_path authentication to this? See v1.25 for the functionality using old API
61  std::cout << "===> WARNING! auth_path is specified as " << auth_path;
62  std::cout << " but is not used explicitely. Is it being used at all?" << std::endl;
64  //conn.configure( cond::CmsDefaults );
65  conn.configuration().setAuthenticationPath(auth_path);
66  //conn.configuration().setMessageLevel( coral::Debug );
67  conn.configure();
69  session.open(connect);
70  std::vector<std::string> alltags;
71  try{
72  cond::MetaData metadata_svc(session);
73  cond::DbScopedTransaction tr(session);
74  tr.start(true);
75  metadata_svc.listAllTags(alltags);
76  tr.commit();
77  }catch(cond::Exception& er){
78  std::cout<<er.what()<<std::endl;
79  }catch(std::exception& er){
80  std::cout<<er.what()<<std::endl;
81  }
82  return alltags;
83 }
virtual char const * what() const
Definition: Exception.cc:141
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:159
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:83
DbSession createSession() const
Definition: DbConnection.cc:66
void setAuthenticationPath(const std::string &p)
tuple alltags
Definition: lumiTag.py:77
tuple cout
Definition: gather_cfg.py:121
tuple conn
Definition: results_mgr.py:53
int HcalO2OManager::getListOfUpdateIovs ( std::vector< uint32_t > &  _iovs,
std::string  _tag,
std::string  pool_connect_string,
std::string  pool_auth_path 
)

Definition at line 364 of file HcalO2OManager.cc.

References gather_cfg::cout, and o2o::iov.

368  {
369  //std::cout << "DEBUG: " << pool_connect_string << std::endl;
370  std::vector<uint32_t> omds_iovs;
371  std::vector<uint32_t> pool_iovs;
372  getListOfOmdsIovs(omds_iovs, _tag);
373  getListOfPoolIovs(pool_iovs, _tag, pool_connect_string, pool_auth_path);
374  int n_iovs = getListOfNewIovs(_iovs,
375  omds_iovs,
376  pool_iovs);
377  if (n_iovs == -1){
378  std::cout << "HcalO2OManager: O2O is not possible" << std::endl;
379  }
380  else if (n_iovs == 0){
381  std::cout << "HcalO2OManager: O2O is not needed, the tag is up to date" << std::endl;
382  }
383  else{
384  edm::LogInfo("HcalO2OManager") << "These IOVs are to be updated:" << std::endl;
385  for (std::vector<uint32_t>::const_iterator iov = _iovs.begin();
386  iov != _iovs.end();
387  ++iov){
388  std::cout << "O2O_IOV_LIST: " << *iov << std::endl;
389  }
390  }
391  return n_iovs;
392 }
int getListOfNewIovs(std::vector< uint32_t > &iovs, const std::vector< uint32_t > &omds_iovs, const std::vector< uint32_t > &orcon_iovs)
tuple iov
Definition: o2o.py:307
string pool_auth_path
Definition: o2o.py:29
int getListOfPoolIovs(std::vector< uint32_t > &out, std::string tagname, std::string connect, std::string auth_path)
int getListOfOmdsIovs(std::vector< uint32_t > &out, std::string tagname)
tuple cout
Definition: gather_cfg.py:121