def loaddict(dict) : """ Load a LCG dictionary using various mechanisms""" if Helper.loadDynamicLib(dict) == 1 : return else : try: cppyy.loadDict(dict) except: raise ImportError, 'Error loading dictionary library'
def initialize(self): self.msg.info("Initializing %s", self.name) ## storegate self.sg = PyAthena.StoreGate.pointer("StoreGateSvc") # or: PyAthena.py_svc("StoreGateSvc",createIf=True) ## Datavector stuff import cppyy cppyy.loadDict("libAthExThinningEventDict") from RootUtils import PyROOTFixes # noqa: F401 return StatusCode.Success
def __init__(self): self.debug = True print "StreamerInfoGenerator v1.0.0" self.classlist = [] self.problemclasses = [] #MN: ROOT6 strips std:: from types, so we need to check the names self.blacklist = ['std::', 'vector<', 'map<', 'queue<', 'list<'] self.type = cppyy.gbl.RootType self.type.EnableCintex() cppyy.loadDict('libAtlasSTLAddReflexDict') #MN: switch off auto dict generation - god knows what that can mess up cppyy.gbl.gROOT.ProcessLine(".autodict")
def initialize(self): _info = self.msg.info _info("==> initializing [%s]...", self.name()) _info("Electrons: %r", self.electronsName) _info("Min Pt: %r GeV/c", self.eleMinPt / Units.GeV) _info("Max |eta|: %r", self.eleMaxEta) _info("PID cut: %r", self.elePidCut) _info("-" * 40) _info("Tracks: %r", self.tracksName) _info("Min Pt: %r GeV/c", self.trackMinPt / Units.GeV) _info("Max deltaR(track,ele): %r", self.maxDeltaRte) self.sg = PyAthena.py_svc('StoreGateSvc') if not self.sg: self.msg.error("Could not retrieve StoreGateSvc") return StatusCode.Failure self.thSvc = PyAthena.py_svc("ThinningSvc") if not self.thSvc: self.msg.error("Could not retrieve ThinningSvc") return StatusCode.Failure # get the C++ enum... # we have to explicitly load the dictionary holding the enum b/c # of a gccxml/reflex bug import cppyy egdict = cppyy.loadDict("egammaEventDict") self.elePidCut = getattr(PyAthena.egammaPID, self.elePidCut) # get some C++ utils import FourMomUtils.Bindings self.utils = {'deltaR': PyAthena.P4Helpers.deltaR} return StatusCode.Success
def load_Dict(cls, dict_name): """ Loads python dictionaries dict_name = name of the dictionary """ if dict_name and dict_name not in G4AtlasEngine.List_LoadedDict: try: cppyy.loadDict(dict_name) except: print "Unexpected error:", sys.exc_info(), '\n' print 'ROOT5 migration problem: ', dict_name try: G4AtlasEngine.List_LoadedDict.append(dict_name) G4AtlasEngine.log.debug(' G4AtlasEngine:load_Dict: %s loaded' % dict_name) except: raise RuntimeError('Dict %s can not be found' % dict_name)
def main(): import os #we don't use the 'from PathResolver import PathResolver' because that will force Gaudi ApplicationMgr to display #Until we have a way to 'silently' start the applicationmgr, we will do it the 'bad' way import cppyy cppyy.loadDict('libPathResolver') cppyy.loadDict('libPathResolverDict') FindCalibFile = cppyy.gbl.PathResolverFindCalibFile cppyy.gbl.PathResolverSetOutputLevel( 6) #suppress all possible warnings/errors notesFile = FindCalibFile( "dev/ReleaseNotes/%s/%s" % (os.environ['AtlasProject'], os.environ['AtlasVersion'])) if notesFile == "": return 0 #no notes to display with open(notesFile) as f: print(f.read())
from AthenaCommon.DetFlags import DetFlags DetFlags.detdescr.LAr_setOn() from AthenaCommon.AthenaCommonFlags import athenaCommonFlags athenaCommonFlags.isOnline.set_Value(True) import sys import string import ROOT import math import cppyy from AtlasGeoModel import SetGeometryVersion from AtlasGeoModel import GeoModelInit from AtlasGeoModel import SetupRecoGeometry include("CaloIdCnv/CaloIdCnv_joboptions.py") cppyy.loadDict("libxAODTrigL1CaloDict") from GeoModelSvc.GeoModelSvcConf import GeoModelSvc ServiceMgr += GeoModelSvc() theApp.CreateSvc += ["GeoModelSvc"] from AtlasGeoModel import LArGM from IOVDbSvc.IOVDbSvcConf import IOVDbSvc IOVDbSvc().GlobalTag = 'OFLCOND-RUN12-SDR-35' include('LArConditionsCommon/LArConditionsCommon_MC_jobOptions.py') include('LArConditionsCommon/LArIdMap_MC_jobOptions.py') from AthenaCommon.AlgSequence import AlgSequence topSequence = AlgSequence()
from future import standard_library standard_library.install_aliases() __doc__ = "To print the vmem usage before and after instantiating egammaMVACalib" def Vmem(): "Return the Vmem usage in kB" import os, subprocess cmd = "cat /proc/%d/status | grep VmSize | awk '{print($2)}'" % os.getpid() return int( subprocess.getoutput(cmd) ) # initial memUsage = [Vmem()] # import ROOT and load dictionary import ROOT, cppyy, numpy as np # noqa: F401 cppyy.loadDict('egammaMVACalibDict') memUsage.append( Vmem() ) # Electrons m = ROOT.egammaMVACalib(1, True, 'egammaMVACalib/online/v3') memUsage.append( Vmem() ) # Photons m = ROOT.egammaMVACalib(0, True, 'egammaMVACalib/online/v3') memUsage.append( Vmem() ) for i in memUsage: print (i/1e6 , 'GB')
def load(dict): res = Dictionary.loadDict(lib_prefix+dict) return res
import sys, time, platform import cppyy as Dictionary #Dictionary.gbl.Cintex.SetDebug(1) lib_prefix = '' if platform.system()=='Linux': lib_prefix = 'lib' Dictionary.loadDict(lib_prefix+'PVSS_STLDict') gbl = Dictionary.gbl std = gbl.std fifo = None partition = '' def setPartition(name): global partition partition = name def openFMC(fifo_name='/tmp/logPVSSConfig.fifo'): global fifo if fifo: fifo.close() fifo = open(fifo_name,'a') def closeFMC(): global fifo if fifo: fifo.close() fifo = None def makePrint(msg):
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration import AthenaPython.PyAthena as PyAthena from AthenaPython.PyAthena import StatusCode import cppyy import ROOT import math cppyy.loadDictionary('egammaEnumsDict') # Needed for egammaParameters from ROOT import egammaParameters from ROOT import egammaPID cppyy.loadDict("libTrkTrackSummaryDict") cppyy.loadDict('libegammaAnalysisUtilsDict') from ROOT import TLorentzVector def isLoosePP(electron): # https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/IsEMIdentification # 1.1 2012 data analyses with release 17.2 # 1. Standard Method # everything is OK for all the 2012 reprocessed data since the AODFix was used by default. return electron.passID(egammaPID.ElectronIDLoosePP) def isMediumPP(electron): # https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/IsEMIdentification if not electron.trackParticle(): return False if not electron.trackParticle().trackSummary(): return False eta = electron.cluster().etaBE(2)
def _pythonize_tfile(): import cppyy root = import_root() import PyUtils.Helpers as H with H.ShutUp(filters=[ re.compile( 'TClass::TClass:0: RuntimeWarning: no dictionary for.*'), re.compile( 'Warning in <TEnvRec::ChangeValue>: duplicate entry.*' ), ]): cppyy.loadDict("RootUtilsPyROOTDict") rootutils = getattr(root, "RootUtils") pybytes = getattr(rootutils, "PyBytes") # noqa: F841 #MN: lines below fail in ROOT6 if PCM from RootUtils is not found read_root_file = getattr(rootutils, "_pythonize_read_root_file") tell_root_file = getattr(rootutils, "_pythonize_tell_root_file") pass def read(self, size=-1): """read([size]) -> read at most size bytes, returned as a string. If the size argument is negative or omitted, read until EOF is reached. Notice that when in non-blocking mode, less data than what was requested may be returned, even if no size parameter was given. FIXME: probably doesn't follow python file-like conventions... """ SZ = 4096 # FIXME: Once we drop py2, we can simplify this by using a bytes # object directly instead of PyBytes. if size>=0: #size = _adjust_sz(size) #print ("-->0",self.tell(),size) c_buf = read_root_file(self, size) if c_buf and c_buf.sz: v = c_buf.buf if six.PY3: return bytes([ord(v[i]) for i in range(v.size())]) return ''.join([v[i] for i in range(v.size())]) return '' else: size = SZ out = [] while True: #size = _adjust_sz(size) c_buf = read_root_file(self, size) if c_buf and c_buf.sz: v = c_buf.buf if six.PY3: chunk = bytes([ord(v[i]) for i in range(v.size())]) else: chunk = ''.join([v[i] for i in range(v.size())]) out.append(chunk) else: break if six.PY3: return b''.join(out) return ''.join(out) root.TFile.read = read del read root.TFile.seek = root.TFile.Seek root.TFile.tell = lambda self: tell_root_file(self) ## import os ## def tell(self): ## fd = os.dup(self.GetFd()) ## return os.fdopen(fd).tell() ## root.TFile.tell = tell ## del tell return
def _pythonize_tfile(): #import PyCintex; PyCintex.Cintex.Enable() import cppyy root = import_root() import PyUtils.Helpers as H with H.ShutUp(filters=[ re.compile( 'TClass::TClass:0: RuntimeWarning: no dictionary for.*'), re.compile( 'Warning in <TEnvRec::ChangeValue>: duplicate entry.*' ), ]): cppyy.loadDict("RootUtilsPyROOTDict") rootutils = getattr(root, "RootUtils") pybytes = getattr(rootutils, "PyBytes") #MN: lines below fail in ROOT6 if PCM from RootUtils is not found read_root_file = getattr(rootutils, "_pythonize_read_root_file") tell_root_file = getattr(rootutils, "_pythonize_tell_root_file") pass def read(self, size=-1): """read([size]) -> read at most size bytes, returned as a string. If the size argument is negative or omitted, read until EOF is reached. Notice that when in non-blocking mode, less data than what was requested may be returned, even if no size parameter was given. FIXME: probably doesn't follow python file-like conventions... """ SZ = 4096 if size>=0: #size = _adjust_sz(size) #print "-->0",self.tell(),size c_buf = read_root_file(self, size) if c_buf and c_buf.sz: #print "-->1",self.tell(),c_buf.sz #self.seek(c_buf.sz+self.tell()) #print "-->2",self.tell() buf = c_buf.buffer() buf.SetSize(c_buf.sz) return str(buf[:]) return '' else: size = SZ out = [] while True: #size = _adjust_sz(size) c_buf = read_root_file(self, size) if c_buf and c_buf.sz: buf = c_buf.buffer() buf.SetSize(c_buf.sz) out.append(str(buf[:])) else: break return ''.join(out) root.TFile.read = read del read root.TFile.seek = root.TFile.Seek root.TFile.tell = lambda self: tell_root_file(self) ## import os ## def tell(self): ## fd = os.dup(self.GetFd()) ## return os.fdopen(fd).tell() ## root.TFile.tell = tell ## del tell return
#usage is: #from PathResolver import PathResolver #PathResolver.FindCalibFile("blah") import cppyy cppyy.loadDict('libPathResolver') cppyy.loadDict('libPathResolverDict') #why do we have to load both the library and the dict :-( To be fixed by ROOT... FindCalibFile = cppyy.gbl.PathResolverFindCalibFile FindCalibDirectory = cppyy.gbl.PathResolverFindCalibDirectory
# ============================================================================= __author__ = "Vanya BELYAEV <*****@*****.**>" # ============================================================================= import sys, os, os.path, datetime try: import cppyy except ImportError: # FIXME: backward compatibility print "# WARNING: using PyCintex as cppyy implementation" import PyCintex as cppyy import sys sys.modules['cppyy'] = cppyy cppyy.loadDict('RelationsDict') _gbl = GaudiPython.gbl _range = _gbl.Relations.BaseRange def _range_iter_(self): """ Iterator function which allows the sequential iteration over the range >>> range = ... >>> for i in range : print i """ _r = self