Skip to content

Commit

Permalink
Merge pull request #17851 from ggovi/condcore-fixes-0-91X
Browse files Browse the repository at this point in the history
Various fixes: conddb core, conddb tools, runinfo o2o
  • Loading branch information
cmsbuild committed Mar 9, 2017
2 parents d6d088f + a1b7803 commit 8fe3aa1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CondCore/CondDB/src/DbCore.h
Expand Up @@ -591,7 +591,7 @@ namespace cond {
}

void flush(){
m_coralInserter->flush();
if( m_coralInserter.get() ) m_coralInserter->flush();
}
private:
// fixme
Expand Down
34 changes: 15 additions & 19 deletions CondCore/Utilities/python/conddblib.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand All @@ -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:<schema>" (and not a url like proto://...), if so, disentangle
database, schema = database.split(':')
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion CondCore/Utilities/scripts/conddb
Expand Up @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions CondTools/RunInfo/src/RunInfoRead.cc
Expand Up @@ -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
Expand Down

0 comments on commit 8fe3aa1

Please sign in to comment.