Esempio n. 1
0
def main():
    import sys
    import user

    #    sys.path.append("../i686-slc5-gcc43-opt/")

    # output
    outputFile = "out1.root"
    # input
    inputFiles = sys.argv[1].split(',')

    from GaudiPython import AppMgr
    theApp = AppMgr()
    theApp.EvtMax = 1
    # Verboseness threshold level: 0=NIL,1=VERBOSE, 2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL, 7=ALWAYS
    #    theApp.outputLevel = 4
    #    MessageSvc.OutputLevel = 4
    #    EventSelector.OutputLevel = 4
    theApp.JobOptionsType = "NONE"
    theApp.EvtSel = "NONE"
    theApp.Dlls = ["GaudiAlg", "MiniNtuple"]

    myNtp = theApp.algorithm("TMiniNtuple")
    myNtp.InputFileName = inputFiles
    myNtp.OutputFileName = outputFile
    myNtp.Debug = False
    myNtp.ApplyLeptonSkim = True
    myNtp.MinLeptonPt = 9000.

    theApp.topAlg = ["TMiniNtuple"]

    theApp.config()
    theApp.initialize()
    theApp.run(1)
    theApp.exit()
Esempio n. 2
0
def extractAlignmentParameters(
        elementsWithTESAndCondDBNodes,
        since,
        until,
        valueExtractor=lambda detElm: getGlobalPositionFromGeometryInfo(
            detElm.geometry()),
        DDDBtag="default",
        CondDBtag="default",
        alignDBs=[]):
    """
    The method talking to the detector svc

    Extract from all DetectorElements down from each element in elementsWithTESAndCondDBNodes
    ( format { elm : ( detTES, [ condDBNode ] ) } ), alignment parameters using valueExtractor,
    for all iovs between since and until (datetimes), using the CondDBNodes.
    The default database is configured with database tags DDDBtag and CondDBtag,
    and all alignDBs [ (tag, connectString) ] are added as layers to the CondDB.

    Returns a dict { element : [ ( (iovBegin, iovEnd), alignmentTree ) ] }
    """
    # Static configuration of the application manager
    from Configurables import LHCbApp, ApplicationMgr
    from LHCbKernel.Configuration import FATAL, ERROR, WARNING, INFO, DEBUG, VERBOSE

    ApplicationMgr().AppName = "AlignmentCollector"
    ApplicationMgr().OutputLevel = ERROR

    LHCbApp().DDDBtag = DDDBtag
    LHCbApp().CondDBtag = CondDBtag

    # >>> This part stolen from Det/DetCond/tests/scripts/getIOVs.py
    ApplicationMgr().TopAlg = ["LoadDDDB"]

    from Configurables import EventClockSvc, FakeEventTime

    ecs = EventClockSvc(
        InitialTime=toTimeStamp(datetime(2010, 1, 1, 12, tzinfo=pytz.utc)))
    ecs.addTool(FakeEventTime, "EventTimeDecoder")
    ecs.EventTimeDecoder.StartTime = ecs.InitialTime
    ecs.EventTimeDecoder.TimeStep = toTimeStamp(timedelta(days=1))
    # <<< + "lhcbcond" below

    layers = ["LHCBCOND"]

    if len(alignDBs) > 0:
        from Configurables import CondDB, CondDBAccessSvc
        for i, (connectString, tag) in enumerate(alignDBs):
            layerName = "AlignCond%i" % i
            alignCond = CondDBAccessSvc(layerName)
            alignCond.ConnectionString = connectString
            alignCond.DefaultTAG = tag
            CondDB().addLayer(alignCond)
            layers.append(layerName)

    # run a gaudi application
    from GaudiPython import AppMgr, gbl
    gaudi = AppMgr()
    gaudi.createSvc("UpdateManagerSvc")
    updateManagerSvc = gaudi.service("UpdateManagerSvc",
                                     interface="IUpdateManagerSvc")
    gaudi.initialize()

    conddbReaders = list(
        gaudi.service(name, gbl.ICondDBReader) for name in reversed(layers))

    detDataSvc = updateManagerSvc.detDataSvc()

    alignmentTrees = dict(
        (detName, []) for detName in elementsWithTESAndCondDBNodes.iterkeys())

    for detName, (detPath,
                  condNodes) in elementsWithTESAndCondDBNodes.iteritems():
        ### get the IOVs for all elements, and combine them
        timeLine = [("gap", (since, until))]
        for layerReader in conddbReaders:
            timeLineUpdated = list(timeLine)
            alreadyInserted = 0
            for i, (typ, (gapBegin, gapEnd)) in enumerate(timeLine):
                if typ == "gap":
                    iovs = combinedIOVs([
                        list((max(toDateTime(iov.since.ns()), gapBegin),
                              min(toDateTime(iov.until.ns()), gapEnd))
                             for iov in layerReader.getIOVs(
                                 node,
                                 gbl.ICondDBReader.IOV(
                                     gbl.Gaudi.Time(toTimeStamp(gapBegin)),
                                     gbl.Gaudi.Time(toTimeStamp(gapEnd))), 0))
                        for node in TrackingAlignmentCondDBNodes[detName]
                    ])
                    if len(iovs) != 0:
                        updatedTimeSlice = list(
                            ("iov", (begin, end)) for begin, end in iovs)
                        if updatedTimeSlice[0][1][0] > gapBegin:
                            updatedTimeSlice.insert(
                                0,
                                ("gap", (gapBegin, updatedTimeSlice[0][1][0])))
                        if updatedTimeSlice[-1][1][1] < gapEnd:
                            updatedTimeSlice.append(
                                ("gap", (updatedTimeSlice[-1][1][1], gapEnd)))
                        timeLineUpdated[i + alreadyInserted:i +
                                        alreadyInserted + 1] = updatedTimeSlice
                        alreadyInserted += len(updatedTimeSlice) - 1
            logging.debug("timeline after adding %s : %s" %
                          (layerReader, timeLine))
            timeLine = timeLineUpdated
        iovs = list(timespan for typ, timespan in timeLine if typ == "iov")

        ### For every IOV, extract the parameters
        for begin, end in iovs:
            detDataSvc.setEventTime(
                gbl.Gaudi.Time(toTimeStamp(begin + (end - begin) / 2)))
            updateManagerSvc.newEvent()
            motionSystem = None if detName != "Velo" else gaudi.detSvc(
            ).getObject("/dd/Conditions/Online/Velo/MotionSystem")
            logging.info("Extracting parameters for %s between %s and %s" %
                         (detName, begin, end))
            detTree = getAlignableTreeFromDetectorElement(
                gaudi.detSvc().getObject(detPath),
                nodeValue=valueExtractor,
                parentName=detPath,
                motionSystem=motionSystem)
            detTree.name = detName

            alignmentTrees[detName].append(((begin, end), detTree))

    gaudi.finalize()

    gaudi.exit()

    return alignmentTrees
