3 from __future__
import print_function
4 import re,os,sys,shutil,math
8 for i
in range(len(copyargs)):
11 if copyargs[i].
find(
" ") != -1:
12 copyargs[i] =
"\"%s\"" % copyargs[i]
13 commandline =
" ".
join(copyargs)
17 usage=
'./%(prog)s NBLOCKS INFILE OUTFILE [options]\n'+\
18 'takes list of files produced by findQualityFiles.py as INFILE,\n'+\
19 'groups them into maximum NBLOCKS blocks with approximately similar #events.' 26 parser=optparse.OptionParser(usage)
28 parser.add_option(
"-v",
"--verbose",
29 help=
"debug verbosity level",
34 options,args=parser.parse_args()
37 raise SystemError(
"Too few arguments.\n\n"+parser.format_help())
39 NBLOCKS =
int(sys.argv[1])
52 for i
in range(len(mylist)):
55 while last_i
in choosen: last_i += -1
60 block.append(mylist[i])
66 if n+mylist[i][0]<evtn:
69 block.append(mylist[i])
72 if len(choosen)==len(mylist):
77 for i
in range(len(mylist)):
79 newlist.append(mylist[i])
80 print(
"done makeJobBlock n =",n,
" len =",len(block))
81 return block, newlist, n
85 comment1RE = re.compile (
r'^#.+$')
86 fileLineRE = re.compile (
r'^.*\'(.*)\'.+# (\d*).*$')
89 if not os.access(INFILE, os.F_OK):
90 print(
"Cannot find input file ", INFILE)
93 fin = open(INFILE,
"r") 94 lines = fin.readlines() 106 match = comment1RE.match(line)
108 commentLines.append(line)
110 match = fileLineRE.match(line)
114 eventsFiles.append((
int(match.group(2)),
str(match.group(1))))
115 ntotal +=
int(match.group(2))
118 if len(eventsFiles)==0:
119 print(
"no file description strings found")
130 eventsFiles.sort(reverse=
True)
134 print(
"Total = ",ntotal,
" per block =", evtPerJob,
"(would give total of ", evtPerJob*NBLOCKS,
")",
" list length =",len(eventsFiles))
135 if eventsFiles[0][0] > evtPerJob:
136 print(
"the biggest #evt is larger then #evt/block:",eventsFiles[0][0],
">",evtPerJob)
137 print(
"consider lowering NBLOCKS")
144 for j
in range(NBLOCKS):
152 jobsBlocks.append((block,nn))
155 print(
"empty block!")
161 fout = open(OUTFILE, mode=
"w")
163 fout.write(
"### job-split file list produced by:\n")
164 fout.write(
"### "+commandline+
"\n")
165 fout.write(
"### Total #evt= "+
str(ntotal)+
" #files ="+
str(len(eventsFiles))+
" per job #evt=" 166 +
str(evtPerJob)+
" (would give total of"+
str(evtPerJob*NBLOCKS)+
")\n###\n")
167 fout.write(
"### previously produced by:\n")
168 fout.write(
"".
join(commentLines))
169 fout.write(
"\nfileNamesBlocks = [\n")
172 for b
in range(len(jobsBlocks)):
173 fout.write(
' [ # job '+
str(b)+
' with nevt='+
str(jobsBlocks[b][1])+
'\n')
175 for i
in range(len(jobsBlocks[b][0])):
176 if i==len(jobsBlocks[b][0])-1:
179 fout.write(
" '"+ jobsBlocks[b][0][i][1] +
"'"+comma+
" # "+
str(jobsBlocks[b][0][i][0]) +
"\n")
180 if b==len(jobsBlocks)-1:
182 fout.write(
' ]'+commax+
'\n')
S & print(S &os, JobReport::InputFile const &f)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
def makeJobBlock(mylist, evtn)
static std::string join(char **cmd)