Ejemplo n.º 1
0
def _py_init_ClassIDSvc():
    import cppyy
    # IClassIDSvc bindings from dictionary
    _load_dict("libAthenaPythonDict")

    # make sure the global C++ namespace has been created
    gbl = cppyy.makeNamespace('')  # noqa: F841

    # load the AthenaInternal::getClid helper method
    cppyy.makeNamespace('AthenaInternal')
    # Really make sure that dictionaries are loaded.
    # Needed this with 20.7.X-VAL.
    cppyy.gbl.AthenaInternal.ROOT6_AthenaPython_WorkAround_Dummy

    # retrieve the IClassIDSvc class
    global IClassIDSvc
    IClassIDSvc = cppyy.gbl.IClassIDSvc

    _missing_clids = {
        'DataHistory': 83814411,
        83814411: 'DataHistory',
    }

    # re-use the python-based clid generator
    # (faster than calling back into C++ via Reflex bindings)
    from CLIDComps.clidGenerator import clidGenerator
    IClassIDSvc._clidgen = clidGenerator(db=None)

    # add pythonized methods
    @memoize
    def _clid(self, name):
        # handle special cases where CLID has been registered with a typedef
        try:
            name = _clid_typename_aliases[name]
        except KeyError:
            pass
        try:
            return _missing_clids[name]
        except KeyError:
            pass
        return self._clidgen.getClidFromName(name)

    IClassIDSvc.clid = _clid
    del _clid

    @memoize
    def _typename(self, clid):
        # handle special cases of missing clids
        try:
            return _missing_clids[clid]
        except KeyError:
            pass
        return self._clidgen.getNameFromClid(clid)

    IClassIDSvc.typename = _typename
    del _typename

    return IClassIDSvc
Ejemplo n.º 2
0
 def test2GenClids( self ):
    """Testing clidGenerator with no clid.db"""
    # get rid of expected error message
    sys.stdout = open("dummyIgnore.txt", 'w')
    self.cgen = clidGenerator("NOTTHERE.db")
    sys.stdout = sys.__stdout__
    os.remove("dummyIgnore.txt");
    
    self.assertEqual( 245732527, self.cgen.genClidFromName("DataObject") )
    self.assertEqual( 205083834, self.cgen.genClidFromName("Data<Foo23_45___Bar_, dsfl__>") )
Ejemplo n.º 3
0
def gen_typeregistry_dso(oname=_dflt_typereg_fname):
    '''inspect all the accessible reflex types and get their rootmap-naming.
    also associate the clid if available.
    '''
    import CLIDComps.clidGenerator as _c
    cliddb = _c.clidGenerator(db=None)
    del _c

    import PyUtils.path as _p
    oname = _p.path(oname)
    del _p

    import PyUtils.Logging as _L
    msg = _L.logging.getLogger('typereg-dso')
    msg.setLevel(_L.logging.INFO)
    #msg.setLevel(_L.logging.VERBOSE)   #MN
    del _L

    msg.info("installing registry in [%s]...", oname)

    # FIXME: should use the Cxx one...
    #reg = DsoDb()
    reg = PyDsoDb()

    cls_names = reg.db.keys()
    import cppyy
    _load_lib = cppyy.loadDict

    # if int(cppyy.get_version().split('.')[0]) < 6:
    if hasattr(cppyy, 'hasCintex'):
        # load reflex for ROOT ver<6
        msg.debug("::: loading reflex")
        _load_lib('libReflexRflx.so')
        rflx = cppyy.makeNamespace('Reflex')
        if not rflx:
            rflx = cppyy.makeNamespace('ROOT::Reflex')
        rflx = rflx.Type
        assert (rflx)

    def _load_dict(libname, retry=10):
        msg.debug("::: loading [%s]...", libname)
        try:
            return _load_lib(libname)
        except (
                Exception,
                SystemError,
        ), err:
            msg.warning("**error** %s", err)
        return
