diff --git a/cms-YYYY-luminosity/code/lumi_records.py b/cms-YYYY-luminosity/code/lumi_records.py index 979c6add5..a9430c582 100644 --- a/cms-YYYY-luminosity/code/lumi_records.py +++ b/cms-YYYY-luminosity/code/lumi_records.py @@ -5,7 +5,8 @@ import requests import sys -sys.path.insert(1, '../cms-release-info') + +sys.path.insert(1, "../cms-release-info") """ Create a luminosity record. @@ -23,6 +24,7 @@ """ + def create_record(recid, year, era, runtype, uncertainty, lumi_ref, val_recid): """Create record for the given year.""" @@ -31,56 +33,89 @@ def create_record(recid, year, era, runtype, uncertainty, lumi_ref, val_recid): year_created = year year_published = datetime.date.today().strftime("%Y") runtype = str(runtype) - if "pphiref" in runtype : - display_runtype = 'pp' + if "pphiref" in runtype: + display_runtype = "pp" else: display_runtype = runtype - + # Get the energy # Using the run_era, for pp it is needed only here # Could be done differently but this is good enough - url = 'http://api-server-cms-release-info.app.cern.ch/runeras/?run_era='+era - this_json=json.loads(requests.get(url).text.strip()) - energy=this_json[0]["energy"] + url = "http://api-server-cms-release-info.app.cern.ch/runeras/?run_era=" + era + this_json = json.loads(requests.get(url).text.strip()) + energy = this_json[0]["energy"] # NB the reference needs to be to cds for this to work: - url = lumi_ref+'/?of=tm&ot=245__a' + url = lumi_ref + "/?of=tm&ot=245__a" lumi_ref_title = requests.get(url).text.strip() - pp_text='' + pp_text = "" if "pphiref" in runtype: - collision_text = energy+' proton-proton collision data, needed as reference data for heavy-ion data analysis,' + collision_text = ( + energy + + " proton-proton collision data, needed as reference data for heavy-ion data analysis," + ) elif "PbPb" in runtype: - collision_text = energy+' PbPb heavy-ion collision data' + collision_text = energy + " PbPb heavy-ion collision data" elif "pPb" in runtype: - collision_text = energy+' proton-Pb heavy-ion collision data' + collision_text = energy + " proton-Pb heavy-ion collision data" elif "pp" in runtype: - collision_text = energy+' proton-proton collision data' + collision_text = energy + " proton-proton collision data" run_range_input = year - pp_text='(The integrated luminosity for validated runs and luminosity sections of all '+year+' p-p data taking is available in '+year+'lumi.txt.)' + pp_text = ( + "(The integrated luminosity for validated runs and luminosity sections of all " + + year + + " p-p data taking is available in " + + year + + "lumi.txt.)" + ) else: - print('Runtype unknown!') + print("Runtype unknown!") -# normtag file only after Run-1 - normtag_text='' + # normtag file only after Run-1 + normtag_text = "" if int(year) > 2014: - normtag_text='The luminometer giving the best value for each luminosity section is recorded in a normtag file normtag_PHYSICS_'+runtype+'_'+year+'.json that is used in the luminosity calculation.' + normtag_text = ( + 'The luminometer giving the best value for each luminosity section is recorded in a normtag file normtag_PHYSICS_' + + runtype + + "_" + + year + + ".json that is used in the luminosity calculation." + ) rec["abstract"] = {} - url = 'http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year='+year+'&type='+runtype+'-phys&released=yes' + url = ( + "http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year=" + + year + + "&type=" + + runtype + + "-phys&released=yes" + ) od_runs = json.loads(requests.get(url).text.strip()) -# The use of variable in string with two different notations could be fixed in the following... -# NB in the +var+ notation, var needs to be a string + # The use of variable in string with two different notations could be fixed in the following... + # NB in the +var+ notation, var needs to be a string rec["abstract"]["description"] = ( - "

CMS measures the luminosity using different luminometers (luminosity detectors) and algorithms. "+normtag_text+"

" - "

The integrated luminosity for validated runs and luminosity sections of the %s taken in %s (%s) is available in %slumi.txt. %s

" % (collision_text, year, ",".join(od_runs), ",".join(od_runs), pp_text) - + "

For luminosity calculation, a detailed list of luminosity by lumi section is provided in %s_%slumibyls.csv for the list of validated runs and lumi sections.

" % (recid, runtype, year, runtype, year, val_recid) - + "

