ATLAS Offline Software
FileMerger.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 # This function reads the layers that have been recalibrated (using the PixelCalibrationConfig python) and creates a merge file of all of them
4 # the "layers" argument is an array i.e: ["Blayer","L1","L2","disk"] meaning that it will look for files like "calibration_Blayer.txt"... etc
5 
6 import os.path
7 
8 def MergeCalibFiles(layers):
9  if(len(layers)==0):
10  print("MergeCalibFiles - ERROR no layer provided.")
11  return 1
12  mergedDict = {}
13  for i in layers:
14  mergedDict.update(readFile(("calibration_%s.txt" % i)))
15 
16 
17  mergedDict = dict(sorted(mergedDict.items()))
18  f = open("calibration_merged.txt", "w")
19  for value in mergedDict.values():
20  f.write(value)
21  f.close()
22 
23  return 0
24 
25 
26 # Function to read the calibration_XXXXX.txt file of each layer
27 def readFile(name):
28  mydict = {}
29  if not os.path.exists(name):
30  print("MergeCalibFiles - ERROR File name %22s not found" % name)
31  return mydict
32  else:
33  print("MergeCalibFiles - Reading: %22s"% name)
34 
35  with open(name) as fp:
36  lines = fp.readlines()
37  mod = -1
38  for line in lines:
39  # Module names for Pixel layers starts with D or L
40  if line.startswith("L") or line.startswith("D"):
41  line = line.rstrip("\n")
42  splittedline = line.split(" ")
43 
44  if int(splittedline[1]) in mydict.keys():
45  print("MergeCalibFiles - ERROR Module key exists already - Contact pixel offline team")
46  exit(1)
47  else:
48  mydict[int(splittedline[1])] = splittedline[0]+' '+splittedline[1]+"\n"
49  mod = int(splittedline[1])
50 
51  # Pixel frontends start with letter I
52  elif line.startswith("I"):
53  mydict[mod] = mydict[mod] + line
54  else:
55  print("MergeCalibFiles - ERROR Line is not a module or a frontend - Contact pixel offline team")
56  exit(1)
57 
58  return mydict
59 
60 # Just used for testing - Experts only
61 if __name__ == "__main__":
62 
63  MergeCalibFiles(["Blayer","L1","L2","disk"])
64  exit(0)
65 
66 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
FileMerger.readFile
def readFile(name)
Definition: FileMerger.py:27
FileMerger.MergeCalibFiles
def MergeCalibFiles(layers)
Definition: FileMerger.py:8
calibdata.exit
exit
Definition: calibdata.py:236
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
Trk::open
@ open
Definition: BinningType.h:40
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70