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, overrides=None)
 from_json (cls, json_file, run_params=None, properties=None, overrides=None)
 from_database (cls, db_server, smk, l1psk=None, hltpsk=None, run_params=None, overrides=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
 overrides = overrides or RuntimeOverrides()

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.
It sets JobOptionsType and JobOptionsPath on the ApplicationMgr, and TrigConf::JobOptionsSvc
handles both FILE and DB modes transparently.

Definition at line 576 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,
overrides = 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)
   overrides: RuntimeOverrides applied between configure() and initialize()

Definition at line 583 of file athenaEF.py.

584 properties=None, db_server=None, smk=None, overrides=None):
585 """
586 Args:
587 job_options_type: "FILE" or "DB"
588 job_options_path: JSON file path (for FILE) or DB connection string (for DB)
589 run_params: Run parameters dict for prepareForStart
590 properties: Pre-loaded properties dict (optional, for FILE mode)
591 db_server: DB server alias (for store() in DB mode)
592 smk: Super Master Key (for store() in DB mode)
593 overrides: RuntimeOverrides applied between configure() and initialize()
594 """
595 self.job_options_type = job_options_type
596 self.job_options_path = job_options_path
597 self.run_params = run_params or {}
598 self.properties = properties
599 self.db_server = db_server # For store() in DB mode
600 self.smk = smk # For store() in DB mode
601 self.overrides = overrides or RuntimeOverrides()
602 self._app = None
603

Member Function Documentation

◆ from_database()

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

Definition at line 610 of file athenaEF.py.

610 def from_database(cls, db_server, smk, l1psk=None, hltpsk=None, run_params=None, overrides=None):
611 """Create runner for database (TYPE=DB)"""
612 # Build the DB connection string: server=X;smkey=Y;lvl1key=Z;hltkey=W
613 db_path = f"server={db_server};smkey={smk}"
614 if l1psk is not None:
615 db_path += f";lvl1key={l1psk}"
616 if hltpsk is not None:
617 db_path += f";hltkey={hltpsk}"
618 return cls("DB", db_path, run_params, db_server=db_server, smk=smk, overrides=overrides)
619

◆ from_json()

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

Definition at line 605 of file athenaEF.py.

605 def from_json(cls, json_file, run_params=None, properties=None, overrides=None):
606 """Create runner for JSON file (TYPE=FILE)"""
607 return cls("FILE", os.path.abspath(json_file), run_params, properties, overrides=overrides)
608

◆ run()

athenaEF.ConfigRunner.run ( self,
maxEvents = None )
1. Create ApplicationMgr via BootstrapHelper
2. Set JobOptionsSvcType, JobOptionsType, JobOptionsPath
3. configure() -> initialize() -> prepareForStart() -> start() ->
   hltUpdateAfterFork() -> run() -> stop() -> finalize() -> terminate()

Definition at line 620 of file athenaEF.py.

