def main(): parser = create_parser() args = parser.parse_args() runs = frozenset(args.runs) run_data_dir = args.run_data_dir output_dir = args.output_dir if not output_dir: output_dir = run_file_path(args.runs[0]) # Change the run data directory to the user-specified one Config().run_data_dir = run_data_dir configWrapper = AnalysisConfigWrapper(Config().analysis_config) # Create the DB if it doesn't exist already file = Config().dq_db_file_path if os.path.isfile(file): db = DQDB(Config().dq_db_file_path) existing_runs = frozenset(db.get_runs()) db.close() else: db = DQDB(file, 'CREATE') db.close() existing_runs = frozenset() runs_to_process = sorted(list(runs - existing_runs)) for run in runs_to_process: combinerTrunk = configWrapper.getTrunkForRun(run) combinerTrunk.evaluate() combinerTrunk.write_to_db()
def get_run_plot(name, run, reference=False): """Return the object at the plot path in the run file. Keyword arguments: name -- Path within the run file to the plot object. A KeyError is raised if name is not found in the run file run -- Run number reference -- If True, fetch the reference plot for the given plot and run """ if reference: run = utils.reference_run(name, run) # Get the latest run file in the run's directory base = utils.run_file_path(run) files = sorted(glob.glob("{0}/*.root".format(base))) try: path = files[-1] except IndexError: raise IOError("Run file not found for run {0}".format(run)) # Try to open the file f = ROOT.TFile(path) if f.IsZombie(): raise IOError("Run file not found for run {0}".format(run)) # Retrieve the object obj = f.Get(name) if not obj: raise KeyError("Plot {0} not found in run file {1}".format(name, run)) # The file will be closed when the function returns, so we need to clone # the fetched object outside the file's scope ROOT.gROOT.cd() clone = obj.Clone(obj.GetName()) f.Close() return clone
def test_run_file_path(self): """Should return path to ROOT file for the given run.""" self.assertEqual( utils.run_file_path(123987), "/tmp/100000s/120000s/123000s/123900s/123987" )
def test_run_file_path(self): """Should return path to ROOT file for the given run.""" self.assertEqual( utils.run_file_path(123987), os.path.join(Config().run_data_dir, "100000s", "120000s", "123000s", "123900s", "123987"))