Search in sources :

Example 1 with CacheException

use of org.vcell.util.CacheException in project vcell by virtualcell.

the class DataSetControllerImpl method getChomboExtrapolatedValues.

private SimDataBlock getChomboExtrapolatedValues(VCDataIdentifier vcdID, String varName, double time) throws DataAccessException {
    final String methodName = "DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")";
    VCMongoMessage.sendTrace(methodName + " <<ENTER>>");
    try {
        // 
        // check if already cached for non-function variables
        // 
        VCData vcData = getVCData(vcdID);
        if (vcData == null || !(vcData instanceof SimulationData)) {
            return null;
        }
        SimulationData simData = (SimulationData) vcData;
        VCMongoMessage.sendTrace(methodName + " got VCData");
        long dataBlockTimeStamp = simData.getDataBlockTimeStamp(PDE_DATA, time);
        VCMongoMessage.sendTrace(methodName + " got dataBlockTimeStamp");
        PDEDataInfo pdeDataInfo = new PDEDataInfo(vcdID.getOwner(), vcdID.getID(), varName, time, dataBlockTimeStamp);
        SimDataBlock simDataBlock = null;
        if (dataCachingEnabled && chomboExtrapolatedValuesCache == null) {
            chomboExtrapolatedValuesCache = new Cachetable(MessageConstants.MINUTE_IN_MS * 10, 1000000L);
        }
        simDataBlock = chomboExtrapolatedValuesCache.get(pdeDataInfo);
        if (simDataBlock == null) {
            VCMongoMessage.sendTrace(methodName + " read chombo extrapolated values");
            simDataBlock = simData.getChomboExtrapolatedValues(varName, time);
            if (simDataBlock != null && dataCachingEnabled) {
                if (chomboExtrapolatedValuesCache != null) {
                    try {
                        chomboExtrapolatedValuesCache.put(pdeDataInfo, simDataBlock);
                    } catch (CacheException e) {
                        // if can't cache the data, it is ok
                        e.printStackTrace();
                    }
                }
            }
        }
        if (simDataBlock != null) {
            VCMongoMessage.sendTrace(methodName + "  <<EXIT-Success>>");
            return simDataBlock;
        }
        String msg = "failure reading " + varName + " at t=" + time + " for " + vcdID.getOwner().getName() + "'s " + vcdID.getID();
        if (lg.isWarnEnabled())
            lg.warn(methodName + msg);
        throw new DataAccessException(msg);
    } catch (Exception e) {
        lg.error(e.getMessage(), e);
        VCMongoMessage.sendTrace(methodName + "  <<EXIT-Exception>>");
        throw new DataAccessException(e.getMessage());
    }
}
Also used : CacheException(org.vcell.util.CacheException) DataAccessException(org.vcell.util.DataAccessException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) CacheException(org.vcell.util.CacheException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) FileNotFoundException(java.io.FileNotFoundException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException)

Example 2 with CacheException

use of org.vcell.util.CacheException in project vcell by virtualcell.

the class DataSetControllerImpl method getSimDataBlock.

/**
 * This method was created by a SmartGuide.
 * @return double[]
 * @param varName java.lang.String
 * @param time double
 */
