5 from __future__
import print_function
7 from pm.project
import Project
8 from argparse
import ArgumentParser
9 from types
import MethodType
10 from sys
import stdout, stderr
11 from datetime
import datetime
15 parser = ArgumentParser(description=
'Produce a ros2rob map, as a python '
16 'dictionary, from a given partition.')
17 parser.add_argument(
'--database_file',
'-d', required=
True,
18 help=
'A partition filename (e.g. ATLAS.data.xml).')
19 parser.add_argument(
'--partition',
'-p', required=
True,
20 help=
'A partition filename. The name of the partition '
21 'that is read from pfile (e.g. ATLAS).')
22 parser.add_argument(
'--output_file',
'-o',
23 help=
'The output filename. The name of the file to which '
24 'the ros2rob map is written. If omitted, stdout is '
25 'used (e.g. myros2rob.py).')
31 Alter an ArgumentParser so that it shows a help msg whenever there is an
32 error in the command line
35 print(
'error: %s\n' % msg, file=stderr)
38 parser.error = MethodType(error, parser)
42 Get all the ROSes and swRODs in the partition
44 partition =
Project(pfname).getObject(
'Partition', pname)
45 roses = partition.get(
'ROS')
46 swrods = partition.get(
'SwRodApplication')
51 Get the ros2rob map from the ROS list
56 print(
"WARNING: %s is repeated in the partition: ignoring "
57 "second occurrence", file=stderr)
65 Get the list of ROBs that correspond to a ROS
67 return [eformat.helper.SourceIdentifier(rol.Id).
code()
68 for robin
in ros.Contains
for rol
in robin.Contains]
72 Get a hardcoded list of RoIBuilder ROB IDs which are not listed in the partition
78 0x7300a8, 0x7300a9, 0x7300aa, 0x7300ab, 0x7500ac, 0x7500ad,
80 0x910081, 0x910091, 0x910082, 0x910092]
84 Print the ros2rob map as an easily readable/editable python dictionary
86 print(
"ros2rob = {", file=out)
88 for k, v
in ros2rob.items():
90 print(
"\t'%s': \n\t[" % k, file=out)
91 for i
in range(len(v)):
92 print(
"\t\t%s" % hex(v[i]), end=
' ', file=out)
96 print(
"\n\t]", end=
' ', file=out)
97 if count != len(ros2rob):
99 print(
"\n}", file=out)
104 # Copyright (C) 2002-{datetime.now().year} CERN for the benefit of the ATLAS collaboration
108 @brief Store ROS to ROB map extracted from {dbfile}
111 print(header, file=out)
116 \tdef __init__(self):
117 \t\tself.data = ros2rob
119 \tdef get_mapping(self):
122 print(footer, file=out)
125 if __name__ ==
'__main__':
127 out =
open(args.output_file,
'w')
if args.output_file
else stdout
128 print(
"# Extracting ROS2ROB map", file=stderr)