Example #1
0
 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
Example #2
0
    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()
Example #3
0
def GetFSRdict( filename, queue ):


  FSR = { "TimeSpanFSR" :  {'earliest': 0, 'latest': 0},
          "LumiFSRBeamCrossing" :  {'key': 0, 'incr': 0, 'integral':0},
          "LumiFSRBeam1" :  {'key': 0, 'incr': 0, 'integral':0},
          "LumiFSRBeam2" :  {'key': 0, 'incr': 0, 'integral':0},
          "LumiFSRNoBeam" :  {'key': 0, 'incr': 0, 'integral':0},
           "EventCountFSR" :  {'input': 0, 'output': 0, 'statusFlag': 0}}

  options  = "from LumiAlgs.LumiFsrReaderConf import LumiFsrReaderConf as LumiFsrReader; LumiFsrReader().OutputLevel =  INFO; LumiFsrReader().inputFiles = ['%s'] ;" %filename
  options += "LumiFsrReader().Persistency='ROOT'; LumiFsrReader().EvtMax = 1; from Configurables import LHCbApp; LHCbApp().Persistency='ROOT';  from Configurables import CondDB, DDDBConf;"
  options += " CondDB().UseLatestTags=['%s']; DDDBConf(DataType='%s');"%( 2011, 2011 )
  exec options
  app = AppMgr()
  app.run( 1 )
  fsr = app.filerecordsvc()

  lst = fsr.getHistoNames()

  if lst :
    for l in lst :

      ob = fsr.retrieveObject( l )


      if "LumiFSR" in l:

        assert ob.numberOfObjects() == 1
        k = ob.containedObject( 0 )
        runs, files, keys, increment, integral = LumiFSR( k )

        FSR[l[l.rfind( '/' ) + 1:]]['runs'] = runs
        FSR[l[l.rfind( '/' ) + 1:]]['files'] = files
        FSR[l[l.rfind( '/' ) + 1:]]['key'] = keys
        FSR[l[l.rfind( '/' ) + 1:]]['incr'] = increment
        FSR[l[l.rfind( '/' ) + 1:]]['integral'] = integral



      if "TimeSpanFSR" in l:

        FSR["TimeSpanFSR"]['earliest'] = ob.containedObject( 0 ).earliest()
        FSR["TimeSpanFSR"]['latest'] = ob.containedObject( 0 ).latest()

      if "EventCountFSR" in l:

        FSR["EventCountFSR"]['input'] = ob.input()
        FSR["EventCountFSR"]['output'] = ob.output()
        FSR["EventCountFSR"]['statusFlag'] = ob.statusFlag()

  app.stop()
  app.finalize()

  queue.put( FSR )
Example #4
0
def Reader( readerType, filename, qacross, qToEngine ) :
  #
  # Process for reading a file
  # One process for reading Serial File, another for Parallel File
  #
  # First the order of events is determined, (parallel != serial, usually)
  #
  # Then the events are run *in order* using AppMgr().runSelectedEvents(pfn, evtNumber)
  # on both Serial-Reader and Parallel-Reader processes.
  #
  # The string repr of everything in the TES is placed in a dictionary and
  # sent to the comparison Process, which compares the two dictionaries
  #
  a = AppMgr()
  sel = a.evtsel()
  evt = a.evtsvc()

  header = '/Event/Rec/Header'
  sel.open( filename )
  ct = 0
  order = {}
  fname = filename[4:] # runSelectedEvents doesn't need the "PFN:" prefix

  # determine the ordering
  while True :
    a.run( 1 )
    if evt[header] :
      eNumber = int( evt[header].evtNumber() )
      order[eNumber] = ct
      ct += 1
    else : break

  if readerType == SER :
    # send the ordering details to the parallel-reader
    order = switchDict( order )
    qacross.put( order )
    qacross.put( None )
    # changeName
    serOrder = order
  elif readerType == PAR :
    # receive the serial ordering from queue,  and send ordering to SerialReader
    for serOrder in iter( qacross.get, None ) : pass
    lsks = len( serOrder.keys() )
    lpks = len( order.keys() )
    print 'Events in Files (serial/parallel) : %i / %i' % ( lsks, lpks )

  # now run files in the order specified by the serial ordering
  # and send them one by one to the comparison engine
  for i in iter( serOrder.keys() ) :
    if readerType == PAR  : i = order[serOrder[i]]

    a.runSelectedEvents( fname, i )
    lst = evt.getList()

    lst.sort()
    ascii = dict( [ ( l, ( evt[l].__class__.__name__, evt[l].__repr__() ) ) for l in lst ] )
    qToEngine.put( ascii )
  qToEngine.put( None )
  print '%s Reader Finished' % ( readerType )
