ATLAS Offline Software
Loading...
Searching...
No Matches
athenaEF.RunParams Class Reference
Collaboration diagram for athenaEF.RunParams:

Public Member Functions

 __init__ (self, run_number=None, lb_number=None, detector_mask=None, sor_time=None, solenoid_current=None, toroids_current=None, beam_type=None, beam_energy=None, run_type=None, trigger_type=None, recording_enabled=None, conditions_run=None)
 to_dict (self)
 from_args (cls, args)
 from_is (cls, partition=None, webdaq_base=None, strict=False, solenoid_current_override=None, toroids_current_override=None)

Public Attributes

int run_number = run_number if run_number is not None else self.DEFAULT_RUN_NUMBER
int lb_number = lb_number if lb_number is not None else self.DEFAULT_LB_NUMBER
str detector_mask = detector_mask if detector_mask is not None else self.DEFAULT_DETECTOR_MASK
 sor_time = sor_time if sor_time is not None else dt.now().strftime('%d/%m/%y %H:%M:%S.%f')
 solenoid_current = solenoid_current
 toroids_current = toroids_current
int beam_type = beam_type if beam_type is not None else self.DEFAULT_BEAM_TYPE
int beam_energy = beam_energy if beam_energy is not None else self.DEFAULT_BEAM_ENERGY
str run_type = run_type if run_type is not None else self.DEFAULT_RUN_TYPE
int trigger_type = trigger_type if trigger_type is not None else self.DEFAULT_TRIGGER_TYPE
bool recording_enabled = recording_enabled if recording_enabled is not None else self.DEFAULT_RECORDING_ENABLED
 conditions_run = conditions_run

Static Public Attributes

int DEFAULT_RUN_NUMBER = 0
int DEFAULT_LB_NUMBER = 0
str DEFAULT_DETECTOR_MASK = 'f' * 32
 DEFAULT_SOR_TIME = None
float DEFAULT_SOLENOID_CURRENT = 7730.0
float DEFAULT_TOROIDS_CURRENT = 20400.0
int DEFAULT_BEAM_TYPE = 0
int DEFAULT_BEAM_ENERGY = 0
str DEFAULT_RUN_TYPE = "Physics"
int DEFAULT_TRIGGER_TYPE = 0
bool DEFAULT_RECORDING_ENABLED = False

Detailed Description

Container for run parameters needed by HltEventLoopMgr::prepareForStart().

This class centralizes all run parameter defaults or their retrieval from IS.

Definition at line 63 of file athenaEF.py.

Constructor & Destructor Documentation

◆ __init__()

athenaEF.RunParams.__init__ ( self,
run_number = None,
lb_number = None,
detector_mask = None,
sor_time = None,
solenoid_current = None,
toroids_current = None,
beam_type = None,
beam_energy = None,
run_type = None,
trigger_type = None,
recording_enabled = None,
conditions_run = None )
Initialize run parameters with defaults for any unspecified values.

Definition at line 83 of file athenaEF.py.

95 conditions_run=None):
96 """Initialize run parameters with defaults for any unspecified values."""
97 self.run_number = run_number if run_number is not None else self.DEFAULT_RUN_NUMBER
98 self.lb_number = lb_number if lb_number is not None else self.DEFAULT_LB_NUMBER
99 self.detector_mask = detector_mask if detector_mask is not None else self.DEFAULT_DETECTOR_MASK
100 self.sor_time = sor_time if sor_time is not None else dt.now().strftime('%d/%m/%y %H:%M:%S.%f')
101 self.solenoid_current = solenoid_current
102 self.toroids_current = toroids_current
103 self.beam_type = beam_type if beam_type is not None else self.DEFAULT_BEAM_TYPE
104 self.beam_energy = beam_energy if beam_energy is not None else self.DEFAULT_BEAM_ENERGY
105 self.run_type = run_type if run_type is not None else self.DEFAULT_RUN_TYPE
106 self.trigger_type = trigger_type if trigger_type is not None else self.DEFAULT_TRIGGER_TYPE
107 self.recording_enabled = recording_enabled if recording_enabled is not None else self.DEFAULT_RECORDING_ENABLED
108 self.conditions_run = conditions_run # Reference run for conditions lookup (None = use run_number)
109

Member Function Documentation

◆ from_args()

athenaEF.RunParams.from_args ( cls,
args )
Create RunParams from argparse args, using defaults for unset values.

Definition at line 128 of file athenaEF.py.

128 def from_args(cls, args):
129 """Create RunParams from argparse args, using defaults for unset values."""
130 return cls(
131 run_number=args.run_number,
132 lb_number=args.lb_number,
133 detector_mask=args.detector_mask,
134 sor_time=args.sor_time,
135 solenoid_current=getattr(args, 'solenoid_current', None),
136 toroids_current=getattr(args, 'toroids_current', None),
137 conditions_run=getattr(args, 'conditions_run', None),
138 )
139

