65 print(
"Uncompressing files:")
67 for file
in runArgs.inputTARFile:
69 tarfile.open(file).extractall(
".")
71 print(
"ERROR: Failed uncompressing TAR file\n",e)
79 files_list_rt =[item
for item
in glob.glob(
"*_rt.txt")
if "barrel" not in item]
80 files_list_t0 =[item
for item
in glob.glob(
"*_t0.txt")
if "barrel" not in item]
81 files_list_cal=[item
for item
in glob.glob(
"*calibout.root")
if "barrel" not in item]
83 files_list_trk=glob.glob(
"*tracktuple.root")
85 files_list_stw=glob.glob(
"*merged.straw.txt")
87 files_list_ctn=glob.glob(
"*calib_constants_out.txt")
89 def listFiles(v,txt=""):
90 print(
"Number of files for %s: %i" % (txt,len(v)))
93 print(
"ERROR: list of files for %s is empty" % (txt) )
97 print(
"\t-%s: %s" % (txt,i))
99 listFiles(files_list_rt ,
"RT")
100 listFiles(files_list_t0 ,
"T0")
101 listFiles(files_list_cal,
"Cal")
102 listFiles(files_list_trk,
"Track")
103 listFiles(files_list_stw,
"Straws")
104 listFiles(files_list_ctn,
"Constants")
110 command =
"touch calibout.txt ;"
111 command +=
" echo '# Fileformat=2' >> calibout.txt ; "
112 command +=
" echo '# RtRelation' >> calibout.txt ; "
115 for _f
in files_list_rt :
116 command +=
"cat %s >> calibout.txt ; " % (_f)
118 command +=
" echo '# StrawT0' >> calibout.txt ; "
121 for _f
in files_list_t0 :
122 command +=
"cat %s >> calibout.txt ; " % (_f)
125 command +=
" echo '#GLOBALOFFSET 0.0000' >> calibout.txt ; "
127 if os.path.isfile(
"calibout.txt"):
128 print(
"calibout.txt.. already exists. Removed.")
129 os.remove(
"calibout.txt")
131 tryError(command,
"ERROR: Not able to merge the Rt and t0 files\n")
138 command =
" touch oldt0s.txt ;"
139 for _f
in files_list_ctn :
140 command +=
"cat %s >> oldt0s.txt ; " % (_f)
142 if os.path.isfile(
"oldt0s.txt"):
143 print(
"oldt0s.txt.. already exists. Removed.")
144 os.remove(
"oldt0s.txt")
146 tryError(command,
"ERROR: Not able to merge the Rt and t0 files\n")
153 command =
'TRTCalib_cfilter.py calibout.txt calibout.txt oldt0s.txt shiftrt'
155 tryError(command,
"ERROR: Failed in process TRTCalib_cfilter\n")
158 nextstep(
"Run hadd to merge root files")
162 if os.path.isfile(
"merge.root"):
163 print(
"merge.root.. already exists. Removed.")
164 os.remove(
"merge.root")
166 command =
'hadd merge.root '
168 for _f
in files_list_cal :
169 command +=
"%s " % (_f)
171 command +=
"%s " % files_list_trk[0]
173 tryError(command,
"ERROR: Failed in process hadd\n")
179 outputFile = runArgs.outputTAR_MERGEDFile
180 runNumber =
int(runArgs.inputTARFile[0].
split(
'.')[1])
183 command =
"mv -v calibout.txt %s.calibout.txt ; " % outputFile
184 command +=
"mv -v merge.root %s.merge.root ; " % outputFile
186 command +=
"mv -v %s straws.%d.txt ; " % (files_list_stw[0], runNumber)
188 command +=
"mv -v dbconst.txt %s.dbconst.txt" % outputFile
190 tryError(command,
"ERROR: Failed in process hadd\n")
197 command =
"TRTCalib_makeplots itersum %s.merge.root %s/lastconfigfile" % (outputFile, os.path.abspath(
'.'))
199 tryError(command,
"ERROR: Failed in creating plots (itersum.ps file)\n")
205 command =
"ps2pdf itersum.ps %s.itersum.pdf" % (outputFile)
207 tryError(command,
"ERROR: Failed in creating itersum.pdf from itersum.ps)\n")
213 command =
"mkdir -p -v output/ ; TRTCalib_StrawStatusReport %d" % (runNumber)
215 tryError(command,
"ERROR: Failed running TRTCalib_StrawStatusReport.cxx\n")
218 nextstep(
"Straw status plots (.cxx)")
221 command =
"TRTCalib_StrawStatusPlots"
223 tryError(command,
"ERROR: Failed running root macro TRTCalib_StrawStatusPlots\n")
231 files_list=glob.glob(outputFile+
".*")
233 tar = tarfile.open(outputFile,
"w:gz")
234 print(
"\nCompressing files in %s output file:" % outputFile)
235 for file
in files_list:
240 print(
"ERROR: Failed compressing the output files\n",e)
245 nextstep(
"Copying files to AFS Directory")
248 outDIR =
"%s/run_%d" % (runArgs.attrtcal_dir, runNumber)
251 outputFile_split = outputFile.split(
'.')
253 if len(outputFile_split) > 5:
254 if "iter" in outputFile_split[5]:
255 itera = (outputFile_split[5])[-1:]
257 command =
"mkdir -p -v %s ; " % (outDIR)
258 command +=
"cp -v %s.merge.root %s/trtcalib_0%s_histograms.root ; " % (outputFile, outDIR, itera)
259 command +=
"cp -v %s.calibout.txt %s/calibout.%d.NoShifted.txt ; " % (outputFile, outDIR, runNumber)
260 command +=
"cp -v %s.itersum.pdf %s/Plots.%d.pdf ; " % (outputFile, outDIR, runNumber)
261 command +=
"cp -v %s.dbconst.txt %s/dbconst.%d.txt ; " % (outputFile, outDIR, runNumber)
262 command +=
"cp -v %s.dbconst.txt %s/calibout.%d.txt ; " % (outputFile, outDIR, runNumber)
263 command +=
"cp -v straws.%d.txt %s/straws.%d.txt; " % (runNumber, outDIR, runNumber)
264 command +=
"cp -v TRT_StrawStatusReport.txt %s/TRT_StrawStatusReport.%d.txt; " % (outDIR, runNumber)
265 command +=
"cp -v allPlots.pdf %s/TRT_StrawStatusReport.%d.pdf; " % (outDIR, runNumber)
267 tryError(command,
"ERROR: Files cannot be copied to the chosen directory\n")
275 command =
"python -m TRT_CalibAlgs.TRTCalib_Extractor %s/trtcalib_0%s_histograms.root > %s/extraction.txt" % (outDIR, itera, outDIR)
277 tryError(command,
"ERROR: Extracting information for email notification\n")
283 res_ba = 0 ; tres_ba = 0
284 res_bc = 0 ; tres_bc = 0
285 res_ea = 0 ; tres_ea = 0
286 res_ec = 0 ; tres_ec = 0
289 with open(
"%s/extraction.txt" % (outDIR))
as exfile:
291 if fnmatch.fnmatch(line,
'* res *')
and fnmatch.fnmatch(line,
'*part 1*') :
292 res_ba = line.split()[6]
293 if fnmatch.fnmatch(line,
'* tresmean *')
and fnmatch.fnmatch(line,
'*part 1*') :
294 tres_ba = line.split()[6]
295 if fnmatch.fnmatch(line,
'* res *')
and fnmatch.fnmatch(line,
'*part -1*') :
296 res_bc = line.split()[6]
297 if fnmatch.fnmatch(line,
'* tresmean *')
and fnmatch.fnmatch(line,
'*part -1*') :
298 tres_bc = line.split()[6]
299 if fnmatch.fnmatch(line,
'* res *')
and fnmatch.fnmatch(line,
'*part 2*') :
300 res_ea = line.split()[6]
301 if fnmatch.fnmatch(line,
'* tresmean *')
and fnmatch.fnmatch(line,
'*part 2*') :
302 tres_ea = line.split()[6]
303 if fnmatch.fnmatch(line,
'* res *')
and fnmatch.fnmatch(line,
'*part -2*') :
304 res_ec = line.split()[6]
305 if fnmatch.fnmatch(line,
'* tresmean *')
and fnmatch.fnmatch(line,
'*part -2*') :
306 tres_ec = line.split()[6]
308 print(
"ERROR: Failed reading %s/extraction.txt file\n" % (outDIR) ,e)
311 if runArgs.sendNotification
and runArgs.emailList :
312 send_statusmail(itera, runNumber, runArgs.emailList, outDIR, res_ba, tres_ba, res_bc, tres_bc, res_ea, tres_ea, res_ec, tres_ec)
314 print(
"INFO: No email notification sent since --sendNotification=%r or empty --emailList=" % (runArgs.sendNotification), runArgs.emailList)