Ejemplo n.º 4
0
def gen_typeregistry_dso(oname=_dflt_typereg_fname):
    '''inspect all the accessible reflex types and get their rootmap-naming.
    also associate the clid if available.
    '''
    import CLIDComps.clidGenerator as _c
    cliddb = _c.clidGenerator(db=None)
    del _c

    import PyUtils.path as _p
    oname = _p.path(oname)
    del _p
        
    import PyUtils.Logging as _L
    msg = _L.logging.getLogger('typereg-dso')
    #msg.setLevel(_L.logging.INFO)
    msg.setLevel(_L.logging.VERBOSE)
    del _L
    
    msg.info("installing registry in [%s]...", oname)

    # FIXME: should use the Cxx one...
    #reg = DsoDb()
    reg = PyDsoDb()
    
    cls_names = reg.db.keys()
    msg.debug("::: loading reflex")
    import PyCintex
    PyCintex.Cintex.Enable()
    PyCintex.loadDict('libReflexRflx.so')
    rflx = PyCintex.makeNamespace('Reflex')
    if not rflx:
        rflx = PyCintex.makeNamespace('ROOT::Reflex')
    rflx = rflx.Type
    assert(rflx)

    import PyCintex
    _load_lib = PyCintex.loadDict
    def _load_dict(libname,retry=10):
        msg.debug("::: loading [%s]...", libname)
        try:
            return _load_lib(libname)
        except (Exception,SystemError,), err:
            msg.warning("**error** %s", err)
        return
Ejemplo n.º 5
0
def _extract_fields_esi(value):
    result = {}

    result['eventTypes'] = []
    for eventType in value.m_eventTypes:
        result['eventTypes'].append(_convert_value(eventType))

    result['numberOfEvents'] = value.m_numberOfEvents
    result['runNumbers'] = list(value.m_runNumbers)
    result['lumiBlockNumbers'] = list(value.m_lumiBlockNumbers)
    result['processingTags'] = list(value.m_processingTags)
    result['itemList'] = []

    # Get the class name in the repository with CLID <clid>
    from CLIDComps.clidGenerator import clidGenerator
    cgen = clidGenerator("")
    for clid, sgkey in value.m_itemList:
        result['itemList'].append((cgen.getNameFromClid(clid), sgkey))

    return result
Ejemplo n.º 6
0
Python script that creates C++ .h/.cxx files that contain the container and object class
representing the structure of a database folder.
"""

import argparse
import os.path
import string
import sys
import uuid

from CLIDComps.clidGenerator import clidGenerator
from PyCool import cool, coral

_dbSvc = cool.DatabaseSvcFactory.databaseService()
_cliddb = clidGenerator("")

_container_header = """// -*- C++ -*-
#ifndef TRIGT1CALOCALIBCONDITIONS_${CONTAINERNAME}_H
#define TRIGT1CALOCALIBCONDITIONS_${CONTAINERNAME}_H

#include <map>
#include <string>
#include <vector>
#include "AthenaKernel/CLASS_DEF.h"
#include "GaudiKernel/DataObject.h"
#include "TrigT1CaloCalibConditions/AbstractL1CaloPersistentCondition.h"
#include "TrigT1CaloCalibConditions/L1CaloCoolChannelId.h"

class CondAttrListCollection;
class ${ObjectName};
Ejemplo n.º 7
0
    cppyy.gbl.AthenaInternal.ROOT6_AthenaPython_WorkAround_Dummy
    _getClid = cppyy.gbl.AthenaInternal.getClid

    # retrieve the IClassIDSvc class
    global IClassIDSvc
    IClassIDSvc = cppyy.gbl.IClassIDSvc

    _missing_clids = {
        'DataHistory': 83814411L,
        83814411L: 'DataHistory',
    }

    # re-use the python-based clid generator
    # (faster than calling back into C++ via Reflex bindings)
    from CLIDComps.clidGenerator import clidGenerator
    IClassIDSvc._clidgen = clidGenerator(db=None)

    # add pythonized methods
    @memoize
    def _clid(self, name):
        # handle special cases where CLID has been registered with a typedef
        try:
            name = _clid_typename_aliases[name]
        except KeyError:
            pass
        try:
            return _missing_clids[name]
        except KeyError:
            pass
        return self._clidgen.getClidFromName(name)
Ejemplo n.º 8
0
 def test1ClidDB(self):
     """Testing clidGenerator with Gaudi_clid.db"""
     self.cgen = clidGenerator("Gaudi_clid.db")
     self.assertEqual(1, self.cgen.genClidFromName("DataObject"))
     self.assertEqual("DataObject", self.cgen.getNameFromClid(1))
Ejemplo n.º 9
0
# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration

from __future__ import print_function
import cppyy
from CLIDComps.clidGenerator import clidGenerator

clidg = clidGenerator("")
from ROOT import HLT
stringSerializer = cppyy.gbl.StringSerializer()


