Skip to content

Commit 3658e37

Browse files
katilptiborsimko
authored andcommitted
cms-YYYY-luminosity: black formatting
1 parent b2d66a5 commit 3658e37

File tree

1 file changed

+92
-56
lines changed

1 file changed

+92
-56
lines changed

cms-YYYY-luminosity/code/lumi_records.py

Lines changed: 92 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import requests
66

77
import sys
8-
sys.path.insert(1, '../cms-release-info')
8+
9+
sys.path.insert(1, "../cms-release-info")
910

1011
"""
1112
Create a luminosity record.
@@ -23,6 +24,7 @@
2324
2425
"""
2526

27+
2628
def create_record(recid, year, era, runtype, uncertainty, lumi_ref, val_recid):
2729
"""Create record for the given year."""
2830

@@ -31,56 +33,89 @@ def create_record(recid, year, era, runtype, uncertainty, lumi_ref, val_recid):
3133
year_created = year
3234
year_published = datetime.date.today().strftime("%Y")
3335
runtype = str(runtype)
34-
if "pphiref" in runtype :
35-
display_runtype = 'pp'
36+
if "pphiref" in runtype:
37+
display_runtype = "pp"
3638
else:
3739
display_runtype = runtype
38-
40+
3941
# Get the energy
4042
# Using the run_era, for pp it is needed only here
4143
# Could be done differently but this is good enough
42-
url = 'http://api-server-cms-release-info.app.cern.ch/runeras/?run_era='+era
43-
this_json=json.loads(requests.get(url).text.strip())
44-
energy=this_json[0]["energy"]
44+
url = "http://api-server-cms-release-info.app.cern.ch/runeras/?run_era=" + era
45+
this_json = json.loads(requests.get(url).text.strip())
46+
energy = this_json[0]["energy"]
4547

4648
# NB the reference needs to be to cds for this to work:
47-
url = lumi_ref+'/?of=tm&ot=245__a'
49+
url = lumi_ref + "/?of=tm&ot=245__a"
4850
lumi_ref_title = requests.get(url).text.strip()
4951

50-
pp_text=''
52+
pp_text = ""
5153
if "pphiref" in runtype:
52-
collision_text = energy+' proton-proton collision data, needed as reference data for heavy-ion data analysis,'
54+
collision_text = (
55+
energy
56+
+ " proton-proton collision data, needed as reference data for heavy-ion data analysis,"
57+
)
5358
elif "PbPb" in runtype:
54-
collision_text = energy+' PbPb heavy-ion collision data'
59+
collision_text = energy + " PbPb heavy-ion collision data"
5560
elif "pPb" in runtype:
56-
collision_text = energy+' proton-Pb heavy-ion collision data'
61+
collision_text = energy + " proton-Pb heavy-ion collision data"
5762
elif "pp" in runtype:
58-
collision_text = energy+' proton-proton collision data'
63+
collision_text = energy + " proton-proton collision data"
5964
run_range_input = year
60-
pp_text='(The integrated luminosity for validated runs and luminosity sections of all '+year+' p-p data taking is available in '+year+'lumi.txt.)'
65+
pp_text = (
66+
"(The integrated luminosity for validated runs and luminosity sections of all "
67+
+ year
68+
+ " p-p data taking is available in "
69+
+ year
70+
+ "lumi.txt.)"
71+
)
6172
else:
62-
print('Runtype unknown!')
73+
print("Runtype unknown!")
6374

64-
# normtag file only after Run-1
65-
normtag_text=''
75+
# normtag file only after Run-1
76+
normtag_text = ""
6677
if int(year) > 2014:
67-
normtag_text='The luminometer giving the best value for each luminosity section is recorded in a <strong>normtag</strong> file <a href=\"/record/'+str(recid)+'/files/normtag_PHYSICS_'+runtype+'_'+year+'.json\">normtag_PHYSICS_'+runtype+'_'+year+'.json</a> that is used in the luminosity calculation.'
78+
normtag_text = (
79+
'The luminometer giving the best value for each luminosity section is recorded in a <strong>normtag</strong> file <a href="/record/'
80+
+ str(recid)
81+
+ "/files/normtag_PHYSICS_"
82+
+ runtype
83+
+ "_"
84+
+ year
85+
+ '.json">normtag_PHYSICS_'
86+
+ runtype
87+
+ "_"
88+
+ year
89+
+ ".json</a> that is used in the luminosity calculation."
90+
)
6891

6992
rec["abstract"] = {}
7093

71-
url = 'http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year='+year+'&type='+runtype+'-phys&released=yes'
94+
url = (
95+
"http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year="
96+
+ year
97+
+ "&type="
98+
+ runtype
99+
+ "-phys&released=yes"
100+
)
72101
od_runs = json.loads(requests.get(url).text.strip())
73102