Esempio n. 3
0
def main():
    import sys
    import user
    import glob
    import os

    fpath = '/UserDisk2/othrif/data/MiniNtuple/v44-3/'
    #    folder = sys.argv[1]
    filename = sys.argv[1]

    # output
    #    outputFile = os.path.join(fpath, 'user.othrif.'+filename)
    outputFile = os.path.join(fpath, filename)

    # input
    path = os.path.join('/UserDisk2/othrif/data/Ximo/v44-3/' + filename)
    inputFiles = glob.glob(path)

    #    outputFile = "/tmp/test_out1.root"
    #    inputFiles = glob.glob('/UserDisk2/othrif/susy/mc_method/Ximo.v18/user.jpoveda.t0616_v18.00270816.physics_Main.DAOD_SUSY2.f611_m1463_p2375_output.root/*.root')
    #   inputFiles = glob.glob('/UserDisk2/othrif/susy/test/mc15_13TeV.370602.MGPy8EG_A14N23LO_NUHM2_m12_400_strong.merge.DAOD.e4209_a766_a777_r6282.root')

    #    filename = sys.argv[1]
    # output
    #    outputFile = "/tmp/test_out1.root"
    #    outputFile = '/tmp/',filename,'.root'
    # input
    #    inputFiles = glob.glob('/users/orifki/workarea/susy_ss3l/input/user.jpoveda.5286937._000001.output.root')
    #    inputFiles = glob.glob('/data3/orifki/gtt_above_diag_FULL/validation/mc12_8TeV.156581.Herwigpp_UEEE3_CTEQ6L1_Gtt_G1100_T2500_L200.merge.NTUP_SUSY.e1221_s1469_s1470_r3542_r3549_p1328_tid01151387_00/NTUP_SUSY.01151387._000001.root.1')

    # run over data
    #    inputFiles = glob.glob('/data3/orifki/susy/cutflow/user.jpoveda.t0609_v12.00266904.physics_Main.DAOD_SUSY9.f594_m1435_p2361_output.root.30695488/user.jpoveda.5632900._000001.output.root')
    #    inputFiles = glob.glob('/afs/cern.ch/user/o/othrif/data/user.jpoveda.t0609_v12.00266904.physics_Main.DAOD_SUSY9.f594_m1435_p2361_output.root.30695488/user.jpoveda.5632900._000001.output.root')

    #    inputFiles = glob.glob('/afs/cern.ch/user/o/othrif/data/user.jpoveda.t0609_v12.410000.PowhegPythiaEvtGen_P2012_ttbar_hdamp172p5_nonallhad.DAOD_SUSY1.s2608_r6633_p2353_output.root.*/*.root')

    #    inputFiles = glob.glob('/UserDisk2/othrif/susy/mc_method/user.jpoveda.t0615_v17.00266904.physics_Main.DAOD_SUSY9.r6847_p2358_p2361_output.root/*.root')

    #    inputFiles = glob.glob('/UserDisk2/othrif/susy/mc_method/user.jpoveda.t0616_v18.410067.MadGraphPythia8EvtGen_A14NNPDF23LO_ttW_Np1.DAOD_SUSY2.s2608_r6793_p2375_output.root/user.jpoveda.6120928._000001.output.root')

    #    inputFiles = glob.glob('/UserDisk2/othrif/susy/mc_method/user.jpoveda.t0615_v17.361106.PowhegPythia8EvtGen_AZNLOCTEQ6L1_Zee.DAOD_SUSY2.s2576_r6630_p2375_output.root/*.root')

    from GaudiPython import AppMgr
    theApp = AppMgr()
    theApp.EvtMax = 100
    # Verboseness threshold level: 0=NIL,1=VERBOSE, 2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL, 7=ALWAYS
    #    theApp.outputLevel = 4
    #    MessageSvc.OutputLevel = 4
    #    EventSelector.OutputLevel = 4
    theApp.JobOptionsType = "NONE"
    theApp.EvtSel = "NONE"
    theApp.Dlls = ["GaudiAlg", "MiniNtuple"]

    myNtp = theApp.algorithm("TMiniNtuple")
    myNtp.InputFileName = inputFiles
    myNtp.OutputFileName = outputFile
    myNtp.Debug = False
    myNtp.ApplyLeptonSkim = True
    myNtp.MinLeptonPt = 13000.

    theApp.topAlg = ["TMiniNtuple"]

    theApp.config()
    theApp.initialize()
    theApp.run(1)
    theApp.exit()