◆ from_is()

athenaEF.RunParams.from_is ( cls,
partition = None,
webdaq_base = None,
strict = False,
solenoid_current_override = None,
toroids_current_override = None )
Create RunParams by reading from IS via the WEBDAQ REST API.

This uses the webis_server REST API to fetch run parameters, avoiding
direct dependencies on TDAQ libraries. The API endpoint is determined by:
1. The webdaq_base parameter if provided
2. The TDAQ_WEBDAQ_BASE environment variable

The IS objects accessed are:
- RunParams.RunParams: run_number, det_mask, timeSOR, trigger_type, etc.
- Magnets.Magnets: SolenoidCurrent, ToroidsCurrent

Args:
   partition: The partition name (default: from TDAQ_PARTITION env var)
   webdaq_base: Base URL for webis_server (default: from TDAQ_WEBDAQ_BASE env var)
   strict: If True, raise an exception if IS read fails (for --online-environment)
   solenoid_current_override: If provided, skip IS fetch for solenoid (command-line override)
   toroids_current_override: If provided, skip IS fetch for toroids (command-line override)

Returns:
   RunParams instance with values from IS, or defaults if unavailable

Raises:
   RuntimeError: If strict=True and IS read fails

Definition at line 141 of file athenaEF.py.

142 solenoid_current_override=None, toroids_current_override=None):
143 """
144 Create RunParams by reading from IS via the WEBDAQ REST API.
145
146 This uses the webis_server REST API to fetch run parameters, avoiding
147 direct dependencies on TDAQ libraries. The API endpoint is determined by:
148 1. The webdaq_base parameter if provided
149 2. The TDAQ_WEBDAQ_BASE environment variable
150
151 The IS objects accessed are:
152 - RunParams.RunParams: run_number, det_mask, timeSOR, trigger_type, etc.
153 - Magnets.Magnets: SolenoidCurrent, ToroidsCurrent
154
155 Args:
156 partition: The partition name (default: from TDAQ_PARTITION env var)
157 webdaq_base: Base URL for webis_server (default: from TDAQ_WEBDAQ_BASE env var)
158 strict: If True, raise an exception if IS read fails (for --online-environment)
159 solenoid_current_override: If provided, skip IS fetch for solenoid (command-line override)
160 toroids_current_override: If provided, skip IS fetch for toroids (command-line override)
161
162 Returns:
163 RunParams instance with values from IS, or defaults if unavailable
164
165 Raises:
166 RuntimeError: If strict=True and IS read fails
167 """
168 import requests
169
170 # Determine the base URL
171 if webdaq_base is None:
172 webdaq_base = os.environ.get('TDAQ_WEBDAQ_BASE')
173
174 if not webdaq_base:
175 msg = "TDAQ_WEBDAQ_BASE not set, cannot read from IS"
176 if strict:
177 raise RuntimeError(msg + " (required for --online-environment)")
178 log.warning(msg + ". Using defaults.")
179 return cls()
180
181 # Determine partition
182 if partition is None:
183 partition = os.environ.get('TDAQ_PARTITION', 'ATLAS')
184
185 log.info("Reading run parameters from IS via WEBDAQ: %s (partition=%s)", webdaq_base, partition)
186
187 params = {}
188
189 # Fetch RunParams from IS
190 # API: GET /info/current/{partition}/is/{server}/{server}.{name}?format=compact
191 # Response format: [name, type, timestamp, data] - we need element [3]
192 try:
193 url = f"{webdaq_base}/info/current/{partition}/is/RunParams/RunParams.RunParams?format=compact"
194 log.debug("Fetching RunParams from: %s", url)
195
196 response = requests.get(url, timeout=10)
197 if response.status_code == 200:
198 response_data = response.json()
199 log.debug("RunParams response from IS: %s", response_data)
200
201 # Response is [name, type, timestamp, data]
202 if isinstance(response_data, list) and len(response_data) >= 4:
203 runparams = response_data[3]
204 else:
205 runparams = response_data
206
207 log.debug("RunParams data: %s", runparams)
208
209 # Map IS fields to our RunParams fields
210 if 'run_number' in runparams:
211 params['run_number'] = int(runparams['run_number'])
212 if 'lumiblock' in runparams:
213 params['lb_number'] = int(runparams['lumiblock'])
214 if 'det_mask' in runparams:
215 params['detector_mask'] = runparams['det_mask']
216 if 'timeSOR' in runparams:
217 sor_time = runparams['timeSOR']
218 # Ensure microseconds are present (TrigSORFromPtreeHelper expects format with .%f)
219 if '.' not in sor_time:
220 sor_time += '.000000'
221 params['sor_time'] = sor_time
222 if 'beam_type' in runparams:
223 params['beam_type'] = int(runparams['beam_type'])
224 if 'beam_energy' in runparams:
225 params['beam_energy'] = int(runparams['beam_energy'])
226 if 'run_type' in runparams:
227 params['run_type'] = runparams['run_type']
228 if 'trigger_type' in runparams:
229 params['trigger_type'] = int(runparams['trigger_type'])
230 if 'recording_enabled' in runparams:
231 params['recording_enabled'] = runparams['recording_enabled'] in ('1', 'true', 'True', True, 1)
232
233 log.info("Got run parameters from IS: run=%s, lb=%s",
234 params.get('run_number'), params.get('lb_number'))
235 else:
236 msg = f"Failed to fetch RunParams from IS: HTTP {response.status_code}"
237 if strict:
238 raise RuntimeError(msg + " (required for --online-environment)")
239 log.warning(msg)
240
241 except requests.exceptions.RequestException as e:
242 msg = f"Error fetching RunParams from IS: {e}"
243 if strict:
244 raise RuntimeError(msg + " (required for --online-environment)")
245 log.warning(msg)
246 except (ValueError, KeyError) as e:
247 msg = f"Error parsing RunParams from IS: {e}"
248 if strict:
249 raise RuntimeError(msg + " (required for --online-environment)")
250 log.warning(msg)
251
252 # Fetch Magnets from IS
253 # In strict mode (online environment), magnets are required unless provided via command line
254 # If command-line overrides are provided, use those instead of fetching from IS
255 have_solenoid_override = solenoid_current_override is not None
256 have_toroids_override = toroids_current_override is not None
257
258 if have_solenoid_override:
259 params['solenoid_current'] = solenoid_current_override
260 log.info("Using solenoid_current=%.1f from command line override", solenoid_current_override)
261 if have_toroids_override:
262 params['toroids_current'] = toroids_current_override
263 log.info("Using toroids_current=%.1f from command line override", toroids_current_override)
264
265 # Only fetch from IS if we need at least one value
266 if not (have_solenoid_override and have_toroids_override):
267 try:
268 url = f"{webdaq_base}/info/current/{partition}/is/Magnets/Magnets.Magnets?format=compact"
269 log.debug("Fetching Magnets from: %s", url)
270
271 response = requests.get(url, timeout=10)
272 if response.status_code == 200:
273 response_data = response.json()
274 log.debug("Magnets response from IS: %s", response_data)
275
276 magnets = response_data[3] if isinstance(response_data, list) and len(response_data) >= 4 else response_data
277 log.debug("Magnets data: %s", magnets)
278
279 # Magnets structure: { "SolenoidCurrent": {"value": ..., "ts": ...},
280 # "ToroidsCurrent": {"value": ..., "ts": ...} }
281 if not have_solenoid_override:
282 params['solenoid_current'] = float(magnets['SolenoidCurrent']['value'])
283 if not have_toroids_override:
284 params['toroids_current'] = float(magnets['ToroidsCurrent']['value'])
285
286 log.info("Got magnet currents from IS: solenoid=%s, toroids=%s",
287 params.get('solenoid_current'), params.get('toroids_current'))
288 elif strict:
289 raise RuntimeError(f"Magnets not available from IS: HTTP {response.status_code} "
290 "(required for --online-environment, use --solenoid-current and --toroids-current to override)")
291 else:
292 log.debug("Magnets not available from IS: HTTP %d", response.status_code)
293
294 except requests.exceptions.RequestException as e:
295 if strict:
296 raise RuntimeError(f"Error fetching Magnets from IS: {e} "
297 "(required for --online-environment, use --solenoid-current and --toroids-current to override)")
298 log.debug("Error fetching Magnets from IS: %s", e)
299 except (ValueError, KeyError, TypeError) as e:
300 if strict:
301 raise RuntimeError(f"Error parsing Magnets from IS: {e} "
302 "(required for --online-environment, use --solenoid-current and --toroids-current to override)")
303 log.debug("Error parsing Magnets from IS: %s", e)
304
305 # In strict mode, verify we got at least run_number from IS
306 if strict and 'run_number' not in params:
307 raise RuntimeError("Failed to get run_number from IS (required for --online-environment)")
308
309 return cls(**params)
310
311

