예제 #1
0
def runsandbox(head,
               find=None,
               outputname="sandbox.dst",
               runAllAfter=False,
               findalg=findalg):
    from GaudiConf.Manipulations import configurableInstanceFromString, nameFromConfigurable, postConfigCallable, configurableClassFromString
    if find is None:
        raise ValueError("You didn't ask me to search for anything!")
    found, before, contains, after, contained_stuff = findalg(head, find)
    print found, before, contains, after, contained_stuff
    if not found:
        raise NameError("I could not find the thing you asked me to excise!")
    user_algs = getUserAlgs()
    for a in before:
        if a not in contains and a not in user_algs and a not in contained_stuff:
            ac = configurableInstanceFromString(a)
            ac.Enable = False
    if not insertEmptyKiller(contains[-1], find):
        raise ValueError("Could not insert EmptyNodeKiller")
    if not insertSomething(contains[-1], find,
                           GaudiSequencer('PreExciseUserAlgs')):
        raise ValueError("Could not insert PreAlgs")
    if not insertSomething(
            contains[-1], find, GaudiSequencer('PostExciseUserAlgs'),
            before=False):
        raise ValueError("Could not insert PostAlgs")
    if not runAllAfter:
        for a in after:
            if a not in before and a not in contains and a not in user_algs and a not in contained_stuff:
                ac = configurableInstanceFromString(a)
                ac.Enable = False
    from GaudiConf import IOExtension
    IOExtension().inputFiles([outputname], clear=True)
    return
예제 #2
0
    def listOutputs(self):
        """
        Cascade down the database and find all output locations
        """
        outputs = []
        if type(self.Outputs) is list:
            outputs = outputs + self.Outputs
        elif type(self.Outputs) is dict:
            for key in self.Outputs:
                if self.Outputs[key] is None:
                    ops = self.__getprop__(
                        configurableInstanceFromString(self.FullName), key)
                    if ops is not None and type(ops) is str:
                        ops = [ops]
                    for op in ops:
                        if op not in outputs:
                            outputs.append(op)
                else:
                    ops = self.Outputs[key]
                    if ops is not None and type(ops) is str:
                        ops = [ops]
                    for op in ops:
                        if op not in outputs:
                            outputs.append(op)

        for tool in self.PrivateTools + self.PublicTools:
            if tool in self.__db__:
                thieroutputs = self.__db__[tool].listOutputs()
                outputs = outputs + [
                    val for val in thieroutputs if val not in outputs
                ]
        return outputs
예제 #3
0
 def overrideOutputs(self, output):
     """
     Set a list or dict of OutputLocations, set to all daughters
     """
     #print "GAAAAAAAHHHHHHHHH!!!!!!", output, self.FullName
     if not self.isOutputSettable():
         raise AttributeError("My output is not settable " + self.FullName)
     if type(self.Outputs) is list and len(self.Outputs):
         raise TypeError(self.FullName + ": outputs must be a dict, not " +
                         str(type(self.Outputs)))
     if type(self.Outputs) is dict and len(self.Outputs):
         #print "recognized I can set the output"
         for k, op in self.Outputs.items():
             #get this entry in any supplied dictionary
             setoutput = output
             if type(setoutput) is dict:
                 if k in setoutput:
                     setoutput = setoutput[k]
                 else:
                     continue
             #determine the type I need to set
             ensuretype = list
             if op is None:
                 #determine default type, first get my configurable
                 thedecoder = configurableInstanceFromString(self.FullName)
                 prop = self.__getprop__(thedecoder, k)
                 if isinstance(prop, DataObjectHandleBase):
                     # special case for datahandles
                     ensuretype = str
                 else:
                     ensuretype = type(prop)
             else:
                 ensuretype = type(op)
             #set this type
             #print "Type converted"
             if type(setoutput) == ensuretype:
                 self.Outputs[k] = setoutput
             elif type(setoutput) is list and (len(setoutput) > 1
                                               or len(setoutput)
                                               == 0) and ensuretype is str:
                 raise TypeError(
                     "Cannot set property of type list to this string, " +
                     self.FullName + " " + setoutput.__str__())
             elif type(setoutput) is list and len(
                     setoutput) == 1 and ensuretype is str:
                 self.Outputs[k] = setoutput[0]
             elif ensuretype is list and type(setoutput) is str:
                 self.Outputs[k] = [setoutput]
             else:
                 raise TypeError(self.FullName +
                                 ": Cannot convert from type " +
                                 str(type(setoutput)) + " to " +
                                 str(ensuretype))
     #then cascade downwards
     for tool in self.PublicTools + self.PrivateTools:
         if tool in self.__db__:
             if self.__db__[tool].isOutputSettable():
                 self.__db__[tool].overrideOutputs(output)