Esempio n. 4
0
def main():

    parser = optparse.OptionParser(usage="usage: %prog [options]")

    parser.add_option("--debug",
                      action="store_true",
                      dest="debug",
                      default=False,
                      help="Debug?")

    parser.add_option("-d",
                      "--datatype",
                      action="store",
                      dest="DataType",
                      default="2015",
                      help="DataType to run on.")

    parser.add_option("-n",
                      "--evtmax",
                      type="int",
                      action="store",
                      dest="EvtMax",
                      default=10000,
                      help="Number of events to run")

    parser.add_option("--dddbtag",
                      action="store",
                      dest="DDDBtag",
                      default='dddb-20150526',
                      help="DDDBTag to use")

    parser.add_option("--conddbtag",
                      action="store",
                      dest="CondDBtag",
                      default='cond-20150617',
                      help="CondDBtag to use")

    parser.add_option("--settings",
                      action="store",
                      dest="ThresholdSettings",
                      default='Physics_25ns_September2015',
                      help="ThresholdSettings to use")

    parser.add_option("--TCK",
                      action="store",
                      dest="TCK",
                      default='',
                      help="HLT TCK. If unspecified,then run from settings")

    parser.add_option("--simulation",
                      action="store_true",
                      dest="Simulation",
                      default=False,
                      help="Run on simulated data")

    parser.add_option("--input_rate",
                      action="store",
                      dest="input_rate",
                      default=1.e6,
                      help="Input rate from L0 in Hz")

    parser.add_option("--tuplefile",
                      action="store",
                      dest="tuplefile",
                      default="",
                      help="Output root file")

    parser.add_option("--inputdata",
                      action="store",
                      dest="inputdata",
                      default="Physics1600TestNode",
                      help="Name of inputdata")

    # Parse the arguments
    (options, args) = parser.parse_args()

    #### configured from the arguments
    input_rate = options.input_rate
    Moore().EvtMax = options.EvtMax
    Moore().DDDBtag = options.DDDBtag
    Moore().CondDBtag = options.CondDBtag
    Moore().Simulation = options.Simulation
    Moore().DataType = options.DataType
    if options.TCK != "":
        Moore().UseTCK = True
        Moore().InitialTCK = options.TCK
    else:
        Moore().ThresholdSettings = options.ThresholdSettings
        Moore().UseTCK = False

    #### hard coded here
    Moore().ForceSingleL0Configuration = False
    Moore().OutputLevel = 6
    Moore().RemoveInputHltRawBanks = True
    Moore().Simulation = False
    Moore().Split = ""
    Moore().CheckOdin = False
    from Configurables import CondDB
    CondDB().IgnoreHeartBeat = True
    CondDB().EnableRunChangeHandler = True
    EventSelector().PrintFreq = 100

    #### configure raw data
    importOptions('$STDOPTS/DecodeRawEvent.py')
    EventPersistencySvc().CnvServices.append('LHCb::RawDataCnvSvc')
    from Configurables import DataOnDemandSvc
    DataOnDemandSvc().AlgMap['Hlt/DecReports'] = "HltDecReportsDecoder"

    from GaudiConf import IOHelper
    if options.inputdata == "Physics1600":
        IOHelper("MDF").inputFiles([
            "mdf:root://eoslhcb.cern.ch//eos/lhcb/wg/HLT/BWdivData/Run164440_L0Filtered_0x00A2_Mika/2015NB_25ns_0x00A2_0.mdf"
        ])
    elif options.inputdata == "Physics1600TestNode":
        IOHelper("MDF").inputFiles([
            "/localdisk/bw_division/run164440_L0Filtered_0x00A2_Mika/2015NB_25ns_0x00A2_0.mdf",
            "/localdisk/bw_division/run164440_L0Filtered_0x00A2_Mika/2015NB_25ns_0x00A2_1.mdf",
            "/localdisk/bw_division/run164440_L0Filtered_0x00A2_Mika/2015NB_25ns_0x00A2_2.mdf",
            "/localdisk/bw_division/run164440_L0Filtered_0x00A2_Mika/2015NB_25ns_0x00A2_3.mdf",
            "/localdisk/bw_division/run164440_L0Filtered_0x00A2_Mika/2015NB_25ns_0x00A2_4.mdf"
        ])

    ### getting ready for the event loop
    gaudi = AppMgr(outputlevel=4)
    gaudi.ExtSvc += ['ToolSvc']
    gaudi.ExtSvc.append('DataOnDemandSvc')
    gaudi.initialize()

    ### get the list of active line names
    Lines = {}
    for level in ["Hlt1", "Hlt2"]:
        Lines[level] = set()
        for m in Sequence(level).Members:
            Lines[level].add(m.name())

    ### remove certain lines from the accounting
    remove = set(
        ["Hlt1MBNoBias", "Hlt2Transparent", "Hlt1Global", "Hlt2Global"])

    Lines["Hlt1"] -= remove
    Lines["Hlt2"] -= remove
    ### this is what I would prefer to do...
    #appendPostConfigAction( setLines(Lines["Hlt1"],Lines["Hlt2"]))

    ### option to create a tuple with all of the decisions
    if options.tuplefile != "":
        from ROOT import (TTree, TFile)
        from array import array
        TF = TFile(options.tuplefile, "RECREATE")
        DecMaps = {}  ## dicto of branches for the TTrees
        DecTrees = {}  ## dicto of TTrees
        for level in ["Hlt1", "Hlt2"]:
            DecTrees[level] = TTree('Tuple%s' % level, 'Tuple%s' % level)
            DecMaps[level] = {}
            for l in Lines[level]:
                DecMaps[level][l] = array('i', [0])
                DecTrees[level].Branch(l, DecMaps[level][l],
                                       '%sDecision/I' % l)

    ### this will be dictionary of lines and their counters for the rates
    line_stats = {}
    for line in Lines["Hlt1"].union(Lines["Hlt2"]).union(
            set(["Hlt1Global", "Hlt2Global"])):
        line_stats[line] = {"passed_incl": 0, "passed_excl": 0}

    ### counters for various regex
    stream_stats = {
        "Turbo": {
            "filter": "Hlt2.(?!.*?TurboCalib).*Turbo"
        },
        "Turcal": {
            "filter": "Hlt2.*TurboCalib"
        },
        "Full": {
            "filter": "Hlt2.(?!.*?Turbo).(?!.*?TurboCalib)"
        }
    }
    for k, v in stream_stats.iteritems():
        v["pass_this_event"] = False
        v["passed"] = 0

    print '*' * 100
    print Lines
    print line_stats
    print stream_stats
    print '*' * 100

    i = 0
    processed = 0
    #### start of the event loop
    while i < Moore().EvtMax:
        i += 1
        # run the sequences on this event
        gaudi.run(1)
        processed += 1
        if not gaudi.evtsvc()['Hlt1/DecReports']: break

        ### reset the stream counters
        for s in stream_stats.keys():
            stream_stats[s]["pass_this_event"] = False

        ### this is a nasty hack since I can't seem to switch
        ### off some of the Hlt1 lines with a post config action
        ### so I have to do my own book-keeping to see if one
        ### of the good hlt1 lines fired.
        ### I only consider events in Hlt2 if they pass my subset
        ### of good hlt1 lines.
        PassMyGlobal = {"Hlt1": False, "Hlt2": False}

        # loop over levels
        for level in ["Hlt1", "Hlt2"]:
            if level == "Hlt2" and not PassMyGlobal["Hlt1"]: continue

            # do the dec reports exist?
            # for Hlt2 this check does the job of telling us whether the event passed Hlt1
            if gaudi.evtsvc()['%s/DecReports' % level]:
                # get the dec reports
                reps = gaudi.evtsvc()['%s/DecReports' % level]
                # get the list of lines from the reports
                #lines = reps.decReports().keys()
                # counter for how many hlt lines fired in this event
                nPassed = 0
                # loop over all lines
                for line in Lines[level]:
                    # protection. why is this needed though?
                    if not line + "Decision" in reps.decReports().keys():
                        print '%s not in %s' % (line, reps.decReports().keys())
                        continue

                    # just check this once
                    LINE_FIRED = reps.decReport(line + "Decision").decision()

                    # my global counter
                    if LINE_FIRED: PassMyGlobal[level] = True

                    # does this event fire any lines that match my "streams"?
                    if LINE_FIRED and level == "Hlt2" and not line == "Hlt2Global":  # and not line in remove:
                        for s in stream_stats.keys():
                            if re.match(stream_stats[s]["filter"],
                                        line,
                                        flags=0):
                                stream_stats[s]["pass_this_event"] = True

                    # set the variable to be stored in the tuple
                    if options.tuplefile != "":
                        if LINE_FIRED:
                            DecMaps[level][line][0] = 1
                        else:
                            DecMaps[level][line][0] = 0

                    # if this is the first fired event then
                    # need to initialise the dictionary entry
                    #if not line in line_stats.keys():
                    #    line_stats[line] = {"passed_incl":0,
                    #                        "passed_excl":0}
                    # increment the counter for this line
                    if LINE_FIRED:
                        line_stats[line]["passed_incl"] += 1
                        if not "Global" in line:
                            nPassed += 1  ### for the exclusives

                # my own global counter
                if PassMyGlobal[level]:
                    line_stats["%sGlobal" % level]["passed_incl"] += 1
                # now go back and count the number of exclusive fires of this line
                # just need to ignore HltXGlobal
                for line in Lines[level]:
                    if not line + "Decision" in reps.decReports().keys():
                        continue  # protection
                    if reps.decReport(line +
                                      "Decision").decision() and nPassed == 1:
                        if not "Global" in line:
                            line_stats[line]["passed_excl"] += 1

                # fill the tree
                if options.tuplefile != "":
                    DecTrees[level].Fill()

                # stream accounting
                for s in stream_stats.keys():
                    if stream_stats[s]["pass_this_event"] == True:
                        stream_stats[s]["passed"] += 1

    # write the root file
    if options.tuplefile != "":
        TF.Write()

    # I was hoping that this would dump all of the gaudi related
    # printout before I print the summary that I'm interested in.
    # Apparently this doesn't work, but it's only really a cosmetic thing.
    #gaudi.finalize()

    sys.stdout.flush()
    #############################################
    ###### print the summary tables #############
    #############################################
    for k, v in line_stats.iteritems():
        v["processed"] = processed
    for k, v in stream_stats.iteritems():
        v["processed"] = processed

    GlobalRates = {}
    print '-' * 100
    print 'HLT rates summary starts here'
    print '-' * 100
    #### print the global rates
    print 'removed lines: %s' % remove
    print 'processed: %s' % processed
    print '%s Hlt1Lines' % (len(Lines['Hlt1']))
    print '%s Hlt2Lines' % (len(Lines['Hlt2']))
    for level in ['Hlt1', 'Hlt2']:
        rate = getrate(1.e-3 * input_rate,
                       line_stats["%sGlobal" % level]["passed_incl"],
                       line_stats["%sGlobal" % level]["processed"])
        print '%sGlobal rate = (%s+-%s)kHz' % (level, rate[0], rate[1])
    ### print the stream rates
    for k, v in stream_stats.iteritems():
        print '%s rate = %s kHz' % (k, v["passed"] / float(v["processed"]))
    #### order by inclusive rate
    for level in ['Hlt1', 'Hlt2']:
        iLine = -1  ## counter for line
        table_row("**", "*Line*", "*Incl.*", "*Excl.*")
        OrderedStats = {}
        for key, value in line_stats.iteritems():
            if level in key:
                OrderedStats[key] = value["passed_incl"]
        for line_name, rate in sorted(OrderedStats.iteritems(),
                                      key=lambda (v, k): (k, v),
                                      reverse=True):
            iLine += 1
            rate_incl = getrate(1.e-3 * input_rate,
                                line_stats[line_name]["passed_incl"],
                                line_stats[line_name]["processed"])
            rate_excl = getrate(1.e-3 * input_rate,
                                line_stats[line_name]["passed_excl"],
                                line_stats[line_name]["processed"])
            if "Global" in line_name:
                GlobalRates[level] = rate_incl
            else:
                table_row(iLine, line_name.replace("Decision", ""),
                          "%.2f+-%.2f" % (rate_incl[0], rate_incl[1]),
                          "%.2f+-%.2f" % (rate_excl[0], rate_excl[1]))

    ## do we pass the test??
    MaxRates = {"Hlt1": 400., "Hlt2": 40.}
    for level in ['Hlt1', 'Hlt2']:
        if GlobalRates[level][0] > MaxRates[level]:
            print '%s rate = %s > max = %s' % (level, GlobalRates[level][0],
                                               MaxRates[level])
        elif GlobalRates[level][0] == 0:
            print '%s rate is zero' % level
        else:
            print '%s rates OK' % level
    print '-' * 100
    print 'HLT rates summary ends here'
    print '-' * 100
    sys.stdout.flush()
