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  March 2015

HPS-SVN March 2015

Subject:

r2348 - /java/trunk/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java

From:

[log in to unmask]

Reply-To:

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

Date:

Sat, 7 Mar 2015 22:21:02 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (197 lines)

Author: [log in to unmask]
Date: Sat Mar  7 14:20:57 2015
New Revision: 2348

Log:
Improvements to conditions initialization in command line tool.  Detector name should no longer be required but can still be supplied.  A default run number of 0 will be used if none is given.

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	Sat Mar  7 14:20:57 2015
@@ -4,6 +4,7 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.HelpFormatter;
@@ -13,6 +14,8 @@
 import org.apache.commons.cli.PosixParser;
 import org.hps.conditions.database.DatabaseConditionsManager;
 import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.util.log.DefaultLogFormatter;
+import org.lcsim.util.log.LogUtil;
 
 /**
  * <p>
@@ -24,8 +27,9 @@
  * 
  * @author Jeremy McCormick <[log in to unmask]>
  */
-// TODO: Add detector name and run number as arguments on the basic tool rather than sub-commands.
 public class CommandLineTool {
+    
+    static Logger logger = LogUtil.create(CommandLineTool.class.getSimpleName(), new DefaultLogFormatter(), Level.WARNING);
 
     Options options = new Options();
     Map<String, AbstractCommand> commands = new HashMap<String, AbstractCommand>();
@@ -43,12 +47,12 @@
                 printUsage();
                 exit(0);
             }
-
+            
             CommandLine commandLine = null;
             try {
                 commandLine = parser.parse(options, arguments, true);
             } catch (ParseException e) {
-                e.printStackTrace();
+                logger.log(Level.SEVERE, "error parsing the options", e);
                 printUsage();
                 exit(1);
             }
@@ -58,22 +62,29 @@
                 exit(0);
             }
 
+            // Set verbosity.
             if (commandLine.hasOption("v")) {
+                logger.setLevel(Level.ALL);
+                logger.getHandlers()[0].setLevel(Level.ALL);
                 verbose = true;
+                logger.config("verbose mode enabled");
             }
 
+            // Setup conditions manager from command line options.
             setupConditionsManager(commandLine);
 
+            // Get the sub-command to use.
             String commandName = commandLine.getArgs()[0];
-
             AbstractCommand command = commands.get(commandName);
             if (command == null) {
                 throw new IllegalArgumentException("Unknown command " + commandName);
             }
 
+            // Copy remaining arguments for sub-command.
             String[] commandArguments = new String[commandLine.getArgs().length - 1];
             System.arraycopy(commandLine.getArgs(), 1, commandArguments, 0, commandArguments.length);
 
+            // Excecute the sub-command.
             command.setVerbose(verbose);
             command.execute(commandArguments);
         } catch (Exception e) {
@@ -84,38 +95,64 @@
         }
     }
 
-    private void setupConditionsManager(CommandLine commandLine) {
+    void setupConditionsManager(CommandLine commandLine) {
+
+        logger.info("setting up conditions manager");
+        
+        // Create new manager.
         conditionsManager = new DatabaseConditionsManager();
-        if (verbose) {
-            conditionsManager.setLogLevel(Level.ALL);
-        } else {
-            conditionsManager.setLogLevel(Level.WARNING);
-        }
+
+        // Set log level.
+        conditionsManager.setLogLevel(logger.getLevel());
+
+        // Connection properties.
         if (commandLine.hasOption("p")) {
             File connectionPropertiesFile = new File(commandLine.getOptionValue("p"));
-            if (verbose)
-                System.out.println("using connection properties file " + connectionPropertiesFile.getPath());
             conditionsManager.setConnectionProperties(connectionPropertiesFile);
+            logger.config("connection properties -p " + connectionPropertiesFile);
         } 
+        
+        // XML config.
         if (commandLine.hasOption("x")) {
             File xmlConfigFile = new File(commandLine.getOptionValue("x"));
             conditionsManager.setXmlConfig(xmlConfigFile);
-            if (verbose)
-                System.out.println("using XML config file " + xmlConfigFile.getPath());
-        }         
+            logger.config("XML config -x " + xmlConfigFile);
+        }
         
-        String detectorName = DatabaseConditionsManager.getDefaultEngRunDetectorName();
-        if (commandLine.hasOption("d")) {
-            detectorName = commandLine.getOptionValue("d");
-        }
-        int runNumber = 2000;
-        if (commandLine.hasOption("r")) {
-            runNumber = Integer.parseInt(commandLine.getOptionValue("r"));
-        }
-        try {
-            DatabaseConditionsManager.getInstance().setDetector(detectorName, runNumber);
-        } catch (ConditionsNotFoundException e) {
-            throw new RuntimeException(e);
+        // If there is a run number or detector number then attempt to initialize the conditions system.
+        if (commandLine.hasOption("r") || commandLine.hasOption("d")) {
+            
+            logger.config("detector name or run number supplied so manager will be initialized");
+
+            // Set detector name.
+            String detectorName = null;
+            if (commandLine.hasOption("d")) {
+                detectorName = commandLine.getOptionValue("d");
+                logger.config("detector -d " + detectorName);
+            } else {
+                detectorName = "HPS-ECalCommissioning-v2";
+                logger.config("default detector " + detectorName + " is being used");
+            }
+
+            // Get run number.
+            Integer run = null;
+            if (commandLine.hasOption("r")) {
+                run = Integer.parseInt(commandLine.getOptionValue("r"));
+                logger.config("run -r " + run);
+            } else {
+                run = 0;
+                logger.config("default run number " + run + " is being used");
+            }
+
+            // Setup the conditions manager with user detector name and run number.
+            try {
+                logger.config("initializing conditions manager with detector " + detectorName + " and run " + run);
+                DatabaseConditionsManager.getInstance().setDetector(detectorName, run);
+                logger.config("conditions manager initialized successfully");
+                logger.getHandlers()[0].flush();
+            } catch (ConditionsNotFoundException e) {
+                throw new RuntimeException(e);
+            }
         }
     }
 
@@ -142,15 +179,14 @@
     static CommandLineTool create() {
         CommandLineTool cli = new CommandLineTool();
         cli.options.addOption(new Option("h", false, "Print help and exit"));
-        cli.options.addOption(new Option("v", false, "Enable verbose terminal output"));
-        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.options.addOption(new Option("d", true, "Set the detector name"));
         cli.options.addOption(new Option("r", true, "Set the run number"));
+        cli.options.addOption(new Option("v", false, "Enable verbose print output"));
+        cli.options.addOption(new Option("p", true, "Set the database connection properties file"));
+        cli.options.addOption(new Option("x", true, "Set the conditions XML configuration file"));
         cli.registerCommand(new LoadCommand());
         cli.registerCommand(new PrintCommand());
         cli.registerCommand(new AddCommand());
         return cli;
     }
-
-}
+}

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