12 Script to upload local database to ConditionsDB.
14 This script takes a local database file and will upload all payloads defined in
15 this file to the ConditionsDB and create iovs for each payload. It assumes that
16 all tags already exist.
20 from basf2
import B2ERROR, LogLevel, logging
21 from conditions_db
import file_checksum
26 """Class to keep information about an entry in the testing payloads storage file"""
29 """Create new entry from line in testing payloads storage file"""
31 name, revision, iov = line.split()
33 raise ValueError(
"line must be of the form 'dbstore/<payloadname> <revision> "
34 "<firstExp>,<firstRun>,<finalExp>,<finalRun>'")
41 self.
modulemodule = name.split(
"/")[1]
43 raise ValueError(
"payload name must be of the form dbstore/<payloadname>")
46 iov = [int(e)
for e
in iov.split(
",")]
48 raise ValueError(
"experiment and run numbers must be integers")
51 raise ValueError(
"IoV needs to be four values (firstExp,firstRun,finalExp,finalRun)")
54 self.
filenamefilename = os.path.join(basedir, f
"dbstore_{self.module}_rev_{self.revision}.root")
56 self.
firstRunfirstRun = {
"exp": iov[0],
"run": iov[1]}
58 self.
finalRunfinalRun = {
"exp": iov[2],
"run": iov[3]}
69 """Normalize the root file to have the same checksum for the same content"""
70 normalize_file(self.
filenamefilename, in_place=
True, name=name, root_version=root_version)
75 """Return checksum, calculated on first access"""
81 """Convert to useful string representation"""
85 """Compare to other entries, only consider package, module and iov for equality"""
86 return self.
__id__id == other.__id
89 """Compare to other entries, only consider package, module and iov for equality"""
90 return self.
__id__id <= other.__id
93 """Compare to other entries, only consider package, module and iov for equality"""
94 return self.
__id__id < other.__id
97 """Provide hash function to be able to create a set"""
98 return hash(self.
__id__id)
102 """Return a tuple with the valid exp,run range"""
106 """String representation of IoV"""
107 return f
"{self.firstRun['exp']}/{self.firstRun['run']} - {self.finalRun['exp']}/{self.finalRun['run']}"
110 def parse_testing_payloads_file(filename, check_existing=True):
112 Parse a testing payload storage file
114 This is the python equivalent of TestingPayloadStorage::read implemented in
115 python. Each line in in the file should be of the form
117 "dbstore/{payloadname} {revision} {firstExp},{firstRun},{finalExp},{finalRun}"
119 Comments can be started using "#", everything including this character to
120 the end of the line will be ignored.
123 filename (str): filename of the testing payload storage file to parse
124 check_existing (bool): if True check if the payloads actually exist where
128 a list of TestingPayloadEntry objects or None if there were any errors
132 if not os.path.exists(filename):
133 B2ERROR(
"Given database file does not exist")
137 payload_dir = os.path.dirname(filename)
141 old_error_count = logging.log_stats[LogLevel.ERROR]
143 with open(filename)
as dbfile:
144 for lineno, line
in enumerate(dbfile, 1):
146 line = line.split(
"#", 1)[0].strip()
153 except ValueError
as e:
154 B2ERROR(
"{filename}:{line} error: {error}".format(
155 filename=filename, line=lineno, error=e
159 if check_existing
and not os.path.exists(entry.filename):
160 B2ERROR(
"{filename}:{line} error: cannot find payload file {missing}".format(
161 filename=filename, line=lineno, missing=entry.filename
165 entries.append(entry)
168 if logging.log_stats[LogLevel.ERROR] > old_error_count:
finalRun
experiment/run of the final run
firstRun
experiment/run of the first run
def __init__(self, line, basedir)
def normalize(self, name=None, root_version=61408)
__checksum
variable for checksum, calculated on first access
payload
payload id, to be filled later
revision
revision stored in the file
iov
iov id, to be filled later
__id
object to uniquely identify this entry (payload + iov)