74-
# The use of variable in string with two different notations could be fixed in the following...
75-
# NB in the +var+ notation, var needs to be a string
103+
# The use of variable in string with two different notations could be fixed in the following...
104+
# NB in the +var+ notation, var needs to be a string
76105
rec["abstract"]["description"] = (
77-
"<p>CMS measures the luminosity using different luminometers (luminosity detectors) and algorithms. "+normtag_text+"</p>"
78-
"<p>The integrated luminosity for validated runs and luminosity sections of the %s taken in %s (%s) is available in %slumi.txt. %s</p>" % (collision_text, year, ",".join(od_runs), ",".join(od_runs), pp_text)
79-
+ "<p> For luminosity calculation, a detailed list of luminosity by lumi section is provided in <a href=\"/record/%s/files/%s_%slumibyls.csv\">%s_%slumibyls.csv</a> for the <a href=\"/record/%s\">list of validated runs</a> and lumi sections.</p>" % (recid, runtype, year, runtype, year, val_recid)
80-
+ "<p>The uncertainty in the luminosity measurement of %s data should be considered as %s%% (reference <a href=\"%s\">%s</a>).</p>" % (year, uncertainty, lumi_ref, lumi_ref_title)
81-
+ "<p>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 <a href=\"/record/%s/files/prescale_%s%s.csv\">prescale_%s%s.csv</a>.</p>" % (recid, runtype, year, runtype, year)
82-
+ "<p>Additional information on how to extract luminosity values using the <strong>brilcalc tool</strong> can be found in the <a href=\"/docs/cms-guide-luminosity-calculation\"> luminosity calculation guide</a>.</p>"
83-
)
106+
"<p>CMS measures the luminosity using different luminometers (luminosity detectors) and algorithms. "
107+
+ normtag_text
108+
+ "</p>"
109+
"<p>The integrated luminosity for validated runs and luminosity sections of the %s taken in %s (%s) is available in %slumi.txt. %s</p>"
110+
% (collision_text, year, ",".join(od_runs), ",".join(od_runs), pp_text)
111+
+ '<p> For luminosity calculation, a detailed list of luminosity by lumi section is provided in <a href="/record/%s/files/%s_%slumibyls.csv">%s_%slumibyls.csv</a> for the <a href="/record/%s">list of validated runs</a> and lumi sections.</p>'
112+
% (recid, runtype, year, runtype, year, val_recid)
113+
+ '<p>The uncertainty in the luminosity measurement of %s data should be considered as %s%% (reference <a href="%s">%s</a>).</p>'
114+
% (year, uncertainty, lumi_ref, lumi_ref_title)
115+
+ '<p>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 <a href="/record/%s/files/prescale_%s%s.csv">prescale_%s%s.csv</a>.</p>'
116+
% (recid, runtype, year, runtype, year)
117+
+ '<p>Additional information on how to extract luminosity values using the <strong>brilcalc tool</strong> can be found in the <a href="/docs/cms-guide-luminosity-calculation"> luminosity calculation guide</a>.</p>'
118+
)
84119

85120
rec["accelerator"] = "CERN-LHC"
86121

@@ -106,32 +141,28 @@ def create_record(recid, year, era, runtype, uncertainty, lumi_ref, val_recid):
106141
rec["license"]["attribution"] = "CC0"
107142

108143
rec["links"] = {}
109-
rec["links"] = [
110-
{
111-
"url": lumi_ref,
112-
"title": lumi_ref_title
113-
}
114-
]
144+
rec["links"] = [{"url": lumi_ref, "title": lumi_ref_title}]
115145

116146
rec["publisher"] = "CERN Open Data Portal"
117147

118148
rec["recid"] = str(recid)
119149

120150
rec["relations"] = {}
121-
rec["relations"] = [
122-
{
123-
"recid": str(val_recid),
124-
"type": "isRelatedTo"
125-
}
126-
]
127-
128-
url = 'http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year='+year+'&type='+runtype+'-phys'
129-
#rec["run_period"] = read_run_periods(year, 'pp-phys')
151+
rec["relations"] = [{"recid": str(val_recid), "type": "isRelatedTo"}]
152+
153+
url = (
154+
"http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year="
155+
+ year
156+
+ "&type="
157+
+ runtype
158+
+ "-phys"
159+
)
160+
# rec["run_period"] = read_run_periods(year, 'pp-phys')
130161
rec["run_period"] = json.loads(requests.get(url).text.strip())
131162

132163
rec["title"] = (
133-
"CMS luminosity information for "+collision_text+" taken in "+year
134-
)
164+
"CMS luminosity information for " + collision_text + " taken in " + year
165+
)
135166

136167
rec["type"] = {}
137168
rec["type"]["primary"] = "Supplementaries"
@@ -141,6 +172,7 @@ def create_record(recid, year, era, runtype, uncertainty, lumi_ref, val_recid):
141172

142173
return rec
143174

175+
144176
# @click.command()
145177
def main():
146178
"Do the job."
@@ -154,28 +186,33 @@ def main():
154186
# this would read from the local json file
155187
# with open('./inputs/cms_release_info.json') as f:
156188
# data = f.read()
157-
189+
158190
# # reconstructing the data as a dictionary
159-
# all_years = json.loads(data)
191+
# all_years = json.loads(data)
160192
# this_year = all_years[year]
161193

162-
# this gets json from the api server
163-
url = 'http://api-server-cms-release-info.app.cern.ch/years?year='+year+'&type='+runtype+'&output=plain'
164-
this_year = json.loads(requests.get(url).text.strip())
165-
194+
# this gets json from the api server
195+
url = (
196+
"http://api-server-cms-release-info.app.cern.ch/years?year="
197+
+ year
198+
+ "&type="
199+
+ runtype
200+
+ "&output=plain"
201+
)
202+
this_year = json.loads(requests.get(url).text.strip())
203+
166204
records.append(
167205
create_record(
168206
recid,
169207
year,
170208
era,
171-
runtype,
209+
runtype,
172210
this_year["lumi_uncertainty"],
173211
this_year["luminosity_reference"],
174-
this_year["val_json"][0]["recid"]) # This requires the json files to be in a specific order, with "golden" first
212+
this_year["val_json"][0]["recid"],
213+
) # This requires the json files to be in a specific order, with "golden" first
175214
)
176215

177-
178-
179216
print(
180217
json.dumps(
181218
records,
@@ -189,4 +226,3 @@ def main():
189226

190227
if __name__ == "__main__":
191228
main()
192-

0 commit comments

Comments
 (0)