예제 #4
0
def insertSomething(seq, entry, insertme, before=True):
    from GaudiConf.Manipulations import configurableInstanceFromString, nameFromConfigurable, postConfigCallable, configurableClassFromString
    seqname = nameFromConfigurable(seq)
    seq = configurableInstanceFromString(seqname)
    entryname = nameFromConfigurable(entry)
    entry = configurableInstanceFromString(entry)
    if type(insertme) is not list:
        insertme = [insertme]
    dumpnames = [s.getFullName() for s in insertme]
    for p in ['Members', 'Filter0', 'Filter1', 'TopAlg', 'OutStream']:
        if not hasattr(seq, p): continue
        lists = getattr(seq, p)
        bef = []
        me = None
        af = []
        if entryname in lists:
            bef = lists[:lists.index(entryname)]
            me = lists[lists.index(entryname)]
            if len(lists) > lists.index(entryname):
                af = lists[lists.index(entryname) + 1:]
            if before:
                seq.setProp(p, bef + dumpnames + [me] + af)
            else:
                seq.setProp(p, bef + [me] + dumpnames + af)
            return True
        if entry in lists:
            bef = lists[:lists.index(entry)]
            me = lists[lists.index(entry)]
            if len(lists) > lists.index(entry):
                af = lists[lists.index(entry) + 1:]
            if before:
                seq.setProp(p, bef + insertme + [me] + af)
            else:
                seq.setProp(p, bef + [me] + insertme + af)
            return True

    raise ValueError("Failed to insert " + insertme.__str__() + " in " +
                     seqname + " " + " about " + entryname)
예제 #5
0
def createsandbox(head, find="", outputname="sandbox.dst"):
    from GaudiConf.Manipulations import configurableInstanceFromString, nameFromConfigurable, postConfigCallable, configurableClassFromString
    found, before, contains, after, contained_stuff = findalg(head, find)
    print found, before, contains, after, contained_stuff
    if not found:
        raise NameError("I could not find the thing you asked me to excise!")
    for a in after:
        #needed here for algs/sequencers which appear twice!
        if a not in before and a not in contains and a not in contained_stuff:
            ac = configurableInstanceFromString(a)
            ac.Enable = False
    if not contains[-1].startswith("ProcessPhase"):
        #if not insertEmptyKiller(contains[-1],find):
        #     raise ValueError("Could not insert EmptyNodeKiller")
        if not insertDump(contains[-1], find, outputname):
            raise ValueError("Could not insert OutputStream")
    else:
        raise NameError(
            "#Cannot excise from the middle of a ProcessPhase. Try Excising the ProcessPhase itself, called "
            + contains[-1])
    if not Gaudi.Excise['runAlg']:
        ac = configurableInstanceFromString(find)
        dc.Enable = False
    return
