class E3RunDbInterface(MySQLdb.connections.Connection): """ Basic interface to the run database. """ CFG_FILE_PATH = os.path.join(E3PIPE_DB, 'rundb.cfg') def __init__(self): """ Constructor. """ if not os.path.exists(self.CFG_FILE_PATH): abort('Could not find configuration file %s' % self.CFG_FILE_PATH) logger.info('Reading db configuration file %s...' % self.CFG_FILE_PATH) parser = ConfigParser.ConfigParser() parser.read(self.CFG_FILE_PATH) try: host = parser.get('General', 'host') user = parser.get('General', 'user') dbname = parser.get('General', 'dbname') pwd = parser.get('General', 'pwd') except ConfigParser.NoOptionError, e: abort(e) logger.info('Connecting to %s on %s (as %s)' % (dbname, host, user)) MySQLdb.connections.Connection.__init__(self, host, user, pwd, dbname) logger.info('Done, setting up cursor...') self.__Cursor = self.cursor() logger.info('Interface to the run database ready.')
def crawlFolder(self, folderPath): """ Overloaded class method. Mind that here we skip the last file, after we sorted the list, as that (though older than self.__MinHoursSinceSynch) might still being transferred from the school. """ fileList = [] numTotal = 0 numNew = 0 numProcessed = 0 numLocked = 0 numReady = 0 for filePath in glob.glob(os.path.join(folderPath, '*.bin')): runInfo = E3RawDataInfo(filePath) _new = runInfo.hoursSinceSynch() < self.__MinHoursSinceSynch _processed = runInfo.processed() _locked = runInfo.locked() numTotal += 1 if _new: numNew += 1 elif _processed: numProcessed += 1 elif _locked: numLocked += 1 else: numReady += 1 if (not _processed or self.__Overwrite) and \ not _new and not _locked: fileList.append(runInfo.RawFilePath) logger.info('%d file(s), %d ready, %d processed, %d locked, %d new.' %\ (numTotal, numReady, numProcessed, numLocked, numNew)) fileList.sort() return fileList
def writeAscii(self, outputFilePath, delimiter = ',', endline = '\r\n'): """ Write the chain to a text file. """ logger.info('Writing %s to %s...' % (self.GetName(), outputFilePath)) outputFile = open(outputFilePath, 'w') branchList = [] formatList = [] for branch in self.GetListOfBranches(): (branchName, branchType) = branch.GetTitle().split('/') if self.GetBranchStatus(branchName): branchList.append(branch.GetName()) if branchType == 'D': formatList.append('%.12e') elif branchType == 'F': formatList.append('%.6e') elif branchType=='C': formatList.append('%s') else: formatList.append('%d') outputFile.write('#') for branchName in branchList[:-1]: outputFile.write('%s,' % branchName) outputFile.write('%s%s' % (branchList[-1], endline)) rowSpecifier = zip(branchList, formatList) for i in xrange(self.GetEntries()): self.GetEntry(i) for branchName, fmt in rowSpecifier[:-1]: val = fmt % self.arrayValue(branchName) outputFile.write('%s,' % val) val = formatList[-1] % self.arrayValue(branchList[-1]) outputFile.write('%s%s' % (val, endline)) outputFile.close() logger.info('Output file closed, done.')
def e3recon(rawFilePath, copyFiles = True, suffix = None): """ Run the analyzer, build the DST and run the DQM (i.e., effectively run the full reconstruction for one single run). TODO: we should add some protection to make sure that everything went fine before we actually try and copy the output files over. TODO: we are instantiating a E3RawDataInfo object, here, and therefore we are in principle recalculating all the path, which the crawler might have already done. While this is not elegant, I don't think we'll ever notice the overhead. """ baseFilePath = e3analyzer(rawFilePath, suffix) dstFilePath = e3dst(baseFilePath) dqmFolderPath = '%s_DQM' % baseFilePath e3dqm(dstFilePath, dqmFolderPath) if copyFiles: logger.info('Setting up to copy files...') runInfo = E3RawDataInfo(rawFilePath) logger.info(runInfo) calibFilePath = os.path.join(E3PIPE_TEMP, E3_CALIB_FILE_NAME) if os.path.exists(calibFilePath): __utils__.cp(calibFilePath, runInfo.CalibFilePath, True) __utils__.cp(dstFilePath, runInfo.DstFilePath, True) if os.path.exists(runInfo.DqmFolderPath): __utils__.rmdir(runInfo.DqmFolderPath) __utils__.cp(dqmFolderPath, runInfo.DqmFolderPath, True)
def crawlFolder(self, folderPath): """ Overloaded class method. Mind that here we skip the last file, after we sorted the list, as that (though older than self.__MinHoursSinceSynch) might still being transferred from the school. """ fileList = [] numTotal = 0 numNew = 0 numProcessed = 0 numLocked = 0 numReady = 0 for filePath in glob.glob(os.path.join(folderPath, '*.bin')): runInfo = E3RawDataInfo(filePath) _new = runInfo.hoursSinceSynch() < self.__MinHoursSinceSynch _processed = runInfo.processed() _locked = runInfo.locked() numTotal += 1 if _new: numNew += 1 elif _processed: numProcessed += 1 elif _locked: numLocked += 1 else: numReady += 1 if (not _processed or self.__Overwrite) and \ not _new and not _locked: fileList.append(runInfo.RawFilePath) logger.info('%d file(s), %d ready, %d processed, %d locked, %d new.' %\ (numTotal, numReady, numProcessed, numLocked, numNew)) fileList.sort() return fileList
def setupTreeFormulae(self): """ Setup tree formulae for all the aliases. """ logger.info('Compiling TTreeFormula objects for the aliases...') for key, value in self.ALIAS_DICT.items(): self.__setupTreeFormula(key, value) logger.info('Done.')
def setupTreeFormulae(self): """ Setup tree formulae for all the aliases. """ logger.info('Compiling TTreeFormula objects for the aliases...') for key, value in self.ALIAS_DICT.items(): self.__setupTreeFormula(key, value) logger.info('Done.')
def writeAscii(self, outputFilePath, delimiter=',', endline='\r\n'): """ Write the chain to a text file. """ logger.info('Writing %s to %s...' % (self.GetName(), outputFilePath)) outputFile = open(outputFilePath, 'w') branchList = [] formatList = [] for branch in self.GetListOfBranches(): (branchName, branchType) = branch.GetTitle().split('/') if self.GetBranchStatus(branchName): branchList.append(branch.GetName()) if branchType == 'D': formatList.append('%.12e') elif branchType == 'F': formatList.append('%.6e') elif branchType == 'C': formatList.append('%s') else: formatList.append('%d') outputFile.write('#') for branchName in branchList[:-1]: outputFile.write('%s,' % branchName) outputFile.write('%s%s' % (branchList[-1], endline)) rowSpecifier = zip(branchList, formatList) for i in xrange(self.GetEntries()): self.GetEntry(i) for branchName, fmt in rowSpecifier[:-1]: val = fmt % self.arrayValue(branchName) outputFile.write('%s,' % val) val = formatList[-1] % self.arrayValue(branchList[-1]) outputFile.write('%s%s' % (val, endline)) outputFile.close() logger.info('Output file closed, done.')
def e3recon(rawFilePath, copyFiles=True, suffix=None): """ Run the analyzer, build the DST and run the DQM (i.e., effectively run the full reconstruction for one single run). TODO: we should add some protection to make sure that everything went fine before we actually try and copy the output files over. TODO: we are instantiating a E3RawDataInfo object, here, and therefore we are in principle recalculating all the path, which the crawler might have already done. While this is not elegant, I don't think we'll ever notice the overhead. """ baseFilePath = e3analyzer(rawFilePath, suffix) dstFilePath = e3dst(baseFilePath) dqmFolderPath = '%s_DQM' % baseFilePath e3dqm(dstFilePath, dqmFolderPath) if copyFiles: logger.info('Setting up to copy files...') runInfo = E3RawDataInfo(rawFilePath) logger.info(runInfo) calibFilePath = os.path.join(E3PIPE_TEMP, E3_CALIB_FILE_NAME) if os.path.exists(calibFilePath): __utils__.cp(calibFilePath, runInfo.CalibFilePath, True) __utils__.cp(dstFilePath, runInfo.DstFilePath, True) if os.path.exists(runInfo.DqmFolderPath): __utils__.rmdir(runInfo.DqmFolderPath) __utils__.cp(dqmFolderPath, runInfo.DqmFolderPath, True)
def hist1d(self, expression, cut = '', name = None, title = None, xmin = None, xmax = None, xbins = 100, xpad = 0, **kwargs): """ Create a 1-dimensional histogram. """ logger.info('Creating 1-d histogram for %s with cut "%s"...' %\ (expression, cut)) kwargs['XTitle'] = kwargs.get('XTitle', expression) kwargs['YTitle'] = kwargs.get('YTitle', 'Entries/bin') name = name or expression title = title or name if xmin is None or xmax is None: _xmin = self.GetMinimum(expression) _xmax = self.GetMaximum(expression) if _xmin == 0 and _xmax == 0: _xmax = 1 _xrange = _xmax - _xmin if xmin is None: xmin = _xmin - xpad*_xrange if xmax is None: xmax = _xmax + xpad*_xrange if xmin == xmax: if xmin == 0: xmin = -0.5 xmax = 0.5 else: xmin -= 0.1*xmin xmax += 0.1*xmax hist = E3H1D(name, title, xbins, xmin, xmax, **kwargs) self.Project(name, expression, cut) self.store(hist) return hist
def __e3analyzer_pisa(filePath): """ Run the Pisa custom analyzer. """ _cmd = 'cd %s; %s %s' % (E3PIPE_TEMP, E3_ANALYZER_PI, filePath) logger.info('Running the EEE Analyzer in the Pisan flavor') exitCode = __utils__.cmd(_cmd) if exitCode: sys.exit(exitCode)
def __e3analyzer_pisa(filePath): """ Run the Pisa custom analyzer. """ _cmd = 'cd %s; %s %s' % (E3PIPE_TEMP, E3_ANALYZER_PI, filePath) logger.info('Running the EEE Analyzer in the Pisan flavor') exitCode = __utils__.cmd(_cmd) if exitCode: sys.exit(exitCode)
def fillEventDict(self): """ Fill a dictionary with the information about the second tracks. """ logger.info('Parsing .2tt file and filling the event dict...') for event in self: self.__EventDict[event['EventNumber']] = event logger.info('Done, %d event(s) with two tracks found.' %\ len(self.__EventDict))
def addBranch(self, branchName, branchType): """ Add a branch to the output tree. """ branchTitle = '%s/%s' % (branchName, branchType) logger.info('Adding branch %s to %s...' % (branchTitle, self.GetName())) a = numpy.array([0], dtype = root2numpy(branchType)) self.__ArrayDict[branchName] = a self.Branch(branchName, a, branchTitle)
def __init__(self): """ Constructor. """ logger.info('Initializing muon flux service...') self.__ThetaDist = ROOT.TF1('muon_theta', 'sin(x)*cos(x)**[0]', 0, math.pi/2.) self.__ThetaDist.SetParameter(0, 2.0) self.__PhiDist = ROOT.TF1('muon_phi', '1', -math.pi, math.pi)
def setupArrays(self): """ Setup the arrays to be attached to all the enabled tree branches. """ logger.info('Creating array(s) to be attached to the branches...') for branch in self.GetListOfBranches(): self.__setupArray(branch) logger.info('Done, arrays ready.')
def fillEventDict(self): """ Fill a dictionary with the information about the second tracks. """ logger.info('Parsing .2tt file and filling the event dict...') for event in self: self.__EventDict[event['EventNumber']] = event logger.info('Done, %d event(s) with two tracks found.' %\ len(self.__EventDict))
def selectBranches(self, *branches): """ """ logger.info('Disabling all branches...') self.SetBranchStatus('*', 0) for branch in branches: logger.info('Enabling branch %s...' % branch) self.SetBranchStatus(branch, 1)
def refitTrack(self, verbose = True): """ Refit the track points. """ logger.info('Refitting track points...') self.__FittingTool.run(self.__CurrentHits) if verbose: print self.__FittingTool return self.__FittingTool.track()
def __init__(self): """ Constructor. """ logger.info('Initializing muon flux service...') self.__ThetaDist = ROOT.TF1('muon_theta', 'sin(x)*cos(x)**[0]', 0, math.pi / 2.) self.__ThetaDist.SetParameter(0, 2.0) self.__PhiDist = ROOT.TF1('muon_phi', '1', -math.pi, math.pi)
def __e3analyzer2(filePath, opts): """ Run the brand new analyzer. """ _cmd = 'cd %s; %s %s %s' % (E3PIPE_TEMP, E3_ANALYZER_NEW, opts, filePath) logger.info('Generating the calibration file...') exitCode = __utils__.cmd(_cmd) if exitCode: sys.exit(exitCode)
def setupArrays(self): """ Setup the arrays to be attached to all the enabled tree branches. """ logger.info('Creating array(s) to be attached to the branches...') for branch in self.GetListOfBranches(): self.__setupArray(branch) logger.info('Done, arrays ready.')
def selectBranches(self, *branches): """ """ logger.info('Disabling all branches...') self.SetBranchStatus('*', 0) for branch in branches: logger.info('Enabling branch %s...' % branch) self.SetBranchStatus(branch, 1)
def refitTrack(self, verbose=True): """ Refit the track points. """ logger.info('Refitting track points...') self.__FittingTool.run(self.__CurrentHits) if verbose: print self.__FittingTool return self.__FittingTool.track()
def dqmPreformat(dstFile): """ Generic hook to format stuff in the DST before it's plotted. """ logger.info('Preformatting DST for DQM...') dstFile.Get('RateHitEvents').GetYaxis().SetRangeUser(0, 100) dstFile.Get('RateTrackEvents').GetYaxis().SetRangeUser(0, 100) dstFile.Get('FractionTrackEvents').GetYaxis().SetRangeUser(0, 1.1) logger.info('Done.')
def addBranch(self, branchName, branchType): """ Add a branch to the output tree. """ branchTitle = '%s/%s' % (branchName, branchType) logger.info('Adding branch %s to %s...' % (branchTitle, self.GetName())) a = numpy.array([0], dtype=root2numpy(branchType)) self.__ArrayDict[branchName] = a self.Branch(branchName, a, branchTitle)
def __init__(self, filePath): """ Constructor. """ E3Chain.__init__(self, filePath, self.TREE_NAME) self.StartTime = self.value('Timestamp', 0) self.StopTime = self.value('Timestamp', self.GetEntries() - 1) self.Duration = self.StopTime - self.StartTime logger.info('Time range: %.3f--%.3f (%.3f) s' %\ (self.StartTime, self.StopTime, self.Duration))
def __init__(self, filePath, **kwargs): """ Constructor. """ css = kwargs.get('css', self.DEFAULT_CSS_FILE_PATH) title = kwargs.get('title', self.DEFAULT_TITLE) header = kwargs.get('header', self.DEFAULT_HEADER_TEXT) logger.info('Opening output file %s...' % filePath) file.__init__(self, filePath, 'w') self.write(HTML_HEADER % (title, css, header))
def __init__(self, filePath): """ Constructor. """ E3Chain.__init__(self, filePath, self.TREE_NAME) self.StartTime = self.value('Timestamp', 0) self.StopTime = self.value('Timestamp', self.GetEntries() - 1) self.Duration = self.StopTime - self.StartTime logger.info('Time range: %.3f--%.3f (%.3f) s' %\ (self.StartTime, self.StopTime, self.Duration))
def cleanup(): """ """ global ROOT_OBJECT_POOL logger.info('Cleaning up ROOT pool...') for obj in ROOT_OBJECT_POOL: if isinstance(obj, ROOT.TFile): logger.info('Closing %s...' % obj.GetName()) obj.Close() ROOT_OBJECT_POOL.remove(obj)
def __init__(self, filePath, extension=None): """ """ if not os.path.exists(filePath): abort('Could not find input file %s' % filePath) if extension is not None and not filePath.endswith(extension): abort('Wrong file extension for input file %s (%s expected)' %\ (filePath, extension)) logger.info('Opening input file %s...' % filePath) file.__init__(self, filePath)
def __setupArray(self, branch): """ Setup an array to be attached to a tree branch. """ branchTitle = branch.GetTitle() (branchName, branchType) = branchTitle.split('/') if self.GetBranchStatus(branchName): logger.info('Setting up numpy array for %s...' % branchTitle) x = numpy.empty((1, ), ROOT_TO_NUMPY_DICT[branchType]) self.__ArrayDict[branchName] = x self.SetBranchAddress(branchName, x)
def writeString(key, value): """ Write a string to the current ROOT file. The text can be retrieved from the file using the E3InputRootFile.readString() method. """ string = ROOT.TNamed(key, str(value)) logger.info('Writing %s (%s) to output file...' % (key, value)) string.Write() return string
def popLastFiles(self): """ """ logger.info('Popping out last file found for each station...') nstart = len(self) self.__FileList = [] for station in self.stations(): self.__FileDict[station] = self.__FileDict[station][:-1] self.__FileList += self.__FileDict[station] logger.info('Done, %d file(s) left (were %d).' % (len(self), nstart))
def __init__(self, filePath, extension = None): """ """ if not os.path.exists(filePath): abort('Could not find input file %s' % filePath) if extension is not None and not filePath.endswith(extension): abort('Wrong file extension for input file %s (%s expected)' %\ (filePath, extension)) logger.info('Opening input file %s...' % filePath) file.__init__(self, filePath)
def cleanup(folderPath, patterns = ['*~', '*.pyc', '*.pyo']): """ Cleanup a folder. """ logger.info('Cleaning up folder %s...' % folderPath) fileList = [] for pattern in patterns: fileList += glob.glob(os.path.join(folderPath, pattern)) for filePath in fileList: logger.info('Removing %s...' % filePath) os.remove(filePath)
def cleanupdist(): """ """ if os.path.exists(E3PIPE_DIST): logger.info('Removing %s altogether...' % E3PIPE_DIST) shutil.rmtree(E3PIPE_DIST) filePath = os.path.join(E3PIPE_BASE, 'MANIFEST') if os.path.exists(filePath): logger.info('Removing %s...' % filePath) os.remove(filePath)
def __setupArray(self, branch): """ Setup an array to be attached to a tree branch. """ branchTitle = branch.GetTitle() (branchName, branchType) = branchTitle.split('/') if self.GetBranchStatus(branchName): logger.info('Setting up numpy array for %s...' % branchTitle) x = numpy.empty((1,), ROOT_TO_NUMPY_DICT[branchType]) self.__ArrayDict[branchName] = x self.SetBranchAddress(branchName, x)
def execute(self, query, commit = True): """ Execute a query. """ logger.info('About to execute "%s"...' % query) if commit: try: self.__Cursor.execute(query) self.commit() except Exception, e: logger.error('%s, rolling back change...' % e) self.rollback()
def execute(self, query, commit=True): """ Execute a query. """ logger.info('About to execute "%s"...' % query) if commit: try: self.__Cursor.execute(query) self.commit() except Exception, e: logger.error('%s, rolling back change...' % e) self.rollback()
def write(self, filePath): """ """ logger.info('Writing alarm summary to %s...' % filePath) outputFile = open(filePath, 'w') outputFile.write('Status: %s\n' % self.status()) for status in [E3Alarm.STATUS_ERROR, E3Alarm.STATUS_WARNING, E3Alarm.STATUS_CLEAN, E3Alarm.STATUS_UNSET]: outputFile.write('%s alarms: %s\n' % (status, self[status])) outputFile.close() logger.info('Done.')
def __e3analyzer_standard(filePath): """ Run the standard EEE analyzer (all stations but Pisa). """ _cmd = 'cd %s; %s %s' % (E3PIPE_TEMP, E3_ANALYZER, filePath) logger.info('Generating the calibration file...') exitCode = __utils__.cmd(_cmd) if exitCode: sys.exit(exitCode) logger.info('Running the EEE Analyzer for real!') exitCode = __utils__.cmd(_cmd) if exitCode: sys.exit(exitCode)
def __init__(self, title = None): """ Constructor. """ ROOT.TTree.__init__(self, self.NAME, title or self.NAME) E3TreePlotter.__init__(self) self.__ArrayDict = {} for branch in self.BRANCHES: self.addBranch(branch.Name, branch.Type) self.BranchList = [branch.Name for branch in self.BRANCHES] for key, value in self.ALIAS_DICT.items(): logger.info('Setting alias "%s" -> "%s"...' % (key, value)) self.SetAlias(key, value)
def __init__(self, title=None): """ Constructor. """ ROOT.TTree.__init__(self, self.NAME, title or self.NAME) E3TreePlotter.__init__(self) self.__ArrayDict = {} for branch in self.BRANCHES: self.addBranch(branch.Name, branch.Type) self.BranchList = [branch.Name for branch in self.BRANCHES] for key, value in self.ALIAS_DICT.items(): logger.info('Setting alias "%s" -> "%s"...' % (key, value)) self.SetAlias(key, value)
def rmdir(folderPath): """ Remove an entire (empty or non empty) folder. """ logger.info('About to remove folder %s...' % folderPath) try: shutil.rmtree(folderPath) logger.info('Folder succesfully removed.') status = 0 except Exception as e: logger.error('Could not remove folder (%s)' % e) status = 1 return status
def rmdir(folderPath): """ Remove an entire (empty or non empty) folder. """ logger.info('About to remove folder %s...' % folderPath) try: shutil.rmtree(folderPath) logger.info('Folder succesfully removed.') status = 0 except Exception as e: logger.error('Could not remove folder (%s)' % e) status = 1 return status
def __e3analyzer_standard(filePath): """ Run the standard EEE analyzer (all stations but Pisa). """ _cmd = 'cd %s; %s %s' % (E3PIPE_TEMP, E3_ANALYZER, filePath) logger.info('Generating the calibration file...') exitCode = __utils__.cmd(_cmd) if exitCode: sys.exit(exitCode) logger.info('Running the EEE Analyzer for real!') exitCode = __utils__.cmd(_cmd) if exitCode: sys.exit(exitCode)
def write(self, filePath): """ """ logger.info('Writing alarm summary to %s...' % filePath) outputFile = open(filePath, 'w') outputFile.write('Status: %s\n' % self.status()) for status in [ E3Alarm.STATUS_ERROR, E3Alarm.STATUS_WARNING, E3Alarm.STATUS_CLEAN, E3Alarm.STATUS_UNSET ]: outputFile.write('%s alarms: %s\n' % (status, self[status])) outputFile.close() logger.info('Done.')
def Add(self, filePath): """ Add a file to the chain. Note that we are doing some basic check, here, in order to try and prevent simple issues. """ if not '*' in filePath: if not os.path.exists(filePath): abort('Could not find input file %s' % filePath) if not filePath.endswith(E3RootFileBase.EXTENSION): abort('Wrong file extension for input file %s (%s expected)' %\ (filePath, E3RootFileBase.EXTENSION)) logger.info('Adding %s...' % filePath) ROOT.TChain.Add(self, filePath)
def mv(source, dest): """ Move a file. Return 0 upon succesfull operation, 1 otherwise. """ logger.info('About to move %s to %s...' % (source, dest)) try: shutil.move(source, dest) logger.info('File succesfully copied.') status = 0 except Exception as e: logger.error('Could not move file (%s)' % e) status = 1 return status
def data2hist(data, key, xmin=-0.5, xmax=35.5): """ TODO: move this to the sumfile class? """ xbins = int(xmax - xmin + 0.5) name = key title = key.replace('Mult', ' multiplicity ') logger.info('Filling histogram %s...' % name) h = ROOT.TH1I(name, title, xbins, xmin, xmax) h.SetXTitle(title) content = data[key] for value, weight in content.items(): h.Fill(value, weight) h.SetEntries(h.GetSumOfWeights()) return h
def Add(self, filePath): """ Add a file to the chain. Note that we are doing some basic check, here, in order to try and prevent simple issues. """ if not '*' in filePath: if not os.path.exists(filePath): abort('Could not find input file %s' % filePath) if not filePath.endswith(E3RootFileBase.EXTENSION): abort('Wrong file extension for input file %s (%s expected)' %\ (filePath, E3RootFileBase.EXTENSION)) logger.info('Adding %s...' % filePath) ROOT.TChain.Add(self, filePath)
def e3jointCrawl(endDate = None, daysSpanned = 2, minSize = 0, blackList = [], overwrite = False, maxNumRuns = None, dryRun = False): """ Crawl the raw data and process the files. """ logDate = datetime.datetime.today() datestr = date2str(logDate) timestr = logDate.strftime('%Y-%m-%d-%H-%M-%S-%f') logFilePath = os.path.join(E3PIPE_LOG_BASE, datestr, '%s.log' % timestr) logFolder = os.path.dirname(logFilePath) __utils__.createFolder(logFolder) logFileHandler = E3FileHandler(logFilePath) crawler = E3RunDbRawFileCrawler(endDate, daysSpanned, minSize, blackList, overwrite) logger.info(crawler) if dryRun: logger.info('Just kidding, dry run :-)') return numFiles = maxNumRuns or len(crawler) curFile = 1 for filePath in crawler: logger.info('Processing file %d/%d: %s with NEW pipe' % (curFile, numFiles, filePath)) _cmd = 'e3process2.py %s' % filePath exitCode = __utils__.cmd(_cmd) logger.info('Processing file %d/%d: %s with OLD pipe' % (curFile, numFiles, filePath)) _cmd = 'e3process.py %s' % filePath exitCode = __utils__.cmd(_cmd) if maxNumRuns is not None and curFile >= maxNumRuns: break curFile += 1 logFileHandler.close()
def mv(source, dest): """ Move a file. Return 0 upon succesfull operation, 1 otherwise. """ logger.info('About to move %s to %s...' % (source, dest)) try: shutil.move(source, dest) logger.info('File succesfully copied.') status = 0 except Exception as e: logger.error('Could not move file (%s)' % e) status = 1 return status
def data2hist(data, key, xmin = -0.5, xmax = 35.5): """ TODO: move this to the sumfile class? """ xbins = int(xmax - xmin + 0.5) name = key title = key.replace('Mult', ' multiplicity ') logger.info('Filling histogram %s...' % name) h = ROOT.TH1I(name, title, xbins, xmin, xmax) h.SetXTitle(title) content = data[key] for value, weight in content.items(): h.Fill(value, weight) h.SetEntries(h.GetSumOfWeights()) return h