3 from __future__
import print_function
4 from builtins
import range
5 import re,os,sys,shutil,math
9 for i
in range(len(copyargs)):
12 if copyargs[i].
find(
" ") != -1:
13 copyargs[i] =
"\"%s\"" % copyargs[i]
14 commandline =
" ".
join(copyargs)
18 usage=
'./%(prog)s NBLOCKS INFILE OUTFILE [options]\n'+\
19 'takes list of files produced by findQualityFiles.py as INFILE,\n'+\
20 'groups them into maximum NBLOCKS blocks with approximately similar #events.' 27 parser=optparse.OptionParser(usage)
29 parser.add_option(
"-v",
"--verbose",
30 help=
"debug verbosity level",
35 options,args=parser.parse_args()
38 raise SystemError(
"Too few arguments.\n\n"+parser.format_help())
40 NBLOCKS =
int(sys.argv[1])
53 for i
in range(len(mylist)):
56 while last_i
in choosen: last_i += -1
61 block.append(mylist[i])
67 if n+mylist[i][0]<evtn:
70 block.append(mylist[i])
73 if len(choosen)==len(mylist):
78 for i
in range(len(mylist)):
80 newlist.append(mylist[i])
81 print(
"done makeJobBlock n =",n,
" len =",len(block))
82 return block, newlist, n
86 comment1RE = re.compile (
r'^#.+$')
87 fileLineRE = re.compile (
r'^.*\'(.*)\'.+# (\d*).*$')
90 if not os.access(INFILE, os.F_OK):
91 print(
"Cannot find input file ", INFILE)
94 fin = open(INFILE,
"r") 95 lines = fin.readlines() 107 match = comment1RE.match(line)
109 commentLines.append(line)
111 match = fileLineRE.match(line)
115 eventsFiles.append((
int(match.group(2)),
str(match.group(1))))
116 ntotal +=
int(match.group(2))
119 if len(eventsFiles)==0:
120 print(
"no file description strings found")
131 eventsFiles.sort(reverse=
True)
135 print(
"Total = ",ntotal,
" per block =", evtPerJob,
"(would give total of ", evtPerJob*NBLOCKS,
")",
" list length =",len(eventsFiles))
136 if eventsFiles[0][0] > evtPerJob:
137 print(
"the biggest #evt is larger then #evt/block:",eventsFiles[0][0],
">",evtPerJob)
138 print(
"consider lowering NBLOCKS")
145 for j
in range(NBLOCKS):
153 jobsBlocks.append((block,nn))
156 print(
"empty block!")
162 fout = open(OUTFILE, mode=
"w")
164 fout.write(
"### job-split file list produced by:\n")
165 fout.write(
"### "+commandline+
"\n")
166 fout.write(
"### Total #evt= "+
str(ntotal)+
" #files ="+
str(len(eventsFiles))+
" per job #evt=" 167 +
str(evtPerJob)+
" (would give total of"+
str(evtPerJob*NBLOCKS)+
")\n###\n")
168 fout.write(
"### previously produced by:\n")
169 fout.write(
"".
join(commentLines))
170 fout.write(
"\nfileNamesBlocks = [\n")
173 for b
in range(len(jobsBlocks)):
174 fout.write(
' [ # job '+
str(b)+
' with nevt='+
str(jobsBlocks[b][1])+
'\n')
176 for i
in range(len(jobsBlocks[b][0])):
177 if i==len(jobsBlocks[b][0])-1:
180 fout.write(
" '"+ jobsBlocks[b][0][i][1] +
"'"+comma+
" # "+
str(jobsBlocks[b][0][i][0]) +
"\n")
181 if b==len(jobsBlocks)-1:
183 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)