Example #5
0
    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()
Example #6
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()
Example #7
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()
Example #8
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()
Example #9
0
#
# Stolen from I. Belyaev at http://indico.cern.ch/getFile.py/access?contribId=1&sessionId=7&resId=2&materialId=0&confId=25000
#
from Gaudi.Configuration import *

importOptions('demo2.opts')

import GaudiKernel.SystemOfUnits as Units

from GaudiPython import AppMgr

gaudi = AppMgr()

from LoKiPhys.decorators import *
from LoKiCore.functions import monitor

evtSvc = gaudi.evtSvc()

minPT = MINTREE('mu+' == ABSID, PT) / Units.GeV
# minPT = monitor(MINTREE( 'mu+' ==ABSID , PT ) / Units.GeV )

for i in range(1, 100):
    gaudi.run(1)
    psis = evtSvc['Phys/Psi2MuMu/Particles']

    for psi in psis:
        print ' Mass=%s, ptMin=%s' % (M(psi), minPT(psi))
Example #10
0
    def _test_spirce_candidate(self):
        fun = TC_Source >> (TrP > 90)
        print type(fun)
        #self.assertEqual(len(result),1 )


# =============================================================================
if '__main__' == __name__:

    print '*' * 120
    print __doc__
    print ' Author  : %s ' % __author__
    print ' Version : %s ' % __version__
    print ' Date    : %s ' % __date__
    print '*' * 120
    gaudi = AppMgr()
    unittest.main()

#    Hlt = LoKiCore.basic.cpp.Hlt
#    LoKi = LoKiCore.basic.cpp.LoKi
#    Hlt.Candidate.ConstVector = LoKiCore.basic.std.vector('const Hlt::Candidate*')
#
#
#    for item in cs:
#        print 'track: TrP=%s' % TrP(item.currentStage()._get())
#
#    fun1 = select(TC_ALL) >> ( monitor ( TrP ) > 90)
#
#    mc = LoKi.L0.L0MuonCut()
#    fun2 = select(TC_ALL) >> mc
#
Example #11
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
Example #12
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
Example #13
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
Example #14
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()
Example #15
0
# decides to do importOptions or exec)
options = ["importOptions(%r)" % f for f in args]

# "execute" the configuration script generated (if any)
from Gaudi.Configuration import logging
if options:
    g = {}
    l = {}
    exec "from Gaudi.Configuration import *" in g, l
    for o in options:
        logging.debug(o)
        exec o in g, l

## Instantiate application manager
from GaudiPython.Bindings import AppMgr
appMgr = AppMgr()
evtSel = appMgr.evtSel()
evtSel.OutputLevel = 1
mainSeq = appMgr.algorithm("EscherSequencer")
print evtSel.Input

for i in range(opts.numiter):
    print "Iteration nr: ", i
    mainSeq.Enable = False
    evtSel.rewind()
    mainSeq.Enable = True
    # steer the monitor sequence depending on the iteration
    appMgr.algorithm('AlignMonitorSeq').Enable = (i == 0)
    appMgr.algorithm('Moni').Enable = (i == 0)
    if opts.numiter > 1:
        appMgr.algorithm('AlignPostMonitorSeq').Enable = (i == opts.numiter -
Example #16
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()
Example #17
0
 def initialize(self):
     self._appMgr = AppMgr()
     self._appMgr.initialize()
Example #18
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()
Example #19
0
def main():

    # Setup the option parser
    usage = "usage: %prog [options] inputfile <inputfile>"
    parser = optparse.OptionParser(usage=usage)
    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='MC09-20090602',
                      help="DDDBTag to use")
    parser.add_option("--conddbtag",
                      action="store",
                      dest="CondDBtag",
                      default='sim-20090402-vc-md100',
                      help="CondDBtag to use")
    parser.add_option("--settings",
                      action="store",
                      dest="ThresholdSettings",
                      default='Physics_25ns_September2015',
                      help="ThresholdSettings to use")
    parser.add_option("-s",
                      "--simulation",
                      action="store_true",
                      dest="Simulation",
                      default=False,
                      help="Run on simulated data")
    parser.add_option("--dbsnapshot",
                      action="store_true",
                      dest="UseDBSnapshot",
                      default=False,
                      help="Use a DB snapshot")
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="Verbose",
                      default=False,
                      help="Verbose output")
    parser.add_option("--rch",
                      action="store_true",
                      dest="RunChangeHandler",
                      default=False,
                      help="Use the RunChangeHandler")

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

    # Make sure there is data to run on

    # Put the options into the Moore configurable
    Moore().ThresholdSettings = options.ThresholdSettings

    #Moore().OutputLevel="VERBOSE"
    Moore().EvtMax = options.EvtMax

    #Moore().UseDBSnapshot = options.UseDBSnapshot # DEPRECATED
    from Configurables import CondDB
    CondDB().UseDBSnapshot = options.UseDBSnapshot
    #
    Moore().DDDBtag = options.DDDBtag
    Moore().CondDBtag = options.CondDBtag
    Moore().Simulation = options.Simulation
    Moore().DataType = options.DataType
    Moore().inputFiles = args

    EventSelector().PrintFreq = 100

    # Instanciate the AppMgr to get the Hlt lines from their Sequences
    appMgr = AppMgr()

    hlt1Seq = Sequence("Hlt1")
    hlt1Lines = set()
    for m in hlt1Seq.Members:
        hlt1Lines.add(m.name())

    hlt2Seq = Sequence("Hlt2")
    hlt2Lines = set()
    for m in hlt2Seq.Members:
        hlt2Lines.add(m.name())

    # The AppMgr is no longer needed
    appMgr.exit()

    print "HLT1LINES"
    for line in hlt1Lines:
        print line
    print "HLT2LINES"
    for line in hlt2Lines:
        print line
