LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  May 2016

HPS-SVN May 2016

Subject:

r4355 - /java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/DetectorConverter.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Mon, 16 May 2016 21:32:08 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (138 lines)

Author: [log in to unmask]
Date: Mon May 16 14:32:06 2016
New Revision: 4355

Log:
[HPSJAVA-670] Implement command line tool that allows setting of run number for conditions initialization.

Added:
    java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/DetectorConverter.java

Added: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/DetectorConverter.java
 =============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/DetectorConverter.java	(added)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/DetectorConverter.java	Mon May 16 14:32:06 2016
@@ -0,0 +1,122 @@
+package org.hps.detector;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.imageio.spi.ServiceRegistry;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.hps.conditions.database.DatabaseConditionsManager;
+import org.lcsim.conditions.ConditionsManagerImplementation;
+import org.lcsim.conditions.ConditionsReader;
+import org.lcsim.geometry.compact.converter.Converter;
+import org.lcsim.util.loop.DummyConditionsConverter;
+import org.lcsim.util.loop.DummyDetector;
+
+/**
+ * A rewrite of the LCSim detector converter that supports setting of the run number
+ * for conditions system initialization so that database conditions are available.
+ * 
+ * @author jeremym
+ */
+public class DetectorConverter {
+    
+    private static Options OPTIONS = new Options();
+    static {
+        OPTIONS.addOption(new Option("i", "input-file", true, "input compact.xml file"));
+        OPTIONS.getOption("i").setRequired(true);
+        OPTIONS.addOption(new Option("o", "ouput-file", true, "output file"));
+        OPTIONS.getOption("o").setRequired(true);
+        OPTIONS.addOption(new Option("f", "format", true, "input compact.xml file"));
+        OPTIONS.addOption(new Option("r", "run-number", true, "run number for conditions initialization"));
+    }
+    
+    private DefaultParser parser = new DefaultParser();
+    private File inputFile = null;
+    private File outputFile = null;
+    private String outputFormat = null;
+    private Integer runNumber = null;
+    
+    public static void main(String args[]) throws Exception {
+        DetectorConverter cnv = new DetectorConverter();
+        cnv.run(args);
+    }
+    
+    private static List<Converter> getConverters() {
+        Iterator<Converter> iter = getServices(Converter.class);
+        List<Converter> result = new ArrayList<Converter>();
+        while (iter.hasNext()) result.add(iter.next());
+        return result;
+    }
+    
+    private static <T> Iterator<T> getServices(Class<T> providerClass) {
+       return ServiceRegistry.lookupProviders(providerClass, DetectorConverter.class.getClassLoader());
+    }
+        
+    private void run(String args[]) throws Exception {
+        CommandLine cl = parser.parse(OPTIONS, args);
+        if (!cl.hasOption("i")) {
+            throw new RuntimeException("Missing required -i arg.");
+        }
+        if (!cl.hasOption("o")) {
+            throw new RuntimeException("Missing required -o arg.");
+        }        
+        inputFile = new File(cl.getOptionValue("i"));
+        outputFile = new File(cl.getOptionValue("o"));
+        if (cl.hasOption("f")) {
+            outputFormat = cl.getOptionValue("f");
+        }
+        if (cl.hasOption("r")) {
+            runNumber = Integer.parseInt(cl.getOptionValue("r"));
+        } else {
+            runNumber = 0;
+        }
+        
+        Converter cnv = null;
+        
+        if (outputFormat != null) {
+            for (Converter c : getConverters()) {
+                if (c.getOutputFormat().equalsIgnoreCase(outputFormat)) {
+                    cnv = c;
+                    break;
+                }
+            }
+        } else {
+            for (Converter c : getConverters()) {
+               if (c.getFileFilter().accept(outputFile))
+               {
+                  cnv = c;
+                  break;
+               }
+            }
+        }
+        if (cnv == null) throw new IllegalArgumentException("No converter found for format: " + outputFormat);
+        
+        if (runNumber != null) {
+            String name = "DUMMY";            
+            DatabaseConditionsManager mgr = DatabaseConditionsManager.getInstance();
+            ConditionsReader dummyReader = ConditionsReader.createDummy();
+            ((ConditionsManagerImplementation) mgr).setConditionsReader(dummyReader, name);
+            DummyDetector detector = new DummyDetector(name);
+            mgr.registerConditionsConverter(new DummyConditionsConverter(detector));
+            mgr.setDetector(name, runNumber);
+        }
+        
+        InputStream in = new BufferedInputStream(new FileInputStream(inputFile));
+        OutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile));
+        cnv.convert(inputFile.getCanonicalPath(), in, out);
+        in.close();
+        out.close();
+    }                  
+}

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use