ATLAS Offline Software
Loading...
Searching...
No Matches
InnerDetector
InDetCalibAlgs
TRT_CalibAlgs
python
TRTCalib_merge_Skeleton.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3
import
sys, glob, subprocess, tarfile
4
5
def
nextstep
(text):
6
print
(
"\n"
+
"#"
*100)
7
print
(
"#"
)
8
print
(
"# %s"
% (text))
9
print
(
"#"
)
10
print
(
"#"
*100,
"\n"
)
11
12
def
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
24
def
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)
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
TRTCalib_merge_Skeleton.tryError
tryError(command, error)
Definition
TRTCalib_merge_Skeleton.py:12
TRTCalib_merge_Skeleton.fromRunArgs
fromRunArgs(runArgs)
Definition
TRTCalib_merge_Skeleton.py:24
TRTCalib_merge_Skeleton.nextstep
nextstep(text)
Definition
TRTCalib_merge_Skeleton.py:5
Generated on
for ATLAS Offline Software by
1.14.0