Skip to content

Commit 8d91232

Browse files
committed
cms-YYYY-validated-runs: black formatting
1 parent db70546 commit 8d91232

File tree

1 file changed

+70
-45
lines changed

1 file changed

+70
-45
lines changed

cms-YYYY-validated-runs/code/vali_records.py

Lines changed: 70 additions & 45 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
from helpers import run_range_text
1011

1112
"""
@@ -25,70 +26,78 @@
2526
2627
"""
2728

29+
2830
def create_record(recid, year, era, runtype, filename):
2931
"""Create record for the given year."""
3032

3133
rec = {}
3234

33-
year=str(year)
35+
year = str(year)
3436
year_created = year
3537
year_published = datetime.date.today().strftime("%Y")
3638
runtype = str(runtype)
3739
# print(year)
3840
# print(runtype)
3941
# print(era)
40-
if "pphiref" in runtype :
41-
display_runtype = 'pp'
42+
if "pphiref" in runtype:
43+
display_runtype = "pp"
4244
else:
4345
display_runtype = runtype
4446

4547
# Get the energy
4648
# Using the run_era, for pp it is needed only here
4749
# Could be done differently but this is good enough
48-
url = 'http://api-server-cms-release-info.app.cern.ch/runeras/?run_era='+era
49-
this_json=json.loads(requests.get(url).text.strip())
50-
energy=this_json[0]["energy"]
50+
url = "http://api-server-cms-release-info.app.cern.ch/runeras/?run_era=" + era
51+
this_json = json.loads(requests.get(url).text.strip())
52+
energy = this_json[0]["energy"]
5153

52-
#print(energy)
54+
# print(energy)
5355

5456
if "Muon" in filename:
55-
muon_text = ', only valid muons'
56-
muon_desc = ', for analyses requiring only valid muons'
57+
muon_text = ", only valid muons"
58+
muon_desc = ", for analyses requiring only valid muons"
5759
else:
58-
muon_text = ''
59-
muon_desc = ''
60+
muon_text = ""
61+
muon_desc = ""
6062

6163
run_range_input = era
6264
if "pphiref" in runtype:
63-
collision_text = energy+' proton-proton collision data, needed as reference data for heavy-ion data analysis,'
65+
collision_text = (
66+
energy
67+
+ " proton-proton collision data, needed as reference data for heavy-ion data analysis,"
68+
)
6469
elif "PbPb" in runtype:
65-
collision_text = energy+' PbPb heavy-ion collision data'
70+
collision_text = energy + " PbPb heavy-ion collision data"
6671
elif "pPb" in runtype:
67-
collision_text = energy+' proton-Pb heavy-ion collision data'
72+
collision_text = energy + " proton-Pb heavy-ion collision data"
6873
elif "pp" in runtype:
69-
collision_text = energy+' proton-proton collision data'
74+
collision_text = energy + " proton-proton collision data"
7075
run_range_input = year
7176
else:
72-
print('Runtype unknown!')
77+
print("Runtype unknown!")
7378

7479
# The input to run_range_text depends on runtype, defined above
7580
# Usage: era for HI, HI pp ref, year for normal pp
76-
# run_range_text takes care of taking only released runs when year as input
81+
# run_range_text takes care of taking only released runs when year as input
7782
rec["abstract"] = {}
7883
rec["abstract"]["description"] = (
79-
"<p>This file describes which luminosity sections in which runs are considered good and should be processed"+muon_desc+".</p><p>This list covers "+collision_text+
80-
" taken in "+year+"."+run_range_text(run_range_input)+"</p>"
81-
)
84+
"<p>This file describes which luminosity sections in which runs are considered good and should be processed"
85+
+ muon_desc
86+
+ ".</p><p>This list covers "
87+
+ collision_text
88+
+ " taken in "
89+
+ year
90+
+ "."
91+
+ run_range_text(run_range_input)
92+
+ "</p>"
93+
)
8294

8395
rec["accelerator"] = "CERN-LHC"
8496

8597
rec["collaboration"] = {}
8698
rec["collaboration"]["name"] = "CMS collaboration"
8799

88-
rec["collections"] = [
89-
"CMS-Validated-Runs",
90-
"CMS-Validation-Utilities"
91-
]
100+
rec["collections"] = ["CMS-Validated-Runs", "CMS-Validation-Utilities"]
92101

93102
rec["collision_information"] = {}
94103
rec["collision_information"]["energy"] = energy
@@ -105,23 +114,31 @@ def create_record(recid, year, era, runtype, filename):
105114
rec["license"] = {}
106115
rec["license"]["attribution"] = "CC0"
107116

108-
#rec["links"] = {}
117+
# rec["links"] = {}
109118