public SimDataBlock getSimDataBlock(OutputContext outputContext, VCDataIdentifier vcdID, String varName, double time) throws DataAccessException {
    VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<ENTER>>");
    try {
        // 
        // check if already cached for non-function variables
        // 
        VCData simData = getVCData(vcdID);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got VCData");
        long dataBlockTimeStamp = simData.getDataBlockTimeStamp(PDE_DATA, time);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got dataBlockTimeStamp");
        PDEDataInfo pdeDataInfo = new PDEDataInfo(vcdID.getOwner(), vcdID.getID(), varName, time, dataBlockTimeStamp);
        SimDataBlock simDataBlock = null;
        AnnotatedFunction function = getFunction(outputContext, vcdID, varName);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got function");
        if (function == null) {
            simDataBlock = (cacheTable0 != null ? cacheTable0.get(pdeDataInfo) : null);
            if (simDataBlock == null) {
                simDataBlock = simData.getSimDataBlock(outputContext, varName, time);
                if (simDataBlock != null && dataCachingEnabled) {
                    // cacheTable.put(pdeDataInfo,simDataBlock);
                    if (cacheTable0 != null) {
                        try {
                            cacheTable0.put(pdeDataInfo, simDataBlock);
                        } catch (CacheException e) {
                            // if can't cache the data, it is ok
                            e.printStackTrace();
                        }
                    }
                }
            }
        } else {
            if (simData instanceof SimulationData) {
                function = ((SimulationData) simData).simplifyFunction(function);
            }
            VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") evaluating function");
            simDataBlock = evaluateFunction(outputContext, vcdID, simData, function, time);
        }
        CartesianMesh mesh = getMesh(vcdID);
        if (mesh != null && mesh.isChomboMesh()) {
            for (int i = 0; i < simDataBlock.getData().length; i++) {
                if (simDataBlock.getData()[i] == 1.23456789e300) {
                    simDataBlock.getData()[i] = Double.NaN;
                }
            }
        }
        if (simDataBlock != null) {
            VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<EXIT-simDataBlock not null>>");
            return simDataBlock;
        } else {
            String msg = "failure reading " + varName + " at t=" + time + " for " + vcdID.getOwner().getName() + "'s " + vcdID.getID();
            if (lg.isWarnEnabled())
                lg.warn("DataSetControllerImpl.getDataBlockValues(): " + msg);
            VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<EXIT-Exception>>");
            throw new DataAccessException(msg);
        }
    } catch (MathException e) {
        lg.error(e.getMessage(), e);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<EXIT-Exception>>");
        throw new DataAccessException(e.getMessage());
    } catch (IOException e) {
        lg.error(e.getMessage(), e);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<EXIT-Exception>>");
        throw new DataAccessException(e.getMessage());
    } catch (ExpressionException e) {
        lg.error(e.getMessage(), e);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<EXIT-Exception>>");
        throw new DataAccessException(e.getMessage());
    }
}
Also used : CacheException(org.vcell.util.CacheException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) CartesianMesh(cbit.vcell.solvers.CartesianMesh) MathException(cbit.vcell.math.MathException) DataAccessException(org.vcell.util.DataAccessException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 3 with CacheException

use of org.vcell.util.CacheException in project vcell by virtualcell.

the class DBCacheTable method putProtected.

public void putProtected(KeyValue key, Cacheable cacheable) throws CacheException {
    if (!((cacheable instanceof Cloneable) || (cacheable instanceof Immutable) || (cacheable instanceof Serializable))) {
        throw new CacheException("put:Object not Cloneable, Immutable or Serializable");
    }
    if (key == null) {
        throw new CacheException("put: key == null");
    }
    long dataSize = 1000;
    byte[] objData = null;
    try {
        objData = org.vcell.util.BeanUtils.toSerialized(cacheable);
        // 
        // dataSize is length*3 because three copies are stored in DbObjectWrapper (reference/bytes/working).
        // 
        dataSize = objData.length * 3;
    } catch (IOException e) {
        e.printStackTrace(System.out);
        throw new CacheException(e.getMessage());
    }
    TimeWrapper oldTimeWrapper = put(key, new TimeWrapper(new DbObjectWrapper(cacheable, objData), dataSize, key));
    // 
    if (oldTimeWrapper != null) {
        System.out.println("replacing object ALREADY IN DATABASE_CACHE " + oldTimeWrapper.getObject() + " at key " + key);
    }
    // 
    // checking to see if same object (using compareEqual) already in hash
    // 
    // if (cacheable instanceof cbit.vcell.model.Species){
    // Enumeration enum1 = hashTable.elements();
    // while (enum1.hasMoreElements()){
    // TimeWrapper timeWrapper = (TimeWrapper) enum1.nextElement();
    // DbObjectWrapper objWrapper = (DbObjectWrapper) timeWrapper.getObject();
    // Cacheable cacheObj = objWrapper.getWorkingCopy();
    // if (cacheable != cacheObj && cacheable.compareEqual(cacheObj)){
    // //	throw new RuntimeException("DBCacheTable.put("+cacheable+"), already in cache as ("+cacheObj+")");
    // System.out.println("DBCacheTable.put("+cacheable+"), already in cache as ("+cacheObj+")");
    // }
    // }
    // }
    // System.out.print("put(cacheable="+cacheable+") ");
    show();
}
Also used : Immutable(org.vcell.util.Immutable) TimeWrapper(org.vcell.util.TimeWrapper) Serializable(java.io.Serializable) CacheException(org.vcell.util.CacheException) IOException(java.io.IOException)

Example 4 with CacheException

use of org.vcell.util.CacheException in project vcell by virtualcell.

the class DataSetControllerImpl method getVCData.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.simdata.SimResults
 * @param user User
 * @param simID java.lang.String
 */
public VCData getVCData(VCDataIdentifier vcdID) throws DataAccessException, IOException {
    VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") ... <<ENTER>>");
    VCData vcData = (cacheTable0 != null ? cacheTable0.get(vcdID) : null);
    // 
    if (vcData == null) {
        // System.out.println("getVCData " + vcdID);
        if (vcdID instanceof MergedDataInfo) {
            try {
                User user = vcdID.getOwner();
                VCDataIdentifier[] vcdIdentifiers = ((MergedDataInfo) vcdID).getDataIDs();
                VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : creating new MergedData : <<BEGIN>>");
                vcData = new MergedData(user, getPrimaryUserDir(vcdID.getOwner(), false), getSecondaryUserDir(vcdID.getOwner()), this, vcdIdentifiers, ((MergedDataInfo) vcdID).getDataSetPrefix());
                VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : creating new MergedData : <<END>>");
            } catch (IOException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException(e.getMessage());
            }
        } else {
            // assume vcdID instanceof cbit.vcell.solver.SimulationInfo or a test adapter
            VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : creating new SimulationData : <<BEGIN>>");
            SimulationData.SimDataAmplistorInfo simDataAmplistorInfo = AmplistorUtils.getSimDataAmplistorInfoFromPropertyLoader();
            vcData = new SimulationData(vcdID, getPrimaryUserDir(vcdID.getOwner(), false), getSecondaryUserDir(vcdID.getOwner()), simDataAmplistorInfo);
            VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : creating new SimulationData : <<END>>");
        }
        if (cacheTable0 != null) {
            try {
                VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : caching vcData : <<BEGIN>>");
                cacheTable0.put(vcdID, vcData);
                VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : caching vcData : <<END>>");
            } catch (CacheException e) {
                // if  can't cache the data, it is ok
                e.printStackTrace();
            }
        }
    }
    VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") ... <<EXIT>>");
    return vcData;
}
Also used : User(org.vcell.util.document.User) CacheException(org.vcell.util.CacheException) IOException(java.io.IOException) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier)

