Examples of THistoryRecord


Examples of de.desy.tine.server.histories.THistoryRecord

    return getLocalHistoryRecord(property,device,0,TFormat.CF_NULL);
  }
  public THistoryRecord getLocalHistoryRecord(String property,String device,int size,short format)
  {
    int listsize = gLclHstList.size();
    THistoryRecord lhr = null;
    if (property == null || property.length() == 0) return null;
    for (int i=0; i<listsize; i++)
    {
      lhr = (THistoryRecord)gLclHstList.get(i);
      if (lhr.getPrp().compareTo(property) != 0) continue;
      if (device != null && device.length() > 0 &&
          !device.startsWith("#") &&
          lhr.getDev().compareToIgnoreCase(device) != 0)
        continue;
      if (size > 0 && lhr.getArraySize() != size) continue;
      if (format != TFormat.CF_NULL && lhr.getFmt() != (byte)format) continue;
      return lhr;
    }
    return null;
  }
View Full Code Here

Examples of de.desy.tine.server.histories.THistoryRecord

      TExportProperty p = propertyList.getFirstProperty(property);
      if (p == null) return TErrorList.illegal_property;
      TPropertyDescription pd = p.getDescription();
      arrayType = pd == null ? TArrayType.AT_UNKNOWN : pd.getArrayType();   
    }
    THistoryRecord hst = new THistoryRecord(this,device,property,dataSize,dataFormat,arrayType,recordIndex,histSpec);
    if (useMinimalStorage) hst.setUseMinimalStorage(true);
    if (useMonthlyHistoryFiles) hst.setUseMonthlyHistoryFiles(true);
    gLclHstList.add(hst);
    if (histSpec.getDepthLong() <= 0 && histSpec.getDepthShortInSeconds() > 3600 * 6)
    { // no long term storage and more than 6 hours worth of short-term !
      hst.needsToFillSTS = true;
    }
View Full Code Here

Examples of de.desy.tine.server.histories.THistoryRecord

    return 0;   
  }
  private boolean isHstRecordInLst(String dev,String prp,int siz,int fmt)
  {
    if (gLclHstList == null) return false;
    THistoryRecord thr;
    Iterator<THistoryRecord> it = gLclHstList.iterator();
    while (it.hasNext())
    {
      thr = it.next();
      if (thr.getPrp().compareTo(prp) != 0) continue;
      if (thr.getDev().compareTo(dev) != 0) continue;
      if (thr.getArraySize() != siz) continue;
      if (thr.getFmt() != fmt) continue;
      return true;
    }
    return false;
  }
View Full Code Here