Esempio n. 5
0
class CombinedMonitor(Monitor):
    def __init__(self, name, queues, condition):
        Task.__init__(self, name)
        self._config = dict()
        self._name = name
        self._inQueue = queues[0]
        self._outQueue = queues[1]
        self._condition = condition
        self._monitors = {}
        self._done = set()

    def _extra_config(self, seq):
        for n, m in self._config['monitors'].iteritems():
            self._monitors[n] = SubMonitor(m.child_type(),
                                           '_'.join([n, self.name()]))

        opts = set( self._config.keys() ) - set( self._monitors.keys() ) \
               - set( [ 'monitors' ] )

        for n, sub in self._monitors.iteritems():
            mon = sub.monitor()
            for key, val in self._config[n].iteritems():
                mon._config[key] = val
            for key in opts:
                mon._config[key] = self._config[key]
            mon._extra_config(seq)

    def initialize(self):
        # Configure the app by instantiating the AppMgr
        self._appMgr = AppMgr()

        # Get the EventDataSvc for later use
        self._evtSvc = self._appMgr.evtSvc()

        # Initialize
        for sub in self._monitors.values():
            mon = sub.monitor()
            mon._appMgr = self._appMgr
            mon._evtSvc = self._evtSvc
            mon._pre_init()

        if not self._appMgr.state() == 2:
            self._appMgr.initialize()

        for sub in self._monitors.values():
            mon = sub.monitor()
            mon._post_init()

        self._condition.acquire()
        self._condition.notify()
        self._condition.release()

    def run(self):

        nEvents = self._config['EvtMax']
        event = 1
        while True:
            self._condition.acquire()
            self._appMgr.run(1)
            # Get the ODIN
            if not self._evtSvc['DAQ']:
                self.done()
                break

            info = {}
            for n, sub in self._monitors.iteritems():
                # Get the sub infos
                infos = []
                sub_mon = sub.monitor()
                sub_info = sub_mon.make_info()
                if sub_info: infos.append(sub_info)
                sub_info = None
                try:
                    sub_info = sub.outQueue().get(False)
                except IOError:
                    pass
                except Queue.Empty:
                    pass
                if sub_info: infos.append(sub_info)
                if len(infos) != 0:
                    info[n] = infos

            event += 1
            if len(info) != 0: self._outQueue.put(info)
            if event == nEvents:
                self.done()
                break
            else:
                ## self._condition.wait()
                self._condition.release()
            try:
                message = self._inQueue.get(False)
                if message == "BREAK":
                    for sub in self._monitors.itervalues():
                        sub.inQueue().put(message)
                self._condition.release()
                break
            except Queue.Empty:
                pass
