def getCaloRingerPhotonSelectorsBuilder(): "Return the Photon Selectors" #if caloRingerFlags.doPhotonIdentification: # from CaloRingerTools.CaloRingerSelectorsBuilders import CaloRingerPhotonSelectorsBuilder # return CaloRingerPhotonSelectorBuilder().getAllSelectorHandles() #else: return PublicToolHandleArray([])
def getCaloRingerElectronSelectorsBuilder(): "Return the Electron Selectors" if caloRingerFlags.doElectronIdentification(): from CaloRingerTools.CaloRingerSelectorsBuilders import CaloRingerElectronSelectorsBuilder return CaloRingerElectronSelectorsBuilder().getAllSelectorHandles() else: return PublicToolHandleArray([])
def getCaloRingerBuilders(inputReaders): """ Returns a list with the __CaloRingerElectronsReader container names. """ inputReadersTools = transformGaudiToReaders(inputReaders) builders = PublicToolHandleArray() builders += [reader.crBuilder for reader in inputReadersTools \ if reader.crBuilder.getType() in ("Ringer::CaloRingsBuilder", \ "Ringer::CaloAsymRingsBuilder")] mlog.verbose("Found the following builders: [%s] ", \ ', '.join(map(str,[builder.getName() for builder in builders])) ) return builders
def getSelectors(inputReaders): """ Returns a list with the __CaloRingerElectronsReader container names. """ inputReaderTools = transformGaudiToReaders(inputReaders) selectors = PublicToolHandleArray() for reader in inputReaderTools: try: selectors += [selector for selector in reader.ElectronSelectors \ if selector.getType() == "Ringer::AsgElectronRingerSelector"] except AttributeError: pass try: selectors += [selector for selector in reader.PhotonSelectors \ if selector.getType() == "Ringer::AsgPhotonRingerSelector"] except AttributeError: pass return selectors
def getRingerSelectorHandles(self): "Return our holden CaloRinger builder handles" return getSelectors(self._caloRingerAlg.inputReaderTools) if self._caloRingerAlg \ else PublicToolHandleArray([])
def getInputReadersHandles(self): "Return our holden CaloRinger builder handles" return self._caloRingerAlg.inputReaderTools if self._caloRingerAlg \ else PublicToolHandleArray([])
def setDefaultProperty(cls, propertyName, value): # choose according to expected type try: prop = cls._properties[propertyName] except KeyError: raise AttributeError("%s does not have property %s" % (cls.__name__, propertyName)) errorAllowedTypes = None cxxdefault = prop.default if type(cxxdefault) == type(value): cls._userDefaults[propertyName] = copy.copy(value) elif isinstance(cxxdefault, PublicToolHandle): if value is None: cls._userDefaults[propertyName] = PublicToolHandle("") elif type(value) == str: cls._userDefaults[propertyName] = PublicToolHandle(value) elif isinstance(value, ConfigurableAlgTool): cls._userDefaults[propertyName] = PublicToolHandle( value.getFullName()) elif isinstance(value, PublicToolHandle): cls._userDefaults[propertyName] = copy.copy(value) else: errorAllowedTypes = "str,PublicToolHandle,ConfigurableAlgTool" elif isinstance(cxxdefault, PublicToolHandleArray): if value is None: cls._userDefaults[propertyName] = PublicToolHandleArray() elif type(value) == list: cls._userDefaults[propertyName] = PublicToolHandleArray(value) elif isinstance(value, PublicToolHandleArray): cls._userDefaults[propertyName] = copy.copy(value) else: errorAllowedTypes = "list,PublicToolHandleArray" elif isinstance(cxxdefault, PrivateToolHandle): if value is None: cls._userDefaults[propertyName] = PrivateToolHandle("") elif type(value) == str: cls._userDefaults[propertyName] = PrivateToolHandle(value) elif isinstance(value, ConfigurableAlgTool): cls._userDefaults[propertyName] = copy.deepcopy(value) elif isinstance(value, PrivateToolHandle): cls._userDefaults[propertyName] = copy.copy(value) else: errorAllowedTypes = "str,PrivateToolHandle,ConfigurableAlgTool" elif isinstance(cxxdefault, PrivateToolHandleArray): if value is None: cls._userDefaults[propertyName] = PrivateToolHandleArray() elif type(value) == list: cls._userDefaults[propertyName] = PrivateToolHandleArray(value) elif isinstance(value, PrivateToolHandleArray): cls._userDefaults[propertyName] = copy.copy(value) else: errorAllowedTypes = "list,PrivateToolHandleArray" elif isinstance(cxxdefault, ServiceHandle): if value is None: cls._userDefaults[propertyName] = ServiceHandle("") elif type(value) == str: cls._userDefaults[propertyName] = ServiceHandle(value) elif isinstance(value, ConfigurableService): cls._userDefaults[propertyName] = ServiceHandle( value.getFullName()) elif isinstance(value, ServiceHandle): cls._userDefaults[propertyName] = copy.copy(value) else: errorAllowedTypes = "str,ServiceHandle,ConfigurableService" else: cls._userDefaults[propertyName] = value if errorAllowedTypes: raise TypeError( "Setting default property %s.%s with wrong type. Expected %s got %s" % (cls.__name__, propertyName, errorAllowedTypes, type(value).__name__))
class CaloRingerElectronSelectorsBuilder ( Configured ): _looseSelector = GaudiHandle('') _mediumSelector = GaudiHandle('') _tightSelector = GaudiHandle('') _customSelectors = PublicToolHandleArray() _allSelectors = PublicToolHandleArray() def getLooseSelectorHandle(self): "Return the CaloRinger main algorithm handle." return self._looseSelector def getMediumSelectorHandle(self): "Return the CaloRinger MetaData configuration writer algorithm handle." return self._mediumSelector def getTightSelectorHandle(self): "Return the CaloRinger MetaData configuration writer algorithm handle." return self._tightSelector def getCustomSelectorHandles(self): "Return custom selector handles." return self._customSelectors def getAllSelectorHandles(self): "Return all CaloRinger algorithm to write into StoreGate Services." return self._allSelectors def getAllSelectorNames(self): "Return all selector names" selectors = self._allSelectors return [selector.getName() for selector in selectors] def addCustomElectronSelectors(self, customElectronSelectors): """Add custom electron selector to reconstruction. It will work only if it is added before the CaloRingerAlgorithmBuilder is instatiated, otherwise it will only add to its configuration the default tool handles added during this configuration tool default setup. It will only be successful if it is passed a electron selector tool handle.""" try: if not isinstance(customElectronSelectors,(list)): customElectronSelectors = list(customElectronSelectors) for selector in customElectronSelectors: if not selector.getType() is "Ringer::AsgElectronRingerSelector": raise ValueError(("Selector must be of type Ringer::AsgElectronRingerSelector" "and is of type %s"),selector.getType()) self._customSelectors.extend( customElectronSelectors ) self._allSelectors.extend( customElectronSelectors ) from AthenaCommon.AppMgr import ToolSvc ToolSvc += customElectronSelectors except Exception: mlog.error("Could not add custom electron selector. Reason: \n%s", traceback.format_exc()) def configure(self): "This routine will be called when object is initialized" conflog = logging.getLogger( 'CaloRingerSelectorsBuilders::configure:%s:' \ % self.__class__.__name__.replace( ".", '_' ) ) conflog.info('entering') try: menu = caloRingerFlags.electronMenuToUse() from RingerSelectorTools.ConfiguredAsgElectronRingerSelector \ import ConfiguredAsgElectronRingerSelector from AthenaCommon.AppMgr import ToolSvc #try: self._looseSelector = ConfiguredAsgElectronRingerSelector(Ringer.Loose, menu) # Adding it into ToolSvc makes it a PublicTool: ToolSvc += self._looseSelector self._allSelectors.append(self._looseSelector) #except Exception: # conflog.error(("Could not set up Ringer Loose electron " # "selector. Reason:\n%s"),traceback.format_exc()) #try: self._mediumSelector = ConfiguredAsgElectronRingerSelector(Ringer.Medium, menu) ToolSvc += self._mediumSelector self._allSelectors.append(self._mediumSelector) #except Exception: # traceback.print_exc() # conflog.error(("Could not set up Ringer Medium electron " # "selector. Reason:\n%s"),traceback.format_exc()) #try: self._tightSelector = ConfiguredAsgElectronRingerSelector(Ringer.Tight, menu) ToolSvc += self._tightSelector self._allSelectors.append(self._tightSelector) #except Exception: # traceback.print_exc() # conflog.error(("Could not set up Ringer Tight electron " # "selector. Reason:\n%s"),traceback.format_exc()) mlog.info (self._allSelectors) except Exception: for selector in self._allSelectors: removeFromToolSvc(selector) caloRingerFlags.doElectronIdentification = False treatException(("An unexpected error occurred. Due to it, all " "Ringer electron selectors won't be executed.")) traceback.print_exc() return False return True