4 from collections
import OrderedDict
6 parser = argparse.ArgumentParser(description=
'Count the events/POT/exposure in the files specified by a set of constraints')
7 parser.add_argument(
'--dir',
'-d', help=
'Directory of files', type=str)
8 parser.add_argument(
'--match',
'-m', help=
'Match pattern for files', type=str, action=
'append')
9 parser.add_argument(
'--printName',
'-p', help=
'Prints filename of counted files', action=
'store_true')
10 parser.add_argument(
'files', nargs =
'*',
11 help =
'List of files to operate on. Or use --dir and --match.')
12 args = parser.parse_args()
17 ROOT.gErrorIgnoreLevel=100000
19 if args.files
and args.dir:
20 print 'Error: --dir is not compatible with explicitly listing files. Use one or the other' 23 if not args.files
and not args.dir:
24 print 'Must specify either --dir or a list of files. See --help text' 36 fileList = [os.path.join(args.dir, file)
for file
in os.listdir(args.dir)]
40 raise Exception(
"No file list found. Need to pass in a directory with --dir")
43 hists[
"TotalPOT"] = ROOT.TH1F(
"TotalPOT",
";Arbitrary;Total POT", 1, 0,1)
44 hists[
"TotalEvents"] = ROOT.TH1F(
"TotalEvents",
";Arbitrary; Total Events", 1,0,1)
45 hists[
"TotalLivetime"] = ROOT.TH1F(
"TotalLivetime",
";Arbitrary; Total Livetime", 1,0,1)
48 for fileName
in fileList:
49 if not ".caf." in os.path.basename(fileName):
53 for string
in args.match:
54 if not string
in os.path.basename(fileName):
59 file = ROOT.TFile.Open(fileName,
"READ")
61 print os.path.basename(fileName)
62 if file
and not (file.IsZombie()
or file.TestBit(ROOT.TFile.kRecovered)):
64 for histKey
in hists.keys():
65 hists[histKey].Add(file.Get(histKey))
67 print 'Number of files :', nFiles
68 for histKey
in hists.keys():
69 print histKey,
":", hists[histKey].
Integral()
double Integral(const Spectrum &s, const double pot, int cvnregion)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception