Skip to content

Commit

Permalink
Fix for popcon re-worked
Browse files Browse the repository at this point in the history
  • Loading branch information
ggovi authored and smuzaffar committed Mar 9, 2018
1 parent 8176607 commit 1c5d8cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
29 changes: 16 additions & 13 deletions CondCore/Utilities/python/popcon2dropbox.py
Expand Up @@ -8,10 +8,6 @@
import logging
from datetime import datetime

dbName = datetime.datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S-%f')
dbFileName = '%s.db' %dbName
dbFileForDropBox = dbFileName
dbLogFile = '%s_log.db' %dbName
errorInImportFileFolder = 'import_errors'
dateformatForFolder = "%y-%m-%d-%H-%M-%S"
dateformatForLabel = "%y-%m-%d %H:%M:%S"
Expand All @@ -32,7 +28,8 @@
consoleHandler.setFormatter(logFormatter)
logger.addHandler(consoleHandler)

def checkFile():
def checkFile( dbName ):
dbFileName = '%s.db' %dbName
# check if the expected input file is there...
# exit code < 0 => error
# exit code = 0 => skip
Expand All @@ -58,7 +55,7 @@ def checkFile():
logger.error('Check on input data failed: %s' %str(e))
return -2

def saveFileForImportErrors( datef, withMetadata=False ):
def saveFileForImportErrors( datef, dbName, withMetadata=False ):
# save a copy of the files in case of upload failure...
leafFolderName = datef.strftime(dateformatForFolder)
fileFolder = os.path.join( errorInImportFileFolder, leafFolderName)
Expand All @@ -75,7 +72,7 @@ def saveFileForImportErrors( datef, withMetadata=False ):
shutil.copy2(df, metadataDestFile)
logger.error("Upload failed. Data file and metadata saved in folder '%s'" %os.path.abspath(fileFolder))

def upload( args ):
def upload( args, dbName ):
destDb = args.destDb
destTag = args.destTag
comment = args.comment
Expand Down Expand Up @@ -114,14 +111,15 @@ def upload( args ):
print stdout
retCode = pipe.returncode
if retCode != 0:
saveFileForImportErrors( datef, True )
saveFileForImportErrors( datef, dbName, True )
ret |= retCode
except Exception as e:
ret |= 1
logger.error(str(e))
return ret

def copy( args ):
def copy( args, dbName ):
dbFileName = '%s.db' %dbName
destDb = args.destDb
destTag = args.destTag
comment = args.comment
Expand All @@ -144,14 +142,18 @@ def copy( args ):
print stdout
retCode = pipe.returncode
if retCode != 0:
saveFileForImportErrors( datef )
saveFileForImportErrors( datef, dbName )
ret = retCode
except Exception as e:
ret = 1
logger.error( str(e) )
return ret

def run( args ):

dbName = datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S-%f')
dbFileName = '%s.db' %dbName

if args.auth is not None and not args.auth=='':
if auth_path_key in os.environ:
logger.warning("Cannot set authentication path to %s in the environment, since it is already set." %args.auth)
Expand All @@ -164,6 +166,7 @@ def run( args ):
if os.path.exists( '%s.txt' %dbName ):
os.remove( '%s.txt' %dbName )
command = 'cmsRun %s ' %args.job_file
command += ' targetFile=%s' %dbFileName
command += ' destinationDatabase=%s' %args.destDb
command += ' destinationTag=%s' %args.destTag
command += ' 2>&1'
Expand All @@ -176,11 +179,11 @@ def run( args ):
logger.error( 'O2O job failed. Skipping upload.' )
return retCode

ret = checkFile()
ret = checkFile( dbName )
if ret < 0:
return ret
elif ret == 0:
return 0
if args.copy:
return copy( args )
return upload( args )
return copy( args, dbName )
return upload( args, dbName )
8 changes: 6 additions & 2 deletions CondCore/Utilities/python/popcon2dropbox_job_conf.py
Expand Up @@ -3,6 +3,11 @@
import popcon2dropbox

options = VarParsing.VarParsing()
options.register('targetFile',
'popcon.db',
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"the target sqlite file name")
options.register('destinationDatabase',
'',
VarParsing.VarParsing.multiplicity.singleton,
Expand All @@ -23,11 +28,10 @@ def setup_popcon( recordName, tagTimeType ):
)
)

sqliteConnect = 'sqlite:%s' %popcon2dropbox.dbFileForDropBox
sqliteConnect = 'sqlite:%s' %options.targetFile
process = cms.Process("PopCon")
process.load("CondCore.CondDB.CondDB_cfi")
process.CondDB.DBParameters.messageLevel = cms.untracked.int32( 3 )
#process.CondDB.connect = 'sqlite:%s' %popcon2dropbox.dbFileForDropBox

process.PoolDBOutputService = cms.Service("PoolDBOutputService",
DBParameters = cms.PSet( messageLevel = cms.untracked.int32( 3 ),
Expand Down

0 comments on commit 1c5d8cf

Please sign in to comment.