|
|
|
def | check_proxy () |
|
def | compute_product_string (product_string) |
|
def | create_single_iov_db (inputs, run_number, output_db) |
|
def | get_iovs (db, tag) |
|
def | get_process_object (cfg) |
|
def | get_tags (global_tag, records) |
|
def | getDatasetStr (datasetpath) |
|
def | getTerminalSize () |
|
def | haddLocal (localdir, result_file, extension='root') |
|
def | interrupt (signum, frame) |
|
def | listFilesLocal (paths, extension='.root') |
|
def | loadCmsProcess (psetPath) |
|
def | loadCmsProcessFile (psetName) |
|
def | make_unique_runranges (ali_producer) |
|
def | prependPaths (process, seqname) |
|
def | remove_existing_object (path) |
|
def | replace_factors (product_string, name, value) |
|
def | replaceTemplate (template, **opts) |
|
def | run_checked (cmd, suppress_stderr=False) |
|
def | stdinWait (text, default, time, timeoutDisplay=None, **kwargs) |
|
◆ check_proxy()
def tools.check_proxy |
( |
| ) |
|
Check if GRID proxy has been initialized.
Definition at line 220 of file tools.py.
221 """Check if GRID proxy has been initialized."""
224 with open(os.devnull,
"w")
as dump:
225 subprocess.check_call([
"voms-proxy-info",
"--exists"],
226 stdout = dump, stderr = dump)
227 except subprocess.CalledProcessError:
◆ compute_product_string()
def tools.compute_product_string |
( |
|
product_string | ) |
|
Takes `product_string` and returns the product of the factors as string.
Arguments:
- `product_string`: string containing product ('<factor>*<factor>*...')
Definition at line 209 of file tools.py.
210 """Takes `product_string` and returns the product of the factors as string.
213 - `product_string`: string containing product ('<factor>*<factor>*...')
216 factors = [
float(f)
for f
in product_string.split(
"*")]
217 return str(reduce(
lambda x,y: x*y, factors))
References dqmMemoryStats.float, and str.
◆ create_single_iov_db()
def tools.create_single_iov_db |
( |
|
inputs, |
|
|
|
run_number, |
|
|
|
output_db |
|
) |
| |
Create an sqlite file with single-IOV tags for alignment payloads.
Arguments:
- `inputs`: dictionary with input needed for payload extraction
- `run_number`: run for which the IOVs are selected
- `output_db`: name of the output sqlite file
Definition at line 14 of file tools.py.
15 """Create an sqlite file with single-IOV tags for alignment payloads.
18 - `inputs`: dictionary with input needed for payload extraction
19 - `run_number`: run for which the IOVs are selected
20 - `output_db`: name of the output sqlite file
24 for record,tag
in inputs.items():
25 run_is_covered =
False
26 for iov
in reversed(tag[
"iovs"]):
28 tag[
"since"] =
str(iov)
31 if not run_is_covered:
32 msg = (
"Run number {0:d} is not covered in '{1:s}' ({2:s}) from"
33 " '{3:s}'.".
format(run_number, tag[
"tag"], record,
42 for record,tag
in inputs.items():
43 result[record] = {
"connect":
"sqlite_file:"+output_db,
44 "tag":
"_".
join([tag[
"tag"], tag[
"since"]])}
46 if tag[
"connect"] ==
"pro":
47 source_connect =
"frontier://FrontierProd/CMS_CONDITIONS"
48 elif tag[
"connect"] ==
"dev":
49 source_connect =
"frontier://FrontierPrep/CMS_CONDITIONS"
51 source_connect = tag[
"connect"]
53 cmd = (
"conddb_import",
55 "-c", result[record][
"connect"],
57 "-t", result[record][
"tag"],
58 "-b",
str(run_number),
59 "-e",
str(run_number))
62 run_checked([
"sqlite3", output_db,
"update iov set since=1"])
References join(), print(), remove_existing_object(), run_checked(), and str.
◆ get_iovs()
def tools.get_iovs |
( |
|
db, |
|
|
|
tag |
|
) |
| |
Retrieve the list of IOVs from `db` for `tag`.
Arguments:
- `db`: database connection string
- `tag`: tag of database record
Definition at line 167 of file tools.py.
168 """Retrieve the list of IOVs from `db` for `tag`.
171 - `db`: database connection string
172 - `tag`: tag of database record
175 db = db.replace(
"sqlite_file:",
"").
replace(
"sqlite:",
"")
176 db = db.replace(
"frontier://FrontierProd/CMS_CONDITIONS",
"pro")
177 db = db.replace(
"frontier://FrontierPrep/CMS_CONDITIONS",
"dev")
179 con = conddb.connect(url = conddb.make_url(db))
180 session = con.session()
181 IOV = session.get_dbtype(conddb.IOV)
183 iovs = set(session.query(IOV.since).
filter(IOV.tag_name == tag).
all())
185 print(
"No IOVs found for tag '"+tag+
"' in database '"+db+
"'.")
190 return sorted([
int(item[0])
for item
in iovs])
References python.cmstools.all(), ALCARECOTkAlBeamHalo_cff.filter, createfilelist.int, print(), and python.rootplot.root2matplotlib.replace().
◆ get_process_object()
def tools.get_process_object |
( |
|
cfg | ) |
|
Returns cms.Process object defined in `cfg`.
Arguments:
- `cfg`: path to CMSSW config file
Definition at line 87 of file tools.py.
88 """Returns cms.Process object defined in `cfg`.
91 - `cfg`: path to CMSSW config file
94 sys.path.append(os.path.dirname(cfg))
95 cache_stdout = sys.stdout
96 sys.stdout = open(os.devnull,
"w")
99 importlib.import_module(os.path.splitext(os.path.basename(cfg))[0])
100 except Exception
as e:
101 print(
"Problem detected in configuration file '{0}'.".
format(cfg))
103 sys.stdout = cache_stdout
108 if e.args == (2,
"No such file or directory"):
pass
111 return __configuration.process
References print().
◆ get_tags()
def tools.get_tags |
( |
|
global_tag, |
|
|
|
records |
|
) |
| |
Get tags for `records` contained in `global_tag`.
Arguments:
- `global_tag`: global tag of interest
- `records`: database records of interest
Definition at line 132 of file tools.py.
133 """Get tags for `records` contained in `global_tag`.
136 - `global_tag`: global tag of interest
137 - `records`: database records of interest
140 if len(records) == 0:
return {}
143 if global_tag.startswith(
"auto:"):
144 import Configuration.AlCa.autoCond
as AC
146 global_tag = AC.autoCond[global_tag.split(
"auto:")[-1]]
148 print(
"Unsupported auto GT:", global_tag)
152 con = conddb.connect(url = conddb.make_url())
153 session = con.session()
154 GlobalTagMap = session.get_dbtype(conddb.GlobalTagMap)
157 tags = session.query(GlobalTagMap.record, GlobalTagMap.tag_name).\
158 filter(GlobalTagMap.global_tag_name == global_tag,
159 GlobalTagMap.record.in_(records)).
all()
164 return {item[0]: {
"tag": item[1],
"connect":
"pro"}
for item
in tags}
References python.cmstools.all(), ALCARECOTkAlBeamHalo_cff.filter, and print().
◆ getDatasetStr()
def tools.getDatasetStr |
( |
|
datasetpath | ) |
|
Definition at line 20 of file tools.py.
21 datasetstr = datasetpath
23 if datasetstr[0] ==
'/': datasetstr = datasetstr[1:]
24 datasetstr = datasetstr.replace(
'/',
'_')
◆ getTerminalSize()
def tools.getTerminalSize |
( |
| ) |
|
Definition at line 96 of file tools.py.
100 def ioctl_GWINSZ(fd):
102 import fcntl, termios, struct, os
103 cr = struct.unpack(
'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
108 cr = ioctl_GWINSZ(0)
or ioctl_GWINSZ(1)
or ioctl_GWINSZ(2)
111 fd = os.open(os.ctermid(), os.O_RDONLY)
112 cr = ioctl_GWINSZ(fd)
117 cr = (env.get(
'LINES', 25), env.get(
'COLUMNS', 80))
124 return int(cr[1]),
int(cr[0])
References createfilelist.int.
Referenced by CrabHelper.CrabHelper.check_crabtask().
◆ haddLocal()
def tools.haddLocal |
( |
|
localdir, |
|
|
|
result_file, |
|
|
|
extension = 'root' |
|
) |
| |
Definition at line 41 of file tools.py.
41 def haddLocal(localdir,result_file,extension = 'root'):
42 if not os.path.exists( localdir ):
43 raise ValueError(
"localdir for hadd operation does not exist" )
46 process = subprocess.Popen( [
'hadd',
'-f', result_file] + files,
47 stdout=subprocess.PIPE,
48 stderr=subprocess.STDOUT)
49 stdout = process.communicate()[0]
50 return process.returncode
References listFilesLocal().
Referenced by DTWorkflow.DTWorkflow.prepare_common_write().
◆ interrupt()
def tools.interrupt |
( |
|
signum, |
|
|
|
frame |
|
) |
| |
◆ listFilesLocal()
def tools.listFilesLocal |
( |
|
paths, |
|
|
|
extension = '.root' |
|
) |
| |
Definition at line 28 of file tools.py.
31 if not os.path.exists( path ):
32 log.error(
"Specified input path '%s' does not exist!" % path )
34 if path.endswith( extension ):
35 file_paths.append( path )
36 for root, dirnames, filenames
in os.walk( path ):
37 for filename
in fnmatch.filter( filenames,
'*' + extension ):
38 file_paths.append( os.path.join( root, filename ) )
Referenced by haddLocal().
◆ loadCmsProcess()
def tools.loadCmsProcess |
( |
|
psetPath | ) |
|
◆ loadCmsProcessFile()
def tools.loadCmsProcessFile |
( |
|
psetName | ) |
|
Definition at line 52 of file tools.py.
53 pset = imp.load_source(
"psetmodule",psetName)
◆ make_unique_runranges()
def tools.make_unique_runranges |
( |
|
ali_producer | ) |
|
Derive unique run ranges from AlignmentProducer PSet.
Arguments:
- `ali_producer`: cms.PSet containing AlignmentProducer configuration
Definition at line 114 of file tools.py.
115 """Derive unique run ranges from AlignmentProducer PSet.
118 - `ali_producer`: cms.PSet containing AlignmentProducer configuration
121 if (hasattr(ali_producer,
"RunRangeSelection")
and
122 len(ali_producer.RunRangeSelection) > 0):
124 for sel
in ali_producer.RunRangeSelection
125 for iov
in sel.RunRanges])
126 if len(iovs) == 0:
return [1]
References createfilelist.int.
◆ prependPaths()
def tools.prependPaths |
( |
|
process, |
|
|
|
seqname |
|
) |
| |
◆ remove_existing_object()
def tools.remove_existing_object |
( |
|
path | ) |
|
Tries to remove file or directory located at `path`. If the user
has no delete permissions, the object is moved to a backup
file. If this fails it tries 5 times in total and then asks to
perform a cleanup by a user with delete permissions.
Arguments:
- `name`: name of the object to be (re)moved
Definition at line 232 of file tools.py.
234 Tries to remove file or directory located at `path`. If the user
235 has no delete permissions, the object is moved to a backup
236 file. If this fails it tries 5 times in total and then asks to
237 perform a cleanup by a user with delete permissions.
240 - `name`: name of the object to be (re)moved
243 if os.path.exists(path):
244 remove_method = shutil.rmtree
if os.path.isdir(path)
else os.remove
245 move_method = shutil.move
if os.path.isdir(path)
else os.rename
249 if e.args != (13,
"Permission denied"):
raise
250 backup_path = path.rstrip(
"/")+
"~"
253 if os.path.exists(backup_path): remove_method(backup_path)
254 move_method(path, backup_path)
257 if e.args != (13,
"Permission denied"):
raise
259 if os.path.exists(path):
260 msg = (
"Cannot remove '{}' due to missing 'delete' ".
format(path)
261 +
"permissions and the limit of 5 backups is reached. Please "
262 "ask a user with 'delete' permissions to clean up.")
References print(), and FastTimerService_cff.range.
Referenced by create_single_iov_db().
◆ replace_factors()
def tools.replace_factors |
( |
|
product_string, |
|
|
|
name, |
|
|
|
value |
|
) |
| |
Takes a `product_string` and replaces all factors with `name` by `value`.
Arguments:
- `product_string`: input string containing a product
- `name`: name of the factor
- `value`: value of the factor
Definition at line 193 of file tools.py.
194 """Takes a `product_string` and replaces all factors with `name` by `value`.
197 - `product_string`: input string containing a product
198 - `name`: name of the factor
199 - `value`: value of the factor
203 return re.sub(
r"^"+name+
r"$", value,
204 re.sub(
r"[*]"+name+
r"$",
r"*"+value,
205 re.sub(
r"^"+name+
r"[*]", value+
r"*",
206 re.sub(
r"[*]"+name+
r"[*]",
r"*"+value+
r"*",
References str.
◆ replaceTemplate()
def tools.replaceTemplate |
( |
|
template, |
|
|
** |
opts |
|
) |
| |
◆ run_checked()
def tools.run_checked |
( |
|
cmd, |
|
|
|
suppress_stderr = False |
|
) |
| |
Run `cmd` and exit in case of failures.
Arguments:
- `cmd`: list containing the strings of the command
- `suppress_stderr`: suppress output from stderr
Definition at line 67 of file tools.py.
68 """Run `cmd` and exit in case of failures.
71 - `cmd`: list containing the strings of the command
72 - `suppress_stderr`: suppress output from stderr
76 with open(os.devnull,
"w")
as devnull:
78 subprocess.check_call(cmd, stdout = devnull, stderr = devnull)
80 subprocess.check_call(cmd, stdout = devnull)
81 except subprocess.CalledProcessError
as e:
82 print(
"Problem in running the following command:")
References join(), and print().
Referenced by create_single_iov_db().
◆ stdinWait()
def tools.stdinWait |
( |
|
text, |
|
|
|
default, |
|
|
|
time, |
|
|
|
timeoutDisplay = None , |
|
|
** |
kwargs |
|
) |
| |
Definition at line 70 of file tools.py.
70 def stdinWait(text, default, time, timeoutDisplay = None, **kwargs):
72 signal.signal(signal.SIGALRM, interrupt)
79 except (KeyboardInterrupt):
80 printInterrupt = kwargs.get(
"printInterrupt",
True)
82 print(
"Keyboard interrupt")
87 if not timeoutDisplay
is None:
References print().
Referenced by CrabHelper.CrabHelper.check_crabtask().
static std::string join(char **cmd)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def replace(string, replacements)