Isis-fish-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- 3175 discussions
r3761 - in trunk: . src/main/java/fr/ifremer/isisfish/datastore
by echatellier@users.forge.codelutin.com 04 Sep '12
by echatellier@users.forge.codelutin.com 04 Sep '12
04 Sep '12
Author: echatellier
Date: 2012-09-04 10:52:27 +0200 (Tue, 04 Sep 2012)
New Revision: 3761
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3761
Log:
Restore commented stuff after release
Modified:
trunk/pom.xml
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-09-04 08:25:48 UTC (rev 3760)
+++ trunk/pom.xml 2012-09-04 08:52:27 UTC (rev 3761)
@@ -62,14 +62,14 @@
<dependency>
<groupId>org.nuiton.matrix</groupId>
<artifactId>nuiton-matrix</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.nuiton.matrix</groupId>
<artifactId>nuiton-matrix-gui</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-09-04 08:25:48 UTC (rev 3760)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-09-04 08:52:27 UTC (rev 3761)
@@ -25,8 +25,22 @@
package fr.ifremer.isisfish.datastore;
-import static org.nuiton.i18n.I18n._;
-
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.IsisFishRuntimeException;
+import fr.ifremer.isisfish.entities.ActiveRule;
+import fr.ifremer.isisfish.entities.ActiveRuleDAO;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.rule.Rule;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.simulator.SimulationException;
+import fr.ifremer.isisfish.simulator.SimulationPlan;
+import fr.ifremer.isisfish.simulator.SimulationResultGetter;
+import fr.ifremer.isisfish.simulator.SimulationResultListener;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.types.TimeStep;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
@@ -39,36 +53,25 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
-
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.DoubleBigMappedVector;
+import org.nuiton.math.matrix.MatrixFactory;
+import org.nuiton.math.matrix.MatrixHelper;
import org.nuiton.math.matrix.MatrixIterator;
import org.nuiton.math.matrix.MatrixND;
+import org.nuiton.math.matrix.MatrixSemanticsDecorator;
+import org.nuiton.math.matrix.SemanticsDecorator;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.ArrayUtil;
import org.nuiton.util.HashList;
-import fr.ifremer.isisfish.IsisFishDAOHelper;
-import fr.ifremer.isisfish.IsisFishException;
-import fr.ifremer.isisfish.IsisFishRuntimeException;
-import fr.ifremer.isisfish.entities.ActiveRule;
-import fr.ifremer.isisfish.entities.ActiveRuleDAO;
-import fr.ifremer.isisfish.entities.Population;
-import fr.ifremer.isisfish.export.Export;
-import fr.ifremer.isisfish.export.SensitivityExport;
-import fr.ifremer.isisfish.rule.Rule;
-import fr.ifremer.isisfish.simulator.SimulationContext;
-import fr.ifremer.isisfish.simulator.SimulationException;
-import fr.ifremer.isisfish.simulator.SimulationPlan;
-import fr.ifremer.isisfish.simulator.SimulationResultGetter;
-import fr.ifremer.isisfish.simulator.SimulationResultListener;
-import fr.ifremer.isisfish.types.Month;
-import fr.ifremer.isisfish.types.TimeStep;
+import static org.nuiton.i18n.I18n._;
/**
* Cette classe permet de conserver des résultats de simulation. Elle permet
@@ -88,7 +91,7 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(ResultMappedStorage.class);
- //static protected MatrixFactory matrixFactory = MatrixFactory.getInstance(DoubleBigMappedVector.class);
+ static protected MatrixFactory matrixFactory = MatrixFactory.getInstance(DoubleBigMappedVector.class);
protected SimulationStorage simulation = null;
protected RandomAccessFile raf;
@@ -105,7 +108,7 @@
* Convertie une entite, month, timestep en string et inversement.
* Entity = "TopiaId:Entity.toString"
*/
- static protected class EntitySemanticsDecorator /*implements SemanticsDecorator*/ {
+ static protected class EntitySemanticsDecorator implements SemanticsDecorator {
static final private String SEP = ":";
protected TopiaContext tx;
@@ -223,8 +226,8 @@
long dataOffset = offset + size;
int dataSize = raf.readInt(); // en mettant un int on est limite a 2Go x 8 (double) = 16Go par matrice
- //DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
- //this.matrix = matrixFactory.create(name, sems, dimNames, data);
+ DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
+ this.matrix = matrixFactory.create(name, sems, dimNames, data);
size += dataSize * 8; /* un double est sur 8 bytes*/
this.size = size;
@@ -241,7 +244,7 @@
String[] dimNames = matrix.getDimensionNames();
int[] dims = matrix.getDim();
List[] sems = matrix.getSemantics();
- int dataSize = 0; //MatrixHelper.getVectorSize(dims); // en mettant un int on est limite a 2Go x 8 (double) = 16Go par matrice
+ int dataSize = MatrixHelper.getVectorSize(dims); // en mettant un int on est limite a 2Go x 8 (double) = 16Go par matrice
raf.write(step.getStep()); // ecriture du pas de temps
raf.writeUTF(name); // ecriture du nom du resultat
@@ -255,13 +258,13 @@
}
// conversion et enregistrement des semantiques
- //SemanticsDecorator deco = new EntitySemanticsDecorator();
+ SemanticsDecorator deco = new EntitySemanticsDecorator();
for (int i=0; i<sems.length; i ++) {
List l = sems[i];
List undecorate = new ArrayList(l.size());
sems[i] = undecorate;
for (Object o : l) {
- //o = deco.undecorate(o);
+ o = deco.undecorate(o);
undecorate.add(o);
raf.writeUTF(o.toString()); // ecriture de chaque dimension
}
@@ -274,8 +277,8 @@
long dataOffset = offset + size;
// on cree la nouvelle matrice comme il faut (semantique non decore)
- //DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
- //this.matrix = MatrixFactory.getInstance().create(name, sems, dimNames, data);
+ DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
+ this.matrix = MatrixFactory.getInstance().create(name, sems, dimNames, data);
// et on met les valeurs de l'ancienne dans la nouvelle
this.matrix.paste(matrix);
@@ -305,8 +308,8 @@
public MatrixND getMatrix(TopiaContext tx) {
// on met la matrice dans un decorateur pour convertir automatiquement les semantiques
- //MatrixND result = new MatrixSemanticsDecorator(matrix, new EntitySemanticsDecorator(tx));
- return null;
+ MatrixND result = new MatrixSemanticsDecorator(matrix, new EntitySemanticsDecorator(tx));
+ return result;
}
}
@@ -711,7 +714,7 @@
}
// creation de la matrice resultat
- //resultMat = matrixFactory.create(name, sem, dimNames);
+ resultMat = matrixFactory.create(name, sem, dimNames);
// recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
for (ResultMapped result : results.values()) {
@@ -735,7 +738,7 @@
// on decore la matrice resultat au dernier moment, tous les calcules
// ce font avec les strings
tx = getTx(tx);
- //resultMat = new MatrixSemanticsDecorator(resultMat, new EntitySemanticsDecorator(tx));
+ resultMat = new MatrixSemanticsDecorator(resultMat, new EntitySemanticsDecorator(tx));
}
return resultMat;
}
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2012-09-04 08:25:48 UTC (rev 3760)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2012-09-04 08:52:27 UTC (rev 3761)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2005 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
+ * Copyright (C) 2005 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -453,24 +453,24 @@
public ResultStorage getResultStorage() throws StorageException {
if (resultStorage == null) {
- // depuis la version 4.1.1.1 le stockage a changé de base
+ // depuis la version 4.1.1.2 le stockage a changé de base
// de données à fichier mappe pour les resultat
// mais il faut pouvoir relire les anciennes simulations
- /*SimulationParameter param = getParameter();
+ SimulationParameter param = getParameter();
String isisFishVersion = param.getIsisFishVersion();
Version simuVersion = new Version(isisFishVersion);
- Version version4111 = new Version(4,1,1,1);
+ Version version4112 = new Version(4,1,1,2);
// instancier un ResultStorage ou un ResultMappedStorage
- if (simuVersion.before(version4111)) {*/
+ if (simuVersion.before(version4112)) {
resultStorage = new ResultDatabaseStorage(this);
- /*} else {
+ } else {
try {
resultStorage = new ResultMappedStorage(this);
} catch (IOException ex) {
throw new StorageException("Can't get storage", ex);
}
- }*/
+ }
}
return resultStorage;
}
1
0
Author: maven-release
Date: 2012-09-04 10:25:48 +0200 (Tue, 04 Sep 2012)
New Revision: 3760
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3760
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-09-04 08:25:41 UTC (rev 3759)
+++ trunk/pom.xml 2012-09-04 08:25:48 UTC (rev 3760)
@@ -11,7 +11,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>isis-fish</artifactId>
- <version>4.1.1.1</version>
+ <version>4.1.1.2-SNAPSHOT</version>
<!-- POM Relationships : Inheritance : Dependencies -->
<dependencies>
@@ -730,9 +730,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.1</connection>
- <developerConnection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.1</developerConnection>
- <url>http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.1</url>
+ <connection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/trunk</connection>
+ <developerConnection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/trunk</developerConnection>
+ <url>http://svn.forge.codelutin.com/svn/isis-fish/trunk</url>
</scm>
<repositories>
1
0
04 Sep '12
Author: maven-release
Date: 2012-09-04 10:25:41 +0200 (Tue, 04 Sep 2012)
New Revision: 3759
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3759
Log:
[maven-release-plugin] copy for tag isis-fish-4.1.1.1
Added:
tags/isis-fish-4.1.1.1/
Property changes on: tags/isis-fish-4.1.1.1
___________________________________________________________________
Added: svn:ignore
+ maven.log
target
velocity.log
.classpath
.project
isis-fish.ipr
isis-fish.iws
isis-fish.iml
.settings
bin
nbproject
Inputs_Langoustine
Added: svn:mergeinfo
+ /branches/4.1:3601-3670
1
0
Author: maven-release
Date: 2012-09-04 10:25:34 +0200 (Tue, 04 Sep 2012)
New Revision: 3758
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3758
Log:
[maven-release-plugin] prepare release isis-fish-4.1.1.1
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-09-04 08:20:38 UTC (rev 3757)
+++ trunk/pom.xml 2012-09-04 08:25:34 UTC (rev 3758)
@@ -11,7 +11,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>isis-fish</artifactId>
- <version>4.1.1.1-SNAPSHOT</version>
+ <version>4.1.1.1</version>
<!-- POM Relationships : Inheritance : Dependencies -->
<dependencies>
@@ -730,9 +730,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/trunk</connection>
- <developerConnection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/trunk</developerConnection>
- <url>http://svn.forge.codelutin.com/svn/isis-fish/trunk</url>
+ <connection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.1</connection>
+ <developerConnection>scm:svn:http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.1</developerConnection>
+ <url>http://svn.forge.codelutin.com/svn/isis-fish/tags/isis-fish-4.1.1.1</url>
</scm>
<repositories>
1
0
r3757 - trunk/src/main/java/fr/ifremer/isisfish/datastore
by echatellier@users.forge.codelutin.com 04 Sep '12
by echatellier@users.forge.codelutin.com 04 Sep '12
04 Sep '12
Author: echatellier
Date: 2012-09-04 10:20:38 +0200 (Tue, 04 Sep 2012)
New Revision: 3757
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3757
Log:
Add header
Modified:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-09-04 08:18:20 UTC (rev 3756)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-09-04 08:20:38 UTC (rev 3757)
@@ -1,3 +1,28 @@
+/*
+ * #%L
+ * IsisFish
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 Ifremer, Code Lutin, Benjamin Poussin, Chatellier Eric
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+
package fr.ifremer.isisfish.datastore;
import java.util.List;
1
0
r3756 - in trunk: . src/main/java/fr/ifremer/isisfish/datastore
by echatellier@users.forge.codelutin.com 04 Sep '12
by echatellier@users.forge.codelutin.com 04 Sep '12
04 Sep '12
Author: echatellier
Date: 2012-09-04 10:18:20 +0200 (Tue, 04 Sep 2012)
New Revision: 3756
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3756
Log:
Comment current development to prepare release.
Modified:
trunk/pom.xml
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-09-02 23:09:00 UTC (rev 3755)
+++ trunk/pom.xml 2012-09-04 08:18:20 UTC (rev 3756)
@@ -62,7 +62,7 @@
<dependency>
<groupId>org.nuiton.matrix</groupId>
<artifactId>nuiton-matrix</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.1</version>
<scope>compile</scope>
</dependency>
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-09-02 23:09:00 UTC (rev 3755)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-09-04 08:18:20 UTC (rev 3756)
@@ -25,22 +25,8 @@
package fr.ifremer.isisfish.datastore;
-import fr.ifremer.isisfish.IsisFishDAOHelper;
-import fr.ifremer.isisfish.IsisFishException;
-import fr.ifremer.isisfish.IsisFishRuntimeException;
-import fr.ifremer.isisfish.entities.ActiveRule;
-import fr.ifremer.isisfish.entities.ActiveRuleDAO;
-import fr.ifremer.isisfish.entities.Population;
-import fr.ifremer.isisfish.export.Export;
-import fr.ifremer.isisfish.export.SensitivityExport;
-import fr.ifremer.isisfish.rule.Rule;
-import fr.ifremer.isisfish.simulator.SimulationContext;
-import fr.ifremer.isisfish.simulator.SimulationException;
-import fr.ifremer.isisfish.simulator.SimulationPlan;
-import fr.ifremer.isisfish.simulator.SimulationResultGetter;
-import fr.ifremer.isisfish.simulator.SimulationResultListener;
-import fr.ifremer.isisfish.types.Month;
-import fr.ifremer.isisfish.types.TimeStep;
+import static org.nuiton.i18n.I18n._;
+
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
@@ -48,31 +34,41 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.math.matrix.DoubleBigMappedVector;
-import org.nuiton.math.matrix.MatrixFactory;
-import org.nuiton.math.matrix.MatrixHelper;
import org.nuiton.math.matrix.MatrixIterator;
import org.nuiton.math.matrix.MatrixND;
-import org.nuiton.math.matrix.MatrixSemanticsDecorator;
-import org.nuiton.math.matrix.SemanticsDecorator;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.ArrayUtil;
import org.nuiton.util.HashList;
-import static org.nuiton.i18n.I18n._;
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.IsisFishRuntimeException;
+import fr.ifremer.isisfish.entities.ActiveRule;
+import fr.ifremer.isisfish.entities.ActiveRuleDAO;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.rule.Rule;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.simulator.SimulationException;
+import fr.ifremer.isisfish.simulator.SimulationPlan;
+import fr.ifremer.isisfish.simulator.SimulationResultGetter;
+import fr.ifremer.isisfish.simulator.SimulationResultListener;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.types.TimeStep;
/**
* Cette classe permet de conserver des résultats de simulation. Elle permet
@@ -92,7 +88,7 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(ResultMappedStorage.class);
- static protected MatrixFactory matrixFactory = MatrixFactory.getInstance(DoubleBigMappedVector.class);
+ //static protected MatrixFactory matrixFactory = MatrixFactory.getInstance(DoubleBigMappedVector.class);
protected SimulationStorage simulation = null;
protected RandomAccessFile raf;
@@ -109,7 +105,7 @@
* Convertie une entite, month, timestep en string et inversement.
* Entity = "TopiaId:Entity.toString"
*/
- static protected class EntitySemanticsDecorator implements SemanticsDecorator {
+ static protected class EntitySemanticsDecorator /*implements SemanticsDecorator*/ {
static final private String SEP = ":";
protected TopiaContext tx;
@@ -227,8 +223,8 @@
long dataOffset = offset + size;
int dataSize = raf.readInt(); // en mettant un int on est limite a 2Go x 8 (double) = 16Go par matrice
- DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
- this.matrix = matrixFactory.create(name, sems, dimNames, data);
+ //DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
+ //this.matrix = matrixFactory.create(name, sems, dimNames, data);
size += dataSize * 8; /* un double est sur 8 bytes*/
this.size = size;
@@ -245,7 +241,7 @@
String[] dimNames = matrix.getDimensionNames();
int[] dims = matrix.getDim();
List[] sems = matrix.getSemantics();
- int dataSize = MatrixHelper.getVectorSize(dims); // en mettant un int on est limite a 2Go x 8 (double) = 16Go par matrice
+ int dataSize = 0; //MatrixHelper.getVectorSize(dims); // en mettant un int on est limite a 2Go x 8 (double) = 16Go par matrice
raf.write(step.getStep()); // ecriture du pas de temps
raf.writeUTF(name); // ecriture du nom du resultat
@@ -259,13 +255,13 @@
}
// conversion et enregistrement des semantiques
- SemanticsDecorator deco = new EntitySemanticsDecorator();
+ //SemanticsDecorator deco = new EntitySemanticsDecorator();
for (int i=0; i<sems.length; i ++) {
List l = sems[i];
List undecorate = new ArrayList(l.size());
sems[i] = undecorate;
for (Object o : l) {
- o = deco.undecorate(o);
+ //o = deco.undecorate(o);
undecorate.add(o);
raf.writeUTF(o.toString()); // ecriture de chaque dimension
}
@@ -278,8 +274,8 @@
long dataOffset = offset + size;
// on cree la nouvelle matrice comme il faut (semantique non decore)
- DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
- this.matrix = MatrixFactory.getInstance().create(name, sems, dimNames, data);
+ //DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
+ //this.matrix = MatrixFactory.getInstance().create(name, sems, dimNames, data);
// et on met les valeurs de l'ancienne dans la nouvelle
this.matrix.paste(matrix);
@@ -309,10 +305,9 @@
public MatrixND getMatrix(TopiaContext tx) {
// on met la matrice dans un decorateur pour convertir automatiquement les semantiques
- MatrixND result = new MatrixSemanticsDecorator(matrix, new EntitySemanticsDecorator(tx));
- return result;
+ //MatrixND result = new MatrixSemanticsDecorator(matrix, new EntitySemanticsDecorator(tx));
+ return null;
}
-
}
/**
@@ -325,7 +320,15 @@
public ResultMappedStorage(SimulationStorage simulation) throws IOException {
this.simulation = simulation;
File file = SimulationStorage.getResultFile(simulation.getDirectory());
- raf = new RandomAccessFile(file, "rw");
+
+ // le fichier semble se corrompre à la relecture (ouverture
+ // en lecture seule s'il existe déjà)
+ if (file.isFile()) {
+ raf = new RandomAccessFile(file, "r");
+ } else {
+ raf = new RandomAccessFile(file, "rw");
+ }
+
// on lit les donnees deja presente
offset = 0;
while (offset < raf.length()) {
@@ -708,7 +711,7 @@
}
// creation de la matrice resultat
- resultMat = matrixFactory.create(name, sem, dimNames);
+ //resultMat = matrixFactory.create(name, sem, dimNames);
// recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
for (ResultMapped result : results.values()) {
@@ -732,7 +735,7 @@
// on decore la matrice resultat au dernier moment, tous les calcules
// ce font avec les strings
tx = getTx(tx);
- resultMat = new MatrixSemanticsDecorator(resultMat, new EntitySemanticsDecorator(tx));
+ //resultMat = new MatrixSemanticsDecorator(resultMat, new EntitySemanticsDecorator(tx));
}
return resultMat;
}
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2012-09-02 23:09:00 UTC (rev 3755)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2012-09-04 08:18:20 UTC (rev 3756)
@@ -43,6 +43,7 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.util.FileUtil;
+import org.nuiton.util.Version;
import org.nuiton.util.ZipUtil;
import fr.ifremer.isisfish.IsisFish;
@@ -451,13 +452,25 @@
*/
public ResultStorage getResultStorage() throws StorageException {
if (resultStorage == null) {
+
+ // depuis la version 4.1.1.1 le stockage a changé de base
+ // de données à fichier mappe pour les resultat
+ // mais il faut pouvoir relire les anciennes simulations
+ /*SimulationParameter param = getParameter();
+ String isisFishVersion = param.getIsisFishVersion();
+ Version simuVersion = new Version(isisFishVersion);
+ Version version4111 = new Version(4,1,1,1);
+
// instancier un ResultStorage ou un ResultMappedStorage
- //resultStorage = new ResultDatabaseStorage(this);
- try {
- resultStorage = new ResultMappedStorage(this);
- } catch (IOException ex) {
- throw new StorageException("Can't get storage", ex);
- }
+ if (simuVersion.before(version4111)) {*/
+ resultStorage = new ResultDatabaseStorage(this);
+ /*} else {
+ try {
+ resultStorage = new ResultMappedStorage(this);
+ } catch (IOException ex) {
+ throw new StorageException("Can't get storage", ex);
+ }
+ }*/
}
return resultStorage;
}
1
0
r3755 - trunk/src/main/java/fr/ifremer/isisfish/datastore
by bpoussin@users.forge.codelutin.com 02 Sep '12
by bpoussin@users.forge.codelutin.com 02 Sep '12
02 Sep '12
Author: bpoussin
Date: 2012-09-03 01:09:00 +0200 (Mon, 03 Sep 2012)
New Revision: 3755
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3755
Log:
on passe offset a long pour supporter les fichiers de resultats > 2go
Modified:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 18:17:43 UTC (rev 3754)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-09-02 23:09:00 UTC (rev 3755)
@@ -96,7 +96,7 @@
protected SimulationStorage simulation = null;
protected RandomAccessFile raf;
- protected int offset;
+ protected long offset;
protected Map<TimeStep, Map<String, ResultMapped>> stepNameResults =
new TreeMap<TimeStep, Map<String, ResultMapped>>();
protected Map<String, Map<TimeStep, ResultMapped>> nameStepResults =
@@ -186,14 +186,14 @@
*/
static protected class ResultMapped {
protected RandomAccessFile raf;
- protected int offset;
- protected int size;
+ protected long offset;
+ protected long size;
protected TimeStep step;
protected String name;
protected MatrixND matrix;
/** read data from file */
- public ResultMapped(RandomAccessFile raf, int offset) throws IOException {
+ public ResultMapped(RandomAccessFile raf, long offset) throws IOException {
this.raf = raf;
this.offset = offset;
@@ -223,10 +223,10 @@
}
}
- int size = (int) raf.getFilePointer();
- int dataOffset = offset + size;
+ long size = raf.getFilePointer();
+ long dataOffset = offset + size;
- int dataSize = raf.readInt();
+ int dataSize = raf.readInt(); // en mettant un int on est limite a 2Go x 8 (double) = 16Go par matrice
DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
this.matrix = matrixFactory.create(name, sems, dimNames, data);
@@ -235,7 +235,7 @@
}
/** write date to file */
- public ResultMapped(RandomAccessFile raf, int offset,
+ public ResultMapped(RandomAccessFile raf, long offset,
TimeStep step, String name, MatrixND matrix) throws IOException {
this.raf = raf;
this.offset = offset;
@@ -245,7 +245,7 @@
String[] dimNames = matrix.getDimensionNames();
int[] dims = matrix.getDim();
List[] sems = matrix.getSemantics();
- int dataSize = MatrixHelper.getVectorSize(dims);
+ int dataSize = MatrixHelper.getVectorSize(dims); // en mettant un int on est limite a 2Go x 8 (double) = 16Go par matrice
raf.write(step.getStep()); // ecriture du pas de temps
raf.writeUTF(name); // ecriture du nom du resultat
@@ -274,9 +274,9 @@
raf.writeInt(dataSize);
// on prend la position apres l'ecriture de l'entete
- int size = (int) raf.getFilePointer();
+ long size = raf.getFilePointer();
- int dataOffset = offset + size;
+ long dataOffset = offset + size;
// on cree la nouvelle matrice comme il faut (semantique non decore)
DoubleBigMappedVector data = new DoubleBigMappedVector(raf, dataOffset, dataSize);
this.matrix = MatrixFactory.getInstance().create(name, sems, dimNames, data);
@@ -291,7 +291,7 @@
* retourne la taille en nombre de byte
* @return
*/
- public int size() {
+ public long size() {
return size;
}
1
0
r3754 - trunk/src/main/java/fr/ifremer/isisfish/datastore
by bpoussin@users.forge.codelutin.com 31 Aug '12
by bpoussin@users.forge.codelutin.com 31 Aug '12
31 Aug '12
Author: bpoussin
Date: 2012-08-31 20:17:43 +0200 (Fri, 31 Aug 2012)
New Revision: 3754
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3754
Log:
avec un peu de cache, ca va beaucoup mieux :)
13min -> 50s
y'a plus qu'a verifier reellement les resultats :)
Modified:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 16:16:11 UTC (rev 3753)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 18:17:43 UTC (rev 3754)
@@ -27,6 +27,7 @@
import fr.ifremer.isisfish.IsisFishDAOHelper;
import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.IsisFishRuntimeException;
import fr.ifremer.isisfish.entities.ActiveRule;
import fr.ifremer.isisfish.entities.ActiveRuleDAO;
import fr.ifremer.isisfish.entities.Population;
@@ -47,11 +48,14 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+import org.apache.commons.collections.BidiMap;
+import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -109,6 +113,8 @@
static final private String SEP = ":";
protected TopiaContext tx;
+ /** en cle les representation interne (get) en valeur les valeurs decoree (getKey) */
+ protected BidiMap cache = new DualHashBidiMap();
public EntitySemanticsDecorator() {
}
@@ -118,47 +124,54 @@
}
public Object decorate(Object internalValue) {
- Object result = internalValue;
- if (internalValue instanceof String) {
- if (StringUtils.startsWith((String)internalValue, Month.class.getName())) {
- String val = StringUtils.substringAfter((String)internalValue, SEP);
- int monthNumber = Integer.parseInt(val);
- result = new Month(monthNumber);
- } else if (StringUtils.startsWith((String)internalValue, TimeStep.class.getName())) {
- String val = StringUtils.substringAfter((String)internalValue, SEP);
- int stepNumber = Integer.parseInt(val);
- result = new TimeStep(stepNumber);
- } else if (StringUtils.startsWith((String)internalValue, "fr.ifremer.isisfish.entities.")) {
- if (tx == null) {
- result = StringUtils.substringAfter((String)internalValue, SEP);
- } else {
- try {
- String id = StringUtils.substringBefore((String)internalValue, SEP);
- result = tx.findByTopiaId(id);
- } catch (TopiaException eee) {
- log.info("Fallback use string representation because"
- + " i can't decorate (String->Entity): "
- + internalValue, eee);
- // si on arrive pas a convertir cette fois-ci, on
- // renvoi internalValue pour que le undecorate est toutes les infos
- // et donc que la prochaine fois on y arrive peut etre
+ Object result = cache.get(internalValue);
+ if (result == null && internalValue != null) {
+ result = internalValue;
+ if (internalValue instanceof String) {
+ if (StringUtils.startsWith((String)internalValue, Month.class.getName())) {
+ String val = StringUtils.substringAfter((String)internalValue, SEP);
+ int monthNumber = Integer.parseInt(val);
+ result = new Month(monthNumber);
+ } else if (StringUtils.startsWith((String)internalValue, TimeStep.class.getName())) {
+ String val = StringUtils.substringAfter((String)internalValue, SEP);
+ int stepNumber = Integer.parseInt(val);
+ result = new TimeStep(stepNumber);
+ } else if (StringUtils.startsWith((String)internalValue, "fr.ifremer.isisfish.entities.")) {
+ if (tx == null) {
+ result = StringUtils.substringAfter((String)internalValue, SEP);
+ } else {
+ try {
+ String id = StringUtils.substringBefore((String)internalValue, SEP);
+ result = tx.findByTopiaId(id);
+ } catch (TopiaException eee) {
+ log.info("Fallback use string representation because"
+ + " i can't decorate (String->Entity): "
+ + internalValue, eee);
+ // si on arrive pas a convertir cette fois-ci, on
+ // renvoi internalValue pour que le undecorate est toutes les infos
+ // et donc que la prochaine fois on y arrive peut etre
+ }
}
}
}
+ cache.put(internalValue, result);
}
return result;
}
public Object undecorate(Object decoratedValue) {
- String result;
- if (decoratedValue instanceof Month) {
- result = Month.class.getName() + SEP + ((Month)decoratedValue).getMonthNumber();
- } else if (decoratedValue instanceof TimeStep) {
- result = TimeStep.class.getName() + SEP + ((TimeStep)decoratedValue).getStep();
- } else if (decoratedValue instanceof TopiaEntity) {
- result = ((TopiaEntity)decoratedValue).getTopiaId() + SEP + decoratedValue;
- } else {
- result = String.valueOf(decoratedValue);
+ Object result = cache.getKey(decoratedValue);
+ if (result == null && decoratedValue != null) {
+ if (decoratedValue instanceof Month) {
+ result = Month.class.getName() + SEP + ((Month)decoratedValue).getMonthNumber();
+ } else if (decoratedValue instanceof TimeStep) {
+ result = TimeStep.class.getName() + SEP + ((TimeStep)decoratedValue).getStep();
+ } else if (decoratedValue instanceof TopiaEntity) {
+ result = ((TopiaEntity)decoratedValue).getTopiaId() + SEP + decoratedValue;
+ } else {
+ result = String.valueOf(decoratedValue);
+ }
+ cache.put(result, decoratedValue);
}
return result;
}
@@ -575,6 +588,19 @@
return getMatrix(step, newName, null);
}
+ /**
+ * Retourne la matrice stocke pour un pas de temps
+ * @param step le pas de temps que l'on souhaite
+ * @param pop la population pour lequelle on souhaite le resultat
+ * @param name le nom des resultats dont on veut la matrice
+ * @return La matrice demandée ou null si aucune matrice ne correspond a
+ * la demande.
+ */
+ public MatrixND getMatrix(TimeStep step, Population pop, String name, TopiaContext tx) {
+ String newName = name + " " + pop;
+ return getMatrix(step, newName, tx);
+ }
+
public MatrixND getMatrix(TimeStep step, String name) {
return getMatrix(step, name, null);
}
@@ -588,6 +614,7 @@
ResultMapped r = getResult(step, name);
MatrixND mat = null;
if (r != null) {
+ tx = getTx(tx);
mat = r.getMatrix(tx);
}
return mat;
@@ -704,6 +731,7 @@
if (resultMat != null) {
// on decore la matrice resultat au dernier moment, tous les calcules
// ce font avec les strings
+ tx = getTx(tx);
resultMat = new MatrixSemanticsDecorator(resultMat, new EntitySemanticsDecorator(tx));
}
return resultMat;
@@ -763,6 +791,29 @@
return result;
}
+ /**
+ * Try to find better tx. If argument is not null, return it. otherwize
+ * try to get tx in SimulationContext.
+ *
+ * @param tx
+ * @return
+ */
+ protected TopiaContext getTx(TopiaContext tx) {
+ TopiaContext result = tx;
+ if (tx == null) {
+ // si on a pas de tx, on recherche si on est dans une simulation
+ // pour recuperer la tx de la simulation
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ try {
+ result = SimulationContext.get().getDB();
+ } catch (TopiaException eee) {
+ throw new IsisFishRuntimeException("Can't get database from SimulationContext", eee);
+ }
+ }
+ }
+ return result;
+ }
+
/*
* @see fr.ifremer.isisfish.simulator.SimulationListener#afterSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
*/
1
0
r3753 - trunk/src/main/java/fr/ifremer/isisfish/datastore
by bpoussin@users.forge.codelutin.com 31 Aug '12
by bpoussin@users.forge.codelutin.com 31 Aug '12
31 Aug '12
Author: bpoussin
Date: 2012-08-31 18:16:11 +0200 (Fri, 31 Aug 2012)
New Revision: 3753
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3753
Log:
petit oubli du add :(
Modified:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 16:11:36 UTC (rev 3752)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 16:16:11 UTC (rev 3753)
@@ -253,6 +253,7 @@
sems[i] = undecorate;
for (Object o : l) {
o = deco.undecorate(o);
+ undecorate.add(o);
raf.writeUTF(o.toString()); // ecriture de chaque dimension
}
}
1
0
r3752 - trunk/src/main/java/fr/ifremer/isisfish/datastore
by echatellier@users.forge.codelutin.com 31 Aug '12
by echatellier@users.forge.codelutin.com 31 Aug '12
31 Aug '12
Author: echatellier
Date: 2012-08-31 18:11:36 +0200 (Fri, 31 Aug 2012)
New Revision: 3752
Url: http://forge.codelutin.com/repositories/revision/isis-fish/3752
Log:
Extract common interface for ResultStorage
Added:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultDatabaseStorage.java
Modified:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
Copied: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultDatabaseStorage.java (from rev 3750, trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java)
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultDatabaseStorage.java (rev 0)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultDatabaseStorage.java 2012-08-31 16:11:36 UTC (rev 3752)
@@ -0,0 +1,811 @@
+/*
+ * #%L
+ * IsisFish
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2002 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+
+package fr.ifremer.isisfish.datastore;
+
+import static org.nuiton.i18n.I18n._;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixFactory;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.util.ArrayUtil;
+import org.nuiton.util.HashList;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.entities.ActiveRule;
+import fr.ifremer.isisfish.entities.ActiveRuleDAO;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.Result;
+import fr.ifremer.isisfish.entities.ResultDAO;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.rule.Rule;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.simulator.SimulationException;
+import fr.ifremer.isisfish.simulator.SimulationPlan;
+import fr.ifremer.isisfish.simulator.SimulationResultGetter;
+import fr.ifremer.isisfish.types.TimeStep;
+import fr.ifremer.isisfish.types.Month;
+
+/**
+ * Cette classe permet de conserver des résultats de simulation. Elle permet
+ * ensuite de les récupérer.
+ *
+ * Created: 29 sept. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class ResultDatabaseStorage implements SimulationResultGetter, ResultStorage { // ResultDatabaseStorage
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(ResultDatabaseStorage.class);
+
+ protected SimulationStorage simulation = null;
+ // transient protected HashMap<String, MatrixND> globalMatrix = new HashMap<String, MatrixND>();
+ transient protected ReferenceMap cacheContext = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK);
+
+ /** cache to maintains some result. key: String(date + ':' + name), value: matrix
+ * TODO: cache will be more efficient if it keep at min the number of result by year */
+ transient protected ReferenceMap cache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
+ /** contains all available result as string: String(date + ':' + name) */
+ transient protected Set<String> availableResult = null;
+ /** result enabled */
+ transient protected Set<String> enabledResult = null;
+
+ /**
+ * Les ResultStorage ne doivent pas etre instancier directement, mais
+ * recuperer a partir d'un
+ * {@link fr.ifremer.isisfish.datastore.SimulationStorage#getResultStorage()}
+ *
+ * @param simulation storage to get result
+ */
+ public ResultDatabaseStorage(SimulationStorage simulation) {
+ this.simulation = simulation;
+ }
+
+ protected void putInCache(TimeStep step, String name, MatrixND mat, TopiaContext context) {
+ String key = step.getStep() + ":" + name;
+ putInCache(key, mat, context);
+ }
+
+ protected void putInCache(String name, MatrixND mat, TopiaContext context) {
+ if (mat != null) {
+ cache.put(name, mat);
+ cacheContext.put(name, context);
+ }
+ }
+
+ /**
+ * Result can be removed from cache when computed result (from multiple step)
+ * become invalidated by new step result.
+ *
+ * @param name result name to remove
+ */
+ protected void removeInCache(String name) {
+ cache.remove(name);
+ cacheContext.remove(name);
+ }
+
+ protected MatrixND getInCache(TimeStep step, String name) {
+ // do not use toString for step (depend on i18n)
+ String key = step.getStep() + ":" + name;
+ MatrixND result = getInCache(key);
+ return result;
+ }
+
+ protected MatrixND getInCache(String name) {
+ MatrixND result = null;
+ TopiaContext context = (TopiaContext) cacheContext.get(name);
+ if (context != null && !context.isClosed()) {
+ // on verifie que le context existe encore car on peut vouloir
+ // naviguer dans les semantics
+ result = (MatrixND) cache.get(name);
+ }
+ return result;
+ }
+
+ /**
+ * Retourne le nom de tous les resultats disponibles le nom est constitué
+ * de la date et du nom du resultat.
+ *
+ * @return available results
+ */
+ protected Set<String> getAvailableResult() {
+ if (availableResult == null) {
+ availableResult = new HashSet<String>();
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+
+ List<String> result = (List<String>) tx.findAll("Select " + Result.PROPERTY_RESULT_STEP + "||':'||name from fr.ifremer.isisfish.entities.Result");
+ if (mustClose) {
+ tx.closeContext();
+ }
+ availableResult.addAll(result);
+ } catch (Exception eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't get result available", eee);
+ }
+ }
+ }
+ return availableResult;
+ }
+
+ /**
+ * Verifie si un resultat est disponible pour une date donnée.
+ *
+ * @param step
+ * @param name
+ * @return {@code true} if result is available
+ */
+ protected boolean isAvailableResult(TimeStep step, String name) {
+ String key = step.getStep() + ":" + name;
+ boolean result = getAvailableResult().contains(key);
+ return result;
+ }
+
+ /**
+ * Ajoute un resultat comme etant disponible pour une date donnée.
+ *
+ * @param step
+ * @param name
+ */
+ protected void addAvailableResult(TimeStep step, String name) {
+ String key = step.getStep() + ":" + name;
+ getAvailableResult().add(key);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#isEnabled(java.lang.String)
+ */
+ @Override
+ public boolean isEnabled(String name) {
+ name = name.trim();
+ if (enabledResult == null) {
+ enabledResult = new HashSet<String>();
+
+ Collection<String> resultEnabled = simulation.getParameter()
+ .getResultEnabled();
+ enabledResult.addAll(resultEnabled);
+
+ // test on export
+ List<String> exportNames = simulation.getParameter().getExportNames();
+ if (exportNames != null) {
+ for (String exportName : exportNames) {
+ ExportStorage storage = ExportStorage.getExport(exportName);
+ try {
+ Export export = storage.getNewExportInstance();
+ for (String resultName : export.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ } catch (IsisFishException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(_("isisfish.error.instanciate.export",
+ exportName), eee);
+ }
+ }
+ }
+ }
+
+ // test on sensitivity export
+ List<SensitivityExport> sensitivityExports = simulation
+ .getParameter().getSensitivityExport();
+ if (sensitivityExports != null) {
+ for (SensitivityExport sensitivityExport : sensitivityExports) {
+ for (String resultName : sensitivityExport.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ }
+ }
+
+ // test on rules
+ List<Rule> rules = simulation.getParameter().getRules();
+ if (rules != null) {
+ for (Rule rule : rules) {
+ for (String resultName : rule.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ }
+ }
+
+ // test on plans
+ List<SimulationPlan> plans = simulation.getParameter().getSimulationPlans();
+ if (plans != null) {
+ for (SimulationPlan plan : plans) {
+ for (String resultName : plan.getNecessaryResult()) {
+ enabledResult.add(resultName);
+ }
+ }
+ }
+ log.info("Enabled result: " + enabledResult);
+ }
+ boolean result = enabledResult.contains(name);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(TimeStep step, MatrixND mat) throws IsisFishException {
+ addResult(false, step, mat.getName(), mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(false, step, mat.getName(), pop, mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(boolean force, TimeStep step, MatrixND mat) throws IsisFishException {
+ addResult(force, step, mat.getName(), mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(boolean force, TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(force, step, mat.getName(), pop, mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, java.lang.String, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(false, step, name, pop, mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ addResult(false, step, name, mat);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, java.lang.String, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(boolean force, TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
+ if (force || isEnabled(name)) {
+ doAddResult(step, name + " " + pop, mat);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(boolean force, TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ if (force || isEnabled(name)) {
+ doAddResult(step, name, mat);
+ }
+ }
+
+ protected void doAddResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+ doAddResult(step, name, mat, tx);
+ if (mustClose) {
+ tx.commitTransaction();
+ tx.closeContext();
+ }
+ } catch (TopiaException eee) {
+ log.warn("Can't add result '" + name + "' at step " + step, eee);
+ }
+ }
+
+ protected void doAddResult(TimeStep step, String name, MatrixND mat,
+ TopiaContext tx) throws IsisFishException {
+ // si la matrice n'a pas de semantique on refuse
+ for (int i = 0; i < mat.getDimCount(); i++) {
+ // la semantique n'est pas bonne des qu'il y a un null dedans
+ if (mat.getSemantic(i).contains(null)) {
+ throw new SimulationException(
+ "Erreur le résultat que vous souhaitez enregistrer n'a pas d'information convenable pour la dimension: "
+ + i + " " + mat.getDimensionName(i));
+ }
+ }
+
+ // on fait une copie pour avoir reellement des resultats independant
+ // FIXME echatellier 20120829 : faire une copie optimiser
+ // suivant l'implementation du vector plutot qu'un parcourt
+ // via un iterateur de semantiques (plus couteux)
+ MatrixND newMat = mat.copy();
+ try {
+ ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
+ Result result = resultPS.create();
+ result.setResultStep(step);
+ result.setName(name);
+ result.setMatrix(newMat);
+ resultPS.update(result);
+
+ addAvailableResult(step, name);
+ putInCache(step, name, newMat, tx);
+
+ // depuis isis fish 4.1.1, le commit est automatique à chaque
+ // résultat (gain de performance de 20% avec le clearCache)
+ tx.commitTransaction();
+ // vide le cache hibernate. Sans cela, les resultats ne sont
+ // jamais supprimé du cache car la session n'est close
+ // qu'à la fin de la simulation
+ tx.clearCache();
+
+ // remove from cache result computed by #getMatrix(name)
+ // beacause, if a new step is added, result become false
+ // but DO NOT REMOVE result named step + name
+ removeInCache(name);
+
+ } catch (TopiaException eee) {
+ log.warn("Can't add result '" + name + "' at step " + step, eee);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#addActiveRule(fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.rule.Rule)
+ */
+ @Override
+ public void addActiveRule(TimeStep step, Rule rule) throws IsisFishException {
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+ ActiveRuleDAO ps = IsisFishDAOHelper.getActiveRuleDAO(tx);
+ ActiveRule result = ps.create();
+ result.setActiveRuleStep(step);
+ result.setName(RuleStorage.getName(rule));
+ result.setParam(RuleStorage.getParamAsString(rule));
+ ps.update(result);
+ if (mustClose) {
+ tx.commitTransaction();
+ tx.closeContext();
+ }
+ } catch (TopiaException eee) {
+ throw new IsisFishException("Can't add result", eee);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getResultName()
+ */
+ @Override
+ public List<String> getResultName() {
+
+ List<String> result = null;
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+ ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
+
+ result = (List<String>) resultPS.getContext()
+ .findAll("Select distinct name from fr.ifremer.isisfish.entities.Result order by name");
+ if (mustClose) {
+ tx.closeContext();
+ }
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't get result name", eee);
+ }
+ }
+ if (result == null) {
+ result = new ArrayList<String>();
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.entities.Population, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(TimeStep step, Population pop, String name) {
+ String newName = name + " " + pop;
+ return getMatrix(step, newName);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.types.TimeStep, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(TimeStep step, String name) {
+ MatrixND mat = getInCache(step, name);
+ if (mat == null && isAvailableResult(step, name)) {
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+ mat = getMatrix(step, name, tx);
+ if (mustClose) {
+ // FIXME transaction never closed
+ // quand peut on fermer la transaction ?
+ // lorsque plus aucune matrice ne l'utilise.
+ // donc mettre la matrice et la connexion dans une map
+ // la matrice dans une weak reference. Des que la matrice
+ // est liberer faire un close sur la transaction
+ } else {
+ // echatellier 20120829 : vidage du cache hibernate
+ // sinon on fait trop de lecture que la meme transaction
+ // et le cache hibernate se remplit sans se vider
+ tx.clearCache();
+ }
+ } catch (Exception eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't return matrix '" + name + "' for step "
+ + step, eee);
+ }
+ }
+ }
+ return mat;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.topia.TopiaContext)
+ */
+ @Override
+ public MatrixND getMatrix(TimeStep step, String name, TopiaContext tx) {
+ MatrixND mat = getInCache(step, name);
+ if (mat == null && isAvailableResult(step, name)) {
+ try {
+ ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
+ Result result = resultPS.findByProperties(
+ Result.PROPERTY_RESULT_STEP, step,
+ Result.PROPERTY_NAME, name);
+ if (result != null) {
+ mat = result.getMatrix();
+ putInCache(step, name, mat, tx);
+ }
+ } catch (Exception eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't return matrix '" + name + "' for step "
+ + step, eee);
+ }
+ }
+ }
+ return mat;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.entities.Population, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(Population pop, String name) {
+ String newName = name + " " + pop;
+ return getMatrix(newName);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.entities.Population, java.lang.String, org.nuiton.topia.TopiaContext)
+ */
+ @Override
+ public MatrixND getMatrix(Population pop, String name, TopiaContext tx) {
+ String newName = name + " " + pop;
+ return getMatrix(newName, tx);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(String name) {
+ MatrixND resultMat = null;
+ try {
+ TopiaContext tx = null;
+ boolean mustClose = false;
+
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ tx = SimulationContext.get().getDbResult();
+ }
+ if (tx == null) {
+ // not in simulation, create transaction
+ tx = simulation.getStorage().beginTransaction();
+ mustClose = true;
+ }
+ resultMat = getMatrix(name, tx);
+ if (mustClose) {
+ // FIXME transaction never closed
+ // quand peut on fermer la transaction ?
+ // lorsque plus aucune matrice ne l'utilise.
+ // donc mettre la matrice et la connexion dans une map
+ // la matrice dans une weak reference. Des que la matrice
+ // est liberer faire un close sur la transaction
+ } else {
+ // echatellier 20120829 : vidage du cache hibernate
+ // sinon on fait trop de lecture que la meme transaction
+ // et le cache hibernate se remplit sans se vider
+ tx.clearCache();
+ }
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't get result: " + name, eee);
+ }
+ }
+ return resultMat;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(java.lang.String, org.nuiton.topia.TopiaContext)
+ */
+ @Override
+ public MatrixND getMatrix(String name, TopiaContext tx) {
+ log.debug("Get result: " + name);
+
+ MatrixND resultMat = getInCache(name);
+ if (resultMat != null) {
+ return resultMat;
+ }
+
+ // recuperation des resultats qui nous interesse
+ List<Result> results = null;
+ try {
+ ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
+ results = resultPS.findAllByName(name);
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't get result: " + name, eee);
+ }
+ }
+
+ // s'il n'y pas de resultat, on retourne null
+ if (results == null || results.size() == 0) {
+ return null;
+ }
+
+ // Creation des listes pour chaque dimension
+
+ // creation de la liste de date
+ TimeStep lastStep = getLastStep();
+ List<TimeStep> steps = new ArrayList<TimeStep>();
+ TimeStep step = new TimeStep(0);
+ steps.add(step);
+ while (step.before(lastStep)) {
+ step = step.next();
+ steps.add(step);
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("Steps list : " + steps);
+ }
+
+ // recuperation des dimensions des matrices
+ MatrixND mat = (MatrixND) results.get(0).getMatrix();
+
+ // recuperation des noms des dimensions
+ String[] dimNames = new String[1 + mat.getDimCount()];
+ dimNames[0] = _("isisfish.common.date");
+ for (int i = 1; i < dimNames.length; i++) {
+ dimNames[i] = mat.getDimensionName(i - 1);
+ }
+
+ // creation de la semantique pour la matrice resultat. +1 pour les dates
+ List[] sem = new List[1 + mat.getDimCount()];
+ sem[0] = steps;
+
+ for (int i = 1; i < sem.length; i++) {
+ sem[i] = new HashList();
+ }
+
+ for (Result result : results) {
+ MatrixND mattmp = result.getMatrix();
+ if (log.isTraceEnabled()) {
+ log.trace("Ajout de la semantics: "
+ + Arrays.asList(mattmp.getSemantics()));
+ }
+
+ for (int s = 0; s < mattmp.getDimCount(); s++) {
+ sem[s + 1].addAll(mattmp.getSemantic(s));
+ }
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("La semantique final est: " + Arrays.asList(sem));
+ }
+
+ // creation de la matrice resultat
+ resultMat = MatrixFactory.getInstance().create(name, sem, dimNames);
+
+ // recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
+ for (Result result : results) {
+ TimeStep d = result.getResultStep();
+ mat = result.getMatrix();
+ // on met ce resultat dans la matrice result si besoin
+ if (mat != null) {
+ // on recupere dans la matrice resultat l'endroit on il faut
+ // mettre la matrice
+ MatrixND submat = resultMat.getSubMatrix(0, d, 1);
+ // on met les valeur de mat dans la sous matrice extraite
+ for (MatrixIterator mi = mat.iterator(); mi.next();) {
+ submat.setValue(
+ ArrayUtil.concat(new Object[] { d },
+ mi.getSemanticsCoordinates()), mi.getValue());
+ }
+ }
+ }
+
+ putInCache(name, resultMat, tx);
+ return resultMat;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getLastStep()
+ */
+ @Override
+ public TimeStep getLastStep() {
+ int monthNumber = simulation.getParameter().getNumberOfYear()
+ * Month.NUMBER_OF_MONTH;
+ TimeStep result = new TimeStep(monthNumber - 1); // -1 because date begin at 0
+ return result;
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultListener#addResult(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(SimulationContext context, TimeStep step, String name,
+ MatrixND mat) throws IsisFishException {
+ try {
+ doAddResult(step, name, mat, context.getDbResult());
+ } catch (TopiaException eee) {
+ log.warn(_("Can't add result '%1$s' at date %2$s", name, step), eee);
+ }
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(SimulationContext context, TimeStep step, String name) {
+ MatrixND result = null;
+ try {
+ result = getMatrix(step, name, context.getDbResult());
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(_("Can't get result: %1$s", name), eee);
+ }
+ }
+ return result;
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(SimulationContext context, String name) {
+ MatrixND result = null;
+ try {
+ result = getMatrix(name, context.getDbResult());
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(_("Can't get result: %1$s", name), eee);
+ }
+ }
+ return result;
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationListener#afterSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
+ */
+ @Override
+ public void afterSimulation(SimulationContext context) {
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationListener#beforeSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
+ */
+ @Override
+ public void beforeSimulation(SimulationContext context) {
+ }
+
+ // public void addActivatedRule(ResultStorage self, Date date, RegleParam rule){
+ // List rules = (List)activatedRules.get(date);
+ // if(rules == null){
+ // activatedRules.put(date, rules = new LinkedList());
+ // }
+ // rules.add(rule);
+ // }
+
+ // /**
+ // * Retourne pour une date données tous les RegleParam qui ont été activé
+ // * a la date demandé.
+ // * @return une list de {@link fr.ifremer.nodb.RegleParam}
+ // */
+ // public List getActivatedRule(ResultStorage self, Date date){
+ // List rules = (List)activatedRules.get(date);
+ // if(rules == null){
+ // activatedRules.put(date, rules = new LinkedList());
+ // }
+ // return rules;
+ // }
+
+} // ResultDatabaseStorage
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 14:12:18 UTC (rev 3751)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2012-08-31 16:11:36 UTC (rev 3752)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2002 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
+ * Copyright (C) 2012 Ifremer, Code Lutin, Benjamin Poussin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -83,7 +83,7 @@
* par : $Author$
*/
public class ResultMappedStorage implements SimulationResultListener,
- SimulationResultGetter { // ResultStorage
+ SimulationResultGetter, ResultStorage { // ResultStorage
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(ResultMappedStorage.class);
@@ -209,7 +209,6 @@
sems[i].add(s);
}
}
-
int size = (int) raf.getFilePointer();
int dataOffset = offset + size;
@@ -602,6 +601,15 @@
String newName = name + " " + pop;
return getMatrix(newName, null);
}
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.entities.Population, java.lang.String, org.nuiton.topia.TopiaContext)
+ */
+ @Override
+ public MatrixND getMatrix(Population pop, String name, TopiaContext tx) {
+ String newName = name + " " + pop;
+ return getMatrix(newName, tx);
+ }
/**
* Retourne une matrice contenant tous les pas de temps.
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-08-31 14:12:18 UTC (rev 3751)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2012-08-31 16:11:36 UTC (rev 3752)
@@ -1,214 +1,22 @@
-/*
- * #%L
- * IsisFish
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2002 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-2.0.html>.
- * #L%
- */
-
package fr.ifremer.isisfish.datastore;
-import static org.nuiton.i18n.I18n._;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-import org.apache.commons.collections.map.ReferenceMap;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.HibernateException;
-import org.nuiton.math.matrix.MatrixFactory;
-import org.nuiton.math.matrix.MatrixIterator;
import org.nuiton.math.matrix.MatrixND;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.framework.TopiaContextImpl;
-import org.nuiton.util.ArrayUtil;
-import org.nuiton.util.HashList;
-import fr.ifremer.isisfish.IsisFishDAOHelper;
import fr.ifremer.isisfish.IsisFishException;
-import fr.ifremer.isisfish.entities.ActiveRule;
-import fr.ifremer.isisfish.entities.ActiveRuleDAO;
import fr.ifremer.isisfish.entities.Population;
-import fr.ifremer.isisfish.entities.Result;
-import fr.ifremer.isisfish.entities.ResultDAO;
import fr.ifremer.isisfish.export.Export;
import fr.ifremer.isisfish.export.SensitivityExport;
import fr.ifremer.isisfish.rule.Rule;
-import fr.ifremer.isisfish.simulator.SimulationContext;
-import fr.ifremer.isisfish.simulator.SimulationException;
import fr.ifremer.isisfish.simulator.SimulationPlan;
-import fr.ifremer.isisfish.simulator.SimulationResultGetter;
import fr.ifremer.isisfish.simulator.SimulationResultListener;
import fr.ifremer.isisfish.types.TimeStep;
-import fr.ifremer.isisfish.types.Month;
-/**
- * Cette classe permet de conserver des résultats de simulation. Elle permet
- * ensuite de les récupérer.
- *
- * Created: 29 sept. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class ResultStorage implements SimulationResultListener,
- SimulationResultGetter { // ResultStorage
+public interface ResultStorage extends SimulationResultListener {
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(ResultStorage.class);
-
- protected SimulationStorage simulation = null;
- // transient protected HashMap<String, MatrixND> globalMatrix = new HashMap<String, MatrixND>();
- transient protected ReferenceMap cacheContext = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK);
-
- /** cache to maintains some result. key: String(date + ':' + name), value: matrix
- * TODO: cache will be more efficient if it keep at min the number of result by year */
- transient protected ReferenceMap cache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
- /** contains all available result as string: String(date + ':' + name) */
- transient protected Set<String> availableResult = null;
- /** result enabled */
- transient protected Set<String> enabledResult = null;
-
/**
- * Les ResultStorage ne doivent pas etre instancier directement, mais
- * recuperer a partir d'un
- * {@link fr.ifremer.isisfish.datastore.SimulationStorage#getResultStorage()}
- *
- * @param simulation storage to get result
- */
- public ResultStorage(SimulationStorage simulation) {
- this.simulation = simulation;
- }
-
- protected void putInCache(TimeStep step, String name, MatrixND mat, TopiaContext context) {
- String key = step.getStep() + ":" + name;
- putInCache(key, mat, context);
- }
-
- protected void putInCache(String name, MatrixND mat, TopiaContext context) {
- if (mat != null) {
- cache.put(name, mat);
- cacheContext.put(name, context);
- }
- }
-
- /**
- * Result can be removed from cache when computed result (from multiple step)
- * become invalidated by new step result.
- *
- * @param name result name to remove
- */
- protected void removeInCache(String name) {
- cache.remove(name);
- cacheContext.remove(name);
- }
-
- protected MatrixND getInCache(TimeStep step, String name) {
- // do not use toString for step (depend on i18n)
- String key = step.getStep() + ":" + name;
- MatrixND result = getInCache(key);
- return result;
- }
-
- protected MatrixND getInCache(String name) {
- MatrixND result = null;
- TopiaContext context = (TopiaContext) cacheContext.get(name);
- if (context != null && !context.isClosed()) {
- // on verifie que le context existe encore car on peut vouloir
- // naviguer dans les semantics
- result = (MatrixND) cache.get(name);
- }
- return result;
- }
-
- /**
- * Retourne le nom de tous les resultats disponibles le nom est constitué
- * de la date et du nom du resultat.
- *
- * @return available results
- */
- protected Set<String> getAvailableResult() {
- if (availableResult == null) {
- availableResult = new HashSet<String>();
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
-
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
-
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
-
- List<String> result = (List<String>) tx.findAll("Select " + Result.PROPERTY_RESULT_STEP + "||':'||name from fr.ifremer.isisfish.entities.Result");
- if (mustClose) {
- tx.closeContext();
- }
- availableResult.addAll(result);
- } catch (Exception eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't get result available", eee);
- }
- }
- }
- return availableResult;
- }
-
- /**
- * Verifie si un resultat est disponible pour une date donnée.
- *
- * @param step
- * @param name
- * @return {@code true} if result is available
- */
- protected boolean isAvailableResult(TimeStep step, String name) {
- String key = step.getStep() + ":" + name;
- boolean result = getAvailableResult().contains(key);
- return result;
- }
-
- /**
- * Ajoute un resultat comme etant disponible pour une date donnée.
- *
- * @param step
- * @param name
- */
- protected void addAvailableResult(TimeStep step, String name) {
- String key = step.getStep() + ":" + name;
- getAvailableResult().add(key);
- }
-
- /**
* Permet de savoir si lorsque l'on ajoutera ce resultat, il sera
* sauvé ou non.
*
@@ -223,241 +31,41 @@
* @param name result name
* @return {@code true} if result is enabled
*/
- public boolean isEnabled(String name) {
- name = name.trim();
- if (enabledResult == null) {
- enabledResult = new HashSet<String>();
+ public boolean isEnabled(String name);
- Collection<String> resultEnabled = simulation.getParameter()
- .getResultEnabled();
- enabledResult.addAll(resultEnabled);
+ public void addResult(TimeStep step, MatrixND mat) throws IsisFishException;
- // test on export
- List<String> exportNames = simulation.getParameter().getExportNames();
- if (exportNames != null) {
- for (String exportName : exportNames) {
- ExportStorage storage = ExportStorage.getExport(exportName);
- try {
- Export export = storage.getNewExportInstance();
- for (String resultName : export.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- } catch (IsisFishException eee) {
- if (log.isWarnEnabled()) {
- log.warn(_("isisfish.error.instanciate.export",
- exportName), eee);
- }
- }
- }
- }
+ public void addResult(TimeStep step, Population pop, MatrixND mat)
+ throws IsisFishException;
- // test on sensitivity export
- List<SensitivityExport> sensitivityExports = simulation
- .getParameter().getSensitivityExport();
- if (sensitivityExports != null) {
- for (SensitivityExport sensitivityExport : sensitivityExports) {
- for (String resultName : sensitivityExport.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
+ public void addResult(boolean force, TimeStep step, MatrixND mat)
+ throws IsisFishException;
- // test on rules
- List<Rule> rules = simulation.getParameter().getRules();
- if (rules != null) {
- for (Rule rule : rules) {
- for (String resultName : rule.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
+ public void addResult(boolean force, TimeStep step, Population pop,
+ MatrixND mat) throws IsisFishException;
- // test on plans
- List<SimulationPlan> plans = simulation.getParameter().getSimulationPlans();
- if (plans != null) {
- for (SimulationPlan plan : plans) {
- for (String resultName : plan.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
- log.info("Enabled result: " + enabledResult);
- }
- boolean result = enabledResult.contains(name);
- return result;
- }
+ public void addResult(TimeStep step, String name, Population pop,
+ MatrixND mat) throws IsisFishException;
- public void addResult(TimeStep step, MatrixND mat) throws IsisFishException {
- addResult(false, step, mat.getName(), mat);
- }
+ public void addResult(TimeStep step, String name, MatrixND mat)
+ throws IsisFishException;
- public void addResult(TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
- addResult(false, step, mat.getName(), pop, mat);
- }
+ public void addResult(boolean force, TimeStep step, String name,
+ Population pop, MatrixND mat) throws IsisFishException;
- public void addResult(boolean force, TimeStep step, MatrixND mat) throws IsisFishException {
- addResult(force, step, mat.getName(), mat);
- }
+ public void addResult(boolean force, TimeStep step, String name,
+ MatrixND mat) throws IsisFishException;
- public void addResult(boolean force, TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
- addResult(force, step, mat.getName(), pop, mat);
- }
+ public void addActiveRule(TimeStep step, Rule rule)
+ throws IsisFishException;
- public void addResult(TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
- addResult(false, step, name, pop, mat);
- }
-
- public void addResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
- addResult(false, step, name, mat);
- }
-
- public void addResult(boolean force, TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
- if (force || isEnabled(name)) {
- doAddResult(step, name + " " + pop, mat);
- }
- }
-
- public void addResult(boolean force, TimeStep step, String name, MatrixND mat) throws IsisFishException {
- if (force || isEnabled(name)) {
- doAddResult(step, name, mat);
- }
- }
-
- protected void doAddResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
-
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
- doAddResult(step, name, mat, tx);
- if (mustClose) {
- tx.commitTransaction();
- tx.closeContext();
- }
- } catch (TopiaException eee) {
- log.warn("Can't add result '" + name + "' at step " + step, eee);
- }
- }
-
- protected void doAddResult(TimeStep step, String name, MatrixND mat,
- TopiaContext tx) throws IsisFishException {
- // si la matrice n'a pas de semantique on refuse
- for (int i = 0; i < mat.getDimCount(); i++) {
- // la semantique n'est pas bonne des qu'il y a un null dedans
- if (mat.getSemantic(i).contains(null)) {
- throw new SimulationException(
- "Erreur le résultat que vous souhaitez enregistrer n'a pas d'information convenable pour la dimension: "
- + i + " " + mat.getDimensionName(i));
- }
- }
-
- // on fait une copie pour avoir reellement des resultats independant
- // FIXME echatellier 20120829 : faire une copie optimiser
- // suivant l'implementation du vector plutot qu'un parcourt
- // via un iterateur de semantiques (plus couteux)
- MatrixND newMat = mat.copy();
- try {
- ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
- Result result = resultPS.create();
- result.setResultStep(step);
- result.setName(name);
- result.setMatrix(newMat);
- resultPS.update(result);
-
- addAvailableResult(step, name);
- putInCache(step, name, newMat, tx);
-
- // depuis isis fish 4.1.1, le commit est automatique à chaque
- // résultat (gain de performance de 20% avec le clearCache)
- tx.commitTransaction();
- // vide le cache hibernate. Sans cela, les resultats ne sont
- // jamais supprimé du cache car la session n'est close
- // qu'à la fin de la simulation
- tx.clearCache();
-
- // remove from cache result computed by #getMatrix(name)
- // beacause, if a new step is added, result become false
- // but DO NOT REMOVE result named step + name
- removeInCache(name);
-
- } catch (TopiaException eee) {
- log.warn("Can't add result '" + name + "' at step " + step, eee);
- }
- }
-
- public void addActiveRule(TimeStep step, Rule rule) throws IsisFishException {
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
-
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
- ActiveRuleDAO ps = IsisFishDAOHelper.getActiveRuleDAO(tx);
- ActiveRule result = ps.create();
- result.setActiveRuleStep(step);
- result.setName(RuleStorage.getName(rule));
- result.setParam(RuleStorage.getParamAsString(rule));
- ps.update(result);
- if (mustClose) {
- tx.commitTransaction();
- tx.closeContext();
- }
- } catch (TopiaException eee) {
- throw new IsisFishException("Can't add result", eee);
- }
- }
-
/**
* Retourne la liste de tous les résultats. Si le résultat est categorisé
* par une population alors le nom de la population est automatiquement
* ajouté au nom du résultat.
*/
- public List<String> getResultName() {
+ public List<String> getResultName();
- List<String> result = null;
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
-
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
- ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
-
- result = (List<String>) resultPS.getContext()
- .findAll("Select distinct name from fr.ifremer.isisfish.entities.Result order by name");
- if (mustClose) {
- tx.closeContext();
- }
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't get result name", eee);
- }
- }
- if (result == null) {
- result = new ArrayList<String>();
- }
- return result;
- }
-
/**
* Retourne la matrice stocke pour un pas de temps
* @param step le pas de temps que l'on souhaite
@@ -466,50 +74,10 @@
* @return La matrice demandée ou null si aucune matrice ne correspond a
* la demande.
*/
- public MatrixND getMatrix(TimeStep step, Population pop, String name) {
- String newName = name + " " + pop;
- return getMatrix(step, newName);
- }
+ public MatrixND getMatrix(TimeStep step, Population pop, String name);
- public MatrixND getMatrix(TimeStep step, String name) {
- MatrixND mat = getInCache(step, name);
- if (mat == null && isAvailableResult(step, name)) {
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
+ public MatrixND getMatrix(TimeStep step, String name);
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
- mat = getMatrix(step, name, tx);
- if (mustClose) {
- // FIXME transaction never closed
- // quand peut on fermer la transaction ?
- // lorsque plus aucune matrice ne l'utilise.
- // donc mettre la matrice et la connexion dans une map
- // la matrice dans une weak reference. Des que la matrice
- // est liberer faire un close sur la transaction
- } else {
- // echatellier 20120829 : vidage du cache hibernate
- // sinon on fait trop de lecture que la meme transaction
- // et le cache hibernate se remplit sans se vider
- tx.clearCache();
- }
- } catch (Exception eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't return matrix '" + name + "' for step "
- + step, eee);
- }
- }
- }
- return mat;
- }
-
/**
* Retourne la matrice stocke pour un pas de temps.
*
@@ -519,37 +87,14 @@
* @return La matrice demandée ou {@code null} si aucune matrice ne correspond a
* la demande.
*/
- public MatrixND getMatrix(TimeStep step, String name, TopiaContext tx) {
- MatrixND mat = getInCache(step, name);
- if (mat == null && isAvailableResult(step, name)) {
- try {
- ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
- Result result = resultPS.findByProperties(
- Result.PROPERTY_RESULT_STEP, step,
- Result.PROPERTY_NAME, name);
- if (result != null) {
- mat = result.getMatrix();
- putInCache(step, name, mat, tx);
- }
- } catch (Exception eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't return matrix '" + name + "' for step "
- + step, eee);
- }
- }
- }
- return mat;
- }
+ public MatrixND getMatrix(TimeStep step, String name, TopiaContext tx);
/**
* Retourne une matrice contenant tous les pas de temps.
* @param pop la population pour lequel on souhaite la matrice
* @param name le nom des resultats dont on veut une matrice globale.
*/
- public MatrixND getMatrix(Population pop, String name) {
- String newName = name + " " + pop;
- return getMatrix(newName);
- }
+ public MatrixND getMatrix(Population pop, String name);
/**
* Retourne une matrice contenant tous les pas de temps.
@@ -558,245 +103,25 @@
* @param tx la transaction a utiliser
* @since 4.1.0.0
*/
- public MatrixND getMatrix(Population pop, String name, TopiaContext tx) {
- String newName = name + " " + pop;
- return getMatrix(newName, tx);
- }
+ public MatrixND getMatrix(Population pop, String name, TopiaContext tx);
/**
* Retourne une matrice contenant tous les pas de temps.
* @param name le nom des resultats dont on veut une matrice globale.
*/
- public MatrixND getMatrix(String name) {
- MatrixND resultMat = null;
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
+ public MatrixND getMatrix(String name);
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
- resultMat = getMatrix(name, tx);
- if (mustClose) {
- // FIXME transaction never closed
- // quand peut on fermer la transaction ?
- // lorsque plus aucune matrice ne l'utilise.
- // donc mettre la matrice et la connexion dans une map
- // la matrice dans une weak reference. Des que la matrice
- // est liberer faire un close sur la transaction
- } else {
- // echatellier 20120829 : vidage du cache hibernate
- // sinon on fait trop de lecture que la meme transaction
- // et le cache hibernate se remplit sans se vider
- tx.clearCache();
- }
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't get result: " + name, eee);
- }
- }
- return resultMat;
- }
-
/**
* Retourne une matrice contenant tous les pas de temps.
* @param name le nom des resultats dont on veut une matrice globale.
* @param tx TopiaContext a utiliser pour recuperer les resultats et donc les semantiques
*/
- public MatrixND getMatrix(String name, TopiaContext tx) {
- log.debug("Get result: " + name);
+ public MatrixND getMatrix(String name, TopiaContext tx);
- MatrixND resultMat = getInCache(name);
- if (resultMat != null) {
- return resultMat;
- }
-
- // recuperation des resultats qui nous interesse
- List<Result> results = null;
- try {
- ResultDAO resultPS = IsisFishDAOHelper.getResultDAO(tx);
- results = resultPS.findAllByName(name);
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Can't get result: " + name, eee);
- }
- }
-
- // s'il n'y pas de resultat, on retourne null
- if (results == null || results.size() == 0) {
- return null;
- }
-
- // Creation des listes pour chaque dimension
-
- // creation de la liste de date
- TimeStep lastStep = getLastStep();
- List<TimeStep> steps = new ArrayList<TimeStep>();
- TimeStep step = new TimeStep(0);
- steps.add(step);
- while (step.before(lastStep)) {
- step = step.next();
- steps.add(step);
- }
-
- if (log.isTraceEnabled()) {
- log.trace("Steps list : " + steps);
- }
-
- // recuperation des dimensions des matrices
- MatrixND mat = (MatrixND) results.get(0).getMatrix();
-
- // recuperation des noms des dimensions
- String[] dimNames = new String[1 + mat.getDimCount()];
- dimNames[0] = _("isisfish.common.date");
- for (int i = 1; i < dimNames.length; i++) {
- dimNames[i] = mat.getDimensionName(i - 1);
- }
-
- // creation de la semantique pour la matrice resultat. +1 pour les dates
- List[] sem = new List[1 + mat.getDimCount()];
- sem[0] = steps;
-
- for (int i = 1; i < sem.length; i++) {
- sem[i] = new HashList();
- }
-
- for (Result result : results) {
- MatrixND mattmp = result.getMatrix();
- if (log.isTraceEnabled()) {
- log.trace("Ajout de la semantics: "
- + Arrays.asList(mattmp.getSemantics()));
- }
-
- for (int s = 0; s < mattmp.getDimCount(); s++) {
- sem[s + 1].addAll(mattmp.getSemantic(s));
- }
- }
-
- if (log.isTraceEnabled()) {
- log.trace("La semantique final est: " + Arrays.asList(sem));
- }
-
- // creation de la matrice resultat
- resultMat = MatrixFactory.getInstance().create(name, sem, dimNames);
-
- // recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
- for (Result result : results) {
- TimeStep d = result.getResultStep();
- mat = result.getMatrix();
- // on met ce resultat dans la matrice result si besoin
- if (mat != null) {
- // on recupere dans la matrice resultat l'endroit on il faut
- // mettre la matrice
- MatrixND submat = resultMat.getSubMatrix(0, d, 1);
- // on met les valeur de mat dans la sous matrice extraite
- for (MatrixIterator mi = mat.iterator(); mi.next();) {
- submat.setValue(
- ArrayUtil.concat(new Object[] { d },
- mi.getSemanticsCoordinates()), mi.getValue());
- }
- }
- }
-
- putInCache(name, resultMat, tx);
- return resultMat;
- }
-
/**
* Get last simulation date.
*
* @return last simulation date
*/
- public TimeStep getLastStep() {
- int monthNumber = simulation.getParameter().getNumberOfYear()
- * Month.NUMBER_OF_MONTH;
- TimeStep result = new TimeStep(monthNumber - 1); // -1 because date begin at 0
- return result;
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultListener#addResult(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(SimulationContext context, TimeStep step, String name,
- MatrixND mat) throws IsisFishException {
- try {
- doAddResult(step, name, mat, context.getDbResult());
- } catch (TopiaException eee) {
- log.warn(_("Can't add result '%1$s' at date %2$s", name, step), eee);
- }
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String)
- */
- @Override
- public MatrixND getMatrix(SimulationContext context, TimeStep step, String name) {
- MatrixND result = null;
- try {
- result = getMatrix(step, name, context.getDbResult());
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn(_("Can't get result: %1$s", name), eee);
- }
- }
- return result;
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, java.lang.String)
- */
- @Override
- public MatrixND getMatrix(SimulationContext context, String name) {
- MatrixND result = null;
- try {
- result = getMatrix(name, context.getDbResult());
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn(_("Can't get result: %1$s", name), eee);
- }
- }
- return result;
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationListener#afterSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
- */
- @Override
- public void afterSimulation(SimulationContext context) {
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationListener#beforeSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
- */
- @Override
- public void beforeSimulation(SimulationContext context) {
- }
-
- // public void addActivatedRule(ResultStorage self, Date date, RegleParam rule){
- // List rules = (List)activatedRules.get(date);
- // if(rules == null){
- // activatedRules.put(date, rules = new LinkedList());
- // }
- // rules.add(rule);
- // }
-
- // /**
- // * Retourne pour une date données tous les RegleParam qui ont été activé
- // * a la date demandé.
- // * @return une list de {@link fr.ifremer.nodb.RegleParam}
- // */
- // public List getActivatedRule(ResultStorage self, Date date){
- // List rules = (List)activatedRules.get(date);
- // if(rules == null){
- // activatedRules.put(date, rules = new LinkedList());
- // }
- // return rules;
- // }
-
-} // ResultStorage
+ public TimeStep getLastStep();
+}
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2012-08-31 14:12:18 UTC (rev 3751)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2012-08-31 16:11:36 UTC (rev 3752)
@@ -444,15 +444,20 @@
}
/**
- * Get simulation {@link ResultStorage}.
+ * Get simulation {@link ResultDatabaseStorage}.
*
- * @return le {@link ResultStorage} a utiliser pour cette simulation
+ * @return le {@link ResultDatabaseStorage} a utiliser pour cette simulation
+ * @throws StorageException
*/
- public ResultStorage getResultStorage() {
+ public ResultStorage getResultStorage() throws StorageException {
if (resultStorage == null) {
- // FIXME poussin 20120831 en fonction de la version de la base
// instancier un ResultStorage ou un ResultMappedStorage
- resultStorage = new ResultStorage(this);
+ //resultStorage = new ResultDatabaseStorage(this);
+ try {
+ resultStorage = new ResultMappedStorage(this);
+ } catch (IOException ex) {
+ throw new StorageException("Can't get storage", ex);
+ }
}
return resultStorage;
}
1
0