620 def run(self, maxEvents=None):
621 """
622 1. Create ApplicationMgr via BootstrapHelper
623 2. Set JobOptionsSvcType, JobOptionsType, JobOptionsPath
624 3. configure() -> initialize() -> prepareForStart() -> start() ->
625 hltUpdateAfterFork() -> run() -> stop() -> finalize() -> terminate()
626 """
627 from Gaudi.Main import BootstrapHelper
628
629 # For FILE mode, load properties from JSON if not already provided
630 if self.job_options_type == "FILE" and self.properties is None:
631 with open(self.job_options_path, 'r') as f:
632 jocat = json.load(f)
633 self.properties = jocat.get('properties', {})
634
635 bsh = BootstrapHelper()
636 app = bsh.createApplicationMgr()
637 self._app = app
638 #Set trigger defaults here, see ATR-32996
639 app.setProperty("MessageSvcType", "TrigMessageSvc")
640
641 # For FILE mode, set ApplicationMgr properties from JSON before configure
642 if self.job_options_type == "FILE" and self.properties:
643 app_props = self.properties.get('ApplicationMgr', {})
644 for k, v in app_props.items():
645 if k not in ('JobOptionsSvcType', 'JobOptionsType', 'JobOptionsPath'):
646 log.debug("Setting ApplicationMgr.%s = %s", k, v)
647 app.setProperty(k, str(v) if not isinstance(v, str) else v)
648
649 # Set JobOptionsSvc properties
650 log.info("Configuring TrigConf::JobOptionsSvc with TYPE=%s, PATH=%s",
651 self.job_options_type, self.job_options_path)
652 app.setProperty("JobOptionsSvcType", "TrigConf::JobOptionsSvc")
653 app.setProperty("JobOptionsType", self.job_options_type)
654 app.setProperty("JobOptionsPath", self.job_options_path)
655
656 # Configure the application - TrigConf::JobOptionsSvc will load from FILE or DB
657 app.configure()
658
659 # Override EvtMax AFTER configure() only if explicitly specified by user
660 # Otherwise use whatever value is in the DB
661 if maxEvents is not None:
662 log.info("Setting EvtMax=%d (overriding DB value)", maxEvents)
663 app.setProperty('EvtMax', str(maxEvents))
664
665 # Overrides must be applied after configure() but before initialize().
666 self.overrides.apply()
667
668 # THistSvc.Output cannot be scheduled in main(): setTHistSvcOutput() has to run
669 # against the service that configure() actually created.
670 if self.overrides.service_types.get('THistSvc') == 'THistSvc':
671 from GaudiPython.Bindings import iProperty
672 from TriggerJobOpts.TriggerHistSvcConfig import setTHistSvcOutput
673 output = []
674 setTHistSvcOutput(output)
675 iProperty("THistSvc").Output = output
676
677 # Initialize
678 sc = app.initialize()
679 if not sc.isSuccess():
680 log.error("Failed to initialize AppMgr")
681 return sc
682
683 # Initialize TrigServicesHelper for lifecycle calls (prepareForStart, prepareForRun, hltUpdateAfterFork)
684 try:
685 from TrigServices.TrigServicesHelper import TrigServicesHelper
686 helper = TrigServicesHelper()
687 except ImportError as e:
688 log.error("TrigServicesHelper not available: %s", e)
689 log.error("Cannot proceed without TrigServicesHelper - required for HLTEventLoopMgr lifecycle")
690 raise RuntimeError("TrigServicesHelper not available") from e
691
692 # Call prepareForStart to set up ByteStreamMetadata
693 try:
694 run_number = self.run_params['run_number']
695 det_mask = self.run_params['detector_mask']
696 sor_time = self.run_params['sor_time']
697 solenoid_current = self.run_params['solenoid_current']
698 toroids_current = self.run_params['toroids_current']
699 beam_type = self.run_params['beam_type']
700 beam_energy = self.run_params['beam_energy']
701 lb_number = self.run_params['lb_number']
702
703 log.info("Calling prepareForStart with run=%d, det_mask=0x%s, sor_time=%s",
704 run_number, det_mask, sor_time)
705
706 success = helper.prepareForStart(
707 run_number=run_number,
708 det_mask=det_mask,
709 sor_time=sor_time,
710 lb_number=lb_number,
711 beam_type=beam_type,
712 beam_energy=beam_energy,
713 solenoid_current=solenoid_current,
714 toroids_current=toroids_current
715 )
716 if not success:
717 log.error("prepareForStart failed")
718 raise RuntimeError("prepareForStart failed")
719 log.info("prepareForStart completed successfully")
720 except Exception as e:
721 log.error("Error calling prepareForStart: %s", e)
722 traceback.print_exc()
723 raise
724
725 # Start
726 sc = app.start()
727 if not sc.isSuccess():
728 log.error("Failed to start AppMgr")
729 return sc
730
731 # prepareForRun initializes COOL folder helper - must be called after start()
732 # which fires the start incident
733 try:
734 log.info("Calling prepareForRun to initialize COOL folder helper")
735 success = helper.prepareForRun()
736 if not success:
737 log.error("prepareForRun failed")
738 raise RuntimeError("prepareForRun failed")
739 log.info("prepareForRun completed successfully")
740 except Exception as e:
741 log.error("Error calling prepareForRun: %s", e)
742 traceback.print_exc()
743 raise
744
745 # hltUpdateAfterFork initializes the scheduler
746 # worker_id=1 for single-worker, non-forked mode
747 try:
748 log.info("Calling hltUpdateAfterFork to initialize scheduler (worker_id=1)")
749 success = helper.hltUpdateAfterFork(worker_id=1)
750 if not success:
751 log.error("hltUpdateAfterFork failed")
752 raise RuntimeError("hltUpdateAfterFork failed")
753 log.info("hltUpdateAfterFork completed successfully")
754 except Exception as e:
755 log.error("Error calling hltUpdateAfterFork: %s", e)
756 traceback.print_exc()
757 raise
758
759 # Run the event loop
760 # Note: Python signal handlers won't work during C++ execution.
761 nevt = maxEvents if maxEvents is not None else -1
762 sc = app.run(nevt)
763
764 if not sc.isSuccess():
765 log.error("Failure running application")
766 return sc
767
768 # Stop
769 sc = app.stop()
770 if not sc.isSuccess():
771 log.error("Failed to stop AppMgr")
772 return sc
773
774 # Finalize
775 sc = app.finalize()
776 if not sc.isSuccess():
777 log.error("Failed to finalize AppMgr")
778 return sc
779
780 # Terminate
781 sc = app.terminate()
782 return sc
783
784
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:132
int run(int argc, char *argv[])

Member Data Documentation

◆ _app

athenaEF.ConfigRunner._app = None
protected

Definition at line 602 of file athenaEF.py.

◆ db_server

athenaEF.ConfigRunner.db_server = db_server

Definition at line 599 of file athenaEF.py.

◆ job_options_path

athenaEF.ConfigRunner.job_options_path = job_options_path

Definition at line 596 of file athenaEF.py.

◆ job_options_type

athenaEF.ConfigRunner.job_options_type = job_options_type

Definition at line 595 of file athenaEF.py.

◆ overrides

athenaEF.ConfigRunner.overrides = overrides or RuntimeOverrides()

Definition at line 601 of file athenaEF.py.

◆ properties

athenaEF.ConfigRunner.properties = properties

Definition at line 598 of file athenaEF.py.

◆ run_params

athenaEF.ConfigRunner.run_params = run_params or {}

Definition at line 597 of file athenaEF.py.

◆ smk

athenaEF.ConfigRunner.smk = smk

Definition at line 600 of file athenaEF.py.


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