def checkDoPhotonIdentification(): """ Return true if it can doPhotonIdentification. Raise if it was expected to build electrons and it won't be possible. Return false if not asked to run electron identification.""" if caloRingerFlags.doPhotonIdentification(): if not caloRingerFlags.buildPhotonCaloRings(): if not ( inputAvailable(outputCaloRingsType(), outputPhotonCaloRingsKey()) or \ inputAvailable(outputCaloRingsType(), outputPhotonCaloAsymRingsKey()) ) or \ not ( inputAvailable(outputRingSetType(), outputPhotonRingSetsKey()) or \ inputAvailable(outputRingSetType(), outputPhotonAsymRingSetsKey()) ): mlog.warning(( "Requested to do Photon identification using " "Ringer discrimination, but one or more of the Ringer needed " "discrimination inputs are not available. We will request to " "build PhotonCaloRings using default configuration.")) # In this case, the input file does not have CaloRings, we need to build them: caloRingerFlags.buildPhotonCaloRings = True if not checkBuildPhotonCaloRings(): mlog.error( ("Couldn't add PhotonCaloRings reconstruction to " "joboptions.")) raise RuntimeError( "Can't add PhotonCaloRings to reconstruction.") else: mlog.verbose("All Photon identification discrimination input " "available in the file.") else: mlog.verbose( ("It will be used the PhotonCaloRings build within this " "reconstruction to make the classification.")) return True else: return False
def getPhotonCaloRingsBuilder(): "Return the photon CaloRings builder " if caloRingerFlags.buildPhotonCaloRings(): from CaloRingerTools.CaloRingerBuilderFactories import PhotonCaloRingsBuilder, \ PhotonCaloAsymRingsBuilder if caloRingerFlags.useAsymBuilder(): return PhotonCaloAsymRingsBuilder() else: return PhotonCaloRingsBuilder() else: return PublicToolHandle('')
def getCaloRingerInputReaderTools(): """ Returns a list with the CaloRinger tools to get the input objects to be decorated and pass them to their CaloRingerTools""" inputReaders = [] try: if checkBuildElectronCaloRings() or checkDoElectronIdentification(): from CaloRingerTools.CaloRingerInputReaderFactories \ import CaloRingerElectronsReaderTool inputReaders.append(CaloRingerElectronsReaderTool()) mlog.verbose("Added Ringer Electrons reader successfully.") except Exception: if caloRingerFlags.buildElectronCaloRings(): mlog.error(("It won't be possible to build ElectronCaloRings!" " Switching it off!")) caloRingerFlags.buildElectronCaloRings = False if caloRingerFlags.doElectronIdentification(): mlog.error(("It won't be possible to do Electron identification!" " Switching it off!")) caloRingerFlags.doElectronIdentification = False treatException("Could not set up Ringer Electrons reader!") try: if checkBuildPhotonCaloRings() or checkDoPhotonIdentification(): from CaloRingerTools.CaloRingerInputReaderFactories \ import CaloRingerPhotonsReaderTool inputReaders.append(CaloRingerPhotonsReaderTool()) mlog.verbose("Added Ringer Photon reader successfully.") except Exception: if caloRingerFlags.buildPhotonCaloRings(): mlog.error(("It won't be possible to build PhotonCaloRings!" " Switching it off!")) caloRingerFlags.buildPhotonCaloRings = False if caloRingerFlags.doPhotonIdentification(): mlog.error( ("It won't be possible to build do Photon identification!" " Switching it off!")) caloRingerFlags.doPhotonIdentification = False treatException("Could not set up CaloRingerAlgorithm for Photons!") return inputReaders
def checkBuildPhotonCaloRings(): """ Return true if it can build CaloRings for Photons. Raise if it was expected to build electrons and it won't be possible. Return false if not asked to build.""" if caloRingerFlags.buildPhotonCaloRings(): if not rec.doESD(): mlog.info( "Turning off ringer algorithm photon reconstruction since not doing ESD." ) caloRingerFlags.buildPhotonCaloRings = False return False if not inputAvailable(inputPhotonType(), inputPhotonKey()): # Deadtivate photon calo rings if egamma calo seeded is off: if not jobproperties.egammaRecFlags.doEgammaCaloSeeded(): mlog.warning(( "Requested to build PhotonCaloRings but egamma" " calo seeded is off. Deactivating buildPhotonCaloRings.")) caloRingerFlags.buildPhotonCaloRings = False #caloRingerFlags.doPhotonIdentification = False return False else: mlog.verbose( ("Input not available in the file. No problem: it will " " be reconstructed")) else: if jobproperties.egammaRecFlags.doEgammaCaloSeeded(): mlog.verbose( ("There already exists the egamma objects in file, but" " they will be updated during reconstruction to new ones." )) else: mlog.verbose(("Ringer will use the egamma objects available " "in the file to build its patterns.")) return True else: mlog.verbose("It wasn't requested to build Photon CaloRings.") return False
def checkBuildPhotonCaloRings(): """ Return true if it can build CaloRings for Photons. Raise if it was expected to build electrons and it won't be possible. Return false if not asked to build.""" if caloRingerFlags.buildPhotonCaloRings(): if not inputAvailable(inputPhotonType(), inputPhotonKey()): # Try to force egammaBuilder startup if it is not already started: if not egammaBuilderAvailable(): mlog.warning(( "Requested to build PhotonCaloRings but egamma" " builder was not available. Deactivating buildPhotonCaloRings." )) #if rec.doEgamma(): #__enableEgamma() #else: caloRingerFlags.buildPhotonCaloRings = False #caloRingerFlags.doPhotonIdentification = False return False else: mlog.verbose( ("Input not available in the file. No problem: it will " " be reconstructed")) else: if egammaBuilderAvailable(): mlog.verbose( ("There already exists the egamma objects in file, but" " they will be updated during reconstruction to new ones." )) else: mlog.verbose(("Ringer will use the egamma objects available " "in the file to build its patterns.")) return True else: mlog.verbose("It wasn't requested to build Photon CaloRings.") return False
ringerOutputLevel = caloRingerFlags.OutputLevel() # Check if we have our other algorithm dependencies enabled, otherwise disable # ringer: if caloRingerFlags.buildCaloRingsOn(): # Check egamma related objects: if not rec.doEgamma(): if caloRingerFlags.buildElectronCaloRings(): caloRingerFlags.buildElectronCaloRings.set_Value(False) caloRingerFlags.doElectronIdentification.set_Value(False) if not caloRingerFlags.buildElectronCaloRings(): mlog.info( 'No egamma builder available... disabling ElectronCaloRings reconstruction and electron selection.' ) if caloRingerFlags.buildPhotonCaloRings(): caloRingerFlags.buildPhotonCaloRings.set_Value(False) #caloRingerFlags.doPhotonIdentification.set_Value( False ) if not caloRingerFlags.buildPhotonCaloRings(): mlog.info( 'No egamma builder available... disabling PhotonCaloRings reconstruction and electron selection.' ) # To build CaloRings it is required to have doESD flag set to on. if not rec.doESD() and caloRingerFlags.buildCaloRingsOn(): caloRingerFlags.buildCaloRingsOn.set_Value(False) caloRingerFlags.doIdentificationOn.set_Value(False) if not caloRingerFlags.buildCaloRingsOn(): mlog.info('Job will not build CaloRings as we are not doing ESD.') if not caloRingerFlags.doIdentificationOn(): mlog.info('Job will not run Ringer selectors as we are not doing ESD.')
def configure(self): "This method will be called when object is initialized" mlog = logging.getLogger( 'CaloRingerAlgorithmBuilder::configure:%s:' \ % self.__class__.__name__.replace( ".", '_' ) ) mlog.info('entering') try: # Instantiate the main algorithm: MainCaloRingerAlgorithm = AlgFactory( CaloRingerAlgsConf.Ringer__CaloRingerAlgorithm, name="MainCaloRingerAlgorithm", inputReaderTools=FcnWrapper(getCaloRingerInputReaderTools)) self._caloRingerAlg = MainCaloRingerAlgorithm() if caloRingerFlags.buildCaloRingsOn(): # Egamma locker not being used anymore. #postponeEgammaLock(self._caloRingerAlg) pass # Check if CaloRingerAlgorithm has readers: if not self._caloRingerAlg.inputReaderTools: raise RuntimeError(("Cannot instantiate CaloRingerAlgorithm " "without readers.")) if caloRingerFlags.buildCaloRingsOn(): self._eventOutputs = { outputCaloRingsType() : \ getCaloRingerOutputs(self._caloRingerAlg.inputReaderTools,addRingSetsContainers=False), \ outputRingSetType() : \ getCaloRingerOutputs(self._caloRingerAlg.inputReaderTools,addCaloRingsContainers=False) \ } self._output.update(self._eventOutputs) # Check for existing output: self.checkExistingOutput() if not self.ignoreExistingDataObject() \ and ( ( caloRingerFlags.buildElectronCaloRings() and \ ( inputAvailable(outputCaloRingsType(), outputElectronCaloRingsKey()) or \ inputAvailable(outputCaloRingsType(), outputElectronCaloAsymRingsKey()) ) or \ ( inputAvailable(outputRingSetType(), outputElectronRingSetsKey()) or \ inputAvailable(outputRingSetType(), outputElectronAsymRingSetsKey()) ) ) \ or ( caloRingerFlags.buildPhotonCaloRings() and \ ( inputAvailable(outputCaloRingsType(), outputPhotonCaloRingsKey()) or \ inputAvailable(outputCaloRingsType(), outputPhotonCaloAsymRingsKey()) ) or \ ( inputAvailable(outputRingSetType(), outputPhotonRingSetsKey()) or \ inputAvailable(outputRingSetType(), outputPhotonAsymRingSetsKey()) ) ) ): raise RuntimeError(( "Already existing input will be overwriten and not set Ringer flag " "ignoreExistingDataObject.")) except Exception: removeFromTopSequence(self._caloRingerAlg) caloRingerFlags.Enabled = False self._disabled = True treatException(("Could not get handle to CaloRingerAlgorithm." " Reason:\n%s") % traceback.format_exc()) return False return True
): LastCRWriter = CRMetaDataBuilder.getLastWriterHandle() CRMainAlg = CRAlgBuilder.getCaloRingerAlgHandle() CRMetaDataWriterAlg = CRMetaDataBuilder.getMetaDataWriterHandle() try: # FIXME: It seems that the python implementation takes a lot of memory # (https://its.cern.ch/jira/browse/ATLASRECTS-2769?filter=-1), # replace it as egamma is doing to use a C++ implementation pass # Make sure we add it before streams: for pos, alg in enumerate(topSequence): if LastCRWriter.getName() == alg.getName(): from CaloRingerAlgs.CaloRingerLocker import CaloRingerLocker CRLocker = CaloRingerLocker(name = "CaloRingerLocker", \ doElectron = caloRingerFlags.buildElectronCaloRings(), \ doPhoton = caloRingerFlags.buildPhotonCaloRings(), \ EvtStoreName = CRMainAlg.EvtStore.getName(), \ MetaDataStoreName = CRMetaDataWriterAlg.MetaDataStore.getName(), \ CaloRingerDict = CRAlgBuilder.eventOutputs(), \ CaloRingerMetaDict = CRMetaDataBuilder.metaDataOutputs() \ ) topSequence.insert(pos + 1, CRLocker) mlog.verbose( "Successfully added CaloRingerLocker to TopSequence.") break else: treatException("Could not find CaloRingerDecorator algorithm.") except Exception, e: treatException( "Could not set up CaloRingerLocker. Switched off ! Reason:\n %s" % traceback.format_exc())