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.
421 def copy_condor_config(output):
422  """Copy the HTC config to the running directory."""
423 
424  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.
381 def diagnostic(exception: Exception) -> None:
382  """Common diagnostic message for all prefix commands in case of exception."""
383  prefix = os.path.basename(sys.argv[0])
384  versions = (
385  check_output("printDarwinSoftwareVersion", shell=True)
386  .decode()
387  .strip()
388  .split("\n")
389  )
390  versions += [f"Python {sys.version_info.major}.{sys.version_info.minor}"]
391  print(
392  f"\x1B[31m{prefix}: \x1B[1m{exception}\x1B[22m",
393  ", ".join(versions),
394  "Consider opening a GitLab issue if you don't understand the cause of the failure.\x1B[0m",
395  sep="\n",
396  )
397 
398 

◆ find_institute()

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

◆ git_hash()

None git_hash ( str  exec)
Returns the SHA of the executable at compile time.
115 def git_hash(exec: str) -> None:
116  """Returns the SHA of the executable at compile time."""
117  print(check_output(exec + " -g", shell=True).decode(), end="")
118 
119 

◆ 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  parser.add_argument("-p", "--plugin", type=Path, nargs="*")
68 
69  # custom will be in args
70  cmds, args = parser.parse_known_intermixed_args(argv[1:])
71 
72  if any(x in args for x in ["-k", "--nNow"]):
73  raise ValueError("Giving `-k` or `--nNow` is meaningless in this context.")
74  unknown_explicit_args = [arg for arg in args if arg[0] == "-"]
75  if len(unknown_explicit_args) > 0:
76  raise ValueError(
77  f"No unknown explicit option is allowed: {unknown_explicit_args}"
78  )
79 
80  # restore explicit options
81  if cmds.verbose:
82  args += ["-v"]
83  if cmds.mute:
84  args += ["-m"]
85  if cmds.fill:
86  args += ["-f"]
87  if cmds.Friend:
88  args += ["-F"]
89  if cmds.syst:
90  args += ["-s"]
91  if cmds.config:
92  args += ["-c", str(cmds.config.resolve())]
93  if cmds.plugin:
94  for plugin in cmds.plugin:
95  args += ["-p", str(plugin.resolve())]
96 
97  if not cmds.exec:
98  if cmds.help or len(argv) == 1:
99  prefix = os.path.basename(sys.argv[0])
100  print(
101  f"\33[1m{prefix} exec args [...]\33[0m",
102  "where\texec = a command using `Darwin::Tools::Options` with `Darwin::Tools::split`",
103  "\targs = the arguments of the same command, one being called exactly `output`",
104  sep="\n",
105  )
106  if cmds.tutorial:
107  # boost::program_options::options_description::m_default_line_length = 80
108  lines = textwrap.TextWrapper(width=80).wrap(text=tutorial)
109  print(*lines, sep="\n")
110  parser.exit()
111 
112  return cmds, args
113 
114 

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

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

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:381
Darwin::Tools::split
@ split
activate -k and -j to define slice
Definition: Options.h:31
prefix.copy_condor_config
def copy_condor_config(output)
Definition: prefix.py:421
prefix.find_institute
def find_institute()
Definition: prefix.py:120
prefix.preparse
def preparse(List[str] argv, str tutorial, bool multi_opt=False, bool dag_opt=False, bool condor=False)
Definition: prefix.py:32
join
PseudoJet join(const std::vector< PseudoJet > &pieces)
Definition: fjcore.hh:1245
prefix.print_slice
def print_slice(formatting, line, nNow, nSplit, end)
Definition: prefix.py:399
prefix.git_hash
None git_hash(str exec)
Definition: prefix.py:115
prefix.tweak_helper_multi
None tweak_helper_multi(PrefixCommand prefix, bool multi_opt=True, bool dag_opt=False, bool condor=False)
Definition: prefix.py:350