5 Script to upload local database to ConditionsDB.
7 This script takes a local database file and will upload all payloads defined in
8 this file to the ConditionsDB and create iovs for each payload. It assumes that
9 all tags already exist.
13 from basf2
import B2ERROR, LogLevel, logging
14 from .
import file_checksum
19 """Class to keep information about an entry in the testing payloads storage file"""
22 """Create new entry from line in testing payloads storage file"""
24 name, revision, iov = line.split()
26 raise ValueError(
"line must be of the form 'dbstore/<payloadname> <revision> "
27 "<firstExp>,<firstRun>,<finalExp>,<finalRun>'")
32 raise ValueError(
"revision must be an integer")
38 raise ValueError(
"payload name must be of the form dbstore/<payloadname>")
41 iov = [int(e)
for e
in iov.split(
",")]
43 raise ValueError(
"experiment and run numbers must be integers")
46 raise ValueError(
"IoV needs to be four values (firstExp,firstRun,finalExp,finalRun)")
49 self.
filename = os.path.join(basedir, f
"dbstore_{self.module}_rev_{self.revision}.root")
64 """Normalize the root file to have the same checksum for the same content"""
65 normalize_file(self.
filename, in_place=
True, name=name, root_version=root_version)
70 """Return checksum, calculated on first access"""
76 """Convert to useful string representation"""
80 """Compare to other entries, only consider package, module and iov for equality"""
81 return self.
__id == other.__id
84 """Compare to other entries, only consider package, module and iov for equality"""
85 return self.
__id <= other.__id
88 """Compare to other entries, only consider package, module and iov for equality"""
89 return self.
__id < other.__id
92 """Provide hash function to be able to create a set"""
93 return hash(self.
__id)
97 """Return a tuple with the valid exp,run range"""
101 """String representation of IoV"""
102 return f
"{self.firstRun['exp']}/{self.firstRun['run']} - {self.finalRun['exp']}/{self.finalRun['run']}"
105 def parse_testing_payloads_file(filename, check_existing=True):
107 Parse a testing payload storage file
109 This is the python equivalent of TestingPayloadStorage::read implemented in
110 python. Each line in in the file should be of the form
112 "dbstore/{payloadname} {revision} {firstExp},{firstRun},{finalExp},{finalRun}"
114 Comments can be started using "#", everything including this character to
115 the end of the line will be ignored.
118 filename (str): filename of the testing payload storage file to parse
119 check_existing (bool): if True check if the payloads actually exist where
123 a list of TestingPayloadEntry objects or None if there were any errors
127 if not os.path.exists(filename):
128 B2ERROR(
"Given database file does not exist")
132 payload_dir = os.path.dirname(filename)
136 old_error_count = logging.log_stats[LogLevel.ERROR]
138 with open(filename)
as dbfile:
139 for lineno, line
in enumerate(dbfile, 1):
141 line = line.split(
"#", 1)[0].strip()
148 except ValueError
as e:
149 B2ERROR(
"{filename}:{line} error: {error}".format(
150 filename=filename, line=lineno, error=e
154 if check_existing
and not os.path.exists(entry.filename):
155 B2ERROR(
"{filename}:{line} error: cannot find payload file {missing}".format(
156 filename=filename, line=lineno, missing=entry.filename
160 entries.append(entry)
163 if logging.log_stats[LogLevel.ERROR] > old_error_count: