11   """Run on multiple pedestal files 
   13   Used to run on multiple pedestal bytestream files located somewhere on disk. 
   14   Puts results into seperate directories by run-number. It extracts pertinent 
   15   information from the file names, which are expected to be of the form: 
   17   data10_calib.00157081.calibration_pedCSC.daq.RAW._lb0000._CSC-EB._0001.data 
   19   run(numToRun) - process NumToRun (at most) runs out of those not yet run out of. This is the primary interface.  
   20   ReadProcessedFilesList() - find all files already run on from a local text file 
   21   AddProcessedFiles() - save newly run on files to disk 
   22   FindFiles() - Find pattern and run number of a set of files that have not yet been run on 
   23   RunAthena() - run athena job for a set of runs 
   28       inputPattern = "/raid02/schernau/ped/csc/csc/*.data" ,
 
   29       processedFilesList = "ProcessedFiles.list",
 
   30       outputDirBase = "/raid02/lampen/datasets/csc/PedProcessing2",
 
   32       allowDirOverwrite = False,
 
   34     """initialize internal variables""" 
   42   def run(self, numToRun = 10) :
 
   44     Run over all run numbers, find files for each, and submit each set to 
   48     print (
"Running on " + 
str(numToRun) + 
" runsSet.")
 
   52     for runCnt 
in range(numToRun) :
 
   53       print (
">>>>Running on runSet " + 
str(runCnt+1) + 
" of " + 
str(numToRun))
 
   57         runNumbers += [runNumber]
 
   60         print (
"No more unprocessed files. Congrats!")
 
   61         print (
"N runs done: " + 
str(runCnt +1))
 
   64     print (
"finished all " + 
str(numToRun) )
 
   65     print (
"Run numbers include:")
 
   68     print (
"All Processed files:" )
 
   78     ProcessedFiles = pickle.load(f)
 
   87     print (
'Processed String: ')
 
   88     print (ProcessedFiles)
 
   93     """Save new processed files to disk""" 
   95     ProcessedFiles += newFiles
 
   97     pickle.dump(ProcessedFiles,f)
 
  107     FoundUnprocessedFile = 
False 
  118       print (
"Searching for file")
 
  127     for file 
in inputFiles:
 
  128       if not ProcessedFiles.count(file):
 
  130         index = file.find(
"data10")
 
  132           index = file.find(
"data11")
 
  134           print (
"ERROR! Index of -1!")
 
  135           raise Exception(
"Index error") 
 
  136         FoundUnprocessedFile = 
True 
  137         pattern = file[0:index + 22] + 
"*"  
  138         runNumber = file[index + 13: index + 21]
 
  140     if(
not FoundUnprocessedFile):
 
  144       print (
"Found unprocessed file with pattern: " + pattern)
 
  145       print (
"This includes files:")
 
  146       print (glob(pattern))
 
  148     return pattern, runNumber
 
  151     """Run athena on a particular set of files matching pattern""" 
  155       subprocess.call(
"rm -rf " + outputDirPath)
 
  157     print (
"Making directory" + outputDirPath)
 
  159     os.mkdir(outputDirPath,0o755)
 
  165     athOpt = 
"outputPre='" + outputDirPath +
"/" + runNumber 
 
  166     athOpt += 
"';inputPat='" + pattern 
 
  167     athOpt += 
"';reportPrefix='runNumber = "  
  168     athOpt += runNumber + 
"'" 
  171     athArgs = [
"athena.py", 
"-c", athOpt, 
"CscCalcPedMon.py"]
 
  174     logFile = 
open(outputDirPath + 
"/run.log",
"w")
 
  177     print (
"**************************************")
 
  178     print (
"Starting running on run " + 
str(runNumber))
 
  180     subprocess.Popen(athArgs,stdout=logFile,stderr=subprocess.STDOUT).wait()
 
  181     print (
"Finished run " + 
str(runNumber))
 
  182     print (
"**************************************")
 
  189     newProcessedFiles = glob(pattern)