Examples of de.desy.tine.server.histories.THistoryRecord

    return ""+aTol;
  }
  public void dumpHistoryManifest()
  {
    int nHistoryRecords = gLclHstList.size();
    THistoryRecord hst = null;
    THistorySpecification spc = null;
    TInitializer initializer = TInitializerFactory.getInstance().getInitializer();
    String eqm = getLocalName();
    String filename = initializer.getFecHome()+File.separator+eqm;
    String nl = System.getProperty("line.separator");
    try
    {
      new File(filename).mkdirs();
      filename += File.separator+"hstmf.csv";
      FileWriter fw = new FileWriter(filename);
      String ln = hstmfHdr + nl;
      fw.write(ln);
      for (int i=0; i<nHistoryRecords; i++)
      {
        hst = (THistoryRecord)gLclHstList.get(i);
        if (hst.getEqm() != this) continue;
        spc = hst.getHspec();
        ln = ""+hst.getRcdIdx()+", "+eqm+", "+hst.getPrp()+", "+hst.getDev()+
             ", "+hst.getArraySize()+", "+ TFormat.toString(hst.getFmt())+
             ", "+spc.getHeartbeat()+", "+spc.getPollngRate()+", "+spc.getArchiveRate()+
             ", "+getStrToleranceForManifest(spc.getAbsoluteTolerance(),spc.getPercentTolerance())+
             ", "+spc.getDepthShort()+", "+spc.getDepthLong()+nl;
        fw.write(ln);   
      }   
View Full Code Here

Examples of de.desy.tine.server.histories.THistoryRecord

   */
  public int appendHistoryData(String property,String device,TDataType dout)
  {
    int size = dout.dArrayLength;
    short format = dout.dFormat;
    THistoryRecord hst = getLocalHistoryRecord(property, device, size, format);
    if (hst == null) return TErrorList.un_allocated;
    if (dout.getTimeStamp() < hst.getTimestamp()) return TErrorList.out_of_sequence;
    synchronized (hst)
    { // don't concur with historyCycle
      hst.writeRecordToSTS(dout);
      if (needToArchiveRecord(hst))
      {
        hst.writeRecordToLTS(dout);
        if (hst.isPointOfInterest()) hst.writeRecordToPIF(dout);
      }
    }
    return 0;
  }
View Full Code Here

Examples of de.desy.tine.server.histories.THistoryRecord

  }
  protected void historyCycle(boolean isScheduled)
  {
    if (!hasInitialized) return;
    long thisCycleTime = System.currentTimeMillis();
    THistoryRecord hst = null;
    THistorySpecification spc = null;
    TDataType dout = null;
    TDataType din = new TDataType();
    TAccess access = new TAccess(TAccess.CA_HIST + TAccess.CA_READ);
    int cc = 0;
    boolean skip;
    if (!isScheduled && thisCycleTime-lastHistoryCycleTime < historyCycleInterval) return;
    lastHistoryCycleTime = thisCycleTime;
    int nHistoryRecords = gLclHstList.size();
    if (nHistoryRecords == 0) return;
    TEquipmentModuleFactory f = getEquipmentModuleFactory();
    f.setCurrentContractEntry(f.hstcon);
    for (int i=0; i<nHistoryRecords; i++)
    {
      hst = (THistoryRecord)gLclHstList.get(i);
      spc = hst.getHspec();
      if (spc.getDepthShort() <= 0) continue;
      if (hst.needsToFillSTS) hst.fillSTS();
      hst.setArchiveFileName(thisCycleTime); // will also remove outdated files if necessary
      skip = (thisCycleTime-hst.getTimestamp()) < spc.getPollngRate();
      if (hst.isScheduled()) skip = false;
      hst.setScheduled(false);
      if (skip) continue;
      dout = new TDataType(hst.getArraySize(),hst.getFmt());
      dout.setDataTimeStamp(TDataTime.getDataTimeStamp());
      dout.setSystemDataStamp(TEquipmentModuleFactory.getSystemStamp());
      cc = callProperty(hst.getPrp(),hst.getDev(),dout,din,access);
      if (cc != 0) continue;
      synchronized (hst)
      { // don't concur with appendHistoryData
        hst.writeRecordToSTS(dout);
        if (needToArchiveRecord(hst))
        {
          hst.writeRecordToLTS(dout);
          if (hst.isPointOfInterest()) hst.writeRecordToPIF(dout);
        }
      }
    }
    if (!hstManifestDumped &&
        lastHistoryCycleTime > getEquipmentModuleFactory().getServerStartTime() + PRE_DUMP_WINDOW)
View Full Code Here

Examples of de.desy.tine.server.histories.THistoryRecord

                  propertyName = propertyName.replace('\n', (char) 0).trim();
                  propInstances = propertyList.getEqualProperties(propertyName);
                  if ((propInstances == null) || (propInstances.size() == 0))
                      return TErrorList.not_exported;
                  // fill in the targeted property info
                  THistoryRecord lhr = null;
                  TPropertyQuery[] prpq = new TPropertyQuery[propInstances.size()];
                  byte[] tba = new byte[prpq.length * TPropertyQuery.sizeInBytes];
                  Iterator<TExportProperty> it = propInstances.iterator();
                  for (int i = 0; (it.hasNext()) && (i < prpq.length); i++)
                  {
                    prpq[i] = new TPropertyQuery((TExportProperty) it.next(), propInstances.size() - 1);
                    if ((lhr=getLocalHistoryRecord(prpq[i].prpName,"#0")) != null)
                    {
                      prpq[i].prpHistoryDepthLong = (short)lhr.getHspec().getDepthLong();
                      prpq[i].prpHistoryDepthShort = (short)lhr.getHspec().getDepthShort();
                    }
                    System.arraycopy(prpq[i].toByteArray(), 0, tba, i * TPropertyQuery.sizeInBytes,
                        TPropertyQuery.sizeInBytes);
                  }
                  return dout.putData(tba, "PRPQSr4");
                }
                else
                { // want the whole list ...
                  String[] slst = new String[propertyList.countUniqueProperties()];
                  propertyList.getPropertyNames().toArray(slst);
                  TPropertyQuery[] prpq = new TPropertyQuery[slst.length];
                  if (slst.length == 0) break;
                  byte[] tba = new byte[slst.length * TPropertyQuery.sizeInBytes];
                  TExportProperty prp;
                  for (int i=0; i<slst.length; i++)
                  {
                    prp = propertyList.getFirstProperty(slst[i]);
                    prpq[i] = new TPropertyQuery(prp,1);
                    System.arraycopy(prpq[i].toByteArray(), 0, tba, i * TPropertyQuery.sizeInBytes,
                        TPropertyQuery.sizeInBytes);
                  }
                  return dout.putData(tba, "PRPQSr4");
                }               
              }
              else if (dout.getTag().compareTo("XPQS") == 0 || (dout.getArrayLength() % XPropertyQuery.sizeInBytes) == 0)
              {
                if (din != null)
                { // looking for a specific property ...
                  LinkedList<TExportProperty> propInstances;
                  String propertyName = din.toString();
                  propertyName = propertyName.replace('\n', (char) 0).trim();
                  propInstances = propertyList.getEqualProperties(propertyName);
                  if ((propInstances == null) || (propInstances.size() == 0))
                      return TErrorList.not_exported;
                  // fill in the targeted property info
                  THistoryRecord lhr = null;
                  XPropertyQuery[] xpq = new XPropertyQuery[propInstances.size()];
                  byte[] tba = new byte[xpq.length * XPropertyQuery.sizeInBytes];
                  Iterator<TExportProperty> it = propInstances.iterator();
                  for (int i = 0; (it.hasNext()) && (i < xpq.length); i++)
                  {
                    xpq[i] = new XPropertyQuery((TExportProperty) it.next(), propInstances.size() - 1);
                    if ((lhr=getLocalHistoryRecord(xpq[i].prpName,"#0")) != null)
                    {
                      xpq[i].prpHistoryDepthLong = (short)lhr.getHspec().getDepthLong();
                      xpq[i].prpHistoryDepthShort = (short)lhr.getHspec().getDepthShort();
                    }
                    System.arraycopy(xpq[i].toByteArray(), 0, tba, i * XPropertyQuery.sizeInBytes,
                        XPropertyQuery.sizeInBytes);
                  }
                  return dout.putData(tba, "XPQS");
                }
                else
                { // want the whole list ...
                  String[] slst = new String[propertyList.countUniqueProperties()];
                  propertyList.getPropertyNames().toArray(slst);
                  XPropertyQuery[] xpq = new XPropertyQuery[slst.length];
                  if (slst.length == 0) break;
                  byte[] tba = new byte[slst.length * XPropertyQuery.sizeInBytes];
                  TExportProperty prp;
                  for (int i=0; i<slst.length; i++)
                  {
                    prp = propertyList.getFirstProperty(slst[i]);
                    xpq[i] = new XPropertyQuery(prp,1);
                    System.arraycopy(xpq[i].toByteArray(), 0, tba, i * XPropertyQuery.sizeInBytes,
                        XPropertyQuery.sizeInBytes);
                  }
                  return dout.putData(tba, "XPQS");
                }
              }
              else if (dout.getTag().compareTo("PQS") == 0 || (dout.getArrayLength() % PropertyQuery.sizeInBytes) == 0)
              { // legacy request ...
                if (din != null)
                { // looking for a specific property ...
                  LinkedList<TExportProperty> propInstances;
                  String propertyName = din.toString();
                  propertyName = propertyName.replace('\n', (char) 0).trim();
                  propInstances = propertyList.getEqualProperties(propertyName);
                  if ((propInstances == null) || (propInstances.size() == 0))
                      return TErrorList.not_exported;
                  // fill in the targeted property info
                  PropertyQuery[] pqs = new PropertyQuery[1];
                  TExportProperty prp = propertyList.getFirstProperty(propertyName);
                  byte[] tba = new byte[PropertyQuery.sizeInBytes];
                  pqs[0] = new PropertyQuery();
                  pqs[0].name = propertyName;
                  pqs[0].prpDesc = prp.getDescription().getText();
                  pqs[0].prpAccess = (byte)prp.getAccessMode();
                  pqs[0].prpFormat = (byte)(prp.getOutputFormat()%512);
                  pqs[0].prpSize = (short)prp.getOutputSize();
                  System.arraycopy(pqs[0].toByteArray(), 0, tba, 0, PropertyQuery.sizeInBytes);
                  return dout.putData(tba, "PQS");
                }
                else
                { // want the whole list ...
                  String[] slst = new String[propertyList.countUniqueProperties()];
                  propertyList.getPropertyNames().toArray(slst);
                  if (slst.length == 0) break;
                  PropertyQuery[] pqs = new PropertyQuery[slst.length];
                  byte[] tba = new byte[slst.length * PropertyQuery.sizeInBytes];
                  TExportProperty prp;
                  for (int i=0; i<slst.length; i++)
                  {
                    pqs[i] = new PropertyQuery();
                    pqs[i].name = slst[i];
                    prp = propertyList.getFirstProperty(slst[i]);
                    pqs[i].prpDesc = prp.getDescription().getText();
                    pqs[i].prpAccess = (byte)prp.getAccessMode();
                    pqs[i].prpFormat = (byte)(prp.getOutputFormat()%512);
                    pqs[i].prpSize = (short)prp.getOutputSize();
                    System.arraycopy(pqs[i].toByteArray(), 0, tba, i * PropertyQuery.sizeInBytes,
                        PropertyQuery.sizeInBytes);
                  }
                  return dout.putData(tba, "PQS");               
                }
              }
          }
        }
        /**/
        return TErrorList.illegal_format;
      }
    };

    TPropertyHandler metapropertiesStructHandler = new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        if (dout != null)
        {
          int filter = getMetaPrpsCallFilter(din);
          switch (dout.dFormat)
          { // TODO: tidy this copy-and-past job up !
            case TFormat.CF_STRUCT:
              LinkedList<TExportProperty> propInstances;
              if (dout.getTag().compareTo("PRPQSr4") == 0 || (dout.getArrayLength() % TPropertyQuery.sizeInBytes) == 0)
              {
                if (din != null && filter != 0x7fffffff)
                { // looking for a specific property ...
                  String propertyName = din.toString();
                  propertyName = propertyName.replace('\n', (char) 0).trim();
                  propInstances = propertyList.getFilledMetaProperties(propertyName,filter);
                  if ((propInstances == null) || (propInstances.size() == 0))
                      return TErrorList.not_exported;
                  // fill in the targeted property info
                  TPropertyQuery[] prpq = new TPropertyQuery[propInstances.size()];
                  byte[] tba = new byte[prpq.length * TPropertyQuery.sizeInBytes];
                  Iterator<TExportProperty> it = propInstances.iterator();
                  for (int i = 0; (it.hasNext()) && (i < prpq.length); i++)
                  {
                    prpq[i] = new TPropertyQuery((TExportProperty) it.next(), propInstances.size() - 1);
                    System.arraycopy(prpq[i].toByteArray(), 0, tba, i * TPropertyQuery.sizeInBytes,
                        TPropertyQuery.sizeInBytes);
                  }
                  return dout.putData(tba, "PRPQSr4");
                }
                else
                { // want the whole list ...
                  String[] slst = new String[propertyList.countUniqueProperties()];
                  propertyList.getPropertyNames().toArray(slst);
                  if (slst.length == 0) break;
                  propInstances = new LinkedList<TExportProperty>();
                  LinkedList<TExportProperty> theseInstances;
                  for (int i=0; i<slst.length; i++)
                  {
                    theseInstances = propertyList.getFilledMetaProperties(slst[i],filter);
                    if (theseInstances.size() > 0) propInstances.addAll(theseInstances);
                  }
                  int size = propInstances.size();
                  TExportProperty prp;
                  TPropertyQuery[] prpq = new TPropertyQuery[size];
                  byte[] tba = new byte[size * TPropertyQuery.sizeInBytes];
                  for (int i=0; i<size; i++)
                  {
                    prp = propInstances.get(i);
                    prpq[i] = new TPropertyQuery(prp,1);
                    System.arraycopy(prpq[i].toByteArray(), 0, tba, i * TPropertyQuery.sizeInBytes,
                        TPropertyQuery.sizeInBytes);
                  }
                  return dout.putData(tba, "PRPQSr4");
                }               
              }
              else if (dout.getTag().compareTo("PQS") == 0 || (dout.getArrayLength() % PropertyQuery.sizeInBytes) == 0)
              { // legacy request ...
                if (din != null && filter != 0x7fffffff)
                { // looking for a specific property ...
                  String propertyName = din.toString();
                  propertyName = propertyName.replace('\n', (char) 0).trim();
                  propInstances = propertyList.getFilledMetaProperties(propertyName,filter);
                  if ((propInstances == null) || (propInstances.size() == 0))
                      return TErrorList.not_exported;
                  // fill in the targeted property info
                  PropertyQuery[] pqs = new PropertyQuery[1];
                  TExportProperty prp = propertyList.getFirstProperty(propertyName);
                  byte[] tba = new byte[PropertyQuery.sizeInBytes];
                  pqs[0] = new PropertyQuery();
                  pqs[0].name = propertyName;
                  pqs[0].prpDesc = prp.getDescription().getText();
                  pqs[0].prpAccess = (byte)prp.getAccessMode();
                  pqs[0].prpFormat = (byte)(prp.getOutputFormat()%512);
                  pqs[0].prpSize = (short)prp.getOutputSize();
                  System.arraycopy(pqs[0].toByteArray(), 0, tba, 0, PropertyQuery.sizeInBytes);
                  return dout.putData(tba, "PQS");
                }
                else
                { // want the whole list ...
                  String[] slst = new String[propertyList.countUniqueProperties()];
                  propertyList.getPropertyNames().toArray(slst);
                  if (slst.length == 0) break;
                  propInstances = new LinkedList<TExportProperty>();
                  LinkedList<TExportProperty> theseInstances;
                  for (int i=0; i<slst.length; i++)
                  {
                    theseInstances = propertyList.getFilledMetaProperties(slst[i],filter);
                    if (theseInstances.size() > 0) propInstances.addAll(theseInstances);
                  }
                  int size = propInstances.size();
                  PropertyQuery[] pqs = new PropertyQuery[size];
                  byte[] tba = new byte[size * PropertyQuery.sizeInBytes];
                  TExportProperty prp;
                  for (int i=0; i<size; i++)
                  {
                    prp = propInstances.get(i);
                    pqs[i] = new PropertyQuery();
                    pqs[i].name = prp.getName();
                    pqs[i].prpDesc = prp.getDescription().getText();
                    pqs[i].prpAccess = (byte)prp.getAccessMode();
                    pqs[i].prpFormat = (byte)(prp.getOutputFormat()%512);
                    pqs[i].prpSize = (short)prp.getOutputSize();
                    System.arraycopy(pqs[i].toByteArray(), 0, tba, i * PropertyQuery.sizeInBytes,
                        PropertyQuery.sizeInBytes);
                  }
                  return dout.putData(tba, "PQS");               
                }
              }
          }
        }
        /**/
        return TErrorList.illegal_format;
      }
    };
   
    TPropertyHandler alarmsStructHandler = new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        if (dout == null) return TErrorList.dimension_error;
        if (dout.dFormat != TFormat.CF_STRUCT) return TErrorList.illegal_format;
        int[] amrb = new int[4];
        if (din != null)
        {
          switch (din.dFormat)
          {
            case TFormat.CF_STRUCT:
              if (din.dArrayLength != 16) return TErrorList.illegal_format;
              byte[] bdata = din.getDataBuffer();
              byte[] ival = new byte[4];
              for (int i=0; i<3; i++)
              {
                System.arraycopy(bdata,i*4,ival,0,4);
                amrb[i] = Swap.Long(ival);
              }
              break;
            case TFormat.CF_LONG:
              din.getData(amrb);
              break;
            default:
              return TErrorList.illegal_format;
          }
        }
        else
        {
          amrb[0] = 0; // start time
          amrb[1] = (int)(System.currentTimeMillis()/1000); // stop time
          amrb[2] = 0; // minimum severity
          amrb[3] = 0; // as yet unused ...
        }
        boolean collapse = false;
        int dstart, dstop;
        int astart = amrb[0];
        int astop = amrb[1];
        int asev = amrb[2];
        if (devName == null || devName.length() == 0 || devName.startsWith("#") || devName.contains("*"))
        { // currently any of these is a signal that the caller want's ALL alarms
          int nalms = deviceList.getNumberOfAlarms();
          if (nalms > TAlarm.getAlmCollapseWindow()) collapse = true;
          dstart = 0; dstop = deviceList.getNumberOfDevices();
        }
        else
        {
          dstart = deviceList.getDeviceNumber(devName);
          dstop = dstart + 1;
        }
        TAlarm[] alms = null;
        TAlarmMessage[] ams = null;
        int buflength = 0;
        //byte[] tba = null;
        int code = TErrorList.max_alarms_exceeded, na = 0;
        if (collapse)
        { // collapse to a single message
          na = buflength = 1;
          ams = new TAlarmMessage[buflength];
          String atag = "more than "+TAlarm.getAlmCollapseWindow()+" total alarms";
          short[] tna = new short[32];
          int itna = 1;
          tna[0] = (short)deviceList.getNumberOfAlarms();
          TDevice[] tdevs = deviceList.getDeviceList();
          TAlarm[] as;
          int n = 0;
          for (TDevice td : tdevs)
          { // scan thru the device list
            if ((as=td.getAlarmList()) == null ||
                 as.length == 0 || as[0] == null) continue;
            for (int i=0; i<as.length; i++)
              if (isCasInClientList()) as[i].allowRemoval();
            if (code == TErrorList.max_alarms_exceeded) code = as[0].getCode();
            if (itna < 32 && code != tna[itna]) tna[itna] = (short)code;
            if (code != as[0].getCode()) break;
            n++;
          }
          if (n > TAlarm.getAlmCollapseWindow())
          { // at least this many with the same code
              code = TAlarm.isDiskSpaceAlarm(code) ? (code & 0xff) : TAlarm.getBaseCode(code);
              TAlarmDefinition ad = getAlarmDefinition(code);
              atag = ""+n+" alarms: "+ ad != null ? ad.getAlarmTag() : "<no defined alarm tag>";
          }
          TDataType dt = new TDataType(tna);
          ams[0] = new TAlarmMessage(thisEqm.getExportName(),thisEqm.getExportName(),atag,code,
                          deviceList.getHighestAlarmSeverity(null,0),almDynSet,dt);
          //tba = new byte[buflength * TAlarmMessage.sizeInBytes];
        }
        else
        {
          int ts = 0;
          buflength = deviceList.getNumberOfAlarms();
          ams = new TAlarmMessage[buflength];
          //tba = new byte[buflength * TAlarmMessage.sizeInBytes];
          TDevice[] dlst = deviceList.getDeviceList();
          String dnam = null, atag = null;
          for (int i=dstart; i<dstop; i++)
          {
            alms = dlst[i].getAlarmList();
            if ((alms == null) || (alms.length == 0)) continue;
            for (int n=0; n<alms.length && na<buflength; n++)
            {
              if ((ts=alms[n].getTimeStamp()) < astart || ts > astop) continue;
              if (alms[n].getSeverity() < asev) continue;
              dnam = dlst[i].getName();
              code = alms[n].getCode();
              atag = null;
              if (TAlarm.isLinkErrorAlarm(code))
              {
                dnam = thisEqm.getExportName();
                int lid = TAlarm.decodeLinkErrorAlarm(code);
                TLink lnk = TLinkFactory.getInstance().getLinkFromTable(lid);
                if (lnk != null) atag = "link error: "+lnk.getDeviceServer();
              }
              // TODO: if (TAlarm.isDiskSpaceAlarm(code)) dnam = getDiskName();
              ams[na] = new TAlarmMessage(thisEqm,dnam,atag,alms[n]);
              if (TAlarm.isHiddenAlarm(alms[n].getCode()))
              { // flagged as hidden
                ams[na].setAlarmSystem(TAlarm.hideAlarmSystem(ams[na].getAlarmSystem()));
              }
              //System.arraycopy(ams[na].toByteArray(), 0, tba, (na)*TAlarmMessage.sizeInBytes, TAlarmMessage.sizeInBytes);
              // CAS is configured and has now read the alarm => can remove it !
              if (casReadRequired && isCasInClientList()) alms[n].allowRemoval();
              na++;
            }
          }
        }
        byte[] tba = new byte[buflength * TAlarmMessage.sizeInBytes];
        if (dout.getTag().compareTo("AMSr4") == 0)
        { // modern
          for (int i=0; i<buflength && i<na; i++)
          {
            System.arraycopy(ams[i].toByteArray(), 0, tba, i*TAlarmMessage.sizeInBytes, TAlarmMessage.sizeInBytes);
          }
          if (na < dout.getArrayLength()) dout.setArrayLength(na);
          return dout.putData(tba, "AMSr4");
        }
        else
        // is legacy support necessary ?
         
        }
        return TErrorList.invalid_structure_tag;
      }
    };
    TPropertyHandler alarmDefsStructHandler = new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TAlarmDefinition[] adef = (TAlarmDefinition[])alarmDefinitionList.values().toArray(new TAlarmDefinition[0]);
        int almdefsize = alarmDefinitionList.size();
        if (devAccess.isWrite())
        {
          if (din == null) return TErrorList.dimension_error;
          if (din.dFormat != TFormat.CF_STRUCT) return TErrorList.illegal_format;
          if (din.getTag().compareTo("ADSr4") != 0) return TErrorList.invalid_structure_tag;
          TAlarmDefinition[] inpt = new TAlarmDefinition[1];
          inpt[0] = new TAlarmDefinition();
          din.getData(inpt);
          boolean found = false;
          for (int i=0; i<almdefsize; i++)
          {
            if (adef[i].getAlarmCode() == inpt[0].getAlarmCode())
            { // got it
              adef[i].setFields(inpt[0]);
              found = true;
              break;
            }
          }
          if (!found) return TErrorList.un_allocated;
          if (dout == null || dout.getArrayLength() == 0) return 0;
        }
        if (dout == null) return TErrorList.dimension_error;
        if (dout.dFormat != TFormat.CF_STRUCT) return TErrorList.illegal_format;
        int adssize = TStructRegistry.getSizeInBytes("ADSr4");
        byte[] tba = new byte[almdefsize * adssize];
        if (dout.getTag().compareTo("ADSr4") == 0)
        { // modern
          for (int i=0; i<almdefsize; i++)
          {
            System.arraycopy(adef[i].toByteArray(), 0, tba, i*adssize, adssize);
          }
          if (almdefsize < dout.getArrayLength()) dout.setArrayLength(almdefsize);
          return dout.putData(tba, "ADSr4");
        }
        else
        // is legacy support necessary ?
         
        }
        return TErrorList.invalid_structure_tag;
      }
    };
    TPropertyHandler alarmWatchStructHandler = new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        if (dout == null) return TErrorList.dimension_error;
        if (dout.dFormat != TFormat.CF_STRUCT) return TErrorList.illegal_format;
        synchronized (gAlarmWatchList)
        {
          int almwtblsize = gAlarmWatchList.size();
          int awssize = TStructRegistry.getSizeInBytes("AWSr4");
          byte[] tba = new byte[almwtblsize * awssize];
          TAlarmWatchEntry[] aws = (TAlarmWatchEntry[])gAlarmWatchList.toArray(new TAlarmWatchEntry[0])
          if (devAccess.isWrite())
          {
            if (din.getFormat() != TFormat.CF_STRUCT) return TErrorList.illegal_format;
            if (din.getTag().compareTo("AWSr4") == 0)
            {
              TAlarmWatchEntry[] awe = new TAlarmWatchEntry[1];
              awe[0] = new TAlarmWatchEntry();
              din.getData(awe);
              awe[0].setEquipmentModule(getLocalName());
              boolean isNew = false;
              for (int i=0; i<aws.length; i++)
              {
                if (aws[i].equals(awe[0]))
                {
                  aws[i].adjustFrom(awe[0]);
                  isNew = true;
                  break;
                }
              }
              if (isNew)
              { // wasn't in list
                TExportProperty p = propertyList.getFirstProperty(awe[0].getPrp());
                if (p == null) return TErrorList.illegal_property;
                if (awe[0].getSiz() <= 0 || awe[0].getSiz() > p.getOutputSize())
                {
                  awe[0].setSiz(p.getOutputSize());
                }
                awe[0].setFmt(p.getOutputFormat());
                gAlarmWatchList.add(awe[0]);
              }
            }
            else
            {
              return TErrorList.invalid_structure_tag;           
            }
          }
          if (dout.getTag().compareTo("AWSr4") == 0)
          { // modern
            for (int i=0; i<almwtblsize; i++)
            {
              System.arraycopy(aws[i].toByteArray(), 0, tba, i*awssize, awssize);
            }
            if (almwtblsize < dout.getArrayLength()) dout.setArrayLength(almwtblsize);
            return dout.putData(tba, "AWSr4");
          }
        }
        return TErrorList.invalid_structure_tag;
      }
    };
    stockList.addProperty(TStockProperties.NALARMS, new TPropertyHandler()
    {
      int nalmdefs = alarmDefinitionList.size();
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        int devnr = -1;
       
        if (!devName.contains("*") && !devName.startsWith("#"))
        {
          devnr = deviceList.getDeviceNumber(devName);
        }
        if (casName != null  && !hasCasAttached) isCasInClientList();
        int[] nalms = new int[6];
        if (devnr < 0)
        { // all of them
          nalms[0] = deviceList.getNumberOfAlarms();
          nalms[1] = deviceList.getMostRecentAlarmTimestamp(nalms,3);
          nalms[2] = deviceList.getHighestAlarmSeverity(nalms,4);
          nalms[5] = nalmdefs;
          if (nalms[0] > TAlarm.getAlmCollapseWindow())
          {
            nalms[1] = almDynSet.timestamp;
            nalms[4] = nalms[3] = nalms[0] = 1;
          }
        }
        else
        { // just the device given ...
          int mrts = 0, ts, hsv = 0, sv, nts = 0, nsv = 0;
          TDevice[] dlst = deviceList.getDeviceList();
          if (devnr >= dlst.length) return TErrorList.device_not_connected;
          TAlarm[] alms = dlst[devnr].getAlarmList();
          nalms[0] = alms.length;
          for (int i=0; i<alms.length; i++)
          {
            if ((ts=alms[i].getTimeStamp()) > mrts)
            {
              mrts = ts;
              nts = 0;
            }
            if (ts == mrts) nts++;
            if ((sv=alms[i].getSeverity()) > hsv)
            {
              hsv = sv;
              nsv = 0;
            }
            if (sv == hsv) nsv++;
          }
          nalms[1] = mrts;
          nalms[2] = hsv;
          nalms[3] = nts;
          nalms[4] = nsv;
          nalms[5] = nalmdefs;
        }
        if (dout.dArrayLength > 5) nalms[5] = getAlarmDefinitionList().size();
        return dout.putData(nalms);
      }
    });
    stockList.addProperty(TStockProperties.NALARMDEFS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData((short)alarmDefinitionList.size());
      }
    });
    stockList.addProperty(TStockProperties.NALMWATCH, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData((short)gAlarmWatchList.size());
      }
    });
    stockList.addProperty(TStockProperties.ALARMS, alarmsStructHandler);
    stockList.addProperty(TStockProperties.ALARMSEXT, alarmsStructHandler);
    stockList.addProperty(TStockProperties.ALARMSEXT_STRUCTIN, alarmsStructHandler);
    stockList.addProperty(TStockProperties.ALARMDEFS, alarmDefsStructHandler);
    stockList.addProperty(TStockProperties.ALMWATCHTBL, alarmWatchStructHandler);
    stockList.addProperty(TStockProperties.NHISTORIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData((short)gLclHstList.size());
      }
    });
    stockList.addProperty(TStockProperties.HISTORIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return hstCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.HISTORIES_STRUCT, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return hstCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.ADDHISTORY, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        if (devAccess.isWrite())
        {
          if (din.getFormat() != TFormat.CF_STRUCT) return TErrorList.illegal_format;
          if (din.getTag().compareTo("HRSr4") == 0)
          {
            THistoryRecordStruct[] hrs = new THistoryRecordStruct[1];
            hrs[0] = new THistoryRecordStruct();
            din.getData(hrs);
            String prp = hrs[0].getProperty();
            String dev = hrs[0].getDevice();
            THistoryRecord hr = getLocalHistoryRecord(prp,dev);
            if (hr == null)            
            { // wasn't in list
              TExportProperty p = getPropertyList().getFirstProperty(prp);
              TPropertyDescription pd = p.getDescription();
              int at = pd != null ? pd.getArrayType() : TArrayType.AT_UNKNOWN;
              int idx = TEquipmentModuleFactory.getInstance().getNextHistoryRecordIndex();
              THistorySpecification hspec = new THistorySpecification(hrs[0].getPollingRate(), hrs[0].getArchiveRate(), hrs[0].getDepthShort(), hrs[0].getDepthLong(), hrs[0].getHeartbeat(), hrs[0].getPercentTolerance(), hrs[0].getAbsoluteTolerance(), null);
              addLocalHistoryRecord(idx, dev, prp, hrs[0].getSize(), hrs[0].getFormat(),at,hspec);
              dumpHistoryManifest();
            }
            else
            { // just an edit ...
              THistorySpecification hsp = hr.getHspec();
              hsp.setAbsoluteTolerance(hrs[0].getAbsoluteTolerance());
              hsp.setPercentTolerance(hrs[0].getPercentTolerance());
              hsp.setArchiveRate(hrs[0].getArchiveRate());
              hsp.setPollngRate(hrs[0].getPollingRate());
              hsp.setDepthLong(hrs[0].getDepthLong());
View Full Code Here

Examples of de.desy.tine.server.histories.THistoryRecord

              return (short) dout.putData(u);
            default:
              return TErrorList.illegal_format;
          }
        case TMetaProperties.HST_ID:
          THistoryRecord hst = null;
          int listsize = gLclHstList.size();
          int index = 0, sample = 0;
          long start = 0;
          long stop = System.currentTimeMillis()-1000;
          int sysstart = 0, sysstop = 0;
          int cycnr = TEquipmentModuleFactory.getCycleNumber();
          float lwr = 0, upr = 0;
          Object data = null;
          int dataSize = 0, inputDataSize = 0;
          boolean isCentralArchiveRequest = false;
         
          if (TMetaProperties.isCentralArchive(metaPropertyName))
          {
            isCentralArchiveRequest = true;
          }
          boolean isSnapshot = TMetaProperties.isHistorySnapshot(metaPropertyName);
          dataSize = dout.getArrayLength();
          if (dout.dFormat == TFormat.CF_HISTORY)
          { // trap this early
            int hsiz = TFormat.getCarriedFormatSize(dout.getTag());
            if (hsiz > 0) dataSize /= hsiz + TFormat.getHistoryHeaderSize();
          }
          start = stop - dataSize * 1000; // millisecond timestamps here!
          // check the time range and/or filtering criteria the caller has given us ...
          if (din != null && (inputDataSize=din.getArrayLength()) > 0)
          {
            switch (din.getFormat())
            {
              case TFormat.CF_LONG:
                int[] ival = (int[])din.getDataObject();
                switch (inputDataSize)
                {
                  case 6: sysstop = ival[5];
                    if (cycnr == 0) sysstop = 0;
                    if (sysstop > cycnr) sysstop = cycnr;
                  case 5: sysstart = ival[4];
                    if (cycnr == 0) sysstart = 0;
                  case 4: sample = ival[3];
                  case 3: index = ival[2];
                  case 2: if (ival[1] < (int)(stop/1000)) stop = ((long)ival[1])*1000;
                  case 1: start = ((long)ival[0])*1000;
                  default: break;
                }
                if (sample < 0) sample = 0;
                break;
               
              case TFormat.CF_DLONG:
                long[] lval = (long[])din.getDataObject();
                switch (inputDataSize)
                {
                  case 6: sysstop = (int)lval[5];
                    if (cycnr == 0) sysstop = 0;
                    if (sysstop > cycnr) sysstop = cycnr;
                  case 5: sysstart = (int)lval[4];
                    if (cycnr == 0) sysstart = 0;
                  case 4: sample = (int)lval[3];
                  case 3: index = (int)lval[2];
                  case 2: if (lval[1] < stop/1000) stop = (long)(lval[1]*1000);
                  case 1: start = (long)(lval[0]*1000);
                  default: break;
                }
                if (sample < 0) sample = 0;
                break;
               
              case TFormat.CF_DOUBLE:
                double[] dval = (double[])din.getDataObject();
                switch (inputDataSize)
                {
                  case 6: sysstop = (int)dval[5];
                    if (cycnr == 0) sysstop = 0;
                    if (sysstop > cycnr) sysstop = cycnr;
                  case 5: sysstart = (int)dval[4];
                    if (cycnr == 0) sysstart = 0;
                  case 4: sample = (int)dval[3];
                  case 3: index = (int)dval[2];
                  case 2: if (dval[1] < stop/1000) stop = (long)(dval[1]*1000);
                  case 1: start = (long)(dval[0]*1000);
                  default: break;
                }
                if (sample < 0) sample = 0;
                break;
              case TFormat.CF_FWINDOW:
                FWINDOW[] fw = (FWINDOW[])din.getDataObject();
                start = ((FWINDOW[])fw)[0].i1val * 1000;
                stop = ((FWINDOW[])fw)[0].i2val * 1000;
                lwr = ((FWINDOW[])fw)[0].f1val;
                upr = ((FWINDOW[])fw)[0].f2val;
                if (lwr < upr) sample = -1;
                break;
              default:
                return TErrorList.illegal_format;
            }
          }
          else
          { // no input given
            if (dataSize == 1)
            {
              start = stop;
              isSnapshot = true;
            }
          }
          if (isSnapshot)
          {
            if (start < 1) return TErrorList.argument_list_error;
            if (sysstart > 0) sysstop = sysstart; else stop = start;
            sample = 0;
            index = 0;
            lwr = upr = (float)0.0;         
          }
          // what the caller wants returned ....
          boolean literalDevice = false;
          for (int i=0; i<listsize; i++)
          { // go thru the list to see if the requested device was stored literally
            hst = (THistoryRecord)gLclHstList.get(i);
            if (hst.getPrp().compareToIgnoreCase(prp.getName()) != 0) continue;
            if (hst.getDev().compareTo(devName) != 0) continue;
            literalDevice = true;
            break;
          }
          for (int i=0; i<listsize; i++)
          {
            hst = (THistoryRecord)gLclHstList.get(i);
            if (hst.getPrp().compareToIgnoreCase(prp.getName()) == 0)
            {
              if (hst.getDev().compareTo(devName) != 0)
              { // should we look for a match in the device name ?
                if (index == 0 && !literalDevice)
                  index = getDeviceList().getDeviceNumber(devName);
                else
                  continue;
              }
              if (isCentralArchiveRequest)
              {
                String rmtsrv = hst.getRemoteHistoryServer();
                if (rmtsrv == null || rmtsrv.length() == 0)
                { // try the central archive systematics ...
                  rmtsrv = "/"+getContext()+"/HISTORY/"+devName+"["+getExportName()+"."+propertyName+"]";
                }
                return (short)gEqmFactory.setRedirectionString(rmtsrv);
              }
              // snapshots always have index = 0
              if (start == stop && dataSize > 1) index = 0;
              switch (dout.dFormat)
              {
                case TFormat.CF_BYTE:
                  data = new byte[dataSize]; break;
                case TFormat.CF_SHORT:
                  data = new short[dataSize]; break;
                case TFormat.CF_LONG:
                  data = new int[dataSize]; break;
                case TFormat.CF_DLONG:
                  data = new long[dataSize]; break;               
                case TFormat.CF_INTINT:
                  data = new INTINT[dataSize]; break;
                case TFormat.CF_FLOAT:
                  data = new float[dataSize]; break;
                case TFormat.CF_FLTINT:
                  data = new FLTINT[dataSize]; break;
                case TFormat.CF_INTFLTINT:
                  data = new INTFLTINT[dataSize]; break;
                case TFormat.CF_DOUBLE:
                  data = new double[dataSize]; break;
                case TFormat.CF_DBLDBL:
                  data = new DBLDBL[dataSize]; break;
                case TFormat.CF_DBLTIME:
                  data = new DBLTIME[dataSize]; break;
                case TFormat.CF_NAME16: 
                  data = new NAME16[dataSize]; break;
                case TFormat.CF_NAME16I: 
                  data = new NAME16I[dataSize]; break;
                case TFormat.CF_NAME32: 
                  data = new NAME32[dataSize]; break;
                case TFormat.CF_NAME32I: 
                  data = new NAME32I[dataSize]; break;
                case TFormat.CF_NAME64: 
                  data = new NAME64[dataSize]; break;
                case TFormat.CF_NAME64I: 
                  data = new NAME64I[dataSize]; break;
                case TFormat.CF_HISTORY:
                  data = new HISTORY[dataSize];
                  // create the first one so as to pass the tag along
                  short f = TFormat.getFormatCode(dout.getTag());
                  if (f == TFormat.CF_NULL) return TErrorList.illegal_format;
                  TDataType d = new TDataType(1,f);
                  ((HISTORY[])data)[0] = new HISTORY(d);
                  break;
                default:
                  data = TFormat.makeCompoundDataObjectArray(dout.dFormat, dout.getTag(), dataSize);
                  break;
              }
              int nr = hst.getDataFromLTS(index,start,stop,sysstart,sysstop,lwr,upr,data,dataSize,0,sample);
              if (nr < 0)
              {
                if (nr == -TErrorList.server_redirection)
                {
                  String rmtsrv = hst.getRemoteHistoryServer();
                  if (rmtsrv == null || rmtsrv.length() == 0) return TErrorList.not_implemented;
                  return (short)gEqmFactory.setRedirectionString(rmtsrv);
                }
                return (short)-nr;
              }
              boolean needStsData = true;
              if (nr > 0)
              {
                if (isSnapshot || nr >= dataSize - 1)
                { // found the snapshot in or filled the buffer from LTS
                  dout.putData(data);
                  dout.setDataTimeStamp(hst.getLastReadTimestamp());
                  dout.setSystemDataStamp(hst.getLastReadSystemStamp());
                  return 0;
                }
                start = hst.getLastReadTimestamp() + 1;
                if (start >= stop) needStsData = false; // we're finished
              }
              if (needStsData)
              { // still recent points to acquire
                nr = hst.getDataFromSTS(index,start,stop,sysstart,sysstop,lwr,upr,data,dataSize,nr,sample);
                if (nr < 0) return (short)-nr;
              }
              if (dataSize > 1 && nr < dataSize) dout.dArrayLength = nr;
              dout.putData(data);
              dout.setDataTimeStamp(hst.getLastReadTimestamp());
              dout.setSystemDataStamp(hst.getLastReadSystemStamp());
              return 0;
            }
          }
          return TErrorList.not_implemented;
        case TMetaProperties.NAM_ID:
View Full Code Here

Examples of de.desy.tine.server.histories.THistoryRecord

    return getLocalHistoryRecord(property,device,0,TFormat.CF_NULL);
  }
  public THistoryRecord getLocalHistoryRecord(String property,String device,int size,short format)
  {
    int listsize = gLclHstList.size();
    THistoryRecord lhr = null;
    if (property == null || property.length() == 0) return null;
    for (int i=0; i<listsize; i++)
    {
      lhr = (THistoryRecord)gLclHstList.get(i);
      if (lhr.getPrp().compareTo(property) != 0) continue;
      if (device != null && device.length() > 0 &&
          !device.startsWith("#") &&
          lhr.getDev().compareToIgnoreCase(device) != 0)
        continue;
      if (size > 0 && lhr.getArraySize() != size) continue;
      if (format != TFormat.CF_NULL && lhr.getFmt() != (byte)format) continue;
      return lhr;
    }
    return null;
  }
View Full Code Here

Examples of de.desy.tine.server.histories.THistoryRecord

      TExportProperty p = propertyList.getFirstProperty(property);
      if (p == null) return TErrorList.illegal_property;
      TPropertyDescription pd = p.getDescription();
      arrayType = pd == null ? TArrayType.AT_UNKNOWN : pd.getArrayType();   
    }
    THistoryRecord hst = new THistoryRecord(this,device,property,dataSize,dataFormat,arrayType,recordIndex,histSpec);
    if (useMinimalStorage) hst.setUseMinimalStorage(true);
    if (useMonthlyHistoryFiles) hst.setUseMonthlyHistoryFiles(true);
    gLclHstList.add(hst);
    if (histSpec.getDepthLong() <= 0 && histSpec.getDepthShortInSeconds() > 3600 * 6)
    { // no long term storage and more than 6 hours worth of short-term !
      hst.needsToFillSTS = true;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.