110119
rec["publisher"] = "CERN Open Data Portal"
111120

112121
rec["recid"] = str(recid)
113122

114123
# Get run periods from the json file server (takes also not released)
115-
url = 'http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year='+year+'&type='+runtype+'-phys'
116-
rec["run_period"] = json.loads(requests.get(url).text.strip())
124+
url = (
125+
"http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year="
126+
+ year
127+
+ "&type="
128+
+ runtype
129+
+ "-phys"
130+
)
131+
rec["run_period"] = json.loads(requests.get(url).text.strip())
132+
133+
rec["title"] = "CMS list of validated runs " + filename
117134

118-
rec["title"] = (
119-
"CMS list of validated runs "+filename
120-
)
121-
122135
rec["title_additional"] = (
123-
"CMS list of validated runs for "+collision_text+" taken in "+year+muon_text
124-
)
136+
"CMS list of validated runs for "
137+
+ collision_text
138+
+ " taken in "
139+
+ year
140+
+ muon_text
141+
)
125142

126143
rec["type"] = {}
127144
rec["type"]["primary"] = "Environment"
@@ -131,8 +148,10 @@ def create_record(recid, year, era, runtype, filename):
131148

132149
rec["usage"] = {}
133150
rec["usage"]["description"] = (
134-
"<p>Add the following lines in the configuration file for a cmsRun job: <br /> <pre> import FWCore.ParameterSet.Config as cms</pre><pre> import FWCore.PythonUtilities.LumiList as LumiList</pre><pre> goodJSON = '"+filename+"'</pre><pre> myLumis = LumiList.LumiList(filename = goodJSON).getCMSSWString().split(',') </pre></p><p> Add the file path if needed in the file name.</p><p> Add the following statements after the <code>process.source</code> input file definition: <br /><pre> process.source.lumisToProcess = cms.untracked.VLuminosityBlockRange()</pre><pre> process.source.lumisToProcess.extend(myLumis)</pre></p><p>Note that the two last statements must be placed after the <code>process.source</code> statement defining the input files.</p>"
135-
)
151+
"<p>Add the following lines in the configuration file for a cmsRun job: <br /> <pre> import FWCore.ParameterSet.Config as cms</pre><pre> import FWCore.PythonUtilities.LumiList as LumiList</pre><pre> goodJSON = '"
152+
+ filename
153+
+ "'</pre><pre> myLumis = LumiList.LumiList(filename = goodJSON).getCMSSWString().split(',') </pre></p><p> Add the file path if needed in the file name.</p><p> Add the following statements after the <code>process.source</code> input file definition: <br /><pre> process.source.lumisToProcess = cms.untracked.VLuminosityBlockRange()</pre><pre> process.source.lumisToProcess.extend(myLumis)</pre></p><p>Note that the two last statements must be placed after the <code>process.source</code> statement defining the input files.</p>"
154+
)
136155

137156
rec["validation"] = {}
138157
rec["validation"][
@@ -147,6 +166,7 @@ def create_record(recid, year, era, runtype, filename):
147166

148167
return rec
149168

169+
150170
# @click.command()
151171
def main():
152172
"Do the job."
@@ -160,29 +180,35 @@ def main():
160180
# this would read from a local file
161181
# with open('./inputs/cms_release_info.json') as f:
162182
# data = f.read()
163-
183+
164184
# # reconstructing the data as a dictionary
165-
# all_years = json.loads(data)
185+
# all_years = json.loads(data)
166186
# this_year = all_years[year]
167187

168188
# this gets json from the api server
169-
url = 'http://api-server-cms-release-info.app.cern.ch/years?year='+year+'&type='+runtype+'&output=plain'
189+
url = (
190+
"http://api-server-cms-release-info.app.cern.ch/years?year="
191+
+ year
192+
+ "&type="
193+
+ runtype
194+
+ "&output=plain"
195+
)
170196
this_json = json.loads(requests.get(url).text.strip())
171-
172-
recid=int(recid)
197+
198+
recid = int(recid)
173199
for val in this_json["val_json"]:
174200
records.append(
175201
create_record(
176202
str(recid),
177203
this_json["year"],
178204
era,
179205
runtype,
180-
val["url"].split("/")[-1].strip())
181-
#row["val_json_golden"].split("/")[-1].strip())
206+
val["url"].split("/")[-1].strip(),
207+
)
208+
# row["val_json_golden"].split("/")[-1].strip())
182209
)
183210
recid += 1
184211

185-
186212
print(
187213
json.dumps(
188214
records,
@@ -196,4 +222,3 @@ def main():
196222

197223
if __name__ == "__main__":
198224
main()
199-

0 commit comments

Comments
 (0)