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 578 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 585 of file athenaEF.py.

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

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

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

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

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

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

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

◆ db_server

athenaEF.ConfigRunner.db_server = db_server

Definition at line 601 of file athenaEF.py.

◆ job_options_path

athenaEF.ConfigRunner.job_options_path = job_options_path

Definition at line 598 of file athenaEF.py.

◆ job_options_type

athenaEF.ConfigRunner.job_options_type = job_options_type

Definition at line 597 of file athenaEF.py.

◆ overrides

athenaEF.ConfigRunner.overrides = overrides or RuntimeOverrides()

Definition at line 603 of file athenaEF.py.

◆ properties

athenaEF.ConfigRunner.properties = properties

Definition at line 600 of file athenaEF.py.

◆ run_params

athenaEF.ConfigRunner.run_params = run_params or {}

Definition at line 599 of file athenaEF.py.

◆ smk

athenaEF.ConfigRunner.smk = smk

Definition at line 602 of file athenaEF.py.


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