DAS  3.0
Das Analysis System
prefix Namespace Reference

Classes

class  PrefixCommand
 

Functions

def preparse (List[str] argv, str tutorial, bool multi_opt=False, bool dag_opt=False, bool condor=False)
 
None git_hash (str exec)
 
def find_institute ()
 
None tweak_helper_multi (PrefixCommand prefix, bool multi_opt=True, bool dag_opt=False, bool condor=False)
 
None diagnostic (Exception exception)
 
def print_slice (formatting, line, nNow, nSplit, end)
 
def copy_condor_config (output)
 

Variables

list __all__
 
 NPROC = multiprocessing.cpu_count()
 

Function Documentation

◆ copy_condor_config()

def copy_condor_config (   output)
Copy the HTC config to the running directory.
417 def copy_condor_config(output):
418  """Copy the HTC config to the running directory."""
419 
420  copy2(Path(__file__).parent / "condor.jdl", str(output) + "/.condor")

◆ diagnostic()

None diagnostic ( Exception  exception)
Common diagnostic message for all prefix commands in case of exception.
377 def diagnostic(exception: Exception) -> None:
378  """Common diagnostic message for all prefix commands in case of exception."""
379  prefix = os.path.basename(sys.argv[0])
380  versions = (
381  check_output("printDarwinSoftwareVersion", shell=True)
382  .decode()
383  .strip()
384  .split("\n")
385  )
386  versions += [f"Python {sys.version_info.major}.{sys.version_info.minor}"]
387  print(
388  f"\x1B[31m{prefix}: \x1B[1m{exception}\x1B[22m",
389  ", ".join(versions),
390  "Consider opening a GitLab issue if you don't understand the cause of the failure.\x1B[0m",
391  sep="\n",
392  )
393 
394 

◆ find_institute()

def find_institute ( )
Identifies the host from the name of the machine
116 def find_institute():
117  """Identifies the host from the name of the machine"""
118 
119  clusters = {
120  r"naf-cms[1-2][0-9].desy.de": "DESY",
121  r".phy.pku.edu.cn": "PKU",
122  r"lxplus[0-9]*.cern.ch": "CERN",
123  }
124 
125  hostname = socket.gethostname()
126  for key, value in clusters.items():
127  if re.search(key, hostname):
128  return value
129 
130  raise RuntimeError("The host could not be identified")
131 
132 

◆ git_hash()

None git_hash ( str  exec)
Returns the SHA of the executable at compile time.
111 def git_hash(exec: str) -> None:
112  """Returns the SHA of the executable at compile time."""
113  print(check_output(exec + " -g", shell=True).decode(), end="")
114 
115 

◆ preparse()

def preparse ( List[str]  argv,
str  tutorial,
bool   multi_opt = False,
bool   dag_opt = False,
bool   condor = False 
)
Parser for the prefix command itself, relying on ArgumentParser.
32 def preparse(
33  argv: List[str],
34  tutorial: str,
35  multi_opt: bool = False,
36  dag_opt: bool = False,
37  condor: bool = False,
38 ):
39  """Parser for the prefix command itself, relying on ArgumentParser."""
40 
41  parser = ArgumentParser(add_help=False)
42 
43  parser.add_argument("exec", nargs="?")
44  if multi_opt:
45  parser.add_argument("-b", "--background", action="store_true")
46  parser.add_argument("-d", "--dry-run", action="store_true")
47  if dag_opt:
48  parser.add_argument("-D", "--dag", type=Path, nargs='?', default="dag")
49  if condor:
50  parser.add_argument("-n", "--memory-needs", type=int, default=1024)
51 
52  # helper
53  parser.add_argument("-h", "--help", action="store_true")
54  parser.add_argument("-t", "--tutorial", action="store_true")
55  parser.add_argument("-g", "--git", action="store_true")
56  if not dag_opt:
57  parser.add_argument("-e", "--example", action="store_true")
58 
59  # common
60  parser.add_argument("-v", "--verbose", action="store_true")
61  parser.add_argument("-m", "--mute", action="store_true")
62  parser.add_argument("-f", "--fill", action="store_true")
63  parser.add_argument("-F", "--Friend", action="store_true")
64  parser.add_argument("-s", "--syst", action="store_true")
65  parser.add_argument("-c", "--config", type=Path)
66  parser.add_argument("-j", "--nSplit", type=int, default=NPROC)
67 
68  # custom will be in args
69  cmds, args = parser.parse_known_intermixed_args(argv[1:])
70 
71  if any(x in args for x in ["-k", "--nNow"]):
72  raise ValueError("Giving `-k` or `--nNow` is meaningless in this context.")
73  unknown_explicit_args = [arg for arg in args if arg[0] == "-"]
74  if len(unknown_explicit_args) > 0:
75  raise ValueError(
76  f"No unknown explicit option is allowed: {unknown_explicit_args}"
77  )
78 
79  # restore explicit options
80  if cmds.verbose:
81  args += ["-v"]
82  if cmds.mute:
83  args += ["-m"]
84  if cmds.fill:
85  args += ["-f"]
86  if cmds.Friend:
87  args += ["-F"]
88  if cmds.syst:
89  args += ["-s"]
90  if cmds.config:
91  args += ["-c", str(cmds.config.resolve())]
92 
93  if not cmds.exec:
94  if cmds.help or len(argv) == 1:
95  prefix = os.path.basename(sys.argv[0])
96  print(
97  f"\33[1m{prefix} exec args [...]\33[0m",
98  "where\texec = a command using `Darwin::Tools::Options` with `Darwin::Tools::split`",
99  "\targs = the arguments of the same command, one being called exactly `output`",
100  sep="\n",
101  )
102  if cmds.tutorial:
103  # boost::program_options::options_description::m_default_line_length = 80
104  lines = textwrap.TextWrapper(width=80).wrap(text=tutorial)
105  print(*lines, sep="\n")
106  parser.exit()
107 
108  return cmds, args
109 
110 

