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
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
639 app.setProperty("MessageSvcType", "TrigMessageSvc")
640
641
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
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
657 app.configure()
658
659
660
661 if maxEvents is not None:
662 log.info("Setting EvtMax=%d (overriding DB value)", maxEvents)
663 app.setProperty('EvtMax', str(maxEvents))
664
665
666 self.overrides.apply()
667
668
669
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
678 sc = app.initialize()
679 if not sc.isSuccess():
680 log.error("Failed to initialize AppMgr")
681 return sc
682
683
684 try:
685 from TrigServices.TrigServicesHelper import 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
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
726 sc = app.start()
727 if not sc.isSuccess():
728 log.error("Failed to start AppMgr")
729 return sc
730
731
732
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
746
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
760
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
769 sc = app.stop()
770 if not sc.isSuccess():
771 log.error("Failed to stop AppMgr")
772 return sc
773
774
775 sc = app.finalize()
776 if not sc.isSuccess():
777 log.error("Failed to finalize AppMgr")
778 return sc
779
780
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?)
int run(int argc, char *argv[])