ATLAS Offline Software
Loading...
Searching...
No Matches
TRTCalib_merge_Skeleton Namespace Reference

Functions

 nextstep (text)
 tryError (command, error)
 fromRunArgs (runArgs)

Function Documentation

◆ fromRunArgs()

TRTCalib_merge_Skeleton.fromRunArgs ( runArgs)

Definition at line 24 of file TRTCalib_merge_Skeleton.py.

24def fromRunArgs(runArgs):
25
26
27 nextstep("UNTAR files")
28
29
30 print("Uncompressing files:")
31 try:
32 for file in runArgs.inputTARFile:
33 print("\t-",file)
34 tarfile.open(file).extractall(".")
35 except OSError as e:
36 print("ERROR: Failed uncompressing TAR file\n",e)
37 sys.exit(e.errno)
38
39
40 nextstep("Generating the tracktuple and StrawStatus file")
41
42
43 command = 'TRTCalib_bhadd merged_histo.root %s' % ("".join(("%s " % str(file)) for file in glob.glob("*.basic.root") ))
44 tryError(command,"ERROR: Failed in process TRTCalib_bhadd\n")
45
46
47 nextstep("Renaming Binary output file")
48
49
50 command = 'mv -v merged_histo.root.part0 %s.basic.root' % (runArgs.outputTAR_MERGEDFile)
51 tryError(command,"ERROR: Renaming binary file \"merged_histo.root.part0\"\n")
52
53
54 nextstep("Merging *.tracktuple.root files")
55
56
57 command = 'hadd -f %s.tracktuple.root %s' % (runArgs.outputTAR_MERGEDFile, "".join(("%s " % str(file)) for file in glob.glob("*.tracktuple.root") ))
58 tryError(command,"ERROR: Failed in process merging *.tracktuple.root files\n")
59
60
61 nextstep("Merging *.straw.txt files")
62
63
64 command = 'TRTCalib_StrawStatus_merge %s.merged.straw.txt %s' % (runArgs.outputTAR_MERGEDFile, "".join(("%s " % str(file)) for file in glob.glob("*.straw.txt") ))
65 tryError(command,"ERROR: Failed in process merging *.straw.txt files\n")
66
67
68 nextstep("TAR'ing files")
69
70
71 try:
72 # Getting list of files to be compressed
73 files_list=glob.glob(runArgs.outputTAR_MERGEDFile+".*")
74 # Compressing
75 tar = tarfile.open(runArgs.outputTAR_MERGEDFile, "w:gz")
76 print("\nCompressing files in %s output file:" % runArgs.outputTAR_MERGEDFile)
77 for file in files_list:
78 print("\t-",file)
79 tar.add(file)
80 tar.close()
81 except OSError as e:
82 print("ERROR: Failed compressing the output files\n",e)
83 sys.exit(e.errno)
84
85
86 # Prints all types of txt files present in a Path
87 print("\nListing files:")
88 for file in sorted(glob.glob("./*", recursive=True)):
89 print("\t-",file)
void print(char *figname, TCanvas *c1)

◆ nextstep()

TRTCalib_merge_Skeleton.nextstep ( text)

Definition at line 5 of file TRTCalib_merge_Skeleton.py.

5def nextstep(text):
6 print("\n"+"#"*100)
7 print("#")
8 print("# %s" % (text))
9 print("#")
10 print("#"*100,"\n")
11

◆ tryError()

TRTCalib_merge_Skeleton.tryError ( command,
error )

Definition at line 12 of file TRTCalib_merge_Skeleton.py.

12def tryError(command, error):
13 try:
14 print(" Running: %s\n" % (command))
15 stdout, stderr = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
16 print("STD::OUTPUT: \n%s" % (stdout.decode('ascii')))
17 print("STD::ERRORS: %s" % ("NONE" if stderr.decode('ascii')=='' else "\n"+stderr.decode('ascii')))
18 if "error" in stderr.decode('ascii').lower():
19 raise RuntimeError(f"Error from subprocess:\n{stderr.decode('ascii')}")
20 except RuntimeError as e:
21 print(error,e)
22 sys.exit(1)
23