예제 #6
0
 def setup(self, cascade=True, configured=None, onlyInputs=False):
     """
     Return the configured configurable of this algorithm or public tool. Options:
     cascade: whether to follow down and configure the private tools of this alg also.
     configured: internal use only for configuring private tools
     """
     thedecoder = configured
     if thedecoder is None:
         thedecoder = configurableInstanceFromString(self.FullName)
     #configure me
     if type(self.Inputs) is dict:
         for prop in self.Inputs:
             if self.Inputs[prop] is not None:
                 self.__setprop__(thedecoder, prop, self.Inputs[prop])
     if not onlyInputs:
         for prop in self.Properties:
             if self.Properties[prop] is not None:
                 self.__setprop__(thedecoder, prop, self.Properties[prop])
         if type(self.Outputs) is dict:
             for prop in self.Outputs:
                 if self.Outputs[prop] is not None:
                     self.__setprop__(thedecoder, prop, self.Outputs[prop])
     if not cascade or self.__db__ is None:
         self.__used__ = True
         return thedecoder
     #configure public tools
     for atool in self.PublicTools:
         if atool in self.__db__:
             self.__db__[atool].setup(True, onlyInputs=onlyInputs)
         else:
             raise KeyError(
                 "Error: " + atool +
                 " not found in DB, set cascade=False, remove this from the list, or re-validate the db"
             )
     #configure private tools
     for atool in self.PrivateTools:
         if atool in self.__db__:
             thetool = addPrivateToolFromString(thedecoder, atool)
             self.__db__[atool].setup(True, thetool, onlyInputs=onlyInputs)
         else:
             raise KeyError(
                 "Error: " + atool +
                 " not found in DB, set cascade=False, remove this from the list, or re-validate the db"
             )
     self.__used__ = True
     return thedecoder
예제 #7
0
 def overrideInputs(self, input):
     """
     Set a List of input locations to search, set to all daughters
     """
     if not self.isInputSettable():
         raise AttributeError("My input is not settable " + self.FullName)
     #if type(self.Inputs) is list and len(self.Inputs):
     #    if type(input) is list:
     #        self.Inputs=input
     #    if type(input) is str:
     #        self.Inputs=[input]
     if type(self.Inputs) is dict and len(self.Inputs):
         for k, ip in self.Inputs.items():
             ensuretype = list
             if ip is None:
                 #determine default type, first get my configurable
                 thedecoder = configurableInstanceFromString(self.FullName)
                 ensuretype = type(self.__getprop__(thedecoder, k))
             else:
                 ensuretype = type(ip)
             if type(input) == ensuretype:
                 self.Inputs[k] = input
             elif type(input) is list and len(
                     input) > 0 and ensuretype is str:
                 raise TypeError(
                     self.FullName +
                     " cannot set property of type list to this string, " +
                     self.FullName + " " + input.__str__())
             elif ensuretype is list and type(input) is str:
                 self.Inputs[k] = [input]
             elif ensuretype is DataObjectHandleBase:
                 path = input if type(input) is str else ':'.join(input)
                 self.Inputs[k] = DataObjectHandleBase(path)
             else:
                 raise TypeError(self.FullName +
                                 " cannot convert input from type " +
                                 str(type(input)) + " to " +
                                 str(ensuretype))
     #then cascade downwards
     for tool in self.PublicTools + self.PrivateTools:
         if tool in self.__db__:
             if self.__db__[tool].isInputSettable():
                 self.__db__[tool].overrideInputs(input)
예제 #8
0
 def listInputs(self):
     """
     Cascade down the database and find all input locations
     """
     inputs = []
     #maybe I'm just a list
     if type(self.Inputs) is list:
         inputs = inputs + self.Inputs
     #or I'm a dict
     elif type(self.Inputs) is dict:
         for key in self.Inputs:
             #do I have to be found from the configurable?
             if self.Inputs[key] is None:
                 #OK, find me then
                 ips = self.__getprop__(
                     configurableInstanceFromString(self.FullName), key)
                 #only add if not already in the list
                 if ips is not None and type(ips) is str:
                     ips = [ips]
                 for ip in ips:
                     if ip not in inputs:
                         inputs.append(ip)
             else:
                 #no? well add me to the list
                 ips = self.Inputs[key]
                 if ips is not None and type(ips) is str:
                     ips = [ips]
                 for ip in ips:
                     if ip not in inputs:
                         inputs.append(ip)
     #cascade down the tools
     for tool in self.PrivateTools + self.PublicTools:
         if tool in self.__db__:
             thierinputs = self.__db__[tool].listInputs()
             inputs = inputs + [
                 val for val in thierinputs if val not in inputs
             ]
     return inputs
