6 parser = argparse.ArgumentParser(description=
'Dump a tree to text.')
7 parser.add_argument(
'--fluxswapdir',
'-f', type=str, required=
True,
8 help=
"""Directory with fluxswap files.""")
9 parser.add_argument(
'--nonswapdir',
'-n', type=str, required=
True,
10 help=
"""Directory with nonswap files.""")
12 parser.add_argument(
'--ntrain', type=int, required=
True,
13 help=
"""Number of pairs of fluxswap and nonswap 14 files for training sample.""")
16 parser.add_argument(
'--ncv', type=int, required=
True,
17 help=
"""Number of pairs of fluxswap and nonswap files for CV smaple .""")
19 parser.add_argument(
'--artext', type=str, default=
".cvn.root",
20 help=
"""Extension of art-ROOT files.""")
22 parser.add_argument(
'--histext', type=str, default=
".cvnevents.root",
23 help=
"""Extension of hist-ROOT files with CVN events for training.""")
26 parser.add_argument(
'--haddpath', type=str,
27 help=
"""Location to place hadd files for training and lists for cv sample""")
30 args = parser.parse_args()
45 return self.
artPath < other.artPath
48 cmdList = [
"hadd",
"-f", outputName] + files
50 subprocess.call(cmdList)
54 dirs[
"fluxswap"] = args.fluxswapdir
55 dirs[
"nonswap"] = args.nonswapdir
60 for key, dir
in dirs.items():
61 fileList = os.listdir(dir)
62 artFiles = [f
for f
in fileList
if f.endswith(args.artext)]
63 histFiles = [f
for f
in fileList
if f.endswith(args.histext)]
65 for artFile
in artFiles:
66 histFileMatches = [f
for f
in histFiles \
67 if f.replace(args.histext,
"") == artFile.replace(args.artext,
"")]
68 if len(histFileMatches) > 1:
69 raise Exception(
"too many hist file matches for this file:" + artFile)
70 elif len(histFileMatches) == 0:
71 print "Warning: failed to find hist match for this art file: ", artFile
74 os.path.join(dir, histFileMatches[0])))
81 trainFilePairs = filePairs[
"fluxswap"][0:args.ntrain] + \
82 filePairs[
"nonswap" ][0:args.ntrain]
83 haddName = os.path.join(args.haddpath,
"train_%s_hadd.root" %(args.ntrain))
84 trainListPath = os.path.join(args.haddpath,
"train_%s.txt" %(args.ntrain))
85 trainList = [f.histPath
for f
in trainFilePairs]
86 trainArtList = [f.artPath
for f
in trainFilePairs]
88 open(trainListPath,
'w').
write(
"\n".join(trainArtList ))
90 cvFilePairs = filePairs[
"fluxswap"][-args.ncv:] + \
91 filePairs[
"nonswap" ][-args.ncv:]
92 cvArtList = [f.artPath
for f
in cvFilePairs]
93 cvListPath = os.path.join(args.haddpath,
"cv_%s_train_%s.txt" %(args.ncv,
95 open(cvListPath,
'w').
write(
"\n".join(cvArtList))
def haddFiles(files, outputName)
def __init__(self, artPath, histPath)
procfile open("FD_BRL_v0.txt")
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception