def recordedInvMicrobarnsShotgun(jsons, cores = 2, cacheDir = './' ) : os.system('\n'.join([cvsEnv(),lumiEnv(True)])) pickles = ["%s/%d.pickle"%(cacheDir,hash(str(sorted([(key,val) for key,val in json.iteritems()])))) for json in jsons] def worker(pickle, json) : if not os.path.exists(pickle) : utils.writePickle(pickle, recordedInvMicrobarns(json)) utils.operateOnListUsingQueue(cores, utils.qWorker(worker), zip(pickles,jsons)) return [utils.readPickle(pickle) for pickle in pickles ]
def fnal(self): with open('lib/fnal_cmsJob.sh') as f: prelude = f.readlines() with open('lib/fnal_cmsTemplate.condor') as f: condtemplate = f.readlines() delit = False def sub(iJob, cmd): with tempfile.NamedTemporaryFile(prefix='job%04d_' % iJob, suffix='.sh', dir="%s/condor" % os.environ['PWD'], delete=delit) as scr: print >> scr, ''.join(prelude) print >> scr, "cd", os.environ['PWD'] print >> scr, cmd scr.flush() os.system('chmod +x %s' % scr.name) with tempfile.NamedTemporaryFile(prefix='job%04d_' % iJob, suffix='.condor', dir="%s/condor" % os.environ['PWD'], delete=delit) as cond: print >> cond, ''.join(condtemplate).replace( 'JOBFLAG', scr.name.split('/')[-1]).replace('OUTFLAG', './') cond.flush() subCmd = "; ".join(["lib/fnal_cmsSub.sh %s" % cond.name]) os.system(subCmd) lib.operateOnListUsingQueue(self.nCores, lib.qWorker(sub), enumerate(self.cmds))
def ic(self): with open('lib/ic_cmsJob.sh') as f: prelude = f.readlines() def sub(iJob,cmd): with tempfile.NamedTemporaryFile('w',prefix='job%04d_'%iJob,suffix='.sh') as tmp: print>>tmp, ''.join(prelude) print>>tmp, "cd", os.environ['PWD'] print>>tmp, cmd tmp.flush() os.system('./lib/ic_cmsSub.sh %s'%tmp.name) lib.operateOnListUsingQueue(self.nCores, lib.qWorker(sub), enumerate(self.cmds))
def ic(self): with open('lib/ic_cmsJob.sh') as f: prelude = f.readlines() def sub(iJob, cmd): with tempfile.NamedTemporaryFile('w', prefix='job%04d_' % iJob, suffix='.sh') as tmp: print >> tmp, ''.join(prelude) print >> tmp, "cd", os.environ['PWD'] print >> tmp, cmd tmp.flush() os.system('./lib/ic_cmsSub.sh %s' % tmp.name) lib.operateOnListUsingQueue(self.nCores, lib.qWorker(sub), enumerate(self.cmds))
def fnal(self): with open('lib/fnal_cmsJob.sh') as f: prelude = f.readlines() with open('lib/fnal_cmsTemplate.condor') as f: condtemplate = f.readlines() delit = False def sub(iJob,cmd): with tempfile.NamedTemporaryFile(prefix='job%04d_'%iJob,suffix='.sh',dir="%s/condor"%os.environ['PWD'], delete=delit) as scr: print>>scr, ''.join(prelude) print>>scr, "cd", os.environ['PWD'] print>>scr, cmd scr.flush() os.system('chmod +x %s'%scr.name) with tempfile.NamedTemporaryFile(prefix='job%04d_'%iJob,suffix='.condor',dir="%s/condor"%os.environ['PWD'], delete=delit) as cond: print>>cond, ''.join(condtemplate).replace('JOBFLAG',scr.name.split('/')[-1]).replace('OUTFLAG','./') cond.flush() subCmd = "; ".join(["lib/fnal_cmsSub.sh %s" % cond.name]) os.system(subCmd) lib.operateOnListUsingQueue(self.nCores, lib.qWorker(sub), enumerate(self.cmds))
def recordedInvMicrobarns(json) : jsonALT = dict([(int(run),sum([range(begin,end+1) for begin,end in lumis],[])) for run,lumis in json.items()]) session = sessionManager.sessionManager("frontier://LumiCalc/CMS_LUMI_PROD").openSession( cpp2sqltype = [('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')]) session.transaction().start(True) lumidata = lumiCalcAPI.lumiForRange( session.nominalSchema(), jsonALT, norm = 1.0, finecorrections = lumiCorrections.pixelcorrectionsForRange(session.nominalSchema(),jsonALT.keys()), lumitype='PIXEL', branchName='DATA') return sum( sum(data[6] for data in lumis) for run,lumis in lumidata.iteritems() if lumis) def recordedInvMicrobarnsShotgun(jsons, cores = 2, cacheDir = './' ) : pickles = ["%s/%d.pickle"%(cacheDir,hash(str(sorted([(key,val) for key,val in json.iteritems()])))) for json in jsons] def worker(pickle, json) : if not os.path.exists(pickle) : utils.writePickle(pickle, recordedInvMicrobarns(json)) utils.operateOnListUsingQueue(cores, utils.qWorker(worker), zip(pickles,jsons)) return [utils.readPickle(pickle) for pickle in pickles ] if __name__=='__main__' : print if len(sys.argv)<2 : print 'Pass list of "{json}" and/or filenames as argument'; sys.exit(0) def output(arg) : json = eval(arg if '{' in arg else open(arg).readline()) lumi = recordedInvMicrobarns(json) print "%.4f/pb in %s"%(lumi/1e6,arg) print utils.operateOnListUsingQueue(configuration.nCoresDefault(), utils.qWorker(output), [(a,) for a in sys.argv[1:]])
def default(self): lib.operateOnListUsingQueue(self.nCores, lib.qWorker(os.system), zip(self.cmds))