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, T0_project_tag='', stream='', lumiblock=0)
 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
 T0_project_tag = T0_project_tag
 stream = stream
 lumiblock = lumiblock

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,
T0_project_tag = '',
stream = '',
lumiblock = 0 )
Initialize run parameters with defaults for any unspecified values.

Definition at line 83 of file athenaEF.py.

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

Member Function Documentation

◆ from_args()

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

Definition at line 137 of file athenaEF.py.

137 def from_args(cls, args):
138 """Create RunParams from argparse args, using defaults for unset values."""
139 return cls(
140 run_number=args.run_number,
141 lb_number=args.lb_number,
142 detector_mask=args.detector_mask,
143 sor_time=args.sor_time,
144 solenoid_current=getattr(args, 'solenoid_current', None),
145 toroids_current=getattr(args, 'toroids_current', None),
146 beam_type=getattr(args, 'beam_type', None),
147 beam_energy=getattr(args, 'beam_energy', None),
148 conditions_run=getattr(args, 'conditions_run', None),
149 T0_project_tag=getattr(args, 'T0_project_tag', ''),
150 stream=getattr(args, 'stream', ''),
151 lumiblock=getattr(args, 'lumiblock', 0),
152 )
153

◆ 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 155 of file athenaEF.py.

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

◆ to_dict()

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

Definition at line 116 of file athenaEF.py.

116 def to_dict(self):
117 """Return run parameters as a dictionary for prepareForStart."""
118 return {
119 'run_number': self.run_number,
120 'lb_number': self.lb_number,
121 'detector_mask': self.detector_mask,
122 'sor_time': self.sor_time,
123 'solenoid_current': self.solenoid_current,
124 'toroids_current': self.toroids_current,
125 'beam_type': self.beam_type,
126 'beam_energy': self.beam_energy,
127 'run_type': self.run_type,
128 'trigger_type': self.trigger_type,
129 'recording_enabled': self.recording_enabled,
130 'conditions_run': self.conditions_run,
131 'T0_project_tag': self.T0_project_tag,
132 'stream': self.stream,
133 'lumiblock': self.lumiblock,
134 }
135

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 107 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 106 of file athenaEF.py.

◆ conditions_run

athenaEF.RunParams.conditions_run = conditions_run

Definition at line 111 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 102 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 101 of file athenaEF.py.

◆ lumiblock

athenaEF.RunParams.lumiblock = lumiblock

Definition at line 114 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 110 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 100 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 108 of file athenaEF.py.

◆ solenoid_current

athenaEF.RunParams.solenoid_current = solenoid_current

Definition at line 104 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 103 of file athenaEF.py.

◆ stream

athenaEF.RunParams.stream = stream

Definition at line 113 of file athenaEF.py.

◆ T0_project_tag

athenaEF.RunParams.T0_project_tag = T0_project_tag

Definition at line 112 of file athenaEF.py.

◆ toroids_current

athenaEF.RunParams.toroids_current = toroids_current

Definition at line 105 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 109 of file athenaEF.py.


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