◆ to_dict()

athenaEF.RunParams.to_dict ( self)
Return run parameters as a dictionary for prepareForStart.

Definition at line 110 of file athenaEF.py.

110 def to_dict(self):
111 """Return run parameters as a dictionary for prepareForStart."""
112 return {
113 'run_number': self.run_number,
114 'lb_number': self.lb_number,
115 'detector_mask': self.detector_mask,
116 'sor_time': self.sor_time,
117 'solenoid_current': self.solenoid_current,
118 'toroids_current': self.toroids_current,
119 'beam_type': self.beam_type,
120 'beam_energy': self.beam_energy,
121 'run_type': self.run_type,
122 'trigger_type': self.trigger_type,
123 'recording_enabled': self.recording_enabled,
124 'conditions_run': self.conditions_run,
125 }
126

Member Data Documentation

◆ beam_energy

athenaEF.RunParams.beam_energy = beam_energy if beam_energy is not None else self.DEFAULT_BEAM_ENERGY

Definition at line 104 of file athenaEF.py.

◆ beam_type

athenaEF.RunParams.beam_type = beam_type if beam_type is not None else self.DEFAULT_BEAM_TYPE

Definition at line 103 of file athenaEF.py.

◆ conditions_run

athenaEF.RunParams.conditions_run = conditions_run

