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  November 2014

HPS-SVN November 2014

Subject:

r1493 - in /java/trunk/conditions/src/main/java/org/hps/conditions/cli: CommandLineTool.java PrintCommand.java

From:

[log in to unmask]

Reply-To:

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

Date:

Tue, 11 Nov 2014 02:56:59 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (172 lines)

Author: [log in to unmask]
Date: Mon Nov 10 18:56:56 2014
New Revision: 1493

Log:
First implementation of print command for CLI.

Added:
    java/trunk/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java
Modified:
    java/trunk/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java	Mon Nov 10 18:56:56 2014
@@ -80,6 +80,7 @@
             command.execute(commandArguments);
         } catch (Exception e) {
             e.printStackTrace();
+            System.exit(1);
         } finally {
             conditionsManager.closeConnection();
         }
@@ -96,11 +97,7 @@
             if (verbose)
                 System.out.println("using connection properties file " + connectionPropertiesFile.getPath());
             conditionsManager.setConnectionProperties(connectionPropertiesFile);
-        } else {
-            if (verbose)
-                System.out.println("using connection resource " + CONNECTION_PROPERTIES_RESOURCE);
-            conditionsManager.setConnectionResource(CONNECTION_PROPERTIES_RESOURCE);
-        }
+        } 
         if (commandLine.hasOption("x")) {
             File xmlConfigFile = new File(commandLine.getOptionValue("x"));
             conditionsManager.configure(xmlConfigFile);
@@ -111,7 +108,6 @@
                 System.out.println("using XML config resource " + XML_CONFIG_RESOURCE);
             conditionsManager.configure(XML_CONFIG_RESOURCE);
         }
-        conditionsManager.register();
         conditionsManager.openConnection();
     }
 
@@ -142,6 +138,7 @@
         cli.options.addOption(new Option("p", true, "Set the connection properties file"));
         cli.options.addOption(new Option("x", true, "Set the conditions database XML configuration file"));
         cli.registerCommand(new LoadCommand());
+        cli.registerCommand(new PrintCommand());
         return cli;
     }
 

Added: java/trunk/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java	(added)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java	Mon Nov 10 18:56:56 2014
@@ -0,0 +1,112 @@
+package org.hps.conditions.cli;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+
+import org.apache.commons.cli.Option;
+import org.hps.conditions.ConditionsObject;
+import org.hps.conditions.ConditionsObjectCollection;
+import org.hps.conditions.ConditionsRecord;
+import org.hps.conditions.ConditionsRecord.ConditionsRecordCollection;
+import org.hps.conditions.ConditionsSeries;
+import org.hps.conditions.DatabaseConditionsManager;
+import org.hps.conditions.TableMetaData;
+import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+
+/**
+ * This sub-command of the conditions CLI prints conditions table data to
+ * the console file or optionally writes it to an output file.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class PrintCommand extends AbstractCommand {
+
+    private static int DEFAULT_RUN_NUMBER = 0;
+    private static String DEFAULT_DETECTOR_NAME = "HPS-Proposal2014-v8-6pt6";
+    
+    PrintCommand() {
+        super("print", "Print the table data for a conditions set");
+        this.options.addOption(new Option("t", true, "Set the conditions set key"));
+        this.options.addOption(new Option("r", true, "Set the run number"));
+        this.options.addOption(new Option("d", true, "Set the detector name"));
+        this.options.addOption(new Option("f", true, "Write output to a file"));
+    }
+    
+    void execute(String[] arguments) {
+        super.execute(arguments);
+        
+        DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
+        
+        String conditionsKey = null;
+        if (this.commandLine.hasOption("t")) {
+            conditionsKey = this.commandLine.getOptionValue("t");
+        } else {
+            this.printUsage();
+            System.exit(1);
+        }
+        
+        String detectorName = DEFAULT_DETECTOR_NAME;
+        if (this.commandLine.hasOption("d")) {
+            detectorName = this.commandLine.getOptionValue("d");
+        }
+        
+        int runNumber = DEFAULT_RUN_NUMBER;
+        if (this.commandLine.hasOption("r")) {
+            runNumber = Integer.parseInt(this.commandLine.getOptionValue("r"));
+        }
+        
+        File outputFile = null;
+        if (this.commandLine.hasOption("f")) {
+            outputFile = new File(commandLine.getOptionValue("f"));
+            if (outputFile.exists()) {
+                System.err.println("Specified output file already exists.");
+                System.exit(1);
+            }
+        }
+        
+        try {
+            conditionsManager.setDetector(detectorName, runNumber);
+        } catch (ConditionsNotFoundException e) {
+            throw new RuntimeException(e);
+        }
+                
+        ConditionsRecordCollection conditionsRecords = conditionsManager.findConditionsRecords(conditionsKey);
+        for (ConditionsRecord conditionsRecord : conditionsRecords) {
+            System.out.println(conditionsRecord.toString());
+        }
+                
+        ConditionsSeries series = conditionsManager.getConditionsSeries(conditionsKey);
+ 
+        PrintStream ps = System.out;
+        if (outputFile != null) {
+            try {
+                ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFile, false)));
+            } catch (FileNotFoundException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        
+        TableMetaData tableMetaData = conditionsManager.findTableMetaData(conditionsKey);
+        ps.print("id");
+        ps.print(' ');
+        String[] fieldNames = tableMetaData.getFieldNames();
+        for (String columnName : fieldNames) {
+            ps.print(columnName);
+            ps.print(' ');
+        }
+        ps.println();
+        
+        for (ConditionsObjectCollection collection : series.getCollections()) {
+            for (Object object : collection.getObjects()) {
+                //ConditionsObject conditionsObject = (ConditionsObject) object;
+                ps.print(object.toString());
+                ps.println();
+            }
+        }
+        ps.flush();
+        ps.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