ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetCalibAlgs
TRT_CalibAlgs
python
TRTCalib_accu_Skeleton.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3
import
sys, os, glob, subprocess, tarfile
4
from
PyJobTransforms.CommonRunArgsToFlags
import
commonRunArgsToFlags
5
from
PyJobTransforms.TransformUtils
import
processPreExec, processPreInclude, processPostExec, processPostInclude
6
from
TRT_CalibAlgs.TRTCalibrationMgrConfig
import
CalibConfig, TRT_CalibrationMgrCfg, TRT_StrawStatusCfg
7
from
AthenaConfiguration.MainServicesConfig
import
MainServicesCfg
8
9
10
def
nextstep
(text):
11
print
(
"\n"
+
"#"
*100)
12
print
(
"#"
)
13
print
(
"# %s"
% (text))
14
print
(
"#"
)
15
print
(
"#"
*100,
"\n"
)
16
17
def
tryError
(command, error):
18
try
:
19
print
(
" Running: %s\n"
% (command))
20
stdout, stderr = subprocess.Popen(command, shell=
True
, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
21
print
(
"OUTPUT: \n%s"
% (stdout.decode(
'ascii'
)))
22
print
(
"ERRORS: %s"
% (
"NONE"
if
stderr.decode(
'ascii'
)==
''
else
"\n"
+stderr.decode(
'ascii'
)))
23
if
stderr:
24
exit(1)
25
except
OSError
as
e:
26
print
(error,e)
27
sys.exit(e.errno)
28
29
def
fromRunArgs
(runArgs):
30
31
32
nextstep
(
"Building tracks: ATHENA"
)
33
34
35
from
AthenaConfiguration.AllConfigFlags
import
initConfigFlags
36
flags=initConfigFlags()
37
38
commonRunArgsToFlags(runArgs, flags)
39
40
processPreInclude(runArgs, flags)
41
processPreExec(runArgs, flags)
42
43
if
"TRTCalibAccu_ART_Output"
in
runArgs.outputTARFile:
44
print
(
"WARNING - Testing the TRTCalib_accu transform"
)
45
else
:
46
print
(
"INFO - Running TRTCalib_accu transform"
)
47
48
flags.Input.Files=runArgs.inputRAWFile
49
flags.Output.HISTFileName=runArgs.outputTARFile
50
51
#Importing flags - Switching off detector parts and monitoring
52
CalibConfig(flags)
53
54
# To respect --athenaopts
55
flags.fillFromArgs()
56
flags.lock()
57
flags.dump()
58
59
cfg=MainServicesCfg(flags)
60
61
from
ByteStreamCnvSvc.ByteStreamConfig
import
ByteStreamReadCfg
62
cfg.merge(ByteStreamReadCfg(flags))
63
64
from
InDetConfig.TrackRecoConfig
import
InDetTrackRecoCfg
65
cfg.merge(InDetTrackRecoCfg(flags))
66
67
cfg.merge(TRT_StrawStatusCfg(flags))
68
cfg.merge(TRT_CalibrationMgrCfg(flags, calibconstants=runArgs.calibconstants ,DoCalibrate=runArgs.calibrate))
69
70
processPostInclude(runArgs, flags, cfg)
71
processPostExec(runArgs, flags, cfg)
72
73
with
open(
"ConfigTRTCalib_accu.pkl"
,
"wb"
)
as
f:
74
cfg.store(f)
75
76
sc = cfg.run()
77
78
if
not
sc.isSuccess():
79
sys.exit(
not
sc.isSuccess())
80
81
outputFile = runArgs.outputTARFile
82
83
nextstep
(
"Generating the tracktuple and StrawStatus file"
)
84
85
86
os.rename(outputFile, outputFile+
'.basic.root'
)
87
command =
'TRTCalib_bhadd dumfile %s.basic.root'
% (outputFile)
88
89
tryError
(command,
"ERROR: Failed in process TRTCalib_bhadd\n"
)
90
91
92
nextstep
(
"Renaming outputs from Athena and TRTCalib_bhadd"
)
93
94
95
command =
"mv -v tracktuple.root %s.tracktuple.root ; "
% (outputFile)
96
command +=
"mv -v %s %s.straw.txt"
% (glob.glob(
'TRT_StrawStatusOutput.*newFormat.txt'
)[0],outputFile)
97
98
tryError
(command,
"ERROR: Failed in renaming\n"
)
99
100
101
nextstep
(
"TAR'ing files"
)
102
103
104
try
:
105
# Getting list of files to be compressed
106
files_list=glob.glob(outputFile+
".*"
)
107
# Compressing
108
tar = tarfile.open(outputFile,
"w:gz"
)
109
print
(
"Compressing files in %s output file:"
% outputFile)
110
for
file
in
files_list:
111
print
(
"\t-"
,file)
112
tar.add(file)
113
tar.close()
114
except
OSError
as
e:
115
print
(
"ERROR: Failed compressing the output files\n"
,e)
116
sys.exit(e.errno)
117
118
# Prints all types of txt files present in a Path
119
print
(
"\nListing files:"
)
120
for
file
in
sorted(glob.glob(
"./*"
, recursive=
True
)):
121
print
(
"\t-"
,file)
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
TRTCalib_accu_Skeleton.nextstep
nextstep(text)
Definition
TRTCalib_accu_Skeleton.py:10
TRTCalib_accu_Skeleton.fromRunArgs
fromRunArgs(runArgs)
Definition
TRTCalib_accu_Skeleton.py:29
TRTCalib_accu_Skeleton.tryError
tryError(command, error)
Definition
TRTCalib_accu_Skeleton.py:17
Generated on
for ATLAS Offline Software by
1.17.0