From a1b7803c16eb5423589f04afa2f816060959e464 Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Thu, 9 Mar 2017 12:20:26 +0100 Subject: [PATCH] Various fixes: conddb core, conddb tools, runinfo o2o --- CondCore/CondDB/src/DbCore.h | 2 +- CondCore/Utilities/python/conddblib.py | 34 ++++++++++++-------------- CondCore/Utilities/scripts/conddb | 2 +- CondTools/RunInfo/src/RunInfoRead.cc | 7 +++--- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/CondCore/CondDB/src/DbCore.h b/CondCore/CondDB/src/DbCore.h index 7bf3b8c8f4cd4..59c89bda795d2 100644 --- a/CondCore/CondDB/src/DbCore.h +++ b/CondCore/CondDB/src/DbCore.h @@ -591,7 +591,7 @@ namespace cond { } void flush(){ - m_coralInserter->flush(); + if( m_coralInserter.get() ) m_coralInserter->flush(); } private: // fixme diff --git a/CondCore/Utilities/python/conddblib.py b/CondCore/Utilities/python/conddblib.py index 8ca2c26f88d58..b568dfb9d7952 100644 --- a/CondCore/Utilities/python/conddblib.py +++ b/CondCore/Utilities/python/conddblib.py @@ -300,17 +300,13 @@ class TagLog: # CondDB object class Connection(object): - def __init__(self, url, init=False): + def __init__(self, url): # Workaround to avoid creating files if not present. # Python's sqlite3 module does not use sqlite3_open_v2(), # and therefore we cannot disable SQLITE_OPEN_CREATE. # Only in the case of creating a new database we skip the check. if url.drivername == 'sqlite': - #if not init and url.database is not None and not os.path.isfile(url.database): - # # url.database is None if opening a in-memory DB, e.g. 'sqlite://' - # raise Exception('SQLite database %s not found.' % url.database) - self.engine = sqlalchemy.create_engine(url) enabled_foreign_keys = self.engine.execute('pragma foreign_keys').scalar() @@ -411,18 +407,17 @@ def init(self, drop=False): if drop: logging.debug('Dropping tables...') self.metadata.drop_all(self.engine) + self._is_valid = False else: - if self._is_valid: - raise Exception('Looks like the database is already a valid CMS Conditions one.') - - logging.debug('Creating tables...') - self.get_dbtype(Tag).__table__.create(bind = self.engine) - self.get_dbtype(Payload).__table__.create(bind = self.engine) - self.get_dbtype(IOV).__table__.create(bind = self.engine) - self.get_dbtype(TagLog).__table__.create(bind = self.engine) - self.get_dbtype(GlobalTag).__table__.create(bind = self.engine) - self.get_dbtype(GlobalTagMap).__table__.create(bind = self.engine) - self._is_valid = self.is_valid() + if not self._is_valid: + logging.debug('Creating tables...') + self.get_dbtype(Tag).__table__.create(bind = self.engine) + self.get_dbtype(Payload).__table__.create(bind = self.engine) + self.get_dbtype(IOV).__table__.create(bind = self.engine) + self.get_dbtype(TagLog).__table__.create(bind = self.engine) + self.get_dbtype(GlobalTag).__table__.create(bind = self.engine) + self.get_dbtype(GlobalTagMap).__table__.create(bind = self.engine) + self._is_valid = True # Connection helpers def _getCMSFrontierConnectionString(database): @@ -438,6 +433,8 @@ def _getCMSSQLAlchemyConnectionString(technology,service,schema_name): # Entry point def make_url(database='pro',read_only = True): + if database.startswith('sqlite:') or database.startswith('sqlite_file:'): + ignore, database = database.split(':',1) if ':' in database and '://' not in database: # check if we really got a shortcut like "pro:" (and not a url like proto://...), if so, disentangle database, schema = database.split(':') @@ -481,7 +478,7 @@ def make_url(database='pro',read_only = True): url = sqlalchemy.engine.url.make_url('sqlite:///%s' % database) return url -def connect(url, init=False, authPath=None, verbose=0): +def connect(url, authPath=None, verbose=0): '''Returns a Connection instance to the CMS Condition DB. See database_help for the description of the database parameter. @@ -505,7 +502,6 @@ def connect(url, init=False, authPath=None, verbose=0): if authPath is not None: authFile = os.path.join(authPath,'.netrc') if authFile is not None: - print 'url=%s host=%s username=%s' %(url,url.host,url.username) entryKey = url.host.lower()+"/"+url.username.lower() logging.debug('Looking up credentials for %s in file %s ' %(entryKey,authFile) ) import netrc @@ -531,7 +527,7 @@ def connect(url, init=False, authPath=None, verbose=0): if verbose >= 2: logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG) - return Connection(url, init=init) + return Connection(url) def _exists(session, primary_key, value): diff --git a/CondCore/Utilities/scripts/conddb b/CondCore/Utilities/scripts/conddb index 9e9044b6dad8e..fc198999da394 100755 --- a/CondCore/Utilities/scripts/conddb +++ b/CondCore/Utilities/scripts/conddb @@ -267,7 +267,7 @@ def _connect(db, init, read_only, args): connTo = '%s [%s]' %(db,pretty_url) logging.info('Connecting to %s', connTo) logging.debug('DB url: %s',url) - connection = conddb.connect(url, init=init, authPath=args.authPath, verbose=0 if args.verbose is None else args.verbose - 1) + connection = conddb.connect(url, authPath=args.authPath, verbose=0 if args.verbose is None else args.verbose - 1) if not read_only: diff --git a/CondTools/RunInfo/src/RunInfoRead.cc b/CondTools/RunInfo/src/RunInfoRead.cc index 21542fd755a3b..c79d3dd802cf5 100644 --- a/CondTools/RunInfo/src/RunInfoRead.cc +++ b/CondTools/RunInfo/src/RunInfoRead.cc @@ -117,10 +117,9 @@ RunInfoRead::readData( const std::string & runinfo_schema edm::LogInfo( "RunInfoReader" ) << osstart.str() << std::endl; } else { - edm::LogInfo( "RunInfoReader" ) << "[RunInfoRead::" << __func__ << "]: run " << r_number - << " start time not found." << std::endl; - temp_sum.m_start_time_str = "null"; - temp_sum.m_start_time_ll = -1; + std::stringstream errMsg; + errMsg << "[RunInfoRead::" << __func__ << "]: run " << r_number << " start time not found."; + throw std::runtime_error(errMsg.str()); } //new query to obtain the stop_time