Esempio n. 6
0
class Monitor(Task):
    def __init__(self, name, queues, condition):
        Task.__init__(self, name)
        self._config = dict()
        self._name = name
        self._inQueue = queues[0]
        self._outQueue = queues[1]
        self._condition = condition

    def configure(self, configuration):
        from Configurables import LHCbApp
        app = LHCbApp()
        for (attr, value) in configuration.items():
            if hasattr(app, attr):
                setattr(app, attr, value)
            self._config[attr] = value

        EventSelector().Input = self._config['Input']
        if 'Catalogs' in self._config.keys():
            FileCatalog().Catalogs = self._config['Catalogs']

        from Configurables import DecodeRawEvent
        importOptions("$L0DUOPTS/L0DUConfig.opts")
        EventPersistencySvc().CnvServices.append('LHCb::RawDataCnvSvc')

        EventSelector().PrintFreq = 1000

        from Configurables import CondDB
        CondDB().Online = True

        from Configurables import GaudiSequencer as Sequence
        from Configurables import createODIN, HltRoutingBitsFilter
        seq = Sequence("MonitorSequence")
        physFilter = HltRoutingBitsFilter("PhysFilter",
                                          RequireMask=[0x0, 0x4, 0x0])
        co = createODIN()
        seq.Members = [co, physFilter]

        from DAQSys.Decoders import DecoderDB
        from itertools import product
        for stage, t in product(('Hlt1', 'Hlt2'), ('Dec', 'Sel', 'Vertex')):
            an = "{0}{1}ReportsDecoder".format(stage, t)
            seq.Members += [
                DecoderDB["Hlt%sReportsDecoder/%s" % (t, an)].setup()
            ]

        ApplicationMgr().TopAlg = [seq]
        self._extra_config(seq)

    def _extra_config(self, seq):
        pass

    def _pre_init(self):
        pass

    def _post_init(self):
        self._filter = self._appMgr.algorithm('PhysFilter')._ialg

    def initialize(self):
        # Configure the app by instantiating the AppMgr
        self._appMgr = AppMgr()

        # Get the EventDataSvc for later use
        self._evtSvc = self._appMgr.evtSvc()

        # Initialize
        self._pre_init()
        self._appMgr.initialize()
        self._post_init()

        self._condition.acquire()
        self._condition.notify()
        self._condition.release()

    def run(self):

        nEvents = self._config['EvtMax']
        event = 1
        while True:
            self._condition.acquire()
            self._appMgr.run(1)
            # Get the ODIN
            if not self._evtSvc['DAQ']:
                self.done()
                break
            # Get the event time
            info = self.make_info()
            if not info:
                self._condition.release()
                continue

            event += 1
            if info: self._outQueue.put(info)
            if event == nEvents:
                self.done()
                break
            else:
                ## self._condition.wait()
                self._condition.release()
            try:
                message = self._inQueue.get(False)
                if message == "BREAK":
                    self._condition.release()
                    break
            except Queue.Empty:
                pass

    def make_info(self):
        pass

    def finalize(self):
        self._appMgr.stop()
        self._appMgr.finalize()

    def done(self):
        # Max events reached, signal done to the main process
        self._outQueue.put('DONE')
        self._condition.release()

    def name(self):
        return self._name

    def filterPassed(self):
        return self._filter.filterPassed()
Esempio n. 7
0
class EventWriter(Task):
    def __init__(self, name, queues, condition):
        Task.__init__(self, name)
        self._inQueue = queues[0]
        self._outQueue = queues[1]
        self._condition = condition
        self._config = dict()

    def configure(self, configuration):
        # Configure the writing process
        from Configurables import LHCbApp
        for (attr, value) in configuration.items():
            if hasattr(LHCbApp, attr):
                setattr(LHCbApp, attr, value)
            self._config[attr] = value

        if not 'Output' in self._config:
            print "An output filename must be specified."
            raise Exception

        if not 'Input' in self._config:
            print "Input must be specified."
            raise Exception

        EventDataSvc().RootCLID = 1
        from Configurables import LHCb__RawDataCnvSvc as RawDataCnvSvc
        EventPersistencySvc().CnvServices.append(
            RawDataCnvSvc('RawDataCnvSvc'))

        EventSelector().Input = self._config['Input']
        EventSelector().PrintFreq = 100
        FileCatalog().Catalogs = self._config['Catalogs']

        from Configurables import LHCb__MDFWriter as MDFWriter
        writer = MDFWriter('MDFWriter',
                           Compress=0,
                           ChecksumType=1,
                           GenerateMD5=True,
                           Connection=self._config['Output'])
        writer.OutputLevel = INFO
        ApplicationMgr().OutStream = [writer]

    def initialize(self):
        # Initialize the application manager
        self._appMgr = AppMgr()
        self._appMgr.initialize()
        # Disable the execution of the MDFWriter
        algo = self._appMgr.algorithm('MDFWriter')
        self._appMgr.algorithm('MDFWriter').Enable = False

    def run(self):
        # Run the required number of events
        nEvents = self._config['EvtMax']
        event = 0

        nWait = self._config['NPrevious']
        wait = 0

        while True:
            write = self._inQueue.get()
            if type(write) == type(""):
                if write == "DONE":
                    # self.notify()
                    break
            if write == True:
                self._appMgr.algorithm('MDFWriter').Enable = True
                # Write the events
                sc = self._appMgr.run(wait + 1)
                if sc == FAILURE:
                    # No more events in input
                    break
                wait = 0
                self._appMgr.algorithm('MDFWriter').Enable = False
                # print "Writing event " + str( event )
                # self._appMgr.algorithm('MDFWriter').execute()
            else:
                if wait < nWait:
                    wait += 1
                else:
                    sc = self._appMgr.run(1)
                    if sc == FAILURE:
                        # No more events in input
                        break

            # Notify the main program
            self.notify()
            event += 1

    def finalize(self):
        self._appMgr.exit()

    def notify(self):
        self._condition.acquire()
        self._condition.notify()
        self._condition.release()