class hltResult(HLT.HLTResult):
    def __init__(self):
        super(hltResult, self).__init__()
        self.as_int_v = cppyy.gbl.std.vector('unsigned int')()

    def load(self, rob):
        self.nav_payload = []

        data = list(rob.rod_data())
        self.as_int_v.clear()
        self.as_int_v.reserve(len(data))
        [self.as_int_v.push_back(i) for i in data]

        if self.deserialize(self.as_int_v) is False:
            raise Exception('deserialization of the HLT result failed')
        self.__unpack_navigation()

    def __unpack_navigation(self):
        nav_data = list(self.getNavigationResult())
        if len(nav_data) <= 1:
Ejemplo n.º 10
0
if doEDM:
    from TriggerJobOpts.TriggerEDM import EDMDetails
    for item in EDMDetails.keys():
        pers = EDMDetails[item]['persistent']
        objects.append(pers)

for pers in objects:
    SIG.inspect(pers)
    print
fulllist = SIG.classlist
print fulllist
print '*******************************'

from CLIDComps.clidGenerator import clidGenerator
cgen = clidGenerator("")

types_new = 0
types_exist = 0
types_bad = 0
fulllist = list(set(fulllist))
for item in fulllist:
    if doxAODonly and not 'xAOD' in item:
        continue  # current issues seen because of missing xAOD libs not being loaded
    print "Trying to fill item", item, "to root file"
    c_clid = cgen.genClidFromName(item)
    c_typeinfo = cgen.getTidFromClid(c_clid)
    print "CLID", c_clid
    print "TypeInfo", c_typeinfo
    try:
        cls = ROOT.gROOT.GetClass(item)
Ejemplo n.º 11
0
    def setDefaults(cls, handle):

        ## continue, only if it is our Configurable
        if not isinstance(handle, ThinningSvc):
            return

        from AthenaCommon.AlgSequence import AlgSequence
        ## get a handle on the ToolSvc
        from AthenaCommon.AppMgr import ToolSvc as toolSvc
        from AthenaCommon.AppMgr import ServiceMgr as svcMgr

        from AthenaCommon.Logging import logging
        msg = logging.getLogger(handle.name())

        from CLIDComps.clidGenerator import clidGenerator
        cliddb = clidGenerator(db=None)

        def _clid_from_string(s):
            """return the clid (integer) from a string (which can either
            contain the integer or the clid-name associated with it.)
            """
            try:
                clid = int(s)
            except ValueError:
                clid = cliddb.getClidFromName(s)
                if clid is None or clid == 'None':
                    msg.warning('could not infer clid-name for: "%s"', s)
                    clid = None
            return clid

        from PyUtils.Decorators import memoize

        @memoize
        def _retrieve_items_from_input():
            items = []
            from AthenaCommon.AppMgr import ServiceMgr as svcMgr
            import PyUtils.PoolFile as _pf
            # only inspect the first input file
            # that should be enough as we don't really support varying schema
            # shapes anymore (as ROOT doesn't)
            items = _pf.extract_items(svcMgr.EventSelector.InputCollections[0])
            input_items = []
            for item in items:
                clid = _clid_from_string(item[0])
                if clid is None:
                    msg.warning('could not infer clid for: "%s"', item[0])
                    clid = item[0]  # put back the original string, then.
                input_items.append([clid, item[1]])
            return input_items

        def _doScheduleTool(outStream, streamNames):
            outStreamName = outStream.name()
            return outStreamName in streamNames

        def _build_proxy_list(outStream):
            """helper to access the 'ForceRead' and 'TakeItemsFromInput'
            properties of the output stream to build a list of pairs (clid,key)
            the thinning tool will forcingly read during the pre-execute step.
            """
            from collections import defaultdict
            proxies = defaultdict(list)
            props = outStream.properties()

            from_input = outStream.properties()['TakeItemsFromInput']
            if from_input == outStream.propertyNoValue:
                from_input = outStream.getDefaultProperty('TakeItemsFromInput')

            ## fetch the items to be written out
            itemlist = outStream.properties()['ItemList'][:]
            for item in itemlist:
                clid_or_name, sg_key = item.split('#')
                clid_or_name = clid_or_name.strip()
                sg_key = sg_key.strip()
                clid_or_name = _clid_from_string(clid_or_name)
                if clid_or_name is None:
                    msg.warning('could not infer clid for: "%s"', item)
                else:
                    if len(sg_key) == 0:
                        msg.warning('invalid key for item: "%s"', item)
                    else:
                        proxies[clid_or_name].append(sg_key)

            if from_input:
                input_items = _retrieve_items_from_input()
                for clid, sg_key in input_items:
                    proxies[clid].append(sg_key)
            d = proxies
            proxies = []
            for clid, sg_keys in d.iteritems():
                sg_keys = list(set(sg_keys))
                proxies.extend([[str(clid), sg_key] for sg_key in sg_keys])
            return proxies

        # filter out duplicates
        streams = [o for o in set(handle.Streams[:])]

        ## list of streams we know we will apply thinning on
        outstreams = []

        ## connect @c ThinningOutputTool into the HelperTools slot
        AthenaOutputStream = CfgMgr.AthenaOutputStream

        ## first loop over TopAlg (as output stream can be located
        ## into that sequence)
        for o in AlgSequence("TopAlg"):
            if (isinstance(o, AthenaOutputStream)
                    and hasattr(o, 'HelperTools')
                    and _doScheduleTool(o, streams)):
                outstreams.append(o)
                pass
        ## then loop over OutStream sequence
        if AlgSequence.configurables.has_key('Streams'):
            for o in AlgSequence("Streams"):
                if (isinstance(o, AthenaOutputStream)
                        and hasattr(o, 'HelperTools')
                        and _doScheduleTool(o, streams)):
                    outstreams.append(o)
                    pass

        ## set the streams we found
        setattr(handle, 'Streams', [o.name() for o in outstreams])

        if len(outstreams) <= 0:
            handle.Streams = []
            msg.warning("No output stream will be thinned !")
            msg.warning("Check your jobOptions configuration")
            msg.warning("...performing hara-kiri...")
            delattr(svcMgr, handle.name())
            del handle
            return

        _lvl = handle.properties()['OutputLevel']
        if _lvl == handle.propertyNoValue:
            _lvl = handle.getDefaultProperty('OutputLevel')
            pass
        ## get and install the ThinningOutputTool configurable
        from AthenaServicesConf import ThinningOutputTool
        toolName = "ThinningTool_%s" % handle.name()
        tool = ThinningOutputTool(toolName,
                                  OutputLevel=_lvl,
                                  ThinningSvc=handle)
        tool.Proxies = []
        for o in outstreams:
            tool.Proxies += _build_proxy_list(o)
            o.HelperTools.insert(0, tool)
            ## XXX FIXME XXX
            ## see https://savannah.cern.ch/bugs/index.php?40823
            o.HelperTools += []  # just to work-around bug #40823
        ##
        return
