|
2 | 2 | import base64 |
3 | 3 | import dataclasses |
4 | 4 | import re |
| 5 | +import urllib.request |
5 | 6 |
|
6 | 7 | import coffea |
7 | 8 |
|
@@ -95,21 +96,27 @@ def sample_xs(campaign: str, dsid: str) -> float: |
95 | 96 | # extracting this information is expensive, so do it once and cache |
96 | 97 | if "mc20" in campaign: |
97 | 98 | if MC16_XSEC_DICT is None: |
98 | | - # in case of no cvmfs: https://atlas-groupdata.web.cern.ch/atlas-groupdata/dev/PMGTools/PMGxsecDB_mc16.txt |
99 | | - with open("/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/dev/PMGTools/PMGxsecDB_mc16.txt") as f: |
100 | | - content = f.readlines() |
| 99 | + try: |
| 100 | + with open("/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/dev/PMGTools/PMGxsecDB_mc16.txt") as f: |
| 101 | + content = f.readlines() |
| 102 | + except FileNotFoundError: |
| 103 | + print("falling back to reading cross-section information over https") |
| 104 | + content = urllib.request.urlopen("https://atlas-groupdata.web.cern.ch/atlas-groupdata/dev/PMGTools/PMGxsecDB_mc16.txt").read().decode().split("\n") |
101 | 105 |
|
102 | | - MC16_XSEC_DICT = dict([(line.split("\t\t")[0], (line.split("\t\t")[2:5])) for line in content[1:]]) |
| 106 | + MC16_XSEC_DICT = dict([(line.strip().split("\t\t")[0], (line.split("\t\t")[2:5])) for line in content[1:]]) |
103 | 107 |
|
104 | 108 | xsec_dict = MC16_XSEC_DICT |
105 | 109 |
|
106 | 110 | elif "mc23" in campaign: |
107 | 111 | if MC23_XSEC_DICT is None: |
108 | | - # in case of no cvmfs: https://atlas-groupdata.web.cern.ch/atlas-groupdata/dev/PMGTools/PMGxsecDB_mc23.txt |
109 | | - with open("/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/dev/PMGTools/PMGxsecDB_mc23.txt") as f: |
110 | | - content = f.readlines() |
111 | | - |
112 | | - MC23_XSEC_DICT = dict([(line.split("\t\t")[0], (line.split("\t\t")[2:5])) for line in content[1:]]) |
| 112 | + try: |
| 113 | + with open("/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/dev/PMGTools/PMGxsecDB_mc23.txt") as f: |
| 114 | + content = f.readlines() |
| 115 | + except FileNotFoundError: |
| 116 | + print("falling back to reading cross-section information over https") |
| 117 | + content = urllib.request.urlopen("https://atlas-groupdata.web.cern.ch/atlas-groupdata/dev/PMGTools/PMGxsecDB_mc23.txt").read().decode().split("\n") |
| 118 | + |
| 119 | + MC23_XSEC_DICT = dict([(line.strip().split("\t\t")[0], (line.split("\t\t")[2:5])) for line in content[1:]]) |
113 | 120 |
|
114 | 121 | xsec_dict = MC23_XSEC_DICT |
115 | 122 |
|
|
0 commit comments