133 print(
"Uncompressing files:")
135 for file
in runArgs.inputTARFile:
137 tarfile.open(file).extractall(
".")
139 print(
"ERROR: Failed uncompressing TAR file\n",e)
147 files_list_rt =[item
for item
in glob.glob(
"*_rt.txt")
if "barrel" not in item]
148 files_list_t0 =[item
for item
in glob.glob(
"*_t0.txt")
if "barrel" not in item]
149 files_list_cal=[item
for item
in glob.glob(
"*calibout.root")
if "barrel" not in item]
151 files_list_trk=glob.glob(
"*tracktuple.root")
153 files_list_stw=glob.glob(
"*merged.straw.txt")
155 files_list_ctn=glob.glob(
"*calib_constants_out.txt")
157 def listFiles(v,txt=""):
158 print(
"Number of files for %s: %i" % (txt,len(v)))
161 print(
"ERROR: list of files for %s is empty" % (txt) )
165 print(
"\t-%s: %s" % (txt,i))
167 listFiles(files_list_rt ,
"RT")
168 listFiles(files_list_t0 ,
"T0")
169 listFiles(files_list_cal,
"Cal")
170 listFiles(files_list_trk,
"Track")
171 listFiles(files_list_stw,
"Straws")
172 listFiles(files_list_ctn,
"Constants")
178 command =
"touch calibout.txt ;"
179 command +=
" echo '# Fileformat=2' >> calibout.txt ; "
180 command +=
" echo '# RtRelation' >> calibout.txt ; "
183 for _f
in files_list_rt :
184 command +=
"cat %s >> calibout.txt ; " % (_f)
186 command +=
" echo '# StrawT0' >> calibout.txt ; "
189 for _f
in files_list_t0 :
190 command +=
"cat %s >> calibout.txt ; " % (_f)
193 command +=
" echo '#GLOBALOFFSET 0.0000' >> calibout.txt ; "
195 if os.path.isfile(
"calibout.txt"):
196 print(
"calibout.txt.. already exists. Removed.")
197 os.remove(
"calibout.txt")
199 tryError(command,
"ERROR: Not able to merge the Rt and t0 files\n")
206 command =
" touch oldt0s.txt ;"
207 for _f
in files_list_ctn :
208 command +=
"cat %s >> oldt0s.txt ; " % (_f)
210 if os.path.isfile(
"oldt0s.txt"):
211 print(
"oldt0s.txt.. already exists. Removed.")
212 os.remove(
"oldt0s.txt")
214 tryError(command,
"ERROR: Not able to merge the Rt and t0 files\n")
221 command =
'TRTCalib_cfilter.py calibout.txt calibout.txt oldt0s.txt shiftrt'
223 tryError(command,
"ERROR: Failed in process TRTCalib_cfilter\n")
226 nextstep(
"Run hadd to merge root files")
230 if os.path.isfile(
"merge.root"):
231 print(
"merge.root.. already exists. Removed.")
232 os.remove(
"merge.root")
234 command =
'hadd merge.root '
236 for _f
in files_list_cal :
237 command +=
"%s " % (_f)
239 command +=
"%s " % files_list_trk[0]
241 tryError(command,
"ERROR: Failed in process hadd\n")
247 outputFile = runArgs.outputTAR_MERGEDFile
248 runNumber =
int(runArgs.inputTARFile[0].
split(
'.')[1])
251 command =
"mv -v calibout.txt %s.calibout.txt ; " % outputFile
252 command +=
"mv -v merge.root %s.merge.root ; " % outputFile
254 command +=
"mv -v %s straws.%d.txt ; " % (files_list_stw[0], runNumber)
256 command +=
"mv -v dbconst.txt %s.dbconst.txt" % outputFile
258 tryError(command,
"ERROR: Failed in process hadd\n")
265 command =
"TRTCalib_makeplots itersum %s.merge.root %s/lastconfigfile" % (outputFile, os.path.abspath(
'.'))
267 tryError(command,
"ERROR: Failed in creating plots (itersum.ps file)\n")
273 command =
"ps2pdf itersum.ps %s.itersum.pdf" % (outputFile)
275 tryError(command,
"ERROR: Failed in creating itersum.pdf from itersum.ps)\n")
281 command =
"mkdir -p -v output/ ; TRTCalib_StrawStatusReport %d" % (runNumber)
283 tryError(command,
"ERROR: Failed running TRTCalib_StrawStatusReport.cxx\n")
286 nextstep(
"Straw status plots (.cxx)")
289 command =
"TRTCalib_StrawStatusPlots"
291 tryError(command,
"ERROR: Failed running root macro TRTCalib_StrawStatusPlots\n")
299 files_list=glob.glob(outputFile+
".*")
301 tar = tarfile.open(outputFile,
"w:gz")
302 print(
"\nCompressing files in %s output file:" % outputFile)
303 for file
in files_list:
308 print(
"ERROR: Failed compressing the output files\n",e)
313 nextstep(
"Copying files to AFS Directory")
316 outDIR =
"%s/run_%d" % (runArgs.attrtcal_dir, runNumber)
319 outputFile_split = outputFile.split(
'.')
321 if len(outputFile_split) > 5:
322 if "iter" in outputFile_split[5]:
323 itera = (outputFile_split[5])[-1:]
325 command =
"mkdir -p -v %s ; " % (outDIR)
326 command +=
"cp -v %s.merge.root %s/trtcalib_0%s_histograms.root ; " % (outputFile, outDIR, itera)
327 command +=
"cp -v %s.calibout.txt %s/calibout.%d.NoShifted.txt ; " % (outputFile, outDIR, runNumber)
328 command +=
"cp -v %s.itersum.pdf %s/Plots.%d.pdf ; " % (outputFile, outDIR, runNumber)
329 command +=
"cp -v %s.dbconst.txt %s/dbconst.%d.txt ; " % (outputFile, outDIR, runNumber)
330 command +=
"cp -v %s.dbconst.txt %s/calibout.%d.txt ; " % (outputFile, outDIR, runNumber)
331 command +=
"cp -v straws.%d.txt %s/straws.%d.txt; " % (runNumber, outDIR, runNumber)
332 command +=
"cp -v TRT_StrawStatusReport.txt %s/TRT_StrawStatusReport.%d.txt; " % (outDIR, runNumber)
333 command +=
"cp -v allPlots.pdf %s/TRT_StrawStatusReport.%d.pdf; " % (outDIR, runNumber)
335 tryError(command,
"ERROR: Files cannot be copied to the chosen directory\n")
343 command =
"python -m TRT_CalibAlgs.TRTCalib_Extractor %s/trtcalib_0%s_histograms.root > %s/extraction.txt" % (outDIR, itera, outDIR)
345 tryError(command,
"ERROR: Extracting information for email notification\n")
351 res_ba = 0 ; tres_ba = 0
352 res_bc = 0 ; tres_bc = 0
353 res_ea = 0 ; tres_ea = 0
354 res_ec = 0 ; tres_ec = 0
357 with open(
"%s/extraction.txt" % (outDIR))
as exfile:
360 if fnmatch.fnmatch(line,
'* res *')
and fnmatch.fnmatch(line,
'*part 1*') :
361 res_ba =
float(line.split()[6])*1000
362 if fnmatch.fnmatch(line,
'* tresmean *')
and fnmatch.fnmatch(line,
'*part 1*') :
363 tres_ba =
float(line.split()[6])
364 if fnmatch.fnmatch(line,
'* res *')
and fnmatch.fnmatch(line,
'*part -1*') :
365 res_bc =
float(line.split()[6])*1000
366 if fnmatch.fnmatch(line,
'* tresmean *')
and fnmatch.fnmatch(line,
'*part -1*') :
367 tres_bc =
float(line.split()[6])
368 if fnmatch.fnmatch(line,
'* res *')
and fnmatch.fnmatch(line,
'*part 2*') :
369 res_ea =
float(line.split()[6])*1000
370 if fnmatch.fnmatch(line,
'* tresmean *')
and fnmatch.fnmatch(line,
'*part 2*') :
371 tres_ea =
float(line.split()[6])
372 if fnmatch.fnmatch(line,
'* res *')
and fnmatch.fnmatch(line,
'*part -2*') :
373 res_ec =
float(line.split()[6])*1000
374 if fnmatch.fnmatch(line,
'* tresmean *')
and fnmatch.fnmatch(line,
'*part -2*') :
375 tres_ec =
float(line.split()[6])
377 print(
"ERROR: Failed reading %s/extraction.txt file\n" % (outDIR) ,e)
380 if runArgs.sendNotification
and runArgs.emailList :
381 send_statusmail(itera, runNumber, runArgs.emailList, outDIR, res_ba, tres_ba, res_bc, tres_bc, res_ea, tres_ea, res_ec, tres_ec)
383 print(
"INFO: No email notification sent since --sendNotification=%r or empty --emailList=" % (runArgs.sendNotification), runArgs.emailList)