def loadJobOptionsCatalogue( cfg_fname ): """Load properties from a pickle file, previously dumped by storeConfiguration, back into the JobOptionsSvc. """ # read jobopt catalogue dump and pycomps back in cfg = open( cfg_fname, 'rb' ) jocat = pickle.load( cfg ) jocfg = pickle.load( cfg ) pycomps = pickle.load( cfg ) cfg.close() kw = jocfg[ 'ApplicationMgr' ] from AppMgr import theApp theApp.JobOptionsSvcType = kw[ 'JobOptionsSvcType' ] theApp.MessageSvcType = kw[ 'MessageSvcType' ] handle = theApp.getHandle( kw ) del jocfg[ 'ApplicationMgr' ] # no longer want to call setup(), since there are no Configurables to # setup; it would be a no-op, already, but __build_master_sequence is # broken, so make sure this can't be run ... def noop( self ): pass theApp.__class__.setup = noop import AthenaPython.PyAthena as PyAthena josvc = PyAthena.py_svc( 'JobOptionsSvc', createIf = False, iface = 'IJobOptionsSvc' ) # restore job catalogue entries import GaudiPython.Bindings as gaudi for client in jocat: for n,v in jocat[ client ].iteritems(): p = gaudi.StringProperty( n, v ) if not josvc.addPropertyToCatalogue( client, p ).isSuccess(): raise RuntimeError( 'could not add property [%s.%s = %s]' % (client, n, v) ) # restore special services properties for client in jocfg: svc = PyAthena.py_svc( client, createIf = False, iface='IProperty' ) for n,v in jocfg[ client ].iteritems(): p = gaudi.StringProperty( n, v ) svc.setProperty( p ) # pycomps hack-around if pycomps: import AthenaPython.Configurables as _C _C.PyComponents.instances = dict( (p.name, p) for p in pycomps ) for p in pycomps: if hasattr( p, 'setup' ): if callable( p.setup ): p.setup()
def initialize(self): _info = self.msg.info _info("==> initialize...") self.hsvc = PyAthena.py_svc('THistSvc/THistSvc') if not self.hsvc: self.msg.error('Could not retrieve THistSvc') return StatusCode.Failure def print_properties(h): _info(' -%-20s: %i <mean>=%8.3f rms=%8.3f', h.GetName(), h.GetEntries(), h.GetMean(), h.GetRMS()) # load histos from stream and print some of their properties o = self.hsvc.load('/read1/xxx/gauss1d', oid_type='hist') print_properties(o) o = self.hsvc.load('/read2/gauss2d', oid_type='hist') print_properties(o) o = self.hsvc.load('/read2/gauss3d', oid_type='hist') print_properties(o) o = self.hsvc.load('/read2/profile', oid_type='hist') print_properties(o) ## FIXME: 'THistSvc::getTrees' (always) segfaults ## https://savannah.cern.ch/bugs/index.php?36379 try: o = self.hsvc.load('/read2/trees/stuff/tree1', oid_type='tree') _info(' -%-20s: %i', o.GetName(), o.GetEntries()) except KeyError,err: self.msg.error(err) self.msg.error('bug #36379 still not fixed...')
def initialize(self): self.msg.info( "Initializing %s...", self.name() ) self.sg = PyAthena.py_svc("StoreGateSvc") if not self.sg: self.msg.error ("could not retrieve event store") return StatusCode.Failure return StatusCode.Success
def initialize(self): self.msg.info( "Initializing %s", self.name() ) self.sg = PyAthena.py_svc ("StoreGateSvc") if not self.sg: self.msg.error ("could not retrieve event store") return StatusCode.Failure #PyROOTFixes.fix_dv_container( "SgTests::PayLoadDv" ) return StatusCode.Success
def initialize(self): self.sg = PyAthena.py_svc("StoreGateSvc") self.msg.info( "==> initializing [%s]...", self.name() ) self.msg.info( "eta: %r",self.eta ) self.msg.info( "pt: %r",self.pt ) self.msg.info( "px: %r",self.px ) self.mytool.counter += 1 self.msg.info( "tool:%r %r",self.mytool.counter, self.mytool.name() ) return StatusCode.Success
def initialize(self): log.info("Initialize AOD2A4") #self.stvf_algo = make_METRefAlg(_suffix='_STVF') self.sg = PyAthena.py_svc("StoreGateSvc") self.sum_mc_event_weights = 0.0 self.number_events = 0 self.init() return PyAthena.StatusCode.Success
def initialize(self): _info = self.msg.info _info('==> initialize...') # the ugly intertwined part: get some properties from # the AresEventSelector from AthenaCommon.AppMgr import ServiceMgr as svcMgr _evtSel = svcMgr.EventSelector self.inputFiles = _evtSel.InputCollections[:] self.persTreeName = _evtSel.TupleName ## self.dhTreeName = _evtSel.DhTreeName ## self.dhBranchName = _evtSel.DhBranchName ## self.branchNames = _evtSel.BranchNames or dict() ## del _evtSel _info('reading files: %r', self.inputFiles) # try to load the ttree speed-ups try: from RootUtils.PyROOTFixes import enable_tree_speedups enable_tree_speedups() except ImportError: _info('could NOT install the ttree speedups...') pass import ROOT, PyCintex; # load an ARA chain (and fool checkreq) Ara = __import__ ('AthenaROOTAccess').transientTree TChainROOTAccess = ROOT.AthenaROOTAccess.TChainROOTAccess self.__ara_chain = TChainROOTAccess(self.persTreeName) for f in self.inputFiles: self.msg.debug('adding [%r]', f) self.__ara_chain.Add (f) _info('loading ara...') self.ara_tree = Ara.makeTree(self.__ara_chain, persTreeName=self.persTreeName, dhTreeName=self.dhTreeName, dhBranchName=self.dhBranchName, branchNames=self.branchNames) assert isinstance(self.ara_tree, ROOT.TTree),\ "problem while creating transient tree w/ ara" self.nTotEntries = self.ara_tree.GetEntriesFast() _info('#entries: %i', self.nTotEntries) self.hsvc = PyAthena.py_svc('THistSvc') if not self.hsvc: self.msg.error('could not retrieve THistSvc') return StatusCode.Failure ares_tree_name = self.__ares_tree_name%self.persTreeName _info('registering transient tree with ITHistSvc: [%s]', ares_tree_name) self.hsvc[ares_tree_name]=self.ara_tree return StatusCode.Success
def initialize(self): self.msg.info("initializing [%s]", self.name()) self.storeGateSvc = PyAthena.py_svc('StoreGateSvc') if self.storeGateSvc is None: self.msg.error("Problem retrieving storegate !!") return PyAthena.StatusCode.Failure self.tool = PyAthena.py_tool('EGammaAmbiguityTool', iface='IEGammaAmbiguityTool') if not self.tool: self.msg.error("Problem retrieving EgammaAmbiguityTool !!") return PyAthena.StatusCode.Failure return StatusCode.Success
def initialize(self): self.msg.info ('retrieving the coredump svc...') self._svc = PyAthena.py_svc('CoreDumpSvc', iface='IService') if self._svc is None: self.msg.error ('could not retrieve the coredump svc') return StatusCode.Failure import signal import os self.msg.info('sending SIGBUS to pid [%s]...', os.getpid()) os.kill(os.getpid(), signal.SIGBUS) return StatusCode.Success
def initialize(self): # register with the incident svc svc = PyAthena.py_svc('IncidentSvc', iface='IIncidentSvc') if not svc: self.msg.error('unable to get the incident svc') return StatusCode.Failure for incident in ('EndEvent', 'BeginInputFile',): svc.addListener(self, incident) pass return StatusCode.Success
def initialize(self): self.thSvc = PyAthena.py_svc('THistSvc', iface='ITHistSvc') if not self.thSvc: self.msg.error("Could not retrieve THistSvc !") return StatusCode.Failure self.tree = self.thSvc.get('/temp/TTreeStream/egamma', klass='TTree') if not self.tree: self.msg.error('could not retrieve tree from THistSvc') return StatusCode.Failure return StatusCode.Success
def initialize(self): self.msg.info("initializing...") self.sg = PyAthena.py_svc('StoreGateSvc') if not self.sg: self.msg.error("Could not retrieve StoreGateSvc !") return StatusCode.Failure _info = self.msg.info _info("Configuration:") _info(" - ints: [%s]", self.intsName) _info(" - uints: [%s]", self.uintsName) _info(" - floats: [%s]", self.floatsName) _info(" - doubles: [%s]", self.doublesName) self._test_matrix = { 'std::vector<int>' : self.intsName, 'std::vector<unsigned int>' : self.uintsName, 'std::vector<float>' : self.floatsName, 'std::vector<double>' : self.doublesName, } return StatusCode.Success
def initialize(self): # Check the validitly of self.cutDict if len(self.cutDict["pTCuts"])!=self.nObj: self.msg.fatal("Lengths of pTCuts and types are different!!") return StatusCode.Failure if len(self.cutDict["qualityCuts"])!=self.nObj: self.msg.fatal("Lengths of qualityCuts and types are different!!") return StatusCode.Failure if len(self.cutDict["collections"])!=self.nObj: self.msg.fatal("Lengths of collections and types are different!!") return StatusCode.Failure ## Get the StoreGate service self.storeGateSvc = PyAthena.py_svc('StoreGateSvc') if self.storeGateSvc is None: self.msg.fatal("Problem retrieving StoreGateSvc pointer !!") return StatusCode.Failure # AthElectronLikelihoodTool_VeryLoose self.electronLikelihoodTool_VeryLoose = PyAthena.py_tool('AthElectronLikelihoodTool/AthElectronLikelihoodTool_VeryLoose') if self.electronLikelihoodTool_VeryLoose is None: self.msg.error("Problem retrieving AthElectronLikelihoodTool/AthElectronLikelihoodTool_VeryLoose pointer !!") return StatusCode.Recoverable self.msg.info("AthElectronLikelihoodTool/AthElectronLikelihoodTool_VeryLoose retrieved.") # AthElectronLikelihoodTool_Loose self.electronLikelihoodTool_Loose = PyAthena.py_tool('AthElectronLikelihoodTool/AthElectronLikelihoodTool_Loose') if self.electronLikelihoodTool_Loose is None: self.msg.error("Problem retrieving AthElectronLikelihoodTool/AthElectronLikelihoodTool_Loose pointer !!") return StatusCode.Recoverable self.msg.info("AthElectronLikelihoodTool/AthElectronLikelihoodTool_Loose retrieved.") # AthElectronLikelihoodTool_Medium self.electronLikelihoodTool_Medium = PyAthena.py_tool('AthElectronLikelihoodTool/AthElectronLikelihoodTool_Medium') if self.electronLikelihoodTool_Medium is None: self.msg.error("Problem retrieving AthElectronLikelihoodTool/AthElectronLikelihoodTool_Medium pointer !!") return StatusCode.Recoverable self.msg.info("AthElectronLikelihoodTool/AthElectronLikelihoodTool_Medium retrieved.") return StatusCode.Success
def initialize(self): _info = self.msg.info _info('==> initialize...') self.hsvc = PyAthena.py_svc('THistSvc/THistSvc') if not self.hsvc: self.msg.error('could not retrieve THistSvc/THistSvc') return StatusCode.Failure from ROOT import TH1F, TH2F, TH3F, TProfile, TTree # helpers def th1(n,t): return TH1F(n,t,100,0.,100.) def th2(n,t): return TH2F(n,t,100,-50.,50.,100,-50.,50.) def th3(n,t): return TH3F(n,t,100,-50.,50.,100,-50.,50.,100,-50.,50.) def tp (n,t): return TProfile(n,t,100,-50.,50.) # temporary trees self.hsvc['/temp/h1'] = th1('h1', 'Temporary hist 1') self.hsvc['/temp/other/h1a'] = th1('h1a', 'Temporary hist 1a') # write to stream 'new' self.hsvc['/new/hists/h1'] = th1('h1', 'Persistent hist 1') # update to stream 'upd', dir '/xxx' self.hsvc['/upd/xxx/gauss1d'] = TH1F('gauss1d', '1D gaussian', 100,-50.,50.) # recreate stuff in '/' self.hsvc['/rec/gauss2d'] = th2('gauss2d','2D gaussian') self.hsvc['/rec/gauss3d'] = th3('gauss3d','3D gaussian') self.hsvc['/rec/prof'] = tp ('profile','profile') # tree with branches in '/trees/stuff' self.hsvc['/rec/trees/stuff/tree1'] = TTree('tree1','tree title') self._n = -1 return StatusCode.Success
def detStore(self): import AthenaPython.PyAthena as PyAthena return PyAthena.py_svc('StoreGateSvc/DetectorStore')
def initialize(self): print 'LBFilter: Found %i LBs to accept: ' % len(self.lbList), self.lbList if not self.lbList: print 'LBFilter: WARNING: Empty lbList - will accept all events' self.sg = PyAthena.py_svc('StoreGateSvc') return StatusCode.Success
def _evtSize(self): """ retrieve a handle to the ICollectionSize interface of the event loop mgr """ import AthenaPython.PyAthena as PyAthena return PyAthena.py_svc(self.EventLoop, iface='ICollectionSize')
def initialize(self): self.msg.info( '************************************' ) self.msg.info( '==> initialize %s...', self.name() ) self.msg.info( 'Will apply the following electron cuts:' ) self.msg.info( ' EtMinEl = %r', self.cutEtMinEl ) self.msg.info( ' IsEmEl = %s', self.cutIsEM ) self.msg.info( ' AuthorEl = %s', self.cutElAuthor ) self.msg.info( ' ElEtaMax = %r', self.cutElEtaMax ) self.msg.info( ' removeEtaCrack = %r', self.removeEtaCrack ) self.msg.info( ' crackEtaMin = %r', self.crackEtaMin ) self.msg.info( ' crackEtaMax = %r', self.crackEtaMax ) self.msg.info( ' minNumberPassedEl = %r', self.minNumberPassedEl ) self.msg.info( ' passAllEl = %r', self.passAllEl ) self.msg.info( 'And the following muon cuts:' ) self.msg.info( ' PtMinMu = %r', self.cutPtMinMu ) self.msg.info( ' AuthorMu = %s', self.muonAuthors ) self.msg.info( ' MuEtaMax = %r', self.cutMuEtaMax ) if self.doEtconeMu: self.msg.info( ' muon etcone cut = %r', self.etconeMuMax ) self.msg.info( ' passAllMu = %r', self.passAllMu ) self.msg.info( ' minNumberPassedMu = %r', self.minNumberPassedMu ) self.msg.info( '************************************' ) ## Also, declare some counters and initialize them to zero self.nProcessed = 0 self.nEventMinNumPassed = 0 self.nElectrons = 0 self.nEventElPassEta = 0 self.nEventElPassEt = 0 self.nEventElPassIsEM = 0 self.nEventElPassAuthor = 0 self.nMuons = 0 self.nEventMuPassEta = 0 self.nEventMuPassPt = 0 self.nEventMuPassAuthor = 0 self.nEventMuPassPrescale = 0 self.nEventMuPassIsolation = 0 ## Import needed modules import PyUtils.RootUtils as ru ROOT = ru.import_root() if self.doNoTrackIsolMu or self.doPtTrackIsolMu or self.doCaloIsolMu : if self.muonIsolationTool is None: self.msg.warning("Problem retrieving MuonIsolationTool pointer ") self.msg.warning("setting Track and Calo isolation to False ") self.doNoTrackIsolMu = False self.doPtTrackIsolMu = False self.doCaloIsolMu = False ## import some 4-mom utils import FourMomUtils.Bindings self.utils = { 'deltaR' : PyAthena.P4Helpers.deltaR } _append = self.muContainerNames.append if self.usingAOD : if self.muonContainers.__contains__('staco') or self.muonContainers is 'all': _append("StacoMuonCollection") if self.muonContainers.__contains__('muid') or self.muonContainers is 'all': _append("MuidMuonCollection") if self.muonContainers.__contains__('calo') or self.muonContainers is 'all': _append("CaloMuonCollection") else : if self.muonContainers.__contains__('staco') or self.muonContainers is 'all': _append("StacoESDMuonCollection") if self.muonAuthors is 'combined' or self.muonAuthors is 'all' : _append("StacoCombinedMuonContainer") if self.muonAuthors is 'lowpt' or self.muonAuthors is 'all' : _append("StacoCombinedMuonContainerLowPt") if self.muonAuthors is 'standalone' or self.muonAuthors is 'all': _append("MboyESDMuonContainer") if self.muonContainers.__contains__('muid') or self.muonContainers is 'all': _append("MuidESDMuonCollection") if self.muonAuthors is 'combined' or self.muonAuthors is 'all' : _append("MuidCombinedMuonContainer") if self.muonAuthors is 'lowpt' or self.muonAuthors is 'all' : _append("MuGirlCombinedMuonContainer") if self.muonAuthors is 'standalone' or self.muonAuthors is 'all' : _append("MuidExtrMuonContainer") if self.muonContainers.__contains__('calo') or self.muonContainers is 'all': if self.muonAuthors is 'calo' or self.muonAuthors is 'all' : _append("CaloMuonIdContainer") _append("CaloESDMuonCollection") del _append ## Get the StoreGate service self.storeGateSvc = PyAthena.py_svc('StoreGateSvc') if self.storeGateSvc is None: self.msg.error("Problem retrieving StoreGateSvc pointer !!") return StatusCode.Failure return StatusCode.Success
def detStore(self): if not self._pyath_detstore: import AthenaPython.PyAthena as PyAthena self._pyath_detstore = PyAthena.py_svc('StoreGateSvc/DetectorStore') return self._pyath_detstore
except ImportError: from gaudimodule import iProperty return getattr(iProperty("StoreGateSvc", self), attr) def __setattr__(self, attr, value): try: from GaudiPython.Bindings import iProperty except ImportError: from gaudimodule import iProperty return setattr(iProperty("StoreGateSvc", self), attr, value) StoreGateSvc.__getattr__ = __getattr__ StoreGateSvc.__setattr__ = __setattr__ import AthenaPython.PyAthena as PyAthena StoreGateSvc._pyclidsvc = PyAthena.py_svc('ClassIDSvc') def keys(self, clid=None, allKeys=False): """return the list of keys for a given CLID (int, type or class_name) if clid is None, it will return the list of all keys. When 'allKeys' is True it will also return the key aliases. """ if isinstance(clid, str): clid = self._pyclidsvc.clid(clid) if isinstance(clid, type): clid = self._pyclidsvc.clid(clid.__name__) if clid is None: return [p.name() for p in self.proxies()] return list(self._cpp_keys(clid, allKeys)) StoreGateSvc._cpp_keys = StoreGateSvc.keys
def store_configuration(cfg_fname=None): """helper function to inspect the 'configured' JobOptionsSvc and dump the properties of each component into a (sqlite) shelve. it will eventually dump the properties of py-components too. """ jobo_cfg = defaultdict(dict) if cfg_fname is None: import tempfile tmpfile = tempfile.NamedTemporaryFile(suffix='-jobo.pkl') cfg_fname = tmpfile.name tmpfile.close() import os if os.path.exists(cfg_fname): os.remove(cfg_fname) assert cfg_fname from AthenaCommon.AppMgr import theApp def _fill_cfg(client, props): for p in props: n = p[0] v = p[1] if hasattr(v, 'toStringProperty'): v = str(v.toStringProperty().toString()) elif hasattr(v, 'toString'): v = str(v.toString()) else: v = str(v) jobo_cfg[client][n] = v from AthenaCommon.AppMgr import ServiceMgr as svcMgr # special cases: joboptionsvc and messagesvc def _fill_props(svcname): if not hasattr(svcMgr, svcname): return svc = getattr(svcMgr, svcname) props = [] for k,v in svc.properties().iteritems(): if v == svc.propertyNoValue: v = svc.getDefaultProperty(k) props.append((k,v)) _fill_cfg(svcname, props) _fill_props('JobOptionsSvc') _fill_props('MessageSvc') # tickle C++ and configure the whole app theApp.setup() app_props = [(k,v.value()) for k,v in theApp.getHandle().properties().iteritems()] _fill_cfg(theApp.name(), app_props) import AthenaPython.PyAthena as PyAthena josvc = PyAthena.py_svc('JobOptionsSvc', iface='IJobOptionsSvc') assert josvc is not None clients = list(josvc.getClients()) for client in clients: props = josvc.getProperties(client) for prop in props: n = prop.name() v = prop.toString() jobo_cfg[client][n] = v cfg = dbs.open(cfg_fname, 'w') cfg['jobopts'] = jobo_cfg pycomps = [] import sys from .AppMgr import ServiceMgr as svcMgr # all other pycomps from .Configurable import Configurable as C for c in C.allConfigurables.itervalues(): if not isinstance(c, (PyAthena.Alg, PyAthena.AlgTool, PyAthena.Svc, PyAthena.Aud)): continue # FIXME: should check if the component is still 'active' # ie: is it in one of the TopAlg,SvcMgr,ToolSvc and children ? if hasattr(c, 'msg'): delattr(c, 'msg') pycomps.append(c) pass # folder for the pyathena-components cfg['pycomps'] = pycomps cfg.close() return cfg_fname
def cutFlowSvc(self): if not hasattr(self, '_cutflowsvc'): import AthenaPython.PyAthena as PyAthena self._cutflowsvc = PyAthena.py_svc('CutFlowSvc', iface='ICutFlowSvc') return self._cutflowsvc
def initialize(self): self.sg = PyAthena.py_svc("StoreGateSvc") self.msg.info( "==> initializing [%s]...", self.name() ) self.msg.info( "cnt: %r",self.counter ) return StatusCode.Success
) svcMgr.IOVDbSvc.Folders.append( '<db>COOLONL_TRIGGER/CONDBR2</db> /TRIGGER/L1Calo/V1/Calibration/PpmDeadChannels <tag>HEAD</tag>' ) svcMgr.IOVDbSvc.Folders.append( '<db>COOLONL_TRIGGER/CONDBR2</db> /TRIGGER/L1Calo/V2/Configuration/PprChanDefaults <tag>HEAD</tag>' ) svcMgr.IOVDbSvc.Folders.append( '<db>COOLONL_TRIGGER/CONDBR2</db> /TRIGGER/L1Calo/V1/Configuration/PprChanDefaults <tag>HEAD</tag>' ) svcMgr.IOVDbSvc.forceTimestamp = 1446047363 svcMgr.IOVDbSvc.forceRunNumber = 283851 from AthenaPython import PyAthena theApp.initialize() s = PyAthena.py_svc('L1CaloCondSvc', True, 'L1CaloCondSvc') theApp.nextEvent() # test L1CaloPprChanCalib (default, i.e. V2) c = cppyy.gbl.L1CaloPprChanCalibContainer() s.retrieve(c) chan = c.pprChanCalib(0x100000) assert chan.channelId() == 0x100000 assert chan.pedValue() == 33 assert chan.firCoeff1() == 2 assert chan.lutCpOffset() == 32400 assert chan.lutCpSlope() == 1138 # test L1CaloPprChanCalib (V1) c = cppyy.gbl.L1CaloPprChanCalibV1Container()
# allow the use of the pythonized properties interface def __getattr__( self, attr ): try: from GaudiPython.Bindings import iProperty except ImportError: from gaudimodule import iProperty return getattr( iProperty("StoreGateSvc", self), attr ) def __setattr__( self, attr, value ): try: from GaudiPython.Bindings import iProperty except ImportError: from gaudimodule import iProperty return setattr( iProperty("StoreGateSvc", self), attr, value ) StoreGateSvc.__getattr__ = __getattr__ StoreGateSvc.__setattr__ = __setattr__ import AthenaPython.PyAthena as PyAthena StoreGateSvc._pyclidsvc = PyAthena.py_svc('ClassIDSvc') def keys(self, clid=None, allKeys=False): """return the list of keys for a given CLID (int, type or class_name) if clid is None, it will return the list of all keys. When 'allKeys' is True it will also return the key aliases. """ if isinstance(clid, str): clid = self._pyclidsvc.clid(clid) if isinstance(clid, type): clid = self._pyclidsvc.clid(clid.__name__) if clid is None: return [p.name() for p in self.proxies()] return list(self._cpp_keys(clid, allKeys)) StoreGateSvc._cpp_keys = StoreGateSvc.keys StoreGateSvc.keys = keys
def _setup(): import cppyy # StoreGate bindings from dictionary cppyy.loadDictionary("libAthenaPythonDict") # for clidsvc cppyy.loadDictionary("libStoreGateBindingsDict") # for storegatesvc cppyy.loadDictionary("libStoreGateBindings" ) # not linked from libStoreGateBindingsDict in ROOT6 # make sure the global C++ namespace has been created gbl = cppyy.makeNamespace('') # noqa: F841 _ath = cppyy.makeNamespace('AthenaInternal') # ROOT6 workaround, kick the loading of headers _ath.ROOT6_AthenaPython_WorkAround_Dummy _ath.ROOT6_StoreGateBindings_WorkAround_Dummy # end workaround global py_retrieve py_retrieve = cppyy.gbl.AthenaInternal.retrieveObjectFromStore global py_record py_record = cppyy.gbl.AthenaInternal.recordObjectToStore global py_sg_contains py_sg_contains = cppyy.gbl.AthenaInternal.py_sg_contains global py_sg_getitem py_sg_getitem = cppyy.gbl.AthenaInternal.py_sg_getitem # retrieve the StoreGateSvc class global StoreGate, StoreGateSvc StoreGateSvc = cppyy.gbl.StoreGateSvc StoreGate = cppyy.gbl.StoreGate # add specialized retrieve method def retrieve(self, klass, key=None): ret = py_retrieve(self, klass, key) if ret and hasattr(ret, 'setStore') and not ret.hasStore(): if not hasattr(ret, 'trackIndices') or ret.trackIndices(): if py_sg_contains(self, 'SG::IConstAuxStore', key + 'Aux.'): aux = py_retrieve(self, 'SG::IConstAuxStore', key + 'Aux.') ret.setStore(aux) return ret StoreGateSvc.retrieve = retrieve # add specialized record method def record(self, obj, key, allowMods=True, resetOnly=True, noHist=False): return py_record(self, obj, key, allowMods, resetOnly, noHist) StoreGateSvc.record = record # add specialized contains method def contains(self, klass_or_clid, key): print("---- StoreGateSvc.contains() ", klass_or_clid, key) from builtins import int if isinstance(klass_or_clid, str): try: clid = int(klass_or_clid) klass = self._pyclidsvc.typename(clid) except ValueError: klass = str(klass_or_clid) pass elif isinstance(klass_or_clid, int): klass = self._pyclidsvc.typename(klass_or_clid) elif isinstance(klass_or_clid, type): klass = klass_or_clid.__name__ else: raise TypeError( 'argument 2 must be a typename, a clid or a type (got %r)' % type(klass_or_clid)) return py_sg_contains(self, klass, key) StoreGateSvc.contains = contains # dict-pythonization of storegate: __setitem__ def __setitem__(self, key, obj): return py_record(self, obj, key, True, True, False) StoreGateSvc.__setitem__ = __setitem__ # dict-pythonization of storegate: __getitem__ def __getitem__(self, key): try: ret = py_sg_getitem(self, key.encode()) except LookupError as err: raise KeyError(str(err)) if ret and hasattr(ret, 'setStore') and not ret.hasStore(): if not hasattr(ret, 'trackIndices') or ret.trackIndices(): if py_sg_contains(self, 'SG::IConstAuxStore', key + 'Aux.'): aux = py_retrieve(self, 'SG::IConstAuxStore', key + 'Aux.') ret.setStore(aux) return ret StoreGateSvc.__getitem__ = __getitem__ # dict-pythonization of storegate: __len__ def __len__(self): return len(self.keys()) StoreGateSvc.__len__ = __len__ # make dump print, rather than return string def dump(self, fd=None): if fd is None: import sys fd = sys.stdout print(self.__class__._dump(self), file=fd) StoreGateSvc._dump = StoreGateSvc.dump StoreGateSvc.dump = dump # allow the use of the pythonized properties interface def __getattr__(self, attr): try: from GaudiPython.Bindings import iProperty except ImportError: from gaudimodule import iProperty return getattr(iProperty("StoreGateSvc", self), attr) def __setattr__(self, attr, value): try: from GaudiPython.Bindings import iProperty except ImportError: from gaudimodule import iProperty return setattr(iProperty("StoreGateSvc", self), attr, value) StoreGateSvc.__getattr__ = __getattr__ StoreGateSvc.__setattr__ = __setattr__ import AthenaPython.PyAthena as PyAthena StoreGateSvc._pyclidsvc = PyAthena.py_svc('ClassIDSvc') def keys(self, clid=None, allKeys=False): """return the list of keys for a given CLID (int, type or class_name) if clid is None, it will return the list of all keys. When 'allKeys' is True it will also return the key aliases. """ if isinstance(clid, str): clid = self._pyclidsvc.clid(clid) if isinstance(clid, type): clid = self._pyclidsvc.clid(clid.__name__) if clid is None: return [p.name() for p in self.proxies()] return list(self._cpp_keys(clid, allKeys)) StoreGateSvc._cpp_keys = StoreGateSvc.keys StoreGateSvc.keys = keys return
def inputStore(self): import AthenaPython.PyAthena as PyAthena return PyAthena.py_svc('StoreGateSvc/InputMetaDataStore')
def evtStore(self): import AthenaPython.PyAthena as PyAthena return PyAthena.py_svc('StoreGateSvc/StoreGateSvc')
def configure(self, joboptions=None, commands=None, dllname=None, factname=None, extra_options=None): if not (self.app is None): self.msg.info('C++ application already configured') return self.app self.msg.info('configuring application...') usr_cfg = AthCfg() self.cfg.seek(0) usr_cfg << self.cfg.read() # reset self.cfg = AthCfg() if commands: self.cfg << commands+'\n' # common configuration self.cfg << """ # basic job configuration include('AthenaCommon/Atlas.UnixStandardJob.py') include.block('AthenaCommon/Atlas.UnixStandardJob.py') if not (not %(run_batch)s and theApp.EventLoop == 'PyAthenaEventLoopMgr'): # make SIG_INT fatal svcMgr.CoreDumpSvc.FatalHandler = -1 """ % {'run_batch' : self.options.run_batch} self.cfg << """ # user level configuration try: include('$HOME/.athenarc') except IncludeError: pass """ # another user level configuration usr_cfg.seek(0) self.cfg << usr_cfg.read() if isinstance(joboptions, (list,tuple)): for jobo_name in joboptions: self.cfg.include(jobo_name) if not self.options.run_batch: self.cfg << """ theApp.EventLoop = 'PyAthenaEventLoopMgr' svcMgr += CfgMgr.PyAthenaEventLoopMgr() """ self.cfg << """ ### logging and messages --------- from AthenaCommon.Logging import * _msg = log _msg.setLevel(getattr(logging, '%(output_level)s')) import AthenaCommon.Constants as Lvl theApp.setOutputLevel(%(output_level)s) theApp.OutputLevel = Lvl.%(output_level)s from AthenaCommon.AppMgr import ServiceMgr as svcMgr svcMgr.MessageSvc.OutputLevel = Lvl.%(output_level)s """ % dict(output_level=self.options.msg_lvl) self.cfg << """ from AthenaCommon.Include import Include, IncludeError, include include.setShowIncludes(%(showincludes)s) if %(showincludes)s: import AthenaCommon.Include as AthCIncMod AthCIncMod.marker=' -#-' # distinguish bootstrap from other jo-code """ % dict(showincludes=self.options.showincludes) cfg_name = self.cfg._jobo.name.replace('.py','.pkl') self.msg.info('dumping job-configuration into [%s]...', cfg_name) # run configuration in a forked-subprocess... sc = _app_configure(self.cfg, cfg_name, extra_options) if sc: err = 'could not configure application [sc=%d]' % sc self.msg.error(err) raise RuntimeError(err) self.msg.info('configuring application w/ [%s]', cfg_name) import os self.cfg._jobo.close() os.remove(self.cfg._jobo.name) import PyCintex PyCintex.Cintex.Enable() gbl = PyCintex.makeNamespace('') import GaudiPython.Bindings as gaudi # remove the gaudimodule exit handler as to prevent them from clobering import atexit for hdlr in reversed(atexit._exithandlers[:]): module_name = hdlr[0].__module__ if ('GaudiPython' in module_name or 'gaudimodule' in module_name): atexit._exithandlers.remove(hdlr) del hdlr # install our own exit handler (if needed) import sys if hasattr(sys, 'ps1'): # ie: is interactive atexit.register(self.exit) del atexit from . import ResourceLimits ResourceLimits.SetMaxLimits() try: import cPickle as pickle except ImportError: import pickle import PyUtils.dbsqlite as dbs db = dbs.open(cfg_name, 'r') jobo_cfg = db['jobopts'] kw = jobo_cfg['ApplicationMgr'] for k in ('Go', 'Exit', 'AuditInitialize', 'AuditFinalize'): if k in kw: del kw[k] outputlevel = jobo_cfg['ApplicationMgr']['OutputLevel'] self.app = gaudi.AppMgr(outputlevel=outputlevel, selfoptions=kw, dllname=dllname, factname=factname) # open the pycomps folder pycomps = db.get('pycomps', None) # just opening it should do if pycomps: import AthenaPython.Configurables as _C _C.PyComponents.instances = dict((p.name, p) for p in pycomps) #_C.PyComponents.instances = pycomps for p in pycomps: if hasattr(p, 'setup'): if callable(p.setup): p.setup() setattr(self, '_pycomps', pycomps) import AthenaPython.PyAthena as PyAthena josvc = PyAthena.py_svc('JobOptionsSvc', createIf=False, iface='IJobOptionsSvc') assert josvc is not None for client in jobo_cfg: if client == 'ApplicationMgr': continue for n,v in jobo_cfg[client].iteritems(): p = gaudi.StringProperty(n, v) if not josvc.addPropertyToCatalogue(client, p).isSuccess(): self.msg.error( 'could not add property [%s.%s = %s]', client, n, v ) if client in ('MessageSvc', 'JobOptionsSvc'): svc = PyAthena.py_svc(client, iface='IProperty') svc.setProperty(p) db.close() import os if os.path.exists(cfg_name): os.remove(cfg_name) pass #import AthenaCommon.Debugging as dbg #dbg.hookDebugger() return self.app
#Create instance of converter alg, configuring a property of it #Note that this procedure will hopefully be improved soon alg = ROOT.AthAnalysisHelper.createAlgorithm("xAODMaker::xAODTruthCnvAlg/myAlg") myalg = InterfaceCast('IProperty').cast(alg) myalg.setProperty( "AODContainerName" , "GEN_EVENT" ) alg.initialize() tool = ROOT.AthAnalysisHelper.createTool("DerivationFramework::TruthDressingTool/TruthDressing") #this is how to cast the tool in python so you have access to the addBranches method tool = InterfaceCast('DerivationFramework::IAugmentationTool').cast(tool) tool.initialize() #these next two lines are needed for now, #until python bindings for retrieve method of TEvent is working from AthenaPython import PyAthena sg = PyAthena.py_svc("StoreGateSvc") m_ll = [ ROOT.TH1D("m_ll","Dilepton mass",100,0,200) ]; m_ll += [ ROOT.TH1D("m_ll_dressed","Dressed Dilepton mass",100,0,200) ]; for i in range(0,evt.getEntries()): evt.getEntry(i) alg.execute() #converts HepMC into xAOD tool.addBranches() #decorates leptons with pt_dressed etc mc = sg['TruthParticles'] #retrieve objects via the sg storegate obj elplus = [[],[]] elminus = [[],[]] muplus = [[],[]] muminus = [[],[]] for p in mc: if p.status() != 1: continue
def evtStore(self): if not self._pyath_evtstore: import AthenaPython.PyAthena as PyAthena self._pyath_evtstore = PyAthena.py_svc('StoreGateSvc/StoreGateSvc') return self._pyath_evtstore
def condStore(self): if not self._pyath_condstore: import AthenaPython.PyAthena as PyAthena self._pyath_condstore = PyAthena.py_svc( 'StoreGateSvc/ConditionStore') return self._pyath_condstore
def initialize(self): self.evtstore = PyAthena.py_svc('StoreGateSvc') return StatusCode.Success
evLoopName = theApp.EventLoop.split('/')[-1] evLoop = getattr( svcMgr, evLoopName ) props = [] for k,v in evLoop.properties().iteritems(): if v != C.propertyNoValue: props.append( (k,v) ) _fillCfg( evLoopName, props ) except AttributeError, a: pass # no properties defined for EventLoop type # get the values for all other components (these may contain duplicates of # the ones above in cfgSvcs, and there may even be conflicts) import AthenaPython.PyAthena as PyAthena josvc = PyAthena.py_svc( 'JobOptionsSvc', iface = 'IJobOptionsSvc' ) clients = list( josvc.getClients() ) for client in clients: props = josvc.getProperties( client ) for prop in props: n = prop.name() v = prop.toString() jocat[ client ][ n ] = v # take care of some ancient history for k in ( 'Go', 'Exit' ): if k in jocfg[ 'ApplicationMgr' ]: del jocfg[ 'ApplicationMgr' ][k] # workaround for pycomps
def _evtSeek(self): """ retrieve a handle to the IEventSeek interface of the event loop mgr """ import AthenaPython.PyAthena as PyAthena return PyAthena.py_svc(self.EventLoop, iface='IEventSeek')
def initialize (self): self.sg = PyAthena.py_svc('StoreGateSvc') self.cs = PyAthena.py_svc('ClassIDSvc') return 1
def initialize(self): self.sg = PyAthena.py_svc('StoreGateSvc') return StatusCode.Success
def mon_push_back (sgname='StoreGateSvc'): """ Helper method to crawl through collections in a StoreGateSvc instance and assess how much memory they are wasting b/c they 'forgot' to reserve enough space before doing 'push_back'. This task is performed by just comparing what Klass::size() and Klass::capacity() are returning as a value. @param `sgname` the fully qualified Gaudi name of the StoreGateSvc instance @return a dictionary of { <sgkey> : (size, capacity, clid) } """ wasted = {} try: from AthenaPython import PyAthena except ImportError: # arf... release 13... return wasted sg = PyAthena.py_svc (sgname) cl = PyAthena.py_svc ('ClassIDSvc') # retrieve all containers from StoreGate proxies = sg.proxies() for dp in proxies: k = dp.name() # no double counting from symlinks # FIXME: it is actually valid to have 2 different collections # (=/= CLIDs) with the same key... if wasted.has_key(k): continue clid = dp.clID() klass = "%s" % cl.typename(clid) # 'handle' classes for which we were not able to fetch # a C++ typename from the SG::DataProxy classID (e.g. HistoryObjects) if klass == "None": continue try: data = sg.retrieve(klass, k) except Exception: # don't bother user: probably no Reflex dictionary... continue if not data: continue # reject objects we can't inspect or not interested in if not hasattr(data, 'size') or \ not hasattr(data, 'capacity'): continue sz = data.size() cp = data.capacity() rt = 0. if cp != 0.: rt = sz/float(cp)*100. # simple minded filter if rt==0. or rt>=90.: continue wasted[k] = (sz, cp, clid) pass return wasted
def tagStore(self): import AthenaPython.PyAthena as PyAthena return PyAthena.py_svc('StoreGateSvc/TagMetaDataStore')
def initialize(self): _info = self.msg.info _error = self.msg.error _info('==> initialize...') # check our properties and which modus operandi is active if self.evt_list is None and self.filter_fct is None: _error ('invalid properties: evt_list *and* filter_fct are None !') _error ('usage:\n%s', self.__doc__) return StatusCode.Failure if (not (self.evt_list is None)) and \ (not (self.filter_fct is None)): _error ('invalid properties: evt_list *and* filter_fct ' 'are not None !') _error ('usage:\n%s', self.__doc__) return StatusCode.Failure if not (self.filter_fct is None): # checking the filtering function is sound import inspect args = inspect.getargspec (self.filter_fct)[0] # FIXME: class' methods have the hidden 'self' argument... if len(args) != 2: _error ('filter_fct has NOT the expected signature') _error (' nbr of arguments: %i', len(args)) _error (' expected: 2') return StatusCode.Failure if not (self.filter_policy in ('reject', 'accept')): _error ('invalid value for filter_policy: %r', self.filter_policy) _error ("valid values are 'reject' or 'accept'") return StatusCode.Failure else: # transform the list of events into a set of pairs (run,evt) evt_list = self.evt_list[:] self.evt_list = set() for i in evt_list: if isinstance(i, tuple): irun, ievt = i else: irun, ievt = None, i self.evt_list.add ((irun, ievt)) _info ('EventInfo name: %s', self.evt_info if self.evt_info else '<any>') if self.evt_list: _info("filtering mode: evt_list") _info("filtering policy: %s", self.filter_policy) self.filter_policy = False if self.filter_policy == 'reject' else \ True else: _info ("filtering mode: filter_fct") self.sg = PyAthena.py_svc ('StoreGateSvc') if self.sg is None: _error ('could not retrieve event store') return StatusCode.Failure self._evt_cnt = 0 # total number of events processed self._evt_acc_cnt = 0 # total number of events accepted by the filter self._evt_rej_cnt = 0 # total number of events rejected by the filter return StatusCode.Success
if DbgStage.value == "fini": hookDebugger() except: # print a stack trace to know something bad happened ! import traceback, sys traceback.print_exc(file=sys.stdout) # update the exit-code import AthenaCommon.ExitCodes as ath_codes if theApp._exitstate == ath_codes.ALL_OK: theApp._exitstate = ath_codes.UNKNOWN_EXCEPTION # re-raise, in case somebody wants to do something about it raise finally: import AthenaCommon.ExitCodes as ath_codes if theApp._exitstate != ath_codes.ALL_OK: # trigger the AthenaSummarySvc try: from AthenaCommon.AppMgr import ServiceMgr as svcMgr if hasattr(svcMgr, 'AthenaSummarySvc'): from AthenaPython import PyAthena aths = PyAthena.py_svc('AthenaSummarySvc', iface='IAthenaSummarySvc') aths.setStatus(theApp._exitstate) aths.createSummary() except ImportError: print( "import of PyAthena failed: unable to trigger AthenaSummarySvc" ) theApp.exit() # exits program, yields theApp._exitstate on shell, # ok if re-thrown C++ exception: try to exit clean
def initialize(self): self.msg.info('==> initialize...') self.sg = PyAthena.py_svc('StoreGateSvc') return StatusCode.Success
def initialize(self): print 'ZFilter: accepting only primary vertices from',self.zMin,'to',self.zMax self.sg = PyAthena.py_svc('StoreGateSvc') return StatusCode.Success
def initialize(self): print "==> initializing ", self.name print "MinDigitADC: ", self.MinDigitADC print "MaxDeltaT: ", self.MaxDeltaT print "NtupleFileName: ", self.NtupleFileName print "TriggerLines: ", self.TriggerLines # self.sg = PyAthena.py_svc("StoreGateSvc") self.det = PyAthena.StoreGate.pointer("DetectorStore") self.LArOID = self.det.retrieve("LArOnlineID", "LArOnlineID") self.lcs = PyAthena.py_tool('LArCablingService') self.cdd = PyAthena.CaloDetDescrManager.instance() self.cid = self.cdd.getCaloCell_ID() self.tdt = PyAthena.py_tool('Trig::TrigDecisionTool/TrigDecisionTool') self.ntfile = TFile(self.NtupleFileName, "RECREATE") self.hectree = TTree("HECNoise", "HECNoise") self.iRun = array('i', [0]) self.iEvent = array('L', [0]) self.iEventCount = array('i', [0]) self.fPrescale = {} self.iTrigger = {} for tl in self.TriggerLines: self.fPrescale[tl] = array('f', [0.0]) self.iTrigger[tl] = array('i', [0]) pass self.iTime = array('i', [0]) self.iLB = array('i', [0]) self.iBCID = array('i', [0]) self.avgMu = array('f', [0.0]) self.actMu = array('f', [0.0]) self.iGain = array('i', [0]) self.iOID = array('L', [0]) self.iSide = array('i', [0]) self.iSamp = array('i', [0]) self.iReg = array('i', [0]) self.iEta = array('i', [0]) self.iPhi = array('i', [0]) self.iQuality = array('i', [0]) self.e = array('f', [0.0]) self.t = array('f', [0.0]) self.eta = array('f', [0.0]) self.phi = array('f', [0.0]) self.z = array('f', [0.0]) self.r = array('f', [0.0]) self.Ped = array('f', [0.0]) self.PedRMS = array('f', [0.0]) self.iDigi = array('i', 32 * [0]) self.iMax = array('i', [0]) self.iMin = array('i', [0]) # self.hectree.Branch("iRun", self.iRun, "iRun/I") self.hectree.Branch("iEvent", self.iEvent, "iEvent/I") self.hectree.Branch("iEventCount", self.iEventCount, "iEventCount/I") for tl in self.TriggerLines: self.hectree.Branch(tl + "_Prescale", self.fPrescale[tl], tl + "_Prescale/F") self.hectree.Branch(tl + "_Trigger", self.iTrigger[tl], tl + "_Trigger/I") pass self.hectree.Branch("iTime", self.iTime, "iTime/I") self.hectree.Branch("iLB", self.iLB, "iLB/I") self.hectree.Branch("iBCID", self.iBCID, "iBCID/I") self.hectree.Branch("avgMu", self.avgMu, "avgMu/F") self.hectree.Branch("actMu", self.actMu, "actMu/F") self.hectree.Branch("iGain", self.iGain, "iGain/I") self.hectree.Branch("iOID", self.iOID, "iOID/l") self.hectree.Branch("iSide", self.iSide, "iSide/I") self.hectree.Branch("iSamp", self.iSamp, "iSamp/I") self.hectree.Branch("iReg", self.iReg, "iReg/I") self.hectree.Branch("iEta", self.iEta, "iEta/I") self.hectree.Branch("iPhi", self.iPhi, "iPhi/I") self.hectree.Branch("iQuality", self.iQuality, "iQuality/I") self.hectree.Branch("e", self.e, "e/F") self.hectree.Branch("t", self.t, "t/F") self.hectree.Branch("eta", self.eta, "eta/F") self.hectree.Branch("phi", self.phi, "phi/F") self.hectree.Branch("z", self.z, "z/F") self.hectree.Branch("r", self.r, "r/F") self.hectree.Branch("Ped", self.Ped, "Ped/F") self.hectree.Branch("PedRMS", self.PedRMS, "PedRMS/F") self.hectree.Branch("iDigi", self.iDigi, "iDigi[32]/I") self.hectree.Branch("iMax", self.iMax, "iMax/I") self.hectree.Branch("iMin", self.iMin, "iMin/I") # return True
def initialize(self): print ('BCIDFilter: Found %i BCIDs to accept: ' % len(self.bcidList), self.bcidList) if not self.bcidList: print ('BCIDFilter: WARNING: Empty bcidList - will accept all events') self.sg = PyAthena.py_svc('StoreGateSvc') return StatusCode.Success
def initialize(self): self.msg.info("SkimDecisionsContainer name: '%s'"%self.SkimDecisionsContainerName) self.sg = PyAthena.py_svc("StoreGateSvc") return BookkeepingWriterBase.initialize(self)
def store_configuration(cfg_fname=None): """helper function to inspect the 'configured' JobOptionsSvc and dump the properties of each component into a (sqlite) shelve. it will eventually dump the properties of py-components too. """ jobo_cfg = defaultdict(dict) if cfg_fname is None: import tempfile tmpfile = tempfile.NamedTemporaryFile(suffix='-jobo.pkl') cfg_fname = tmpfile.name tmpfile.close() import os if os.path.exists(cfg_fname): os.remove(cfg_fname) assert cfg_fname from AthenaCommon.AppMgr import theApp def _fill_cfg(client, props): for p in props: n = p[0] v = p[1] if hasattr(v, 'toStringProperty'): v = str(v.toStringProperty().toString()) elif hasattr(v, 'toString'): v = str(v.toString()) else: v = str(v) jobo_cfg[client][n] = v from AthenaCommon.AppMgr import ServiceMgr as svcMgr # special cases: joboptionsvc and messagesvc def _fill_props(svcname): if not hasattr(svcMgr, svcname): return svc = getattr(svcMgr, svcname) props = [] for k, v in svc.properties().iteritems(): if v == svc.propertyNoValue: v = svc.getDefaultProperty(k) props.append((k, v)) _fill_cfg(svcname, props) _fill_props('JobOptionsSvc') _fill_props('MessageSvc') # tickle C++ and configure the whole app theApp.setup() app_props = [(k, v.value()) for k, v in theApp.getHandle().properties().iteritems()] _fill_cfg(theApp.name(), app_props) import AthenaPython.PyAthena as PyAthena josvc = PyAthena.py_svc('JobOptionsSvc', iface='IJobOptionsSvc') assert josvc is not None clients = list(josvc.getClients()) for client in clients: props = josvc.getProperties(client) for prop in props: n = prop.name() v = prop.toString() jobo_cfg[client][n] = v cfg = dbs.open(cfg_fname, 'w') cfg['jobopts'] = jobo_cfg pycomps = [] import sys from .AppMgr import ServiceMgr as svcMgr # all other pycomps from .Configurable import Configurable as C for c in C.allConfigurables.itervalues(): if not isinstance( c, (PyAthena.Alg, PyAthena.AlgTool, PyAthena.Svc, PyAthena.Aud)): continue # FIXME: should check if the component is still 'active' # ie: is it in one of the TopAlg,SvcMgr,ToolSvc and children ? if hasattr(c, 'msg'): delattr(c, 'msg') pycomps.append(c) pass # folder for the pyathena-components cfg['pycomps'] = pycomps cfg.close() return cfg_fname
def initialize(self): ## note that we are using the python logging service ## and that the PyAthena.Alg base class has already initialized ## it for us # ----------------------------------------------------------- # Store gate service self.msg.info('initializing [%s]...', self.name()) self.msg.debug('retrieve StoreGateSvc pointer...') self.sg = PyAthena.py_svc('StoreGateSvc') if self.sg is None: self.msg.error('Problem retrieving StoreGateSvc pointer !') return StatusCode.Failure else: self.msg.info('retrieved [%s]', self.sg.name()) # ----------------------------------------------------------- # Detector store service self.msg.debug('retrieve DetectorStoreSvc pointer...') self.det = PyAthena.py_svc('DetDescrCnvSvc') if self.det is None: self.msg.error('Problem retrieving DetectorStoreSvc pointer !') return StatusCode.Failure else: self.msg.info('retrieved [%s]', self.det.name()) # ----------------------------------------------------------- # Message service self.msg.info('initializing [%s]...', self.name()) self.msg.debug('retrieve MessageSvc pointer...') self.msgSvc = PyAthena.py_svc('MessageSvc') if self.msgSvc is None: self.msg.error('Problem retrieving MessageSvc pointer !') return StatusCode.Failure else: self.msg.info('retrieved [%s]', self.msgSvc.name()) # ----------------------------------------------------------- # get database service and open database self.msg.debug('retrieve database service...') self.dbSvc = cool.DatabaseSvcFactory.databaseService() # ----------------------------------------------------------- # Read local copy of condb => LarBadChannel folder # dbstring="sqlite://;schema=./myCondLArDB.db;dbname=CONDBR2" dbstring = "COOLONL_LAR/CONDBR2" try: self.db = self.dbSvc.openDatabase(dbstring, True) except Exception as e: print('Problem opening database', e) sys.exit(-1) print("Opened database", dbstring) # ----------------------------------------------------------- # Initialize onlineID from detector store self.msg.info('inlineID initialization...') from StoreGateBindings.Bindings import StoreGate detStore = StoreGate.pointer("DetectorStore") self.onlineID = detStore.retrieve("LArOnlineID", "LArOnlineID") # ----------------------------------------------------------- # Initialize LArCabling service self.larCablingSvc = PyAthena.py_tool("LArCablingService") if self.larCablingSvc is None: self.msg.error('Problem retrieving LArCablingService pointer !') return StatusCode.Failure else: self.msg.info('retrieved [%s]', self.larCablingSvc.name()) return StatusCode.Success
def configure(self, joboptions=None, commands=None, dllname=None, factname=None, extra_options=None): if not (self.app is None): self.msg.info('C++ application already configured') return self.app self.msg.info('configuring application...') usr_cfg = AthCfg() self.cfg.seek(0) usr_cfg << self.cfg.read() # reset self.cfg = AthCfg() if commands: self.cfg << commands + '\n' # common configuration self.cfg << """ # basic job configuration include('AthenaCommon/Atlas.UnixStandardJob.py') include.block('AthenaCommon/Atlas.UnixStandardJob.py') if not (not %(run_batch)s and theApp.EventLoop == 'PyAthenaEventLoopMgr'): # make SIG_INT fatal svcMgr.CoreDumpSvc.FatalHandler = -1 """ % { 'run_batch': self.options.run_batch } self.cfg << """ # user level configuration try: include('$HOME/.athenarc') except IncludeError: pass """ # another user level configuration usr_cfg.seek(0) self.cfg << usr_cfg.read() if isinstance(joboptions, (list, tuple)): for jobo_name in joboptions: self.cfg.include(jobo_name) if not self.options.run_batch: self.cfg << """ theApp.EventLoop = 'PyAthenaEventLoopMgr' svcMgr += CfgMgr.PyAthenaEventLoopMgr() """ self.cfg << """ ### logging and messages --------- from AthenaCommon.Logging import * _msg = log _msg.setLevel(getattr(logging, '%(output_level)s')) import AthenaCommon.Constants as Lvl theApp.setOutputLevel(%(output_level)s) theApp.OutputLevel = Lvl.%(output_level)s from AthenaCommon.AppMgr import ServiceMgr as svcMgr svcMgr.MessageSvc.OutputLevel = Lvl.%(output_level)s """ % dict(output_level=self.options.msg_lvl) self.cfg << """ from AthenaCommon.Include import Include, IncludeError, include include.setShowIncludes(%(showincludes)s) if %(showincludes)s: import AthenaCommon.Include as AthCIncMod AthCIncMod.marker=' -#-' # distinguish bootstrap from other jo-code """ % dict(showincludes=self.options.showincludes) cfg_name = self.cfg._jobo.name.replace('.py', '.pkl') self.msg.info('dumping job-configuration into [%s]...', cfg_name) # run configuration in a forked-subprocess... sc = _app_configure(self.cfg, cfg_name, extra_options) if sc: err = 'could not configure application [sc=%d]' % sc self.msg.error(err) raise RuntimeError(err) self.msg.info('configuring application w/ [%s]', cfg_name) import os self.cfg._jobo.close() os.remove(self.cfg._jobo.name) import PyCintex PyCintex.Cintex.Enable() gbl = PyCintex.makeNamespace('') import GaudiPython.Bindings as gaudi # remove the gaudimodule exit handler as to prevent them from clobering import atexit for hdlr in reversed(atexit._exithandlers[:]): module_name = hdlr[0].__module__ if ('GaudiPython' in module_name or 'gaudimodule' in module_name): atexit._exithandlers.remove(hdlr) del hdlr # install our own exit handler (if needed) import sys if hasattr(sys, 'ps1'): # ie: is interactive atexit.register(self.exit) del atexit from . import ResourceLimits ResourceLimits.SetMaxLimits() try: import cPickle as pickle except ImportError: import pickle import PyUtils.dbsqlite as dbs db = dbs.open(cfg_name, 'r') jobo_cfg = db['jobopts'] kw = jobo_cfg['ApplicationMgr'] for k in ('Go', 'Exit', 'AuditInitialize', 'AuditFinalize'): if k in kw: del kw[k] outputlevel = jobo_cfg['ApplicationMgr']['OutputLevel'] self.app = gaudi.AppMgr(outputlevel=outputlevel, selfoptions=kw, dllname=dllname, factname=factname) # open the pycomps folder pycomps = db.get('pycomps', None) # just opening it should do if pycomps: import AthenaPython.Configurables as _C _C.PyComponents.instances = dict((p.name, p) for p in pycomps) #_C.PyComponents.instances = pycomps for p in pycomps: if hasattr(p, 'setup'): if callable(p.setup): p.setup() setattr(self, '_pycomps', pycomps) import AthenaPython.PyAthena as PyAthena josvc = PyAthena.py_svc('JobOptionsSvc', createIf=False, iface='IJobOptionsSvc') assert josvc is not None for client in jobo_cfg: if client == 'ApplicationMgr': continue for n, v in jobo_cfg[client].iteritems(): p = gaudi.StringProperty(n, v) if not josvc.addPropertyToCatalogue(client, p).isSuccess(): self.msg.error('could not add property [%s.%s = %s]', client, n, v) if client in ('MessageSvc', 'JobOptionsSvc'): svc = PyAthena.py_svc(client, iface='IProperty') svc.setProperty(p) db.close() import os if os.path.exists(cfg_name): os.remove(cfg_name) pass #import AthenaCommon.Debugging as dbg #dbg.hookDebugger() return self.app
def detStore(self): if not self._pyath_detstore: import AthenaPython.PyAthena as PyAthena self._pyath_detstore = PyAthena.py_svc( 'StoreGateSvc/DetectorStore') return self._pyath_detstore