The uncertainty in the luminosity measurement of %s data should be considered as %s%% (reference %s).

" % (year, uncertainty, lumi_ref, lumi_ref_title) - + "

In your estimate for the integrated luminosity, check for which runs the trigger you have selected is active and sum the values for those runs. For prescaled triggers, the change of prescales (run, lumi section, index of prescales referring to the PrescaleService module in the High-Level Trigger configuration files) is recorded in prescale_%s%s.csv.

" % (recid, runtype, year, runtype, year) - + "

Additional information on how to extract luminosity values using the brilcalc tool can be found in the luminosity calculation guide.

" - ) + "

CMS measures the luminosity using different luminometers (luminosity detectors) and algorithms. " + + normtag_text + + "

" + "

The integrated luminosity for validated runs and luminosity sections of the %s taken in %s (%s) is available in %slumi.txt. %s

" + % (collision_text, year, ",".join(od_runs), ",".join(od_runs), pp_text) + + '

For luminosity calculation, a detailed list of luminosity by lumi section is provided in %s_%slumibyls.csv for the list of validated runs and lumi sections.

' + % (recid, runtype, year, runtype, year, val_recid) + + '

The uncertainty in the luminosity measurement of %s data should be considered as %s%% (reference %s).

' + % (year, uncertainty, lumi_ref, lumi_ref_title) + + '

In your estimate for the integrated luminosity, check for which runs the trigger you have selected is active and sum the values for those runs. For prescaled triggers, the change of prescales (run, lumi section, index of prescales referring to the PrescaleService module in the High-Level Trigger configuration files) is recorded in prescale_%s%s.csv.

' + % (recid, runtype, year, runtype, year) + + '

Additional information on how to extract luminosity values using the brilcalc tool can be found in the luminosity calculation guide.

' + ) rec["accelerator"] = "CERN-LHC" @@ -106,32 +141,28 @@ def create_record(recid, year, era, runtype, uncertainty, lumi_ref, val_recid): rec["license"]["attribution"] = "CC0" rec["links"] = {} - rec["links"] = [ - { - "url": lumi_ref, - "title": lumi_ref_title - } - ] + rec["links"] = [{"url": lumi_ref, "title": lumi_ref_title}] rec["publisher"] = "CERN Open Data Portal" rec["recid"] = str(recid) rec["relations"] = {} - rec["relations"] = [ - { - "recid": str(val_recid), - "type": "isRelatedTo" - } - ] - - url = 'http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year='+year+'&type='+runtype+'-phys' - #rec["run_period"] = read_run_periods(year, 'pp-phys') + rec["relations"] = [{"recid": str(val_recid), "type": "isRelatedTo"}] + + url = ( + "http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year=" + + year + + "&type=" + + runtype + + "-phys" + ) + # rec["run_period"] = read_run_periods(year, 'pp-phys') rec["run_period"] = json.loads(requests.get(url).text.strip()) rec["title"] = ( - "CMS luminosity information for "+collision_text+" taken in "+year - ) + "CMS luminosity information for " + collision_text + " taken in " + year + ) rec["type"] = {} rec["type"]["primary"] = "Supplementaries" @@ -141,6 +172,7 @@ def create_record(recid, year, era, runtype, uncertainty, lumi_ref, val_recid): return rec + # @click.command() def main(): "Do the job." @@ -154,28 +186,33 @@ def main(): # this would read from the local json file # with open('./inputs/cms_release_info.json') as f: # data = f.read() - + # # reconstructing the data as a dictionary - # all_years = json.loads(data) + # all_years = json.loads(data) # this_year = all_years[year] - # this gets json from the api server - url = 'http://api-server-cms-release-info.app.cern.ch/years?year='+year+'&type='+runtype+'&output=plain' - this_year = json.loads(requests.get(url).text.strip()) - + # this gets json from the api server + url = ( + "http://api-server-cms-release-info.app.cern.ch/years?year=" + + year + + "&type=" + + runtype + + "&output=plain" + ) + this_year = json.loads(requests.get(url).text.strip()) + records.append( create_record( recid, year, era, - runtype, + runtype, this_year["lumi_uncertainty"], this_year["luminosity_reference"], - this_year["val_json"][0]["recid"]) # This requires the json files to be in a specific order, with "golden" first + this_year["val_json"][0]["recid"], + ) # This requires the json files to be in a specific order, with "golden" first ) - - print( json.dumps( records, @@ -189,4 +226,3 @@ def main(): if __name__ == "__main__": main() -