Пример #1
0
    def __init__(self, appName, msgConn, req_id, req_type, user, header, label,
                 user_ip, client_ip):
        self.msgConn = msgConn
        self.arclinkRequest = DataModel.ArclinkRequest.Create()
        self.arclinkRequest.setCreated(Core.Time.GMT())
        self.arclinkRequest.setRequestID(req_id)
        self.arclinkRequest.setUserID(str(user))
        self.arclinkRequest.setClientID(appName)
        if user_ip: self.arclinkRequest.setUserIP(user_ip)
        if client_ip: self.arclinkRequest.setClientIP(client_ip)
        self.arclinkRequest.setType(req_type)
        self.arclinkRequest.setLabel(label)
        self.arclinkRequest.setHeader(header)

        self.averageTimeWindow = Core.TimeSpan(0.)
        self.totalLineCount = 0
        self.okLineCount = 0

        self.requestLines = []
        self.statusLines = []
Пример #2
0
    def getDACache(self):
        if not self._daEnabled:
            return None

        now = Core.Time.GMT()
        # check if cache is still valid
        if self._daCache is None or now > self._daCache.validUntil():

            if self.query() is None or \
               not self.query().driver().isConnected():
                dbInt = IO.DatabaseInterface.Open(self.databaseURI())
                if dbInt is None:
                    Logging.error('failed to connect to database')
                    return self._daCache
                else:
                    self.setDatabase(dbInt)

            da = DataModel.DataAvailability()
            self.query().loadDataExtents(da)
            validUntil = now + Core.TimeSpan(self._daCacheDuration, 0)
            self._daCache = DataAvailabilityCache(self, da, validUntil)

        return self._daCache
Пример #3
0
    def run(self):
        if not self._processCommandLineOptions():
            return False

        dbq = self.query()
        ep = DataModel.EventParameters()

        # If we got an event ID as command-line argument...
        if self._evid:
            # Retrieve event from DB
            evt = dbq.loadObject(DataModel.Event.TypeInfo(), self._evid)
            evt = DataModel.Event.Cast(evt)
            if evt is None:
                raise TypeError, "unknown event '" + self._evid + "'"
            # If start time was not specified, compute it from origin time.
            if self._startTime is None:
                orid = evt.preferredOriginID()
                org = dbq.loadObject(DataModel.Origin.TypeInfo(), orid)
                org = DataModel.Origin.Cast(org)
                t0 = org.time().value()
                self._startTime = t0 + Core.TimeSpan(-before)
                self._endTime = t0 + Core.TimeSpan(after)
                print >> sys.stderr, "time window: %s ... %s" % (
                    self._startTime, self._endTime)

            if not self.commandline().hasOption("no-origins"):
                # Loop over all origins of the event
                for org in dbq.getOrigins(self._evid):
                    org = DataModel.Origin.Cast(org)
                    # We only look for manual events.
                    if org.evaluationMode() != DataModel.MANUAL:
                        continue
                    self._orids.append(org.publicID())

        # FIRST the pick query loop, THEN the amplitude query loop!
        # NESTED QUERY LOOPS ARE NOT ALLOWED!!!
        picks = []
        for obj in dbq.getPicks(self._startTime, self._endTime):
            pick = DataModel.Pick.Cast(obj)
            if pick:
                if pick.evaluationMode(
                ) == DataModel.MANUAL and self.commandline().hasOption(
                        "no-manual-picks"):
                    continue
                if pick.waveformID().networkCode() in self._networkBlacklist:
                    continue
                picks.append(pick)
                ep.add(pick)
        print >> sys.stderr, "loaded %d picks                         " % ep.pickCount(
        )

        for i, pick in enumerate(picks):
            # amplitude query loop for each pick, see above comments.
            for obj in dbq.getAmplitudesForPick(pick.publicID()):
                ampl = DataModel.Amplitude.Cast(obj)
                if ampl:
                    ep.add(ampl)
            sys.stderr.write("loaded amplitudes for %d of %d picks\r" %
                             (i, len(picks)))
        print >> sys.stderr, "loaded %d amplitudes                    " % ep.amplitudeCount(
        )

        if not self.commandline().hasOption("no-origins"):
            for i, orid in enumerate(self._orids):
                # XXX There was occasionally a problem with:
                #   org = dbq.loadObject(DataModel.Origin.TypeInfo(), orid)
                #   org = DataModel.Origin.Cast(org)
                # NOTE when org was directly overwritten.
                # resulting in a segfault. The reason is not clear, but
                # is most probably in the Python wrapper. The the segfault
                # can be avoided by creating an intermediate object 'obj'.
                obj = dbq.loadObject(DataModel.Origin.TypeInfo(), orid)
                org = DataModel.Origin.Cast(obj)
                ep.add(org)
                sys.stderr.write("loaded %d of %d manual origins\r" %
                                 (i, len(self._orids)))
            print >> sys.stderr, "loaded %d manual origins                " % ep.originCount(
            )

        # finally dump event parameters as formatted XML archive to stdout
        ar = IO.XMLArchive()
        ar.setFormattedOutput(True)
        ar.create("-")
        ar.writeObject(ep)
        ar.close()
        del ep
        return True
