Print

Print


Author: [log in to unmask]
Date: Wed Oct 21 17:03:42 2015
New Revision: 3870

Log:
[HPSJAVA-624] Import currently used test data into SVN and provide a simple utility for accessing it as a classpath resource.

Added:
    data/trunk/test-data/
    data/trunk/test-data/pom.xml
    data/trunk/test-data/src/
    data/trunk/test-data/src/assembly/
    data/trunk/test-data/src/assembly/archive.xml
    data/trunk/test-data/src/main/
    data/trunk/test-data/src/main/java/
    data/trunk/test-data/src/main/java/org/
    data/trunk/test-data/src/main/java/org/hps/
    data/trunk/test-data/src/main/java/org/hps/data/
    data/trunk/test-data/src/main/java/org/hps/data/test/
    data/trunk/test-data/src/main/java/org/hps/data/test/TestDataUtility.java
    data/trunk/test-data/src/main/resources/
    data/trunk/test-data/src/main/resources/org/
    data/trunk/test-data/src/main/resources/org/hps/
    data/trunk/test-data/src/main/resources/org/hps/data/
    data/trunk/test-data/src/main/resources/org/hps/data/test/
    data/trunk/test-data/src/main/resources/org/hps/data/test/ConditionsTest.slcio   (with props)
    data/trunk/test-data/src/main/resources/org/hps/data/test/DataQualityMonitorTest.slcio   (with props)
    data/trunk/test-data/src/main/resources/org/hps/data/test/MockDataReconTest.slcio   (with props)
    data/trunk/test-data/src/main/resources/org/hps/data/test/ReadoutNoPileupTest.slcio   (with props)
    data/trunk/test-data/src/main/resources/org/hps/data/test/ReadoutToLcioTest.slcio   (with props)
    data/trunk/test-data/src/main/resources/org/hps/data/test/e-_1.056GeV_SLIC-v05-00-00_Geant4-v10-01-02_QGSP_BERT_HPS-EngRun2015-Nominal-v3.slcio   (with props)
    data/trunk/test-data/src/main/resources/org/hps/data/test/hps1351_test.evio   (with props)
    data/trunk/test-data/src/main/resources/org/hps/data/test/run5772_integrationTest.evio   (with props)
    data/trunk/test-data/src/main/resources/org/hps/data/test/run5772_pass1_stripOneFee_5000Events.evio   (with props)
    data/trunk/test-data/src/main/resources/org/hps/data/test/svt_evio_reader_test.evio   (with props)
    data/trunk/test-data/src/main/resources/org/hps/data/test/tritrigv1-egsv3-triv2-g4v1_s2d6_HPS-EngRun2015-Nominal-v3_3.4.0_pairs1_1.slcio   (with props)

Added: data/trunk/test-data/pom.xml
 =============================================================================
--- data/trunk/test-data/pom.xml	(added)
+++ data/trunk/test-data/pom.xml	Wed Oct 21 17:03:42 2015
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>hps-test-data</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <name>test-data</name>
+    <description>test data</description>
+    <parent>
+        <groupId>org.hps</groupId>
+        <artifactId>hps-parent</artifactId>
+        <version>3.4.1</version>
+    </parent>
+    <scm>
+        <url>http://java.freehep.org/svn/repos/hps/list/data/test-data/</url>
+        <connection>scm:svn:svn://svn.freehep.org/hps/data/test-data/</connection>
+        <developerConnection>scm:svn:svn://svn.freehep.org/hps/data/test-data/</developerConnection>
+    </scm>
+    <build>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <excludes>
+                    <exclude>**/*.slcio</exclude>
+                    <exclude>**/*.evio</exclude>
+                </excludes>
+            </resource>
+        </resources>
+        <plugins>
+            <plugin>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <version>2.5.3</version>
+                <configuration>
+                    <descriptor>src/assembly/archive.xml</descriptor>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>create-archive</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Added: data/trunk/test-data/src/assembly/archive.xml
 =============================================================================
--- data/trunk/test-data/src/assembly/archive.xml	(added)
+++ data/trunk/test-data/src/assembly/archive.xml	Wed Oct 21 17:03:42 2015
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
+    <id>archive</id>
+    <formats>
+        <format>jar</format>
+    </formats>
+    <includeBaseDirectory>false</includeBaseDirectory>
+    <fileSets>
+        <fileSet>
+            <directory>${project.basedir}/src/main/resources/org/hps/data/test</directory>
+            <outputDirectory>org/hps/data/test</outputDirectory>
+            <includes>
+                <include>*.slcio</include>
+                <include>*.evio</include>
+            </includes>
+        </fileSet>
+    </fileSets>
+</assembly>

Added: data/trunk/test-data/src/main/java/org/hps/data/test/TestDataUtility.java
 =============================================================================