예제 #9
0
    def listOutputs(self):
        """
        Cascade down the database and find all output locations
        """
        outputs = []
        #maybe I'm just a list
        if type(self.Outputs) is list:
            outputs = outputs + self.Outputs
        #or I'm a dict
        elif type(self.Outputs) is dict:
            for key in self.Outputs:
                #do I have to be found from the configurable?
                if self.Outputs[key] is None:
                    #OK, find me then
                    ops = self.__getprop__(
                        configurableInstanceFromString(self.FullName), key)
                else:
                    #no? well add me to the list
                    ops = self.Outputs[key]

                #only add if not already in the list
                if ops is not None and type(ops) is str:
                    ops = [ops]
                elif isinstance(ops, DataObjectHandleBase):
                    ops = ops.Path.split(":")
                for op in ops:
                    if op not in outputs:
                        outputs.append(op)
        #cascade down the tools
        for tool in self.PrivateTools + self.PublicTools:
            if tool in self.__db__:
                thieroutputs = self.__db__[tool].listOutputs()
                outputs = outputs + [
                    val for val in thieroutputs if val not in outputs
                ]
        return outputs
예제 #10
0
def findalg(head=None, find=""):
    """ Find a given algoritm, return a tuple
    (found_yet?,before,contained_in,after,contains_stuff)
    """
    from GaudiConf.Manipulations import configurableInstanceFromString, nameFromConfigurable, postConfigCallable, configurableClassFromString
    if type(head) is list:
        raise TypeError("findalg, you need to send me one object at a time!")

    if head is None:
        from Gaudi.Configuration import ApplicationMgr
        head = ApplicationMgr()

    headname = nameFromConfigurable(head)

    itsme = False

    if headname is None or head is None:
        return (False, [], [], [])
    if headname == find:
        itsme = True

    head = configurableInstanceFromString(headname)
    found = itsme
    before = []
    contained = []
    after = []
    contains_stuff = []

    orderedkids = []

    for p in ['Members', 'Filter0', 'Filter1', 'TopAlg', 'OutStream']:
        if not hasattr(head, p): continue
        orderedkids = orderedkids + getattr(head, p)
    from Configurables import ProcessPhase
    if type(head) is ProcessPhase:
        orderedkids += [
            "GaudiSequencer/" + headname.split("/")[-1] + d + "Seq"
            for d in head.getProp("DetectorList")
        ]

    if itsme:
        contains_stuff = orderedkids

    for s in orderedkids:
        ifound, ibefore, icontained, iafter, istuff = findalg(s, find)
        if (found and ifound):
            print "#WARNING The algorithm you asked for appears twice! I cannot excise it properly like that. I take the first occurance"
        if ifound and itsme:
            raise NameError(
                "Recursion detected, somehow the algorithm is a container which contains itself, that's really a problem."
            )

        if itsme:
            contains_stuff = contains_stuff + ibefore + icontained + iafter + istuff
        elif found:
            after = after + ibefore + icontained + iafter
        elif ifound:
            before = before + ibefore
            contained = icontained
            after = after + iafter
            found = True
            contains_stuff = contains_stuff + istuff
        else:
            before += ibefore
            if len(iafter) or len(icontained):
                raise ValueError(
                    "I didn't expect sequencers when the alg was said not to be found yet"
                )
    if itsme:
        return (True, [], [], [], contains_stuff)

    #if I found it, register me as containing the thing
    if found:
        contained = [headname] + contained
    else:
        before = [headname] + before

    return (found, before, contained, after, contains_stuff)
# (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration      #
#                                                                             #
# This software is distributed under the terms of the GNU General Public      #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
#                                                                             #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization  #
# or submit itself to any jurisdiction.                                       #
###############################################################################
from Gaudi.Configuration import *
from DAQSys.Configuration import *
DecodeRawEvent().DataOnDemand = True
DecodeRawEvent().__apply_configuration__()

from GaudiConf.Manipulations import configurableInstanceFromString

for k, v in configurableInstanceFromString(
        "DataOnDemandSvc").AlgMap.iteritems():
    if type(v) is str:
        v = configurableInstanceFromString(v)
    print "===================="
    #  DataObjectHandleBase has ('xyz') instead of xyz
    print k.strip("()").strip("'")
    print "--------------------"
    print v.getFullName()
    props = {}
    for prop in v.getProperties():
        props[prop] = v.getProp(prop)
    print props
    print "===================="