Definition at line 108 of file athenaEF.py.

◆ DEFAULT_BEAM_ENERGY

int athenaEF.RunParams.DEFAULT_BEAM_ENERGY = 0
static

Definition at line 78 of file athenaEF.py.

◆ DEFAULT_BEAM_TYPE

int athenaEF.RunParams.DEFAULT_BEAM_TYPE = 0
static

Definition at line 77 of file athenaEF.py.

◆ DEFAULT_DETECTOR_MASK

str athenaEF.RunParams.DEFAULT_DETECTOR_MASK = 'f' * 32
static

Definition at line 73 of file athenaEF.py.

◆ DEFAULT_LB_NUMBER

int athenaEF.RunParams.DEFAULT_LB_NUMBER = 0
static

Definition at line 72 of file athenaEF.py.

◆ DEFAULT_RECORDING_ENABLED

bool athenaEF.RunParams.DEFAULT_RECORDING_ENABLED = False
static

Definition at line 81 of file athenaEF.py.

◆ DEFAULT_RUN_NUMBER

int athenaEF.RunParams.DEFAULT_RUN_NUMBER = 0
static

Definition at line 71 of file athenaEF.py.

◆ DEFAULT_RUN_TYPE

str athenaEF.RunParams.DEFAULT_RUN_TYPE = "Physics"
static

Definition at line 79 of file athenaEF.py.

◆ DEFAULT_SOLENOID_CURRENT

float athenaEF.RunParams.DEFAULT_SOLENOID_CURRENT = 7730.0
static

Definition at line 75 of file athenaEF.py.

◆ DEFAULT_SOR_TIME

athenaEF.RunParams.DEFAULT_SOR_TIME = None
static

Definition at line 74 of file athenaEF.py.

◆ DEFAULT_TOROIDS_CURRENT

float athenaEF.RunParams.DEFAULT_TOROIDS_CURRENT = 20400.0
static

Definition at line 76 of file athenaEF.py.

◆ DEFAULT_TRIGGER_TYPE

int athenaEF.RunParams.DEFAULT_TRIGGER_TYPE = 0
static

Definition at line 80 of file athenaEF.py.

◆ detector_mask

athenaEF.RunParams.detector_mask = detector_mask if detector_mask is not None else self.DEFAULT_DETECTOR_MASK

Definition at line 99 of file athenaEF.py.

◆ lb_number

athenaEF.RunParams.lb_number = lb_number if lb_number is not None else self.DEFAULT_LB_NUMBER

Definition at line 98 of file athenaEF.py.

◆ recording_enabled

athenaEF.RunParams.recording_enabled = recording_enabled if recording_enabled is not None else self.DEFAULT_RECORDING_ENABLED

Definition at line 107 of file athenaEF.py.

◆ run_number

athenaEF.RunParams.run_number = run_number if run_number is not None else self.DEFAULT_RUN_NUMBER

Definition at line 97 of file athenaEF.py.

◆ run_type

athenaEF.RunParams.run_type = run_type if run_type is not None else self.DEFAULT_RUN_TYPE

Definition at line 105 of file athenaEF.py.

◆ solenoid_current

athenaEF.RunParams.solenoid_current = solenoid_current

Definition at line 101 of file athenaEF.py.

◆ sor_time

athenaEF.RunParams.sor_time = sor_time if sor_time is not None else dt.now().strftime('%d/%m/%y %H:%M:%S.%f')

Definition at line 100 of file athenaEF.py.

◆ toroids_current

athenaEF.RunParams.toroids_current = toroids_current

Definition at line 102 of file athenaEF.py.

◆ trigger_type

athenaEF.RunParams.trigger_type = trigger_type if trigger_type is not None else self.DEFAULT_TRIGGER_TYPE

Definition at line 106 of file athenaEF.py.


The documentation for this class was generated from the following file: