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_overrides=None)
 from_json (cls, json_file, run_params=None, properties=None, num_threads=1, num_slots=1, ef_overrides=None)
 from_database (cls, db_server, smk, l1psk=None, hltpsk=None, run_params=None, num_threads=1, num_slots=1, ef_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
 num_threads = num_threads
 num_slots = num_slots
 ef_overrides = ef_overrides 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 522 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_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)
   num_threads: Number of threads for AvalancheSchedulerSvc.ThreadPoolSize
   num_slots: Number of event slots for EventDataSvc.NSlots
   ef_overrides: EFInterfaceSvc properties overriding the DB/JSON configuration

Definition at line 530 of file athenaEF.py.

532 num_threads=1, num_slots=1, ef_overrides=None):
533 """
534 Args:
535 job_options_type: "FILE" or "DB"
536 job_options_path: JSON file path (for FILE) or DB connection string (for DB)
537 run_params: Run parameters dict for prepareForStart
538 properties: Pre-loaded properties dict (optional, for FILE mode)
539 db_server: DB server alias (for store() in DB mode)
540 smk: Super Master Key (for store() in DB mode)
541 num_threads: Number of threads for AvalancheSchedulerSvc.ThreadPoolSize
542 num_slots: Number of event slots for EventDataSvc.NSlots
543 ef_overrides: EFInterfaceSvc properties overriding the DB/JSON configuration
544 """
545 self.job_options_type = job_options_type
546 self.job_options_path = job_options_path
547 self.run_params = run_params or {}
548 self.properties = properties
549 self.db_server = db_server # For store() in DB mode
550 self.smk = smk # For store() in DB mode
551 self.num_threads = num_threads
552 self.num_slots = num_slots
553 self.ef_overrides = ef_overrides or {} # CLI overrides for EFInterfaceSvc
554 self._app = None
555

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_overrides = None )
Create runner for database (TYPE=DB)

Definition at line 564 of file athenaEF.py.

565 num_threads=1, num_slots=1, ef_overrides=None):
566 """Create runner for database (TYPE=DB)"""
567 # Build the DB connection string: server=X;smkey=Y;lvl1key=Z;hltkey=W
568 db_path = f"server={db_server};smkey={smk}"
569 if l1psk is not None:
570 db_path += f";lvl1key={l1psk}"
571 if hltpsk is not None:
572 db_path += f";hltkey={hltpsk}"
573 return cls("DB", db_path, run_params, db_server=db_server, smk=smk,
574 num_threads=num_threads, num_slots=num_slots, ef_overrides=ef_overrides)
575

◆ from_json()

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

Definition at line 557 of file athenaEF.py.

558 num_threads=1, num_slots=1, ef_overrides=None):
559 """Create runner for JSON file (TYPE=FILE)"""
560 return cls("FILE", os.path.abspath(json_file), run_params, properties,
561 num_threads=num_threads, num_slots=num_slots, ef_overrides=ef_overrides)
562

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

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

◆ db_server

athenaEF.ConfigRunner.db_server = db_server

Definition at line 549 of file athenaEF.py.

◆ ef_overrides

athenaEF.ConfigRunner.ef_overrides = ef_overrides or {}

Definition at line 553 of file athenaEF.py.

◆ job_options_path

athenaEF.ConfigRunner.job_options_path = job_options_path

Definition at line 546 of file athenaEF.py.

◆ job_options_type

athenaEF.ConfigRunner.job_options_type = job_options_type

Definition at line 545 of file athenaEF.py.

◆ num_slots

athenaEF.ConfigRunner.num_slots = num_slots

Definition at line 552 of file athenaEF.py.

◆ num_threads

athenaEF.ConfigRunner.num_threads = num_threads

Definition at line 551 of file athenaEF.py.

◆ properties

athenaEF.ConfigRunner.properties = properties

Definition at line 548 of file athenaEF.py.

◆ run_params

athenaEF.ConfigRunner.run_params = run_params or {}

Definition at line 547 of file athenaEF.py.

◆ smk

athenaEF.ConfigRunner.smk = smk

Definition at line 550 of file athenaEF.py.


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