4 Example script to test reading from local sqlite db. 6 from __future__
import print_function
11 import multiprocessing
12 import CondCore.Utilities.conddblib
as conddb
16 'frontier://PromptProd/CMS_CONDITIONS' :
'pro',
17 'frontier://FrontierProd/CMS_CONDITIONS' :
'pro',
18 'frontier://FrontierArc/CMS_CONDITIONS' :
'arc',
19 'frontier://FrontierInt/CMS_CONDITIONS' :
'int',
20 'frontier://FrontierPrep/CMS_CONDITIONS' :
'dev' 26 """This function executes `command` and returns it output. 28 - `command`: Shell command to be invoked by this function. 31 child = os.popen(command)
35 raise Exception(
'%s failed w/ exit code %d' % (command, err))
41 """Retrieve the list of IOVs from `db` for `tag`. 44 - `db`: database connection string 45 - `tag`: tag of database record 50 if db
in officialdbs.keys():
54 db = db.replace(
"sqlite_file:",
"").
replace(
"sqlite:",
"")
56 con = conddb.connect(url = conddb.make_url(db))
57 session = con.session()
58 IOV = session.get_dbtype(conddb.IOV)
60 iovs = set(session.query(IOV.since).
filter(IOV.tag_name == tag).
all())
62 print(
"No IOVs found for tag '"+tag+
"' in database '"+db+
"'.")
67 return sorted([
int(item[0])
for item
in iovs])
73 command =
'conddb --yes --db %s copy %s --destdb %s --from %s --to %s' % (blob[4],
75 blob[5]+
"_IOV_"+
str(blob[2])+
".db",
81 command =
'conddb --yes --db %s copy %s --destdb %s --from %s' % (blob[4],
83 blob[5]+
"_IOV_"+
str(blob[2])+
".db",
88 cmsRunCommand=
'cmsRun $CMSSW_BASE/src/CondTools/HLT/test/AlCaRecoTriggerBitsRcdUpdate_TEMPL_cfg.py \ 89 inputDB=%s inputTag=%s outputDB=%s outputTag=%s firstRun=%s' % (
"sqlite_file:"+blob[5]+
"_IOV_"+
str(blob[2])+
".db",
91 "sqlite_file:"+blob[5]+
"_IOV_"+
str(blob[2])+
"_updated.db",
100 defaultDB =
'sqlite_file:mySqlite.db' 101 defaultInTag =
'myInTag' 102 defaultOutTag =
'myOutTag' 105 parser = optparse.OptionParser(usage =
'Usage: %prog [options] <file> [<file> ...]\n')
106 parser.add_option(
'-f',
'--inputDB',
109 help =
'file to inspect')
110 parser.add_option(
'-i',
'--inputTag',
112 default = defaultInTag,
113 help =
'tag to be inspected')
114 parser.add_option(
'-d',
'--destTag',
116 default = defaultOutTag,
117 help =
'tag to be written')
118 parser.add_option(
'-p',
'--processes',
120 default = defaultProc,
121 help =
'multiprocesses to run')
122 parser.add_option(
"-C",
'--clean',
123 dest=
"doTheCleaning",
126 help =
'if true remove the transient files')
128 (options, arguments) = parser.parse_args()
130 db_url = options.inputDB
131 if db_url
in officialdbs.keys():
132 db_url = officialdbs[db_url]
135 db_url = db_url.replace(
"sqlite_file:",
"").
replace(
"sqlite:",
"")
137 sinces =
get_iovs(options.inputDB,options.InputTag)
139 print(
"List of sinces: %s" % sinces)
143 for i,since
in enumerate(sinces):
146 myInputTuple.append((i,len(sinces)-1,sinces[i],sinces[i+1]-1,db_url,options.InputTag,options.destTag))
148 myInputTuple.append((i,len(sinces)-1,sinces[i],-1,db_url,options.InputTag,options.destTag))
150 pool = multiprocessing.Pool(processes=options.nproc)
151 count = pool.map(updateBits,myInputTuple)
154 for i,since
in enumerate(sinces):
155 mergeCommand=
'conddb --yes --db %s copy %s --destdb %s --from %s' % (options.InputTag+
"_IOV_"+
str(sinces[i])+
"_updated.db",
157 options.destTag+
".db",
162 if(options.doTheCleaning):
163 cleanCommand =
'rm -fr *updated*.db *IOV_*.db' 166 print(
"======> keeping the transient files")
168 if __name__ ==
"__main__":
def replace(string, replacements)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def getCommandOutput(command)
if(threadIdxLocalY==0 &&threadIdxLocalX==0)