3 from __future__
import print_function
12 """Run on multiple pedestal files
14 Used to run on multiple pedestal bytestream files located somewhere on disk.
15 Puts results into seperate directories by run-number. It extracts pertinent
16 information from the file names, which are expected to be of the form:
18 data10_calib.00157081.calibration_pedCSC.daq.RAW._lb0000._CSC-EB._0001.data
20 run(numToRun) - process NumToRun (at most) runs out of those not yet run out of. This is the primary interface.
21 ReadProcessedFilesList() - find all files already run on from a local text file
22 AddProcessedFiles() - save newly run on files to disk
23 FindFiles() - Find pattern and run number of a set of files that have not yet been run on
24 RunAthena() - run athena job for a set of runs
29 inputPattern = "/raid02/schernau/ped/csc/csc/*.data" ,
30 processedFilesList = "ProcessedFiles.list",
31 outputDirBase = "/raid02/lampen/datasets/csc/PedProcessing2",
33 allowDirOverwrite = False,
35 """initialize internal variables"""
43 def run(self, numToRun = 10) :
45 Run over all run numbers, find files for each, and submit each set to
49 print (
"Running on " +
str(numToRun) +
" runsSet.")
53 for runCnt
in range(numToRun) :
54 print (
">>>>Running on runSet " +
str(runCnt+1) +
" of " +
str(numToRun))
58 runNumbers += [runNumber]
61 print (
"No more unprocessed files. Congrats!")
62 print (
"N runs done: " +
str(runCnt +1))
65 print (
"finished all " +
str(numToRun) )
66 print (
"Run numbers include:")
69 print (
"All Processed files:" )
79 ProcessedFiles = pickle.load(f)
88 print (
'Processed String: ')
89 print (ProcessedFiles)
94 """Save new processed files to disk"""
96 ProcessedFiles += newFiles
98 pickle.dump(ProcessedFiles,f)
108 FoundUnprocessedFile =
False
119 print (
"Searching for file")
128 for file
in inputFiles:
129 if not ProcessedFiles.count(file):
131 index = file.find(
"data10")
133 index = file.find(
"data11")
135 print (
"ERROR! Index of -1!")
136 raise Exception(
"Index error")
137 FoundUnprocessedFile =
True
138 pattern = file[0:index + 22] +
"*"
139 runNumber = file[index + 13: index + 21]
141 if(
not FoundUnprocessedFile):
145 print (
"Found unprocessed file with pattern: " + pattern)
146 print (
"This includes files:")
147 print (glob(pattern))
149 return pattern, runNumber
152 """Run athena on a particular set of files matching pattern"""
156 subprocess.call(
"rm -rf " + outputDirPath)
158 print (
"Making directory" + outputDirPath)
160 os.mkdir(outputDirPath,0o755)
166 athOpt =
"outputPre='" + outputDirPath +
"/" + runNumber
167 athOpt +=
"';inputPat='" + pattern
168 athOpt +=
"';reportPrefix='runNumber = "
169 athOpt += runNumber +
"'"
172 athArgs = [
"athena.py",
"-c", athOpt,
"CscCalcPedMon.py"]
175 logFile =
open(outputDirPath +
"/run.log",
"w")
178 print (
"**************************************")
179 print (
"Starting running on run " +
str(runNumber))
181 subprocess.Popen(athArgs,stdout=logFile,stderr=subprocess.STDOUT).wait()
182 print (
"Finished run " +
str(runNumber))
183 print (
"**************************************")
190 newProcessedFiles = glob(pattern)