--- data/trunk/test-data/src/main/java/org/hps/data/test/TestDataUtility.java	(added)
+++ data/trunk/test-data/src/main/java/org/hps/data/test/TestDataUtility.java	Wed Oct 21 17:03:42 2015
@@ -0,0 +1,108 @@
+package org.hps.data.test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.logging.Logger;
+
+/**
+ * Extracts test data from a classpath resource to a specified cache directory.
+ * 
+ * @author Jeremy McCormick, SLAC
+ */
+public final class TestDataUtility {
+    
+    /**
+     * The target directory where data files will be extracted.
+     */
+    private File cacheDir = null;
+    
+    /**
+     * The resource directory where test data is available.
+     */
+    private static String TEST_DATA_RESOURCE_DIR = "/" + TestDataUtility.class.getPackage().getName().replace(".", "/");
+    
+    /**
+     * Default cache dir which is within the target directory of the current Maven project.
+     */
+    private static String DEFAULT_CACHE_DIR = "target/test-data";
+    
+    /**
+     * Package logger.
+     */
+    private static final Logger LOGGER = Logger.getLogger(TestDataUtility.class.getPackage().getName());
+        
+    /**
+     * Class constructor.
+     * @param cacheDir the directory where test data files will be extracted
+     */
+    public TestDataUtility(String cacheDir) {
+        if (cacheDir != null) {
+            this.cacheDir = new File(cacheDir);
+        } else {
+            this.cacheDir = new File(DEFAULT_CACHE_DIR);
+        }
+        if (!this.cacheDir.exists()) {
+            if (!this.cacheDir.mkdirs()) {
+                throw new RuntimeException("Failed to create cache dir.");
+            }
+        }
+        LOGGER.config("initialized with cache dir " + this.cacheDir.getPath());
+    }
+    
+    /**
+     * Class constructor using default cache dir location.
+     */
+    public TestDataUtility() {
+        this(null);
+    }
+    
+    /**
+     * Get test data from a classpath resource and extract it to the local cache directory.
+     * @param fileName name of the resource relative to {@link TEST_DATA_RESOURCE_DIR} 
+     * @return the test data file
+     */
+    public File getTestData(String fileName) {
+        LOGGER.info("getting test data file " + fileName + " ...");
+        InputStream inputStream = null;
+        OutputStream outputStream = null;
+        File testDataFile = null;
+        try {
+            testDataFile = new File(cacheDir.getCanonicalPath() + File.separator + fileName);
+            String resource = TEST_DATA_RESOURCE_DIR + "/" + fileName;
+            LOGGER.info("looking for resource at " + resource + " ...");
+            inputStream = TestDataUtility.class.getResourceAsStream(TEST_DATA_RESOURCE_DIR + "/" + fileName);
+            if (inputStream == null) {
+                throw new IllegalArgumentException("The resource " + resource + " was not found.");
+            }
+            LOGGER.info("extracting file from archive ...");
+            outputStream = new FileOutputStream(testDataFile);
+            int read = 0;
+            byte[] bytes = new byte[1024];
+            while ((read = inputStream.read(bytes)) != -1) {
+                outputStream.write(bytes, 0, read);
+            }
+        } catch (IOException e) {
+            
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (outputStream != null) {
+                try {
+                    outputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        LOGGER.info("extracted test data file to " + testDataFile.getPath());
+        return testDataFile;
+    }
+}

Added: data/trunk/test-data/src/main/resources/org/hps/data/test/ConditionsTest.slcio
 =============================================================================
Binary file - no diff available.

Added: data/trunk/test-data/src/main/resources/org/hps/data/test/DataQualityMonitorTest.slcio
 =============================================================================
Binary file - no diff available.

Added: data/trunk/test-data/src/main/resources/org/hps/data/test/MockDataReconTest.slcio
 =============================================================================
Binary file - no diff available.

Added: data/trunk/test-data/src/main/resources/org/hps/data/test/ReadoutNoPileupTest.slcio
 =============================================================================
Binary file - no diff available.

Added: data/trunk/test-data/src/main/resources/org/hps/data/test/ReadoutToLcioTest.slcio
 =============================================================================
Binary file - no diff available.

Added: data/trunk/test-data/src/main/resources/org/hps/data/test/e-_1.056GeV_SLIC-v05-00-00_Geant4-v10-01-02_QGSP_BERT_HPS-EngRun2015-Nominal-v3.slcio
 =============================================================================
Binary file - no diff available.

Added: data/trunk/test-data/src/main/resources/org/hps/data/test/hps1351_test.evio
 =============================================================================
Binary file - no diff available.

Added: data/trunk/test-data/src/main/resources/org/hps/data/test/run5772_integrationTest.evio
 =============================================================================
Binary file - no diff available.

Added: data/trunk/test-data/src/main/resources/org/hps/data/test/run5772_pass1_stripOneFee_5000Events.evio
 =============================================================================
Binary file - no diff available.

Added: data/trunk/test-data/src/main/resources/org/hps/data/test/svt_evio_reader_test.evio
 =============================================================================
Binary file - no diff available.

Added: data/trunk/test-data/src/main/resources/org/hps/data/test/tritrigv1-egsv3-triv2-g4v1_s2d6_HPS-EngRun2015-Nominal-v3_3.4.0_pairs1_1.slcio
 =============================================================================
Binary file - no diff available.