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 26 of file HcalO2OManager.h.

Constructor & Destructor Documentation

HcalO2OManager::HcalO2OManager ( )

Definition at line 41 of file HcalO2OManager.cc.

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

42 {
44 }
static PluginManager & configure(const Config &)
PluginManager::Config config()
Definition: standard.cc:22
HcalO2OManager::~HcalO2OManager ( )
virtual

Definition at line 47 of file HcalO2OManager.cc.

48 {
49 }

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 240 of file HcalO2OManager.cc.

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

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

Definition at line 203 of file HcalO2OManager.cc.

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

203  {
204  std::vector<uint32_t> omds, orcon, out;
205  orcon.push_back(1);
206  orcon.push_back(100);
207  //orcon.push_back(80000);
208  //orcon.push_back(90000);
209  //orcon.push_back(100000);
210  //orcon.push_back(199000);
211  //orcon.push_back(199001);
212  //orcon.push_back(199002);
213  //orcon.push_back(199003);
214  omds.push_back(1);
215  omds.push_back(100);
216  //omds.push_back(80000);
217  //omds.push_back(90000);
218  //omds.push_back(100000);
219  //omds.push_back(199000);
220  //omds.push_back(199001);
221  //omds.push_back(199002);
222  //omds.push_back(199004);
223  if (getListOfNewIovs(out, omds, orcon) == -1){
224  std::cout << "HcalO2OManager::getListOfNewIovs_test(): O2O is not possible" << std::endl;
225  }
226  else if (getListOfNewIovs(out, omds, orcon) == 0){
227  std::cout << "HcalO2OManager::getListOfNewIovs_test(): O2O is not needed, the tag is up to date" << std::endl;
228  }
229  else{
230  std::cout << "HcalO2OManager::getListOfNewIovs_test(): O2O is possible" << std::endl;
231  std::cout << "HcalO2OManager::getListOfNewIovs_test(): " << out.size() << " IOVs to be copied to ORCON" << std::endl;
232  std::copy (out.begin(),
233  out.end(),
234  std::ostream_iterator<uint32_t>(std::cout,"\n")
235  );
236  }
237 }
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 160 of file HcalO2OManager.cc.

References dtNoiseDBValidation_cfg::cerr, results_mgr::conn, ConnectionManager::connect(), ConnectionManager::disconnect(), alignCSCRings::e, ConnectionManager::getStatement(), o2o::query, and toString().

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

Definition at line 131 of file HcalO2OManager.cc.

References lumiTag::alltags, dtNoiseDBValidation_cfg::cerr, results_mgr::conn, ConnectionManager::connect(), ConnectionManager::disconnect(), alignCSCRings::e, ConnectionManager::getStatement(), o2o::query, and toString().

131  {
132  std::vector<std::string> alltags;
133  static ConnectionManager conn;
134  conn.connect();
135  std::string query = "select ";
136  query += " channel_map_id,subdet,ieta,iphi,depth ";
137  query += "from ";
138  query += " cms_hcl_hcal_cond.hcal_channels ";
139  query += "where ";
140  query += " subdet='HB' or subdet='HE' or subdet='HF' or subdet='HO' ";
141  int _n_tags = 0;
142  try {
143  oracle::occi::Statement* stmt = conn.getStatement(query);
144  oracle::occi::ResultSet *rs = stmt->executeQuery();
145  while (rs->next()) {
146  _n_tags++;
147  //alltags.push_back(rs->getString(1));
148  }
149  }
150  catch (SQLException& e) {
151  std::cerr << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
152  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()));
153  }
154  conn.disconnect();
155  return alltags;
156 }
oracle::occi::Statement * getStatement(const std::string &query)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
std::string toString(const std::pair< T, T > &aT)
Definition: CaloEllipse.h:72
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
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 86 of file HcalO2OManager.cc.

References cond::IOVProxy::begin(), cond::DbScopedTransaction::commit(), cond::DbConnection::configuration(), cond::DbConnection::configure(), results_mgr::conn, 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(), and cms::Exception::what().

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

54  {
55  //edmplugin::PluginManager::configure(edmplugin::standard::config()); // in the constructor for now
56  //
57  // FIXME: how to add auth_path authentication to this? See v1.25 for the functionality using old API
58  std::cout << "===> WARNING! auth_path is specified as " << auth_path;
59  std::cout << " but is not used explicitely. Is it being used at all?" << std::endl;
61  //conn.configure( cond::CmsDefaults );
62  conn.configuration().setAuthenticationPath(auth_path);
63  //conn.configuration().setMessageLevel( coral::Debug );
64  conn.configure();
66  session.open(connect);
67  std::vector<std::string> alltags;
68  try{
69  cond::MetaData metadata_svc(session);
70  cond::DbScopedTransaction tr(session);
71  tr.start(true);
72  metadata_svc.listAllTags(alltags);
73  tr.commit();
74  }catch(cond::Exception& er){
75  std::cout<<er.what()<<std::endl;
76  }catch(std::exception& er){
77  std::cout<<er.what()<<std::endl;
78  }
79  return alltags;
80 }
virtual char const * what() const
Definition: Exception.cc:141
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:144
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:89
DbSession createSession() const
Definition: DbConnection.cc:72
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 361 of file HcalO2OManager.cc.

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

365  {
366  //std::cout << "DEBUG: " << pool_connect_string << std::endl;
367  std::vector<uint32_t> omds_iovs;
368  std::vector<uint32_t> pool_iovs;
369  getListOfOmdsIovs(omds_iovs, _tag);
370  getListOfPoolIovs(pool_iovs, _tag, pool_connect_string, pool_auth_path);
371  int n_iovs = getListOfNewIovs(_iovs,
372  omds_iovs,
373  pool_iovs);
374  if (n_iovs == -1){
375  std::cout << "HcalO2OManager: O2O is not possible" << std::endl;
376  }
377  else if (n_iovs == 0){
378  std::cout << "HcalO2OManager: O2O is not needed, the tag is up to date" << std::endl;
379  }
380  else{
381  edm::LogInfo("HcalO2OManager") << "These IOVs are to be updated:" << std::endl;
382  for (std::vector<uint32_t>::const_iterator iov = _iovs.begin();
383  iov != _iovs.end();
384  ++iov){
385  std::cout << "O2O_IOV_LIST: " << *iov << std::endl;
386  }
387  }
388  return n_iovs;
389 }
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