public class JobControlManager extends Object
This class provides a front end for running and managing LCSim event processing jobs using XML steering files.
More details about this XML format can be found at the
LCSim XML Confluence Page.
The command line syntax is:
java org.lcsim.job.JobManager steeringFile.xml [options]
To see the available command line options with descriptions, run with "-h" as the only option.
Command-line parameters that can be defined using switches are overridden by the corresponding settings in the job XML file, if they are present. This means that if these parameters are to be taken from the CL, the matching settings should be left out of the XML job file. This is not the case, however, for input files specified by the "-i" option, which are appended to the ones listed in the steering file.
Modifier and Type | Field and Description |
---|---|
private File |
cacheDirectory
Root directory for file caching.
|
private ClassLoader |
classLoader
The class loader that will be used for the job.
|
(package private) org.apache.commons.cli.CommandLine |
commandLine
Command line that is setup from
main arguments. |
private Map<String,Double> |
constantsMap
Map of constants definitions.
|
private String |
detectorName
User supplied detector name.
|
private DriverAdapter |
driverAdapter
A driver adapter created on the fly in case it is needed by an external program.
|
private List<Driver> |
driverExec
List of drivers to execute in the job.
|
private Map<String,Driver> |
driverMap
Map of driver names to objects.
|
private boolean |
dryRun
Enable dry run so no events are processed.
|
private boolean |
dummyDetector
Setup a "dummy" detector in the conditions system.
|
private Long |
eventPrintInterval
Event printing interval (null means no event printing).
|
private JDOMExpressionFactory |
factory
JDOM expression factory for variables.
|
private FileCache |
fileCache
File cache.
|
private List<File> |
inputFiles
List of input LCIO files.
|
private boolean |
isSetup
Flag set to
true after setup is performed. |
private long |
jobEnd
The job end timestamp in ms.
|
private long |
jobStart
The job start timestamp in ms.
|
protected static Logger |
LOGGER
Initialize the logger which uses the package name.
|
private LCSimLoop |
loop
The LCIO record loop.
|
private int |
numberOfEvents
Number of events to run before stopping job.
|
private static org.apache.commons.cli.Options |
OPTIONS
The command line options.
|
private ParameterConverters |
paramConverter
Helper for converting Driver parameters.
|
private boolean |
printDriverStatistics
Set to
true to print out driver statistics at the end of the job. |
private File |
rewriteFile
Path for rewriting steering file with variables resolved.
|
private boolean |
rewriteSteering
Enable rewriting of the steering file to a new path with variables resolved.
|
private org.jdom.Element |
root
The root node of the XML document providing config to the manager.
|
private Integer |
runNumber
User supplied run number.
|
private int |
skipEvents
Number of events to skip at start of job.
|
private boolean |
useSteeringResource
Interpret steering file argument as a resource rather than file path.
|
private static Pattern |
VARIABLE_PATTERN
The regular expression for extracting the variables from an XML file.
|
private Map<String,String> |
variableMap
Map of variable names to their values.
|
Constructor and Description |
---|
JobControlManager()
The default constructor.
|
Modifier and Type | Method and Description |
---|---|
private void |
addDriver(String name,
Driver driver)
Add a Driver to the internal Driver map.
|
void |
addInputFile(File inputFile)
Add an input LCIO file to be proceesed.
|
void |
addVariableDefinition(String key,
String value)
Add a variable definition to be substituted into the job's XML file.
|
void |
configure()
Configure start of job (usually done automatically).
|
private static org.apache.commons.cli.Options |
createCommandLineOptions()
Create the command line options.
|
private void |
createDriverAdapter()
Create a driver adapter.
|
private void |
createDriverExecList()
Create the
Driver execution list. |
void |
enableHeadlessMode()
Turn on the batch analysis factory so plots are not shown on the screen even when
Plotter.show() is
called. |
void |
finish()
Activate end of job hooks (usually done automatically).
|
protected String |
getDetectorName()
Get the detector name set by the command line options.
|
DriverAdapter |
getDriverAdapter()
Get a
DriverAdapter from the currently configured Driver list. |
List<Driver> |
getDriverExecList()
Return a list of Drivers to be executed.
|
LCSimLoop |
getLCSimLoop()
Get the
LCSimLoop of this JobManager. |
private static Class |
getPrimitiveType(String name)
Get the Java primitive type class from a type name.
|
protected Integer |
getRunNumber()
Get the run number set by the command line options.
|
private List<Method> |
getSetterMethods(Class klass)
Get a list of a class's setter methods.
|
protected void |
initializeConditions()
Initialize the conditions system before the job starts.
|
private void |
initializeLoop()
Initialize the
LCSimLoop . |
static void |
main(String[] args)
Run from the command line.
|
void |
parse(String[] args)
Parse command-line options and setup job state from them.
|
private static void |
printHelp()
Print help and exit.
|
private void |
printInputFileList()
Print the list of input files.
|
private void |
printUserClasspath()
Print out extra URLs added to the classpath from the XML.
|
private void |
processConstants()
Create the constants from the XML file.
|
private void |
processDriverParameters(Class driverClass,
Driver newDriver,
List<org.jdom.Element> parameters)
A fairly ugly method to process the provided XML parameters on a
Driver . |
void |
processEvent(EventHeader event)
Process a single event.
|
private File |
processFileElement(org.jdom.Element fileElement,
List<File> fileList)
Create a
File object from the text in an XML element. |
private File |
processFileText(String fileText,
List<File> fileList)
Cleanup file text and add to the file list.
|
private String |
processPath(String path)
Process the file path string to substitute in the user's home directory for the "~" character.
|
private void |
rewriteXMLSteering(org.jdom.Document doc)
Rewrite the XML steering file after resolving variables (done externally).
|
boolean |
run()
Execute a job using the current parameters.
|
void |
setDryRun(boolean dryRun)
Set whether a dry run should be performed which will only perform setup and not process any events.
|
void |
setNumberOfEvents(int numberOfEvents)
Set the number of events to run on the loop before ending the job.
|
private void |
setup(org.jdom.Document xmlDocument)
Setup the job parameters from an XML Document.
|
void |
setup(File file)
Setup job parameters from a
File . |
void |
setup(InputStream in)
Setup job parameters from an
InputStream that should be valid XML text. |
void |
setup(String resourceURL)
Setup job parameters from an embedded resource.
|
private void |
setupClassLoader()
Setup the manager's class loader.
|
private void |
setupDrivers()
Create the drivers from the XML.
|
private void |
setupFileCache()
Setup the file cache.
|
private void |
setupInputFiles()
Setup the list of input files to be processed from the XML job file.
|
private void |
setupJobControlParameters()
Setup the job control parameters using the XML steering document.
|
private void |
setupUnits()
Setup the system of units.
|
private void |
substituteVariables(org.jdom.Document doc)
Perform variable substitution within all text data in a entire document.
|
private void |
substituteVariables(org.jdom.Element element)
Substitute values from the
variableMap into an XML element and all its children, recursively. |
protected static final Logger LOGGER
private static final org.apache.commons.cli.Options OPTIONS
private static final Pattern VARIABLE_PATTERN
private File cacheDirectory
private ClassLoader classLoader
org.apache.commons.cli.CommandLine commandLine
main
arguments.private String detectorName
private DriverAdapter driverAdapter
private boolean dryRun
private boolean dummyDetector
private Long eventPrintInterval
private final JDOMExpressionFactory factory
private FileCache fileCache
private boolean isSetup
true
after setup is performed.private long jobEnd
private long jobStart
private LCSimLoop loop
private int numberOfEvents
private final ParameterConverters paramConverter
private boolean printDriverStatistics
true
to print out driver statistics at the end of the job.private File rewriteFile
private boolean rewriteSteering
private org.jdom.Element root
private Integer runNumber
private int skipEvents
private boolean useSteeringResource
private static org.apache.commons.cli.Options createCommandLineOptions()
private static Class getPrimitiveType(String name)
name
- The name of the type.public static void main(String[] args)
Takes command-line options (use -h option to see them).
args
- the command line argumentsprivate static void printHelp()
private void addDriver(String name, Driver driver)
name
- the unique name of the Driverdriver
- the instance of the Driverpublic void addInputFile(File inputFile)
inputFile
- The input LCIO file.public void addVariableDefinition(String key, String value)
key
- The variable name.value
- The variable's value.public void configure()
private void createDriverAdapter()
private void createDriverExecList()
Driver
execution list.public void enableHeadlessMode()
Plotter.show()
is
called.public void finish()
public DriverAdapter getDriverAdapter()
DriverAdapter
from the currently configured Driver list.public List<Driver> getDriverExecList()
setup()
method has been called.List
of Drivers
.public LCSimLoop getLCSimLoop()
LCSimLoop
of this JobManager.private List<Method> getSetterMethods(Class klass)
klass
- The class.private void initializeLoop()
LCSimLoop
.public void parse(String[] args)
setup(File)
to load the
steering paramters from an XML file, after processing other command line options. This method is private so that
callers must all use the main(String[])
routine as the primary entry point.args
- The command line arguments.private void printInputFileList()
private void printUserClasspath()
private void processConstants()
private void processDriverParameters(Class driverClass, Driver newDriver, List<org.jdom.Element> parameters)
Driver
.driverClass
- the Java class of the drivernewDriver
- the instantiated Driverparameters
- the list of XML parameterspublic void processEvent(EventHeader event)
event
- private File processFileElement(org.jdom.Element fileElement, List<File> fileList)
File
object from the text in an XML element.fileElement
- The element containing a file path or URL.fileList
- List to append new File
.File
object.private File processFileText(String fileText, List<File> fileList)
fileText
- the text containing the file's path from the XMLfileList
- the list of files to which the new file will be appendedprivate String processPath(String path)
path
- The original path.private void rewriteXMLSteering(org.jdom.Document doc)
doc
- The XML steering doc with variables substituted.public boolean run()
public void setDryRun(boolean dryRun)
dryRun
- true
to enable a dry runpublic void setNumberOfEvents(int numberOfEvents)
setup(File)
method is called or it will be overridden.private void setup(org.jdom.Document xmlDocument)
This method contains the primary logic for setting up job parameters from an XML file. The other setup methods
such as setup(InputStream)
, setup(String)
and setup(File)
all call this method.
xmlDocument
- The lcsim recon XML document describing the job.public void setup(File file)
File
.file
- the path to the XML filepublic void setup(InputStream in)
InputStream
that should be valid XML text.in
- the XML input streampublic void setup(String resourceURL)
setup(InputStream)
.private void setupClassLoader()
private void setupDrivers()
private void setupFileCache()
private void setupInputFiles()
private void setupJobControlParameters()
private void setupUnits()
private void substituteVariables(org.jdom.Document doc)
doc
- The XML document.private void substituteVariables(org.jdom.Element element)
variableMap
into an XML element and all its children, recursively.element
- The XML element.protected void initializeConditions() throws ConditionsManager.ConditionsNotFoundException
Sub-classes should override this if custom conditions system initialization is required.
ConditionsManager.ConditionsNotFoundException
- if some conditions were not foundprotected Integer getRunNumber()
null
if not setprotected String getDetectorName()
null
if not setCopyright © 2016 Linear Collider Detector (LCD). All rights reserved.