6 from pm.project
import Project
7 from argparse
import ArgumentParser
8 from types
import MethodType
9 from sys
import stdout, stderr
10 from datetime
import datetime
14 parser = ArgumentParser(description=
'Produce a ros2rob map, as a python '
15 'dictionary, from a given partition.')
16 parser.add_argument(
'--database_file',
'-d', required=
True,
17 help=
'A partition filename (e.g. ATLAS.data.xml).')
18 parser.add_argument(
'--partition',
'-p', required=
True,
19 help=
'A partition filename. The name of the partition '
20 'that is read from pfile (e.g. ATLAS).')
21 parser.add_argument(
'--output_file',
'-o',
22 help=
'The output filename. The name of the file to which '
23 'the ros2rob map is written. If omitted, stdout is '
24 'used (e.g. myros2rob.py).')
30 Alter an ArgumentParser so that it shows a help msg whenever there is an
31 error in the command line
34 print(
'error: %s\n' % msg, file=stderr)
37 parser.error = MethodType(error, parser)
41 Get all the ROSes and swRODs in the partition
43 partition =
Project(pfname).getObject(
'Partition', pname)
44 roses = partition.get(
'ROS')
45 swrods = partition.get(
'SwRodApplication')
50 Get the ros2rob map from the ROS list
55 print(
"WARNING: %s is repeated in the partition: ignoring "
56 "second occurrence", file=stderr)
64 Get the list of ROBs that correspond to a ROS
66 return [eformat.helper.SourceIdentifier(rol.Id).
code()
67 for robin
in ros.Contains
for rol
in robin.Contains]
71 Get a hardcoded list of RoIBuilder ROB IDs which are not listed in the partition
77 0x7300a8, 0x7300a9, 0x7300aa, 0x7300ab, 0x7500ac, 0x7500ad,
79 0x910081, 0x910091, 0x910082, 0x910092]
83 Print the ros2rob map as an easily readable/editable python dictionary
85 print(
"ros2rob = {", file=out)
87 for k, v
in ros2rob.items():
89 print(
"\t'%s': \n\t[" % k, file=out)
90 for i
in range(len(v)):
91 print(
"\t\t%s" % hex(v[i]), end=
' ', file=out)
95 print(
"\n\t]", end=
' ', file=out)
96 if count != len(ros2rob):
98 print(
"\n}", file=out)
103 # Copyright (C) 2002-{datetime.now().year} CERN for the benefit of the ATLAS collaboration
107 @brief Store ROS to ROB map extracted from {dbfile}
110 print(header, file=out)
115 \tdef __init__(self):
116 \t\tself.data = ros2rob
118 \tdef get_mapping(self):
121 print(footer, file=out)
124 if __name__ ==
'__main__':
126 out =
open(args.output_file,
'w')
if args.output_file
else stdout
127 print(
"# Extracting ROS2ROB map", file=stderr)