ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArCafJobs
share
LArMerge_tf.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4
5
21
22
import
sys, os, json, time, pprint, subprocess
23
24
25
26
# Utility function
27
def
getSubFileMap
(fname, nevts=0) :
28
if
os.path.isfile(fname) :
29
sz = os.path.getsize(fname)
30
map = {
'name'
: fname,
31
'file_size'
: sz,
32
'nentries'
: nevts,
33
}
34
else
:
35
map = {}
36
return
map
37
38
39
40
41
42
def
larMerge
(dataMap) :
43
44
tstart = time.time()
45
46
print
(
"\n##################################################################"
)
47
print
(
"## ATLAS Tier0 LAr CAF file Merging ##"
)
48
print
(
"##################################################################\n"
)
49
50
# initialize exit values
51
exitCode = 0
52
exitAcronym =
'OK'
53
exitMsg =
'trf finished OK'
54
dt=0
55
nEvents=0
56
outFiles = []
57
inFiles = []
58
59
print
(
"\nFull Tier-0 run options:\n"
)
60
pprint.pprint(dataMap)
61
62
inputList = []
63
inputDSName = dataMap[
'inputLArFiles'
][0][
'dsn'
]
64
65
for
fdict
in
dataMap[
'inputLArFiles'
] :
66
inputList.append(fdict[
'lfn'
])
67
68
print
(
"\ninputLArFiles list:\n"
)
69
pprint.pprint(inputList)
70
71
# output file
72
outputDSName = dataMap[
'outputLArFile'
].
split
(
'#'
)[0]
73
outputFile = dataMap[
'outputLArFile'
].
split
(
'#'
)[1]
74
75
print
(
'\nOutput file name:'
, outputFile)
76
77
cmdline=[
"LArSamplesMerge"
]
78
for
fileName
in
inputList:
79
if
os.access(fileName,os.R_OK):
80
cmdline.append(fileName)
81
else
:
82
print
(
'ERROR : could not open file'
, fileName)
83
exitCode = 74001
84
exitAcronym =
'TRF_LAR_FILE_INPUT_ERROR'
85
exitMsg =
'LAr input file not accessible'
86
break
87
pass
88
89
if
(exitCode==0):
90
writepath=os.path.split(outputFile)[0]
91
if
writepath==
""
: writepath=
"./"
92
if
(os.access(writepath,os.W_OK)):
93
cmdline.append(outputFile)
94
else
:
95
print
(
"ERROR, not allowed to write to oututfile"
, outputFile)
96
exitCode = 74002
97
exitAcronym =
'TRF_LAR_MERGE_ERROR'
98
exitMsg =
'LAR merging error'
99
pass
100
101
if
(exitCode==0):
102
103
logfile=open(
"log.LArMerge"
,
"w"
)
104
105
try
:
106
subprocess.check_call(cmdline,stdout=logfile,stderr=subprocess.STDOUT)
107
except
Exception
as
e:
108
print
(
"ERROR exectution of subprocess failed"
)
109
print
(e)
110
exitAcronym =
'TRF_LAR_MERGE_ERROR'
111
exitMsg =
'LAR merging error'
112
exitCode=1
113
114
logfile.close()
115
logfile=open(
"log.LArMerge"
,
"r"
)
116
117
for
line
in
logfile:
118
print
(line,)
119
if
line.startswith(
"Open file "
):
120
linetok=line.split(
" "
)
121
inFiles.append(
getSubFileMap
(linetok[2],nevts=int(linetok[4])))
122
if
line.startswith(
"Wrote output file "
):
123
linetok=line.split(
" "
)
124
nEvents=int(linetok[5])
125
outFiles.append(
getSubFileMap
(linetok[3], nevts=nEvents))
126
logfile.close()
127
dt = int(time.time() - tstart)
128
# assemble job report map, json it
129
outMap = {
'exitAcronym'
: exitAcronym,
130
'exitCode'
: exitCode,
131
'exitMsg'
: exitMsg,
132
'files'
: {
'output'
: [{
'dataset'
: outputDSName,
133
'subFiles'
: outFiles
134
},],
135
'input'
: [{
'dataset'
: inputDSName,
136
'subFiles'
: inFiles
137
}
138
] },
139
'resource'
: {
'transform'
: {
'processedEvents'
: int(nEvents),
'wallTime'
: dt} }
140
}
141
142
f = open(
'jobReport.json'
,
'w'
)
143
json.dump(outMap, f)
144
f.close()
145
146
print
(
"\n##################################################################"
)
147
print
(
"## End of job."
)
148
print
(
"##################################################################\n"
)
149
150
print
(outMap)
151
152
155
156
if
__name__ ==
"__main__"
:
157
158
159
if
len(sys.argv) == 2
and
sys.argv[1].startswith(
'--argJSON='
) :
160
jsonfile = sys.argv[1][len(
'--argJSON='
):]
161
# extract parameters from json file
162
print
(
"Using json file "
, jsonfile,
" for input parameters"
)
163
f = open(jsonfile,
'r'
)
164
dataMap = json.load(f)
165
f.close()
166
larMerge
(dataMap)
167
elif
len(sys.argv) == 3
and
sys.argv[1].startswith(
'--inputFiles='
)
and
sys.argv[2].startswith(
'--outputFile='
) :
168
inputFiles = sys.argv[1][13:].
split
(
','
)
169
outputFile = sys.argv[2][13:]
170
dataMap = {}
171
dataMap[
'inputLArFiles'
] = inputFiles
172
dataMap[
'outputLArFile'
] = outputFile
173
larMerge
(dataMap)
174
else
:
175
print
(
"Input format wrong --- either have: "
)
176
print
(
" --argJSON=<json-dictionary containing input info> "
)
177
print
(
" with key/value pairs: "
)
178
print
(
" or (old way): "
)
179
print
(
" --inputFiles=file1,file2,...,fileN --outputFile=file"
)
180
exit(1)
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
LArMerge_tf.getSubFileMap
getSubFileMap(fname, nevts=0)
Definition
LArMerge_tf.py:27
LArMerge_tf.larMerge
larMerge(dataMap)
Definition
LArMerge_tf.py:42
Generated on
for ATLAS Offline Software by
1.17.0