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

Public Member Functions

 __init__ (self, job_options_type, job_options_path, run_params=None, properties=None, db_server=None, smk=None, num_threads=1, num_slots=1, ef_files=None)
 from_json (cls, json_file, run_params=None, properties=None, num_threads=1, num_slots=1, ef_files=None)
 from_database (cls, db_server, smk, l1psk=None, hltpsk=None, run_params=None, num_threads=1, num_slots=1, ef_files=None)
 run (self, maxEvents=None)

Public Attributes

str job_options_type = job_options_type
 job_options_path = job_options_path
 run_params = run_params or {}
 properties = properties
 db_server = db_server
 smk = smk
 num_threads = num_threads
 num_slots = num_slots
 ef_files = ef_files or []

Protected Attributes

 _app = None

Detailed Description

Runner class that executes Gaudi configuration from JSON file or database.
Uses TrigConf::JobOptionsSvc with TYPE="FILE" or TYPE="DB" to load configuration.
Same approach used by PSC (Psc.cxx) - it sets JobOptionsType and
JobOptionsPath on the ApplicationMgr, and TrigConf::JobOptionsSvc handles both
FILE and DB modes transparently.

Definition at line 508 of file athenaEF.py.

Constructor & Destructor Documentation

◆ __init__()

athenaEF.ConfigRunner.__init__ ( self,
job_options_type,
job_options_path,
run_params = None,
properties = None,
db_server = None,
smk = None,
num_threads = 1,
num_slots = 1,
ef_files = None )
Args:
   job_options_type: "FILE" or "DB"
   job_options_path: JSON file path (for FILE) or DB connection string (for DB)
   run_params: Run parameters dict for prepareForStart
   properties: Pre-loaded properties dict (optional, for FILE mode)
   db_server: DB server alias (for store() in DB mode)
   smk: Super Master Key (for store() in DB mode)
   num_threads: Number of threads for AvalancheSchedulerSvc.ThreadPoolSize
   num_slots: Number of event slots for EventDataSvc.NSlots
   ef_files: List of input files for EFInterfaceSvc

Definition at line 516 of file athenaEF.py.

518 num_threads=1, num_slots=1, ef_files=None):
519 """
520 Args:
521 job_options_type: "FILE" or "DB"
522 job_options_path: JSON file path (for FILE) or DB connection string (for DB)
523 run_params: Run parameters dict for prepareForStart
524 properties: Pre-loaded properties dict (optional, for FILE mode)
525 db_server: DB server alias (for store() in DB mode)
526 smk: Super Master Key (for store() in DB mode)
527 num_threads: Number of threads for AvalancheSchedulerSvc.ThreadPoolSize
528 num_slots: Number of event slots for EventDataSvc.NSlots
529 ef_files: List of input files for EFInterfaceSvc
530 """
531 self.job_options_type = job_options_type
532 self.job_options_path = job_options_path
533 self.run_params = run_params or {}
534 self.properties = properties
535 self.db_server = db_server # For store() in DB mode
536 self.smk = smk # For store() in DB mode
537 self.num_threads = num_threads
538 self.num_slots = num_slots
539 self.ef_files = ef_files or [] # Input files for EFInterfaceSvc
540 self._app = None
541

Member Function Documentation

◆ from_database()

athenaEF.ConfigRunner.from_database ( cls,
db_server,
smk,
l1psk = None,
hltpsk = None,
run_params = None,
num_threads = 1,
num_slots = 1,
ef_files = None )
Create runner for database (TYPE=DB)

Definition at line 550 of file athenaEF.py.

551 num_threads=1, num_slots=1, ef_files=None):
552 """Create runner for database (TYPE=DB)"""
553 # Build the DB connection string: server=X;smkey=Y;lvl1key=Z;hltkey=W
554 db_path = f"server={db_server};smkey={smk}"
555 if l1psk is not None:
556 db_path += f";lvl1key={l1psk}"
557 if hltpsk is not None:
558 db_path += f";hltkey={hltpsk}"
559 return cls("DB", db_path, run_params, db_server=db_server, smk=smk,
560 num_threads=num_threads, num_slots=num_slots, ef_files=ef_files)
561

◆ from_json()

athenaEF.ConfigRunner.from_json ( cls,
json_file,
run_params = None,
properties = None,
num_threads = 1,
num_slots = 1,
ef_files = None )
Create runner for JSON file (TYPE=FILE)

Definition at line 543 of file athenaEF.py.

544 num_threads=1, num_slots=1, ef_files=None):
545 """Create runner for JSON file (TYPE=FILE)"""
546 return cls("FILE", os.path.abspath(json_file), run_params, properties,
547 num_threads=num_threads, num_slots=num_slots, ef_files=ef_files)
548

◆ run()