◆ print_slice()

def print_slice (   formatting,
  line,
  nNow,
  nSplit,
  end 
)
Prefix the output stream with the slice. The formatting of the
printout is preserved but the slice is printed in default formatting.
395 def print_slice(formatting, line, nNow, nSplit, end):
396  """
397  Prefix the output stream with the slice. The formatting of the
398  printout is preserved but the slice is printed in default formatting.
399  """
400 
401  RESET = "\x1B[0m"
402 
403  # find the special characters to encode the colour and the highlighting
404  special_chars = re.findall(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])", line)
405 
406  # if any was found, check if it should be reset to default
407  if special_chars and special_chars[-1] == RESET:
408  formatting = RESET
409  else:
410  formatting += "".join(special_chars)
411 
412  print(f"{nNow}/{nSplit}\t{formatting}{line}{RESET}", end=end)
413 
414  return formatting
415 
416 

◆ tweak_helper_multi()

None tweak_helper_multi ( PrefixCommand  prefix,
bool   multi_opt = True,
bool   dag_opt = False,
bool   condor = False 
)
Tweak helper to use a directory as output rather than a file
and to reflect the number of cores of the machine.
347  prefix: PrefixCommand,
348  multi_opt: bool = True,
349  dag_opt: bool = False,
350  condor: bool = False,
351 ) -> None:
352  """Tweak helper to use a directory as output rather than a file
353  and to reflect the number of cores of the machine."""
354 
355  print(f"\33[1m{prefix.name} \33[0m", end="")
356  for row in prefix.helper:
357  if "output" in row:
358  row = row.replace("ROOT file", "directory")
359  if "nNow" in row:
360  continue
361  if "nSplit" in row:
362  row = row.replace(
363  "(=1)" if NPROC < 10 else "(=1) ", "(=" + str(NPROC) + ")"
364  )
365  print(row)
366  if "Helper" in row:
367  if multi_opt:
368  print(" -b [ --background ] Do not wait for job to finish")
369  print(" -d [ --dry-run ] Run until the actual executation")
370  if dag_opt:
371  print(" -D [ --dag ] Indicate DAG file")
372  if condor:
373  print(" -n [ --memory-needs] arg Memory needs for HTCondor job")
374  print("")
375 
376 

Variable Documentation

◆ __all__

list __all__
private
Initial value:
1 = [
2  "PrefixCommand",
3  "preparse",
4  "tweak_helper_multi",
5  "diagnostic",
6  "git_hash",
7  "copy_condor_config",
8  "find_institute",
9 ]

◆ NPROC

NPROC = multiprocessing.cpu_count()
prefix.diagnostic
None diagnostic(Exception exception)
Definition: prefix.py:377
Darwin::Tools::split
@ split
activate -k and -j to define slice
Definition: Options.h:26
prefix.copy_condor_config
def copy_condor_config(output)
Definition: prefix.py:417
prefix.find_institute
def find_institute()
Definition: prefix.py:116
prefix.preparse
def preparse(List[str] argv, str tutorial, bool multi_opt=False, bool dag_opt=False, bool condor=False)
Definition: prefix.py:32
prefix.print_slice
def print_slice(formatting, line, nNow, nSplit, end)
Definition: prefix.py:395
prefix.git_hash
None git_hash(str exec)
Definition: prefix.py:111
prefix.tweak_helper_multi
None tweak_helper_multi(PrefixCommand prefix, bool multi_opt=True, bool dag_opt=False, bool condor=False)
Definition: prefix.py:346