示例#1
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 )
示例#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
示例#3
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()