Esempio n. 8
0
class EventReporter(Task):
    def __init__(self, name, queues, condition):
        Task.__init__(self, name)
        self._config = dict()
        self._inQueue = queues[0]
        self._outQueue = queues[1]
        self._condition = condition

    def configure(self, configuration):
        from Configurables import LHCbApp
        app = LHCbApp()
        for (attr, value) in configuration.items():
            if hasattr(app, attr):
                setattr(app, attr, value)
            self._config[attr] = value

        EventSelector().Input = self._config['Input']
        FileCatalog().Catalogs = self._config['Catalogs']

        EventDataSvc().RootCLID = 1
        from Configurables import LHCb__RawDataCnvSvc as RawDataCnvSvc
        EventPersistencySvc().CnvServices.append(
            RawDataCnvSvc('RawDataCnvSvc'))

        EventSelector().PrintFreq = 100

        from Configurables import GaudiSequencer as Sequence
        from Configurables import createODIN
        seq = Sequence("OdinSequence")
        co = createODIN()
        seq.Members = [co]
        ApplicationMgr().TopAlg = [seq]

    def initialize(self):
        self._appMgr = AppMgr()
        self._appMgr.initialize()

    def run(self):
        evt = self._appMgr.evtsvc()
        nEvents = self._config['EvtMax']
        event = 1
        while True:
            self._condition.acquire()
            self._appMgr.run(1)
            # Get the ODIN
            odin = evt['DAQ/ODIN']
            info = None
            if odin:
                info = (odin.runNumber(), odin.eventNumber())
            else:
                self.done()
                break
            # Put the event info on the queue
            self._outQueue.put(info)
            event += 1
            if event == nEvents:
                self.done()
                break
            else:
                self._condition.wait()
                self._condition.release()

    def finalize(self):
        self._appMgr.exit()

    def done(self):
        # Max events reached, signal done to the main process
        self._outQueue.put('DONE')
        self._condition.release()
