Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
###############################
# Disclaimer: you must have set up your cookies according to this recipe firt:
# openssl pkcs12 -clcerts -nokeys -in myCert.p12 -out ~/private/myCert.pem
# openssl pkcs12 -nocerts -in myCert.p12 -out ~/private/myCert.tmp.key
# openssl rsa -in ~/private/myCert.tmp.key -out ~/private/myCert.key
# rm ~/private/myCert.tmp.key
# chmod 644 ~/private/myCert.pem
# chmod 400 ~/private/myCert.key
# cern-get-sso-cookie --cert ~/private/myCert.pem --key ~/private/myCert.key -r -u https://lumis.web.cern.ch/ -o ~/private/ssocookie.txt
#
# see: http://linux.web.cern.ch/linux/docs/cernssocookie.shtml for more details
#
###############################
#/!usr/bin/env python
import ROOT
import calendar
import commands
import datetime
import glob
import json
import numpy
import optparse
import os
import re
import string
import subprocess
import sys
import time
import urllib
first=[315252,315506,316271,317475,318622,319337,319941,320688,321730,322106,323363,323755]
last =[315490,316271,317438,317696,319311,319915,320674,321475,322088,322633,323727,325175]
def getLuminosity(minRun,maxRun,filename,isGood):
if(isGood):
lumifilename="goodlumi_{}_{}.txt".format(minRun,maxRun)
else:
lumifilename="alllumi_{}_{}.txt".format(minRun,maxRun)
output=subprocess.check_output(["/afs/cern.ch/user/m/musich/.local/bin/brilcalc", "lumi", "-b", "STABLE BEAMS","-u", "/pb", "--begin", str(minRun),"--end",str(maxRun),"-i",filename,"-o",lumifilename])
#output=subprocess.check_output(["/afs/cern.ch/user/m/musich/.local/bin/brilcalc", "lumi","-u", "/pb","-i",filename,"-o",lumifilename])
cmd = "more "+lumifilename+" | grep totrecorded -A 1 | tail -1 | awk '{split($0,a,\",\"); print a[6]}'"
#cmd = "less "+lumifilename+" | grep totrecorded -A 2 | tail -1 | awk '{print $12}'"
rec_lumi=commands.getoutput(cmd)
#print rec_lumi
return rec_lumi
def printJSON(minRun,maxRun,isGood):
if (isGood):
cmd="curl -s -L --cookie ~/private/ssocookie.txt --cookie-jar ~/private/ssocookie.txt \"https://lumis.web.cern.ch/api/good/?run_min={}&run_max={}\"".format(minRun,maxRun)
filename="goodlumis_{}_{}.json".format(minRun,maxRun)
else:
cmd="curl -s -L --cookie ~/private/ssocookie.txt --cookie-jar ~/private/ssocookie.txt \"https://lumis.web.cern.ch/api/nodcs/?run_min={}&run_max={}\"".format(minRun,maxRun)
filename="alllumis_{}_{}.json".format(minRun,maxRun)
res=commands.getoutput(cmd)
file=open(filename,"w")
file.write(res)
file.close()
return filename
for i in xrange(0,len(first)):
goodlumifile=printJSON(first[i],last[i],True)
theGoodLumi=getLuminosity(first[i],last[i],goodlumifile,True)
alllumifile=printJSON(first[i],last[i],False)
theFullLumi=getLuminosity(first[i],last[i],alllumifile,False)
print first[i],last[i],theFullLumi,theGoodLumi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.