Example #20
0
def main():

    # Setup the option parser
    usage = "usage: %prog [options] inputfile <inputfile>"
    parser = optparse.OptionParser(usage=usage)
    parser.add_option("-d",
                      "--datatype",
                      action="store",
                      dest="DataType",
                      default="2009",
                      help="DataType to run on.")
    parser.add_option("-n",
                      "--evtmax",
                      type="int",
                      action="store",
                      dest="EvtMax",
                      default=1e4,
                      help="Number of events to run")
    parser.add_option("--dddbtag",
                      action="store",
                      dest="DDDBtag",
                      default='MC09-20090602',
                      help="DDDBTag to use")
    parser.add_option("--conddbtag",
                      action="store",
                      dest="CondDBtag",
                      default='sim-20090402-vc-md100',
                      help="CondDBtag to use")
    parser.add_option("--settings",
                      action="store",
                      dest="ThresholdSettings",
                      default='Physics_10000Vis_1000L0_40Hlt1_Apr09',
                      help="ThresholdSettings to use")
    parser.add_option("-s",
                      "--simulation",
                      action="store_true",
                      dest="Simulation",
                      default=False,
                      help="Run on simulated data")
    parser.add_option("--dbsnapshot",
                      action="store_true",
                      dest="UseDBSnapshot",
                      default=False,
                      help="Use a DB snapshot")
    parser.add_option("--snd",
                      action="store",
                      dest="SnapshotDirectory",
                      default='/user/graven/MOORE/conditions',
                      type="string",
                      help="DB Snapshot directory")
    parser.add_option("--oracle",
                      action="store_true",
                      dest="UseOracle",
                      default=False,
                      help="Use Oracle")
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="Verbose",
                      default=False,
                      help="Verbose output")
    parser.add_option("--acceptslow",
                      action="store_true",
                      dest="AcceptIfSlow",
                      default=False,
                      help="Accept slow events")
    parser.add_option("--hlt1lines",
                      action="store",
                      dest="Hlt1Lines",
                      default="",
                      help="Colon seperated list of additional hlt1 lines")
    parser.add_option("--hlt2lines",
                      action="store",
                      dest="Hlt2Lines",
                      default="",
                      help="Colon seperated list of additional hlt2 lines")
    parser.add_option("--rch",
                      action="store_true",
                      dest="RunChangeHandler",
                      default=False,
                      help="Use the RunChangeHandler")
    parser.add_option("--l0",
                      action="store_true",
                      dest="L0",
                      default=False,
                      help="Rerun L0")
    parser.add_option("--site",
                      action="store",
                      type="string",
                      dest="Site",
                      default="",
                      help="Site at which we run")
    parser.add_option("--tempdir",
                      action="store",
                      type="string",
                      dest="Tempdir",
                      default="/tmpdir",
                      help="Tempdir for the filestager")
    parser.add_option("--tuplefile",
                      action="store",
                      type="string",
                      dest="TupleFile",
                      default="tuples.root",
                      help="NTuple filename")
    parser.add_option("-f",
                      "--filestager",
                      action="store_true",
                      dest="FileStager",
                      default=False,
                      help="Use the filestager")
    parser.add_option(
        "-c",
        "--verbose_classes",
        action="store",
        type="string",
        dest="VerboseClasses",
        default="",
        help="Colon seperated list of classes to be made verbose.")

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

    # Put the options into the Moore configurable
    Moore().ThresholdSettings = options.ThresholdSettings

    Moore().Verbose = options.Verbose
    Moore().EvtMax = options.EvtMax

    Moore().UseDBSnapshot = options.UseDBSnapshot
    Moore().DBSnapshotDirectory = options.SnapshotDirectory
    Moore().DDDBtag = options.DDDBtag
    Moore().CondDBtag = options.CondDBtag
    Moore().Simulation = options.Simulation
    Moore().DataType = options.DataType
    Moore().EnableAcceptIfSlow = options.AcceptIfSlow
    Moore().outputFile = ""
    Moore().ForceSingleL0Configuration = False
    Moore().RequireRoutingBits = [0x0, 0x4, 0x0]
    Moore().L0 = options.L0
    Moore().ReplaceL0BanksWithEmulated = options.L0

    if options.UseOracle:
        CondDB().UseOracle = True
        site = 'UNKNOWN'
        try:
            site = os.environ['DIRACSITE']
        except KeyError:
            if len(options.Site):
                site = options.Site
                config = ConfigLFC(site)
                appendPostConfigAction(config.setLFCSite)

    # Inputdata is now handled through separate option files, this is for
    # testing/convenience
    if len(args):
        Moore().inputFiles = args

    try:
        descriptor = EventSelector().Input[0]
        if descriptor.find(".raw") != -1:
            from Configurables import LHCb__RawDataCnvSvc as RawDataCnvSvc
            EventPersistencySvc().CnvServices.append(
                RawDataCnvSvc('RawDataCnvSvc'))
        elif descriptor.find(".dst") != -1:
            importOptions('$GAUDIPOOLDBROOT/options/GaudiPoolDbRoot.opts')
    except IndexError:
        pass

    freq = 0
    if (len(options.VerboseClasses)):
        freq = 1
    else:
        freq = 100
    EventSelector().PrintFreq = freq

    # RunChangeHandler
    if options.RunChangeHandler:
        Moore().EnableRunChangeHandler = True
        from Configurables import MagneticFieldSvc
        MagneticFieldSvc().UseSetCurrent = True

    # XMLSummary
    from Configurables import LHCbApp
    LHCbApp().XMLSummary = 'summary.xml'

    # Use the filestager?
    if options.FileStager:
        from FileStager.Configuration import configureFileStager
        configureFileStager()

    # Put the comma separated lists of lines into lists
    hlt1Lines = []
    for line in options.Hlt1Lines.split(";"):
        if (len(line.strip())):
            hlt1Lines.append(line)

    hlt2Lines = []
    for line in options.Hlt2Lines.split(";"):
        if (len(line.strip())):
            hlt2Lines.append(line)

    # parse the specification of the classes to set to verbose
    verboseClasses = []
    for cl in options.VerboseClasses.split(";"):
        cl = cl.strip()
        if (len(cl)):
            verboseClasses.append(cl.replace("::", "__"))

    # Instantiate the class to apply the required configuration
    config = Config(hlt1Lines, hlt2Lines)
    appendPostConfigAction(config.postConfigAction)

    # Set the OutputLevel for requested classed
    if len(verboseClasses):
        configOL = ConfigOutputLevel(verboseClasses, 1)
        appendPostConfigAction(configOL.setOutputLevel)

    # Add the TupleHltDecReports alg to the sequence
    if options.TupleFile:
        tupleAlg = TupleHltDecReports("TupleHltDecReports")
        addTupleAlg = ConfigTupleAlg(filename=options.TupleFile)
        appendPostConfigAction(addTupleAlg.addTupleAlg)

    # Instantiate the AppMgr
    appMgr = AppMgr()

    # Make sure that we have Hlt lines to run
    if not len(Sequence("Hlt1").Members) or not len(Sequence("Hlt2").Members):
        print "error, no lines to run\n"
        return 2

    # Run the required number of events
    sc = appMgr.run(Moore().EvtMax)
    if sc.isFailure(): return 2

    # Done
    sc = appMgr.exit()
    if sc.isFailure():
        return 2
    else:
        return 0