Esempio n. 9
0
class DecisionReporter(Task):
    def __init__(self, name, queues, condition):
        Task.__init__(self, name)
        self._config = dict()
        self._inQueue = queues[0]
        self._outQueue = queues[1]
        self._condition = condition

    def configure(self, configuration):
        from Configurables import Moore
        moore = Moore()
        for (attr, value) in configuration.items():
            if attr in moore.__slots__:
                setattr(moore, attr, value)
            self._config[attr] = value

        hlt1Lines = self._config['Hlt1Lines']
        hlt2Lines = self._config['Hlt2Lines']

        #if 'L0' in self._config and self._config[ 'L0' ]:
        #from Configurables import L0MuonAlg
        #L0MuonAlg( "L0Muon" ).L0DUConfigProviderType = "L0DUConfigProvider"

        if 'Dataset' in self._config:
            from PRConfig import TestFileDB
            TestFileDB.test_file_db[self._config['Dataset']].run(
                configurable=Moore())
        else:
            EventSelector().Input = self._config['Input']

        EventSelector().PrintFreq = 100
        FileCatalog().Catalogs = self._config['Catalogs']

        config = Config(hlt1Lines, hlt2Lines)
        appendPostConfigAction(config.postConfigAction)

    def initialize(self):
        self._appMgr = AppMgr()
        self._appMgr.initialize()

    def run(self):
        evt = self._appMgr.evtsvc()
        nEvents = self._config['EvtMax']
        event = 1
        while True:
            if self.wait():
                self._condition.acquire()
            self._appMgr.run(1)
            # Check if there is still event data
            if not bool(evt['/Event']):
                self.done()
                break
            odin = evt['DAQ/ODIN']
            reports = dict()
            reports['event'] = odin.eventNumber()
            reports['run'] = odin.runNumber()
            # Grab the HltDecReports and put the decisions in a dict by line name
            if evt['Hlt1/DecReports']:
                decReports1 = evt['Hlt1/DecReports']
                names1 = decReports1.decisionNames()
                for name in names1:
                    reports[name] = decReports1.decReport(name).decision()
            if evt['Hlt2/DecReports']:
                decReports2 = evt['Hlt2/DecReports']
                names2 = decReports2.decisionNames()
                for name in names2:
                    reports[name] = decReports2.decReport(name).decision()
            # Put our dict on the queue
            self._outQueue.put(reports)
            event += 1
            if event == nEvents:
                self.done()
                break
            elif self.wait():
                self._condition.wait()
                self._condition.release()

    def finalize(self):
        self._appMgr.exit()

    def done(self):
        # Max events reached, signal done to the main process
        self._outQueue.put('DONE')
        if self.wait():
            self._condition.release()

    def wait(self):
        if 'Wait' in self._config:
            return self._config['Wait']
        else:
            return True