1 from __future__
import print_function
2 from builtins
import range
10 import CondCore.Utilities.conddblib
as conddb
11 from functools
import reduce
16 """Create an sqlite file with single-IOV tags for alignment payloads. 19 - `inputs`: dictionary with input needed for payload extraction 20 - `run_number`: run for which the IOVs are selected 21 - `output_db`: name of the output sqlite file 25 for record,tag
in six.iteritems(inputs):
26 run_is_covered =
False 27 for iov
in reversed(tag[
"iovs"]):
29 tag[
"since"] =
str(iov)
32 if not run_is_covered:
33 msg = (
"Run number {0:d} is not covered in '{1:s}' ({2:s}) from" 34 " '{3:s}'.".
format(run_number, tag[
"tag"], record,
43 for record,tag
in six.iteritems(inputs):
44 result[record] = {
"connect":
"sqlite_file:"+output_db,
45 "tag":
"_".
join([tag[
"tag"], tag[
"since"]])}
47 if tag[
"connect"] ==
"pro":
48 source_connect =
"frontier://FrontierProd/CMS_CONDITIONS" 49 elif tag[
"connect"] ==
"dev":
50 source_connect =
"frontier://FrontierPrep/CMS_CONDITIONS" 52 source_connect = tag[
"connect"]
54 cmd = (
"conddb_import",
56 "-c", result[record][
"connect"],
58 "-t", result[record][
"tag"],
59 "-b",
str(run_number),
60 "-e",
str(run_number))
63 run_checked([
"sqlite3", output_db,
"update iov set since=1"])
69 """Run `cmd` and exit in case of failures. 72 - `cmd`: list containing the strings of the command 73 - `suppress_stderr`: suppress output from stderr 77 with open(os.devnull,
"w")
as devnull:
79 subprocess.check_call(cmd, stdout = devnull, stderr = devnull)
81 subprocess.check_call(cmd, stdout = devnull)
82 except subprocess.CalledProcessError
as e:
83 print(
"Problem in running the following command:")
89 """Returns cms.Process object defined in `cfg`. 92 - `cfg`: path to CMSSW config file 95 sys.path.append(os.path.dirname(cfg))
96 cache_stdout = sys.stdout
97 sys.stdout = open(os.devnull,
"w")
100 importlib.import_module(os.path.splitext(os.path.basename(cfg))[0])
101 except Exception
as e:
102 print(
"Problem detected in configuration file '{0}'.".
format(cfg))
104 sys.stdout = cache_stdout
109 if e.args == (2,
"No such file or directory"):
pass 112 return __configuration.process
116 """Derive unique run ranges from AlignmentProducer PSet. 119 - `ali_producer`: cms.PSet containing AlignmentProducer configuration 122 if (hasattr(ali_producer,
"RunRangeSelection")
and 123 len(ali_producer.RunRangeSelection) > 0):
125 for sel
in ali_producer.RunRangeSelection
126 for iov
in sel.RunRanges])
127 if len(iovs) == 0:
return [1]
134 """Get tags for `records` contained in `global_tag`. 137 - `global_tag`: global tag of interest 138 - `records`: database records of interest 141 if len(records) == 0:
return {}
144 if global_tag.startswith(
"auto:"):
147 global_tag = AC.autoCond[global_tag.split(
"auto:")[-1]]
149 print(
"Unsupported auto GT:", global_tag)
153 con = conddb.connect(url = conddb.make_url())
154 session = con.session()
155 GlobalTagMap = session.get_dbtype(conddb.GlobalTagMap)
158 tags = session.query(GlobalTagMap.record, GlobalTagMap.tag_name).\
159 filter(GlobalTagMap.global_tag_name == global_tag,
160 GlobalTagMap.record.in_(records)).
all()
165 return {item[0]: {
"tag": item[1],
"connect":
"pro"}
for item
in tags}
169 """Retrieve the list of IOVs from `db` for `tag`. 172 - `db`: database connection string 173 - `tag`: tag of database record 176 db = db.replace(
"sqlite_file:",
"").
replace(
"sqlite:",
"")
177 db = db.replace(
"frontier://FrontierProd/CMS_CONDITIONS",
"pro")
178 db = db.replace(
"frontier://FrontierPrep/CMS_CONDITIONS",
"dev")
180 con = conddb.connect(url = conddb.make_url(db))
181 session = con.session()
182 IOV = session.get_dbtype(conddb.IOV)
184 iovs = set(session.query(IOV.since).
filter(IOV.tag_name == tag).
all())
186 print(
"No IOVs found for tag '"+tag+
"' in database '"+db+
"'.")
191 return sorted([
int(item[0])
for item
in iovs])
195 """Takes a `product_string` and replaces all factors with `name` by `value`. 198 - `product_string`: input string containing a product 199 - `name`: name of the factor 200 - `value`: value of the factor 204 return re.sub(
r"^"+name+
r"$", value,
205 re.sub(
r"[*]"+name+
r"$",
r"*"+value,
206 re.sub(
r"^"+name+
r"[*]", value+
r"*",
207 re.sub(
r"[*]"+name+
r"[*]",
r"*"+value+
r"*",
211 """Takes `product_string` and returns the product of the factors as string. 214 - `product_string`: string containing product ('<factor>*<factor>*...') 217 factors = [
float(f)
for f
in product_string.split(
"*")]
218 return str(reduce(
lambda x,y: x*y, factors))
222 """Check if GRID proxy has been initialized.""" 225 with open(os.devnull,
"w")
as dump:
226 subprocess.check_call([
"voms-proxy-info",
"--exists"],
227 stdout = dump, stderr = dump)
228 except subprocess.CalledProcessError:
235 Tries to remove file or directory located at `path`. If the user 236 has no delete permissions, the object is moved to a backup 237 file. If this fails it tries 5 times in total and then asks to 238 perform a cleanup by a user with delete permissions. 241 - `name`: name of the object to be (re)moved 244 if os.path.exists(path):
245 remove_method = shutil.rmtree
if os.path.isdir(path)
else os.remove
246 move_method = shutil.move
if os.path.isdir(path)
else os.rename
250 if e.args != (13,
"Permission denied"):
raise 251 backup_path = path.rstrip(
"/")+
"~" 254 if os.path.exists(backup_path): remove_method(backup_path)
255 move_method(path, backup_path)
258 if e.args != (13,
"Permission denied"):
raise 260 if os.path.exists(path):
261 msg = (
"Cannot remove '{}' due to missing 'delete' ".
format(path)
262 +
"permissions and the limit of 5 backups is reached. Please " 263 "ask a user with 'delete' permissions to clean up.")
def replace(string, replacements)
S & print(S &os, JobReport::InputFile const &f)
static std::string join(char **cmd)