def finalize_THistSvc():
    # Hack to finalize and get rid of the THistSvc (actually TrigMonTHistSvc)
    from AthenaCommon.AppMgr import ServiceMgr as svcMgr
    from AthenaCommon.AppMgr import theApp
    if theApp.state():  # if we still didn't finalize
        logging.debug("Finalizing THistSvc")
        svcMgr.THistSvc.getHandle().finalize()
        theApp.getHandle()._svcmgr.removeService('THistSvc')
Example #2
0
 def checkAppState(self):
     from AthenaCommon.AppMgr import theApp, AthAppMgr
     if theApp.state() > AthAppMgr.State.CONFIGURED:
         self.log.fatal(
             'Attempt to add a User Action when athena is already initialized. Check you configuration'
         )
         return False
     return True
def enable_seeking(silent=False):
    """ try to install seek-stuff on the EventSelector side.
   if `silent` is True, only an attempt at installing the seeking is performed.
   otherwise an exception is raised if the seeking could not be installed.
   """

    import sys
    from AthenaCommon.Logging import log as msg
    if not sys.modules.has_key('AthenaPoolCnvSvc.ReadAthenaPool'):
        if silent:
            _msg = msg.debug
        else:
            _msg = msg.info
        # user did not import that module so we give up
        _msg("Cannot enable 'seeking' b/c module "
             "[AthenaPoolCnvSvc.ReadAthenaPool] hasn't been imported...")
        _msg( "Modify your jobOptions to import that module "+ \
              "(or just ignore this message)" )

        if not silent:
            raise RuntimeError("configuration-logic error")

        return

    from AthenaCommon.AppMgr import ServiceMgr as svcMgr
    from AthenaCommon.Configurable import Configurable
    collectionType = svcMgr.EventSelector.properties()["CollectionType"]

    if collectionType in (
            "ImplicitROOT",
            Configurable.propertyNoValue,
    ):
        svcMgr.EventSelector.CollectionType = "SeekableROOT"
        msg.info("=> Seeking enabled.")

    elif collectionType in ("SeekableROOT", ):
        msg.verbose("=> Seeking already enabled.")

    else:
        msg.warning(
            "Input seeking is not compatible with collection type of %s",
            svcMgr.EventSelector.properties()["CollectionType"])
        msg.warning("=> Seeking disabled.")
        if not silent:
            raise RuntimeError("could not install seeking")

    from AthenaCommon.AppMgr import theApp
    if theApp.state() != theApp.State.OFFLINE:
        # do not bring up the whole C++ kaboodle too early in the game
        svcMgr.EventSelector.setup()
    return
Example #4
0
def addAction(actionTool, roles, systemAction=False):
    """
    Add an action tool to the list for a requested role.

    This should only be used in very special cases, by experts. Normally, you
    should use the getter for one of the specialized UASvc versions listed
    above to add an action. If systemAction=True, the action is prepended to
    the list. Otherwise, it is appended.
    """

    from AthenaCommon.AppMgr import theApp, AthAppMgr, ServiceMgr

    roleMap={'Run': 'RunActionTools',
             'Event': 'EventActionTools',
             'Tracking': 'TrackingActionTools',
             'Step': 'SteppingActionTools',
             'Stack': 'StackingActionTools'}

    ##hack to allow for different named Configurations of the UserActionSvc
    basename='UserActionSvc'
    serviceName=''
    for s in ServiceMgr.getAllChildren():
        if basename in s.getName():
            serviceName = s.getName()
            break
    if ''==serviceName:
        Logging.logging.getLogger('G4UASvc').error('addAction: Could not find ' + basename + ' instance in ServiceMgr!')
        raise AttributeError('addAction: Could not find ' + basename + ' instance in ServiceMgr!')
    else:
        Logging.logging.getLogger('G4UASvc').info('addAction: Found a ' + basename + ' instance called ' + serviceName)
    from AthenaCommon.CfgGetter import getService
    theSvc=getService(serviceName)

    if theApp.state() > AthAppMgr.State.CONFIGURED:
        Logging.logging.getLogger('G4UASvc').fatal('Attempt to add a User Action when athena is ' +
                                                   'already initialized. Check your configuration')
        return

    for role in roles:
        roleAttr = roleMap[role]
        if not role in roleMap.keys():
            Logging.logging.getLogger('G4UASvc').fatal('Unkown role '+role+' requested for action ')
        else:
            currentActionList = getattr(theSvc, roleAttr)
            if not actionTool in currentActionList:
                # Add to beginning of list if system, otherwise the end
                if systemAction:
                    setattr(theSvc, roleAttr, [actionTool] + currentActionList)
                else:
                    setattr(theSvc, roleAttr, currentActionList + [actionTool])
def enable_seeking(silent=False):
   """ try to install seek-stuff on the EventSelector side.
   if `silent` is True, only an attempt at installing the seeking is performed.
   otherwise an exception is raised if the seeking could not be installed.
   """

   import sys
   from AthenaCommon.Logging import log as msg
   if not sys.modules.has_key( 'AthenaPoolCnvSvc.ReadAthenaPool' ):
      if silent:
         _msg = msg.debug
      else:
         _msg = msg.info
      # user did not import that module so we give up
      _msg( "Cannot enable 'seeking' b/c module "
            "[AthenaPoolCnvSvc.ReadAthenaPool] hasn't been imported..." )
      _msg( "Modify your jobOptions to import that module "+ \
            "(or just ignore this message)" )

      if not silent:
         raise RuntimeError("configuration-logic error")
      
      return

   from AthenaCommon.AppMgr import ServiceMgr as svcMgr
   from AthenaCommon.Configurable import Configurable
   collectionType = svcMgr.EventSelector.properties()["CollectionType"]

   if collectionType in ( "ImplicitROOT", Configurable.propertyNoValue, ):
      svcMgr.EventSelector.CollectionType = "SeekableROOT"
      msg.info   ( "=> Seeking enabled." )

   elif collectionType in ( "SeekableROOT", ):
      msg.verbose( "=> Seeking already enabled." )

   else:
      msg.warning( "Input seeking is not compatible with collection type of %s",
                   svcMgr.EventSelector.properties()["CollectionType"] )
      msg.warning( "=> Seeking disabled." )
      if not silent:
         raise RuntimeError("could not install seeking")
      
   from AthenaCommon.AppMgr import theApp
   if theApp.state() != theApp.State.OFFLINE:
      # do not bring up the whole C++ kaboodle too early in the game
      svcMgr.EventSelector.setup()
   return
