hadd_reco_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python2
2 
3 #
4 # This script is to make easy hadding the grid output of the RecoValidation jobs.
5 # This script uses the same configuration file as the submit_reco_validation.py script.
6 #
7 
8 from ConfigParser import *
9 import argparse, os, subprocess
10 
11 def source_script(filename):
12  proc = subprocess.Popen(['bash', '-c', 'source {0} && env'.format(filename)], stdout=subprocess.PIPE)
13  for tup in map(lambda s: s.strip().split('=', 1), proc.stdout):
14  if len(tup) > 1:
15  os.environ[tup[0].strip()] = tup[1].strip()
16 
17 #
18 # command line argument parsing
19 #
20 parser = argparse.ArgumentParser()
21 parser.add_argument('-c', '--config_file', type=str, help='configuration file name', default='submit_reco_validation.cfg')
22 args = parser.parse_args()
23 config_file = args.config_file
24 
25 #
26 # read in the configuration file
27 #
28 parser = SafeConfigParser()
29 parser.read(config_file)
30 sam_datasets = [x.strip().strip('\n') for x in parser.get('sam', 'defnames').split('\n')]
31 nfiles = parser.get('sam', 'number_of_files')
32 working_dir = parser.get('working folder', 'path')
33 # grid config variables
34 jobname = parser.get('grid configuration', 'jobname')
35 fcl = parser.get('grid configuration', 'c')
36 dest = parser.get('grid configuration', 'dest')
37 testrel = parser.get('grid configuration', 'testrel')
38 tag = parser.get('grid configuration', 'tag')
39 histTier = parser.get('grid configuration', 'histTier')
40 maxopt = parser.get('grid configuration', 'maxopt')
41 group = parser.get('grid configuration', 'G')
42 njobs = parser.get('grid configuration', 'njobs')
43 files_per_job = parser.get('grid configuration', 'files_per_job')
44 opportunistic = parser.get('grid configuration', 'opportunistic')
45 copyOut = parser.get('grid configuration', 'copyOut')
46 print_jobsub = parser.get('grid configuration', 'print_jobsub')
47 expected_lifetime = parser.get('grid configuration', 'expected_lifetime')
48 
49 #
50 # Check if setup_nova is sourced.
51 #
52 if not 'SRT_DIST' in os.environ.keys():
53  source_script('/grid/fermiapp/nova/novaart/novasvn/setup/setup_nova.sh')
54 
55 #
56 # Copy files to the working directory and hadd them.
57 #
58 for defname in sam_datasets:
59  if not defname: continue
60  cur_dest = os.path.join(dest, defname)
61  grid_copy_dir = os.path.join(working_dir, defname, 'hadded_output', 'grid_copy')
62  os.system('mkdir -p ' + grid_copy_dir)
63  os.system('cp ' + os.path.join(cur_dest, '*.root') + ' ' + grid_copy_dir)
64  cmd = ''
65  if not 'SRT_DIST' in os.environ.keys(): cmd += '. ~/.bashrc;setup_nova;'
66  cmd += 'hadd -T -f -k ' + os.path.join(grid_copy_dir,'../hadded_output.root') + ' ' + os.path.join(grid_copy_dir,'*.root')
67  os.system(cmd)
void split(double tt, double *fr)
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14