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

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

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

Definition at line 48 of file HcalO2OManager.cc.

49 {
50 }

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 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  // use this to keep track of how well the existing OMDS and offline IOV sets match
275  unsigned int _sync_status = 0;
276  for (std::vector<uint32_t>::const_iterator _iov = orcon_iovs.begin();
277  _iov != orcon_iovs.end();
278  ++_iov){
279  _index = (int)(_iov - orcon_iovs.begin());
280 
281  // special case when the first Pool IOV = 1 (must always be true)
282  // but OMDS IOVs do not start with IOV = 1
283  // This can be a ligitimate mismatch when the OMDS tag is created for
284  // current conditions without regard to the history
285  // In such cases, when creating a copy of this tag in offline,
286  // O2O copies the first IOV from OMDS and assigns it as IOV=1.
287  // With later sync passes, O2O must skip the first offline IOV = 1
288  if (_orcon_index_offset == 1 && _index == 0) continue;
289 
290  // current pair of OMDS-offline IOVs does not match
291  // There are several options in such case:
292  //
293  // - with strict matching, the program should quit, as it is not possible
294  // to keep the tag in sync between OMDS and offline because
295  // offline tags do not allow fixes, only updates
296  //
297  // - intermediate solution is to find the latest IOV in the offline tag
298  // and append any IOVs from the OMDS tag that come after it
299  //
300 
301  if (omds_iovs[_index-_orcon_index_offset] != orcon_iovs[_index]){
302 
303  std::cout << std::endl;
304  std::cout << "HcalO2OManager: existing IOVs do not match, cannot sync in the strict sense." << std::endl;
305  std::cout << "HcalO2OManager: mismatched pair is (OMDS/offline): " << omds_iovs[_index-_orcon_index_offset] << "/" << orcon_iovs[_index] << std::endl;
306  std::cout << "HcalO2OManager: In the strict sense, the SYNCHRONIZATION OF THIS TAG HAS FAILED!" << std::endl;
307  std::cout << "HcalO2OManager: As an interim solution, I will still copy to the offline tag" << std::endl;
308  std::cout << "HcalO2OManager: those IOV from the OMDS tag that are newer than the last IOV" << std::endl;
309  std::cout << "HcalO2OManager: currently in the offline tag. " << std::endl;
310 
311  _sync_status = 1; // dunno what for, may be handy in future
312 
313  // existing IOVs do not match
314 
315  if (enforce_strict_matching){
316  return result;
317  }
318  else{
319  break; // _index now contains the last "valid" OMDS IOV
320  }
321 
322  }
323  ++_index;
324  }
325 
326 
327  //
328  //_____ loop over remaining OMDS IOVs
329  //
330  //std::cout << "HcalO2OManager: DEBUG: " << std::endl;
331  int _counter = 0; // count output IOVs
332  uint32_t _lastOrconIov = orcon_iovs[orcon_iovs.size()-1];
333 
334  for (;_index < omds_iovs.size();++_index){
335 
336  uint32_t _aIov = omds_iovs[_index];
337 
338  if (_index == 0 && _aIov > _lastOrconIov){ // can only copy later IOVs
339  iovs.push_back(_aIov);
340  ++_counter;
341  }
342  else if (omds_iovs[_index]>omds_iovs[_index-1] &&
343  _aIov > _lastOrconIov){ // can only copy later IOVs
344  iovs.push_back(omds_iovs[_index]);
345  ++_counter;
346  }
347  else{
348  if (enforce_strict_matching){
349  return result;
350  }
351  else{
352  continue;
353  }
354  }
355  }
356  //if (_counter != 0) result = _counter;
357  result = _counter;
358  return result;
359 }
tuple result
Definition: query.py:137
tuple cout
Definition: gather_cfg.py:41
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:41
int HcalO2OManager::getListOfOmdsIovs ( std::vector< uint32_t > &  out,
std::string  tagname 
)

Definition at line 163 of file HcalO2OManager.cc.

References benchmark_cfg::cerr, ConnectionManager::connect(), ConnectionManager::disconnect(), ConnectionManager::getStatement(), o2o::query, and 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: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
std::vector< std::string > HcalO2OManager::getListOfOmdsTags ( )

Definition at line 134 of file HcalO2OManager.cc.

References benchmark_cfg::cerr, ConnectionManager::connect(), ConnectionManager::disconnect(), ConnectionManager::getStatement(), o2o::query, and 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:22
std::string toString(const std::pair< T, T > &aT)
Definition: CaloEllipse.h:72
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
tuple query
Definition: o2o.py:269
int HcalO2OManager::getListOfPoolIovs ( std::vector< uint32_t > &  out,
std::string  tagname,
std::string  connect,
std::string  auth_path 
)

Definition at line 87 of file HcalO2OManager.cc.

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

90  {
91  //edmplugin::PluginManager::configure(edmplugin::standard::config()); // in the constructor for now
92  // FIXME: how to add auth_path authentication to this? See v1.25 for the functionality using old API
93  std::cout << "===> WARNING! auth_path is specified as " << auth_path;
94  std::cout << " but is not used explicitely. Is it being used at all?" << std::endl;
95  bool details=false;
96  cond::DbConnection conn;
97  //conn.configure( cond::CmsDefaults );
98  conn.configuration().setAuthenticationPath(auth_path);
99  //conn.configuration().setMessageLevel( coral::Debug );
100  conn.configure();
102  session.open(connect);
103  out.clear();
104  try{
105  cond::MetaData metadata_svc(session);
106  cond::DbScopedTransaction tr(session);
107  tr.start(true);
108  std::string token;
109  if(!metadata_svc.hasTag(tag)){
110  //std::cout << "no such tag in the Pool database!" << std::endl;
111  return -1;
112  }
113  token=metadata_svc.getToken(tag);
114  cond::IOVProxy iov(session, token, !details, details);
115  unsigned int counter=0;
116  std::string payloadContainer=iov.payloadContainerName();
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:97
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:119
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:89
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: IOVProxy.h:84
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 connect
process.AlignmentProducer.algoConfig.uvarFile = &#39;.
Definition: align_tpl.py:66
tuple cout
Definition: gather_cfg.py:41
std::vector< std::string > HcalO2OManager::getListOfPoolTags ( std::string  connect,
std::string  auth_path 
)

Definition at line 55 of file HcalO2OManager.cc.

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

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

Definition at line 368 of file HcalO2OManager.cc.

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

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