Ejemplo n.º 12
0
#!/usr/bin/env python
# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration

from AthenaCommon.Logging import logging
log = logging.getLogger('testEDM')

from TriggerEDM import (TriggerL2List, TriggerEFList, TriggerResultsList,
                        TriggerResultsRun1List, TriggerLvl1List,
                        TriggerIDTruth, TriggerHLTList)
from TriggerEDMRun2 import EDMDetails
from CLIDComps.clidGenerator import clidGenerator
cgen = clidGenerator("", False)


def isCLIDDefined(typename):
    c = cgen.genClidFromName(typename)
    pkg = cgen.getPackageFromClid(c)
    return bool(pkg)


def main():
    import re
    serializable_names = []
    serializable_names_no_label = []
    TriggerList = TriggerL2List + TriggerEFList + TriggerResultsList + TriggerResultsRun1List + TriggerLvl1List + TriggerIDTruth + TriggerHLTList
    for TriggerSerializable in TriggerList:
        #print TriggerSerializable
        serializable_name = TriggerSerializable[0]
        serializable_name_no_label = re.sub(r"\#.*", "", serializable_name)
        if '#' not in serializable_name:
            log.error("ERROR, no label for " + serializable_name)
Ejemplo n.º 13
0
    cppyy.gbl.AthenaInternal.ROOT6_AthenaPython_WorkAround_Dummy
    _getClid = cppyy.gbl.AthenaInternal.getClid
    
    # retrieve the IClassIDSvc class
    global IClassIDSvc
    IClassIDSvc = cppyy.gbl.IClassIDSvc

    _missing_clids  = {
        'DataHistory' : 83814411L, 
        83814411L     : 'DataHistory',
        }

    # re-use the python-based clid generator
    # (faster than calling back into C++ via Reflex bindings)
    from CLIDComps.clidGenerator import clidGenerator
    IClassIDSvc._clidgen = clidGenerator(db=None)

    # add pythonized methods
    @memoize
    def _clid (self, name):
        # handle special cases where CLID has been registered with a typedef
        try:   name = _clid_typename_aliases[name]
        except KeyError: pass
        try:
            return _missing_clids[name]
        except KeyError: pass
        return self._clidgen.getClidFromName(name)
    IClassIDSvc.clid = _clid
    del _clid
    
    @memoize