Example 5 with CacheException

use of org.vcell.util.CacheException in project vcell by virtualcell.

the class Cachetable method put.

private synchronized TimeWrapper put(Object key, TimeWrapper timeWrapper) throws CacheException {
    long dataMemSize = timeWrapper.getSize();
    if (dataMemSize >= maxMemSize) {
        throw new CacheException("data item " + key + " with memSize=" + dataMemSize + " too large, maxCacheSize=" + maxMemSize);
    }
    // 
    if (dataMemSize + currMemSize >= maxMemSize) {
        resize(Math.min((long) (maxMemSize * cleanupFraction), maxMemSize - dataMemSize));
    }
    TimeWrapper oldTimeWrapper = (TimeWrapper) hashTable.put(key, timeWrapper);
    currMemSize += dataMemSize;
    if (oldTimeWrapper != null) {
        currMemSize -= oldTimeWrapper.getSize();
    }
    if (currMemSize < 0 || currMemSize >= maxMemSize) {
        throw new CacheException("Error: adding data item " + key + ". currMemSize=" + currMemSize + " maxMemSize=" + maxMemSize);
    }
    // System.out.println("........Cachetable.put(key="+key+")");
    return oldTimeWrapper;
}
Also used : TimeWrapper(org.vcell.util.TimeWrapper) CacheException(org.vcell.util.CacheException)

Aggregations

CacheException (org.vcell.util.CacheException)9 IOException (java.io.IOException)7 DataAccessException (org.vcell.util.DataAccessException)4 TimeWrapper (org.vcell.util.TimeWrapper)4 MathException (cbit.vcell.math.MathException)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 Serializable (java.io.Serializable)2 Immutable (org.vcell.util.Immutable)2 DivideByZeroException (cbit.vcell.parser.DivideByZeroException)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)1 CartesianMesh (cbit.vcell.solvers.CartesianMesh)1 XmlParseException (cbit.vcell.xml.XmlParseException)1 FileNotFoundException (java.io.FileNotFoundException)1 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)1 User (org.vcell.util.document.User)1 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)1