3 import re,os,sys,shutil,math
7 for i
in range(len(copyargs)):
10 if copyargs[i].
find(
" ") != -1:
11 copyargs[i] =
"\"%s\"" % copyargs[i]
12 commandline =
" ".
join(copyargs)
16 usage=
'./%(prog)s NBLOCKS INFILE OUTFILE [options]\n'+\
17 'takes list of files produced by findQualityFiles.py as INFILE,\n'+\
18 'groups them into maximum NBLOCKS blocks with approximately similar #events.'
25 parser=optparse.OptionParser(usage)
27 parser.add_option(
"-v",
"--verbose",
28 help=
"debug verbosity level",
33 options,args=parser.parse_args()
36 raise SystemError(
"Too few arguments.\n\n"+parser.format_help())
38 NBLOCKS = int(sys.argv[1])
51 for i
in range(len(mylist)):
54 while last_i
in choosen: last_i += -1
59 block.append(mylist[i])
65 if n+mylist[i][0]<evtn:
68 block.append(mylist[i])
71 if len(choosen)==len(mylist):
76 for i
in range(len(mylist)):
78 newlist.append(mylist[i])
79 print "done makeJobBlock n =",n,
" len =",len(block)
80 return block, newlist, n
84 comment1RE = re.compile (
r'^#.+$')
85 fileLineRE = re.compile (
r'^.*\'(.*)\'.+# (\d*).*$')
88 if not os.access(INFILE, os.F_OK):
89 print "Cannot find input file ", INFILE
92 fin = open(INFILE,
"r")
93 lines = fin.readlines()
105 match = comment1RE.match(line)
107 commentLines.append(line)
109 match = fileLineRE.match(line)
113 eventsFiles.append((int(match.group(2)), str(match.group(1))))
114 ntotal += int(match.group(2))
117 if len(eventsFiles)==0:
118 print "no file description strings found"
129 eventsFiles.sort(reverse=
True)
132 evtPerJob = int(math.ceil(float(ntotal)/NBLOCKS))
133 print "Total = ",ntotal,
" per block =", evtPerJob,
"(would give total of ", evtPerJob*NBLOCKS,
")",
" list length =",len(eventsFiles)
134 if eventsFiles[0][0] > evtPerJob:
135 print "the biggest #evt is larger then #evt/block:",eventsFiles[0][0],
">",evtPerJob
136 print "consider lowering NBLOCKS"
143 for j
in range(NBLOCKS):
151 jobsBlocks.append((block,nn))
160 fout = open(OUTFILE, mode=
"w")
162 fout.write(
"### job-split file list produced by:\n")
163 fout.write(
"### "+commandline+
"\n")
164 fout.write(
"### Total #evt= "+str(ntotal)+
" #files ="+str(len(eventsFiles))+
" per job #evt="
165 +str(evtPerJob)+
" (would give total of"+str(evtPerJob*NBLOCKS)+
")\n###\n")
166 fout.write(
"### previously produced by:\n")
167 fout.write(
"".
join(commentLines))
168 fout.write(
"\nfileNamesBlocks = [\n")
171 for b
in range(len(jobsBlocks)):
172 fout.write(
' [ # job '+str(b)+
' with nevt='+str(jobsBlocks[b][1])+
'\n')
174 for i
in range(len(jobsBlocks[b][0])):
175 if i==len(jobsBlocks[b][0])-1:
178 fout.write(
" '"+ jobsBlocks[b][0][i][1] +
"'"+comma+
" # "+ str(jobsBlocks[b][0][i][0]) +
"\n")
179 if b==len(jobsBlocks)-1:
181 fout.write(
' ]'+commax+
'\n')
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
static std::string join(char **cmd)