ATLAS Offline Software
Functions | Variables
parseMapping Namespace Reference

Functions

def parsePosition (header_line)
 
def convertToNewFormat (oldFormat)
 
def convertToOldFormat (newFormat)
 
def create_mapping0 (fname)
 
def create_mapping1 (fname)
 
def create_mapping (fname)
 

Variables

def name_position_dict1 = create_mapping1('pixelMapping.h')
 
def name_position_dict = create_mapping('mapping.csv')
 
def v = convertToOldFormat(name_position_dict[n])
 
def v0 = convertToOldFormat(name_position_dict1[n])
 

Function Documentation

◆ convertToNewFormat()

def parseMapping.convertToNewFormat (   oldFormat)

Definition at line 14 of file parseMapping.py.

14 def convertToNewFormat(oldFormat):
15  hash_positionStrings=oldFormat.split()[1:]
16  theHash = int(hash_positionStrings[0])
17  thePositions = [int(x) for x in hash_positionStrings[1].split(',')]
18  result = [theHash]
19  return result + thePositions
20 
21 
22 #old format is a single string, ' : 2027 2,2,39,0'
23 #note: no comma between hash and position coordinates, the hash is r-justified

◆ convertToOldFormat()

def parseMapping.convertToOldFormat (   newFormat)

Definition at line 24 of file parseMapping.py.

24 def convertToOldFormat(newFormat):
25  newFormatPosition = str(newFormat[1:])
26  joinedPosition = "".join(newFormatPosition)[1:-1]
27  spaceStripped = re.sub(r'[\s+]', '', joinedPosition)
28  newFormatHash = str(newFormat[0])
29  return " : "+newFormatHash.rjust(4)+" "+spaceStripped
30 
31 

◆ create_mapping()

def parseMapping.create_mapping (   fname)

Definition at line 123 of file parseMapping.py.

123 def create_mapping(fname):
124  result=dict()
125  module_file = open(fname, 'r')
126  module_data = module_file.read()
127  module_lines = module_data.splitlines()
128  for module in module_lines:
129  if '#' in module:
130  continue
131  components = module.split(',')
132  thisModuleName = components[0]
133  thisModulePosition = [int(x) for x in components[1:]]
134  result[thisModuleName] = thisModulePosition
135  return result
136 
137 

◆ create_mapping0()

def parseMapping.create_mapping0 (   fname)

Definition at line 32 of file parseMapping.py.

32 def create_mapping0(fname):
33  golden_modules = []
34  module_file = open(fname, 'r')
35  module_data = module_file.read()
36  module_lines = module_data.splitlines()
37 
38  for modules in module_lines:
39  modulename = ""
40  modules = modules.split()
41  if len(modules) != 0:
42  if modules[0] == "else" and modules[1] == "if":
43  geographicalID = modules[2].split('"')
44  modulename = geographicalID[1]
45  elif modules[0] == "if":
46  geographicalID = modules[1].split('"')
47  modulename = geographicalID[1]
48  if modulename:
49  golden_modules.append(modulename)
50 
51  golden_hash = []
52  for modules in module_lines:
53  modulehash = ""
54  goldens = modules.split('=')
55  modules = modules.split()
56  if len(modules) != 0:
57  if modules[0] == "else" and modules[1] == "if":
58  golden_hashID = " : " + goldens[3].split(';')[0]
59  golden_bec = goldens[4].split(';')[0].strip()
60  golden_layer = goldens[5].split(';')[0].strip()
61  golden_phi = goldens[6].split(';')[0].strip()
62  golden_eta = goldens[7].split(';')[0].strip()
63  modulehash = golden_hashID + " " + golden_bec + "," + golden_layer + "," + golden_phi + "," + golden_eta
64  elif modules[0] == "if":
65  golden_hashIds = modules[4].split(';')[0]
66  golden_bec = modules[5].split('=')[1].split(';')[0]
67  golden_layer = modules[6].split('=')[1].split(';')[0]
68  golden_phi = modules[8].split(';')[0]
69  golden_eta = modules[10].split(';')[0].strip()
70  if len(golden_hashIds) == 1:
71  golden_hashID = " : " + golden_hashIds
72  elif len(golden_hashIds) == 2:
73  golden_hashID = " : " + golden_hashIds
74  elif len(golden_hashIds) == 3:
75  golden_hashID = " : " + golden_hashIds
76  elif len(golden_hashIds) == 4:
77  golden_hashID = " : " + golden_hashIds
78  modulehash = golden_hashID + " " + golden_bec + "," + golden_layer + "," + golden_phi + "," + golden_eta
79  if modulehash:
80  golden_hash.append(modulehash)
81  return dict(zip(golden_modules, golden_hash))
82 
83 
84 
85 #create new mapping from c++ header file of format March 2013
86 #Two arrays in the file, first one is array of strings
87 #Second one is array of the struct 'positions'

◆ create_mapping1()

def parseMapping.create_mapping1 (   fname)

Definition at line 88 of file parseMapping.py.

88 def create_mapping1(fname):
89 #The following is truly horrible; it parses the .h file to read module names.
90  module_names=[]
91  module_file = open(fname, 'r')
92  module_data = module_file.read()
93  module_lines = module_data.splitlines()
94  found_names=False
95  for modules in module_lines:
96  modulename = ""
97  modules = modules.split()
98  if len(modules) != 0:
99  if found_names:
100  if "};" in modules: #end of list in code
101  break
102  geographicalID = modules[0].split('"')
103  modulename = geographicalID[1]
104  module_names.append(modulename)
105  if "names" in modules: #beginning of list in code
106  found_names=True
107  #
108  found_positions = False
109  module_positions=[]
110  for position_line in module_lines:
111  if len(position_line) != 0:
112  if found_positions:
113  if "}};" in position_line: #end of list in code
114  break
115  position = parsePosition(position_line)
116  if position is None:
117  print('No match')
118  module_positions.append(position)
119  if "values" in position_line: #beginning of list in code
120  found_positions=True
121  return dict(zip(module_names,module_positions))
122 

◆ parsePosition()

def parseMapping.parsePosition (   header_line)

Definition at line 6 of file parseMapping.py.

6 def parsePosition(header_line):
7  #negative signs can appear on the second and last numbers
8  coords=re.match(r'^\s*{\s*(\d+),\s*(-?\d+),\s*(\d+),\s*(\d+),\s*(-?\d+)\s*},?', header_line)
9  if coords is None:
10  return None
11  return [int(x) for x in coords.groups()]
12 
13 #new format is a list with hash and position, [2027, 2, 2, 39, 0]

Variable Documentation

◆ name_position_dict

def parseMapping.name_position_dict = create_mapping('mapping.csv')

Definition at line 142 of file parseMapping.py.

◆ name_position_dict1

def parseMapping.name_position_dict1 = create_mapping1('pixelMapping.h')

Definition at line 141 of file parseMapping.py.

◆ v

def parseMapping.v = convertToOldFormat(name_position_dict[n])

Definition at line 146 of file parseMapping.py.

◆ v0

def parseMapping.v0 = convertToOldFormat(name_position_dict1[n])

Definition at line 149 of file parseMapping.py.

CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
parseMapping.create_mapping1
def create_mapping1(fname)
Definition: parseMapping.py:88
parseMapping.convertToOldFormat
def convertToOldFormat(newFormat)
Definition: parseMapping.py:24
parseMapping.convertToNewFormat
def convertToNewFormat(oldFormat)
Definition: parseMapping.py:14
parseMapping.parsePosition
def parsePosition(header_line)
Definition: parseMapping.py:6
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40
str
Definition: BTagTrackIpAccessor.cxx:11
parseMapping.create_mapping0
def create_mapping0(fname)
Definition: parseMapping.py:32
parseMapping.create_mapping
def create_mapping(fname)
Definition: parseMapping.py:123
Trk::split
@ split
Definition: LayerMaterialProperties.h:38