Пример #4
0
    def _runBatchMode(self):
        ep = self._readEventParametersFromXML()

        # collect the objects
        objs = []
        while ep.pickCount() > 0:
            # FIXME: The cast hack forces the SC3 refcounter to be increased.
            pick = DataModel.Pick.Cast(ep.pick(0))
            ep.removePick(0)
            objs.append(pick)
        while ep.amplitudeCount() > 0:
            # FIXME: The cast hack forces the SC3 refcounter to be increased.
            ampl = DataModel.Amplitude.Cast(ep.amplitude(0))
            ep.removeAmplitude(0)
            objs.append(ampl)
        while ep.originCount() > 0:
            # FIXME: The cast hack forces the SC3 refcounter to be increased.
            origin = DataModel.Origin.Cast(ep.origin(0))
            ep.removeOrigin(0)
            objs.append(origin)
        del ep

        # DSU sort all objects by object creation time
        sortlist = []
        for obj in objs:
            # discard objects that have no creationInfo attribute
            try:
                t = obj.creationInfo().creationTime()
            except:
                continue

            if self._startTime is not None and t < self._startTime:
                continue
            if self._endTime is not None and t > self._endTime:
                continue
            sortlist.append((t, obj))
        sortlist.sort()

        time_of_1st_object, obj = sortlist[0]
        time_of_playback_start = Core.Time.GMT()

        ep = DataModel.EventParameters()
        pickampl = {}

        # go through the sorted list of object and process them sequentially
        for t, obj in sortlist:
            if self.isExitRequested(): return

            if self.speed:
                t = time_of_playback_start + Core.TimeSpan(
                    float(t - time_of_1st_object) / self.speed)
                while t > Core.Time.GMT():
                    time.sleep(0.1)

            if obj.ClassName() not in ["Pick", "Amplitude", "Origin"]:
                continue

            DataModel.Notifier.Enable()
            ep.add(obj)
            msg = DataModel.Notifier.GetMessage()
            if self.commandline().hasOption("test"):
                sys.stderr.write("Test mode - not sending %-10s %s\n" %
                                 (obj.ClassName(), obj.publicID()))
            else:
                if self.connection().send(msg):
                    sys.stderr.write("Sent %s %s\n" %
                                     (obj.ClassName(), obj.publicID()))
                else:
                    sys.stderr.write("Failed to send %-10s %s\n" %
                                     (obj.ClassName(), obj.publicID()))
            DataModel.Notifier.Disable()
            self.sync()

        return
Пример #5
0
    return wrap
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
class RequestTrackerDB(object):

	def __init__(self, dbWrite, req, user):
		self.dbWrite = dbWrite
		self.arclinkRequest = DataModel.ArclinkRequest.Create()
		self.arclinkRequest.setCreated(Core.Time.FromString(str(req.reqDate), "%Y-%m-%d %H:%M:%S"))
		self.arclinkRequest.setRequestID(req.reqID)
		self.arclinkRequest.setUserID(user)
		self.arclinkRequest.setType(req.reqType)
		self.arclinkRequest.setLabel(str(req.reqLabel))
		self.arclinkRequest.setHeader(" ".join(req.constrains))

		self.averageTimeWindow = Core.TimeSpan(0.)
		self.totalLineCount = req.requestLineCount()
		#self.okLineCount = self.totalLineCount - req.errorLineCount()
		self.okLineCount = 0

		for line in req.getRequestLines():
			self.line_status(line)

		for line in req.getVolumeLines():
			self.volume_status(line)

		self.request_status("END", "") # FIXME


	@catch
	def send(self):