Example #6
0
def setupEvtSelForSeekOps():
    """ try to install seek-stuff on the EventSelector side """
    #import sys
    #from AthenaCommon.Logging import log as msg
    msg.debug("setupEvtSelForSeekOps:")
    if sys.modules.has_key('AthenaRootComps.ReadAthenaRoot'):
        # athenarootcomps has seeking enabled by default
        msg.info('=> Seeking enabled.')
        return

    if not sys.modules.has_key('AthenaPoolCnvSvc.ReadAthenaPool'):
        ## user did not import that module so we give up
        msg.info( "Cannot enable 'seeking' b/c module " + \
                   "[AthenaPoolCnvSvc.ReadAthenaPool] hasn't been imported..." )
        msg.info( "Modify your jobOptions to import that module "+ \
                   "(or just ignore this message)" )
        return

    from AthenaCommon.AppMgr import theApp, AthAppMgr
    if theApp.state() != AthAppMgr.State.OFFLINE:
        msg.info( "C++ ApplicationMgr already instantiated, probably seeking "+\
                  "will be ill-configured..." )
        msg.info("EventSelector writers should implement updateHandlers")

    from AthenaCommon.AppMgr import ServiceMgr as svcMgr
    from AthenaCommon.Configurable import Configurable
    collectionType = svcMgr.EventSelector.properties()["CollectionType"]

    if collectionType in (
            "ImplicitROOT",
            Configurable.propertyNoValue,
    ):
        svcMgr.EventSelector.CollectionType = "SeekableROOT"
        msg.info("=> Seeking enabled.")

    elif collectionType in ("SeekableROOT", ):
        msg.verbose("=> Seeking already enabled.")

    else:
        msg.warning(
            "Input seeking is not compatible with collection type of %s",
            svcMgr.EventSelector.properties()["CollectionType"])
        msg.warning("=> Seeking disabled.")
    return
Example #7
0
def dumpMasterSequence():
    """
    Helper function to display on screen the current master sequencer layout
    """
    # if the application manager has already been setup()'d we just have to
    # dump the AthMasterSeq as all the work has been done for us
    from AthenaCommon.AppMgr import theApp, AthAppMgr
    app_state = theApp.state()
    if app_state != AthAppMgr.State.OFFLINE:
        return dumpSequence(AthSequencer("AthMasterSeq"))

    # otherwise, manually do it...
    dumpSequence(AthSequencer("AthMasterSeq"), indent=0)
    dumpSequence(AthSequencer("athAlgEvtSeq"), indent=1)
    dumpSequence(AthSequencer("athBeginSeq"), indent=2)
    dumpSequence(AlgSequence("athAllAlgSeq"), indent=2)
    dumpSequence(AthSequencer("athCondSeq"), indent=3)
    dumpSequence(AthSequencer("athAlgSeq"), indent=3)
    dumpSequence(AthSequencer("athEndSeq"), indent=2)
    dumpSequence(AthSequencer("athOutSeq"), indent=1)
    dumpSequence(AthSequencer("athRegSeq"), indent=1)
Example #8
0
def setupEvtSelForSeekOps():
   """ try to install seek-stuff on the EventSelector side """
   #import sys
   #from AthenaCommon.Logging import log as msg
   msg.debug("setupEvtSelForSeekOps:")
   if sys.modules.has_key('AthenaRootComps.ReadAthenaRoot'):
       # athenarootcomps has seeking enabled by default
       msg.info('=> Seeking enabled.')
       return
   
   if not sys.modules.has_key('AthenaPoolCnvSvc.ReadAthenaPool'):
      ## user did not import that module so we give up
      msg.info( "Cannot enable 'seeking' b/c module " + \
                 "[AthenaPoolCnvSvc.ReadAthenaPool] hasn't been imported..." )
      msg.info( "Modify your jobOptions to import that module "+ \
                 "(or just ignore this message)" )
      return

   from AthenaCommon.AppMgr import theApp, AthAppMgr
   if theApp.state() != AthAppMgr.State.OFFLINE:
      msg.info( "C++ ApplicationMgr already instantiated, probably seeking "+\
                "will be ill-configured..." )
      msg.info( "EventSelector writers should implement updateHandlers" )
   
   from AthenaCommon.AppMgr import ServiceMgr as svcMgr
   from AthenaCommon.Configurable import Configurable
   collectionType = svcMgr.EventSelector.properties()["CollectionType"]

   if collectionType in ( "ImplicitROOT", Configurable.propertyNoValue, ):
      svcMgr.EventSelector.CollectionType = "SeekableROOT"
      msg.info   ( "=> Seeking enabled." )

   elif collectionType in ( "SeekableROOT", ):
      msg.verbose( "=> Seeking already enabled." )

   else:
      msg.warning( "Input seeking is not compatible with collection type of %s",
                   svcMgr.EventSelector.properties()["CollectionType"] )
      msg.warning( "=> Seeking disabled." )
   return