athenaEF.ConfigRunner.run ( self,
maxEvents = None )
This follows the same pattern as PSC (Psc.cxx):
1. Create ApplicationMgr via BootstrapHelper
2. Set JobOptionsSvcType, JobOptionsType, JobOptionsPath
3. configure() -> initialize() -> prepareForStart() -> start() ->
   hltUpdateAfterFork() -> run() -> stop() -> finalize() -> terminate()

Definition at line 562 of file athenaEF.py.

562 def run(self, maxEvents=None):
563 """
564 This follows the same pattern as PSC (Psc.cxx):
565 1. Create ApplicationMgr via BootstrapHelper
566 2. Set JobOptionsSvcType, JobOptionsType, JobOptionsPath
567 3. configure() -> initialize() -> prepareForStart() -> start() ->
568 hltUpdateAfterFork() -> run() -> stop() -> finalize() -> terminate()
569 """
570 from Gaudi.Main import BootstrapHelper
571
572 # For FILE mode, load properties from JSON if not already provided
573 if self.job_options_type == "FILE" and self.properties is None:
574 with open(self.job_options_path, 'r') as f:
575 jocat = json.load(f)
576 self.properties = jocat.get('properties', {})
577
578 bsh = BootstrapHelper()
579 app = bsh.createApplicationMgr()
580 self._app = app
581
582 # For FILE mode, set ApplicationMgr properties from JSON before configure
583 if self.job_options_type == "FILE" and self.properties:
584 app_props = self.properties.get('ApplicationMgr', {})
585 for k, v in app_props.items():
586 if k not in ('JobOptionsSvcType', 'JobOptionsType', 'JobOptionsPath'):
587 log.debug("Setting ApplicationMgr.%s = %s", k, v)
588 app.setProperty(k, str(v) if not isinstance(v, str) else v)
589
590 # Set JobOptionsSvc properties like PSC does in Psc.cxx
591 log.info("Configuring TrigConf::JobOptionsSvc with TYPE=%s, PATH=%s",
592 self.job_options_type, self.job_options_path)
593 app.setProperty("JobOptionsSvcType", "TrigConf::JobOptionsSvc")
594 app.setProperty("JobOptionsType", self.job_options_type)
595 app.setProperty("JobOptionsPath", self.job_options_path)
596
597 # Configure the application - TrigConf::JobOptionsSvc will load from FILE or DB
598 app.configure()
599
600 # Override EvtMax AFTER configure() only if explicitly specified by user
601 # Otherwise use whatever value is in the DB
602 if maxEvents is not None:
603 log.info("Setting EvtMax=%d (overriding DB value)", maxEvents)
604 app.setProperty('EvtMax', str(maxEvents))
605
606 # All property overrides below use iProperty and must be done after configure()
607 # but before initialize() - this is the same pattern as PSC (Psc.cxx)
608 from GaudiPython.Bindings import iProperty
609
610 # Override EFInterfaceSvc.NumEvents if user specified it (overrides DB value)
611 if maxEvents is not None:
612 log.info("Setting EFInterfaceSvc.NumEvents=%d (overriding DB value)", maxEvents)
613 iProperty("EFInterfaceSvc").NumEvents = maxEvents
614
615 # Set threading configuration
616 log.info("Setting threading: ThreadPoolSize=%d, NSlots=%d", self.num_threads, self.num_slots)
617 iProperty("AvalancheSchedulerSvc").ThreadPoolSize = self.num_threads
618 iProperty("EventDataSvc").NSlots = self.num_slots
619
620 # Set input files for EFInterfaceSvc (overrides what's in DB/JSON config)
621 if self.ef_files:
622 log.info("Setting EFInterfaceSvc.Files = %s", self.ef_files)
623 iProperty("EFInterfaceSvc").Files = self.ef_files
624
625 # If HLT PSK is set on command line, read it from DB instead of COOL (ATR-25974)
626 # This is the same logic as TrigPSCPythonDbSetup.py
627 from TrigPSC import PscConfig
628 if PscConfig.forcePSK:
629 log.info("PscConfig.forcePSK is set - configuring HLTPrescaleCondAlg to read from DB instead of COOL")
630 iProperty("HLTPrescaleCondAlg").Source = "DB"
631
632 # Set forceRunNumber on HltEventLoopMgr if conditions_run is specified
633 # This overrides the run number used for IOV lookup in conditions loading
634 conditions_run = self.run_params.get('conditions_run')
635 if conditions_run is not None:
636 log.info("Setting HltEventLoopMgr.forceRunNumber=%d for conditions lookup", conditions_run)
637 iProperty("HltEventLoopMgr").forceRunNumber = conditions_run
638
639 # Initialize
640 sc = app.initialize()
641 if not sc.isSuccess():
642 log.error("Failed to initialize AppMgr")
643 return sc
644
645 # Initialize TrigServicesHelper for lifecycle calls (prepareForStart, prepareForRun, hltUpdateAfterFork)
646 try:
647 from TrigServices.TrigServicesHelper import TrigServicesHelper
648 helper = TrigServicesHelper()
649 except ImportError as e:
650 log.error("TrigServicesHelper not available: %s", e)
651 log.error("Cannot proceed without TrigServicesHelper - required for HLTEventLoopMgr lifecycle")
652 raise RuntimeError("TrigServicesHelper not available") from e
653
654 # Call prepareForStart to set up ByteStreamMetadata (like PSC does)
655 try:
656 run_number = self.run_params['run_number']
657 det_mask = self.run_params['detector_mask']
658 sor_time = self.run_params['sor_time']
659 solenoid_current = self.run_params['solenoid_current']
660 toroids_current = self.run_params['toroids_current']
661
662 log.info("Calling prepareForStart with run=%d, det_mask=0x%s, sor_time=%s",
663 run_number, det_mask, sor_time)
664
665 success = helper.prepareForStart(
666 run_number=run_number,
667 det_mask=det_mask,
668 sor_time=sor_time,
669 solenoid_current=solenoid_current,
670 toroids_current=toroids_current
671 )
672 if not success:
673 log.error("prepareForStart failed")
674 raise RuntimeError("prepareForStart failed")
675 log.info("prepareForStart completed successfully")
676 except Exception as e:
677 log.error("Error calling prepareForStart: %s", e)
678 traceback.print_exc()
679 raise
680
681 # Start
682 sc = app.start()
683 if not sc.isSuccess():
684 log.error("Failed to start AppMgr")
685 return sc
686
687 # prepareForRun initializes COOL folder helper - must be called after start()
688 # which fires the start incident
689 try:
690 log.info("Calling prepareForRun to initialize COOL folder helper")
691 success = helper.prepareForRun()
692 if not success:
693 log.error("prepareForRun failed")
694 raise RuntimeError("prepareForRun failed")
695 log.info("prepareForRun completed successfully")
696 except Exception as e:
697 log.error("Error calling prepareForRun: %s", e)
698 traceback.print_exc()
699 raise
700
701 # hltUpdateAfterFork initializes the scheduler (like PSC does after fork)
702 # worker_id=1 for single-worker, non-forked mode
703 try:
704 log.info("Calling hltUpdateAfterFork to initialize scheduler (worker_id=1)")
705 success = helper.hltUpdateAfterFork(worker_id=1)
706 if not success:
707 log.error("hltUpdateAfterFork failed")
708 raise RuntimeError("hltUpdateAfterFork failed")
709 log.info("hltUpdateAfterFork completed successfully")
710 except Exception as e:
711 log.error("Error calling hltUpdateAfterFork: %s", e)
712 traceback.print_exc()
713 raise
714
715 # Run the event loop
716 # Note: Python signal handlers won't work during C++ execution.
717 nevt = maxEvents if maxEvents is not None else -1
718 sc = app.run(nevt)
719
720 if not sc.isSuccess():
721 log.error("Failure running application")
722 return sc
723
724 # Stop
725 sc = app.stop()
726 if not sc.isSuccess():
727 log.error("Failed to stop AppMgr")
728 return sc
729
730 # Finalize
731 sc = app.finalize()
732 if not sc.isSuccess():
733 log.error("Failed to finalize AppMgr")
734 return sc
735
736 # Terminate
737 sc = app.terminate()
738 return sc
739
740
Helper class to call ITrigEventLoopMgr methods from Python.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
int run(int argc, char *argv[])

Member Data Documentation

◆ _app

athenaEF.ConfigRunner._app = None
protected

Definition at line 540 of file athenaEF.py.

◆ db_server

athenaEF.ConfigRunner.db_server = db_server

Definition at line 535 of file athenaEF.py.

◆ ef_files

athenaEF.ConfigRunner.ef_files = ef_files or []

Definition at line 539 of file athenaEF.py.

◆ job_options_path

athenaEF.ConfigRunner.job_options_path = job_options_path

Definition at line 532 of file athenaEF.py.

◆ job_options_type

athenaEF.ConfigRunner.job_options_type = job_options_type

Definition at line 531 of file athenaEF.py.

◆ num_slots

athenaEF.ConfigRunner.num_slots = num_slots

Definition at line 538 of file athenaEF.py.

◆ num_threads

athenaEF.ConfigRunner.num_threads = num_threads

Definition at line 537 of file athenaEF.py.

◆ properties

athenaEF.ConfigRunner.properties = properties

Definition at line 534 of file athenaEF.py.

◆ run_params

athenaEF.ConfigRunner.run_params = run_params or {}

Definition at line 533 of file athenaEF.py.

◆ smk

athenaEF.ConfigRunner.smk = smk

Definition at line 536 of file athenaEF.py.


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