public final class DatabaseConditionsManager
extends org.lcsim.conditions.ConditionsManagerImplementation
This class provides the top-level API for accessing database conditions, as
well as configuring the database connection, initializing all required
components, and loading required converters and table meta data. It is
registered as the global ConditionsManager
in the constructor.
Differences between Test Run and Engineering Run configurations are handled automatically.
The connection URL, username and password can be set via Java properties from
the command line, e.g. for the default connection:
java -Dorg.hps.conditions.url=jdbc:mysql://hpsdb.jlab.org:3306/hps_conditions
-Dorg.hps.conditions.user=hpsuser -Dorg.hps.conditions.password=darkphoton [...]
To use a local SQLite database, provide a URL that looks something like this:
jdbc:sqlite:hps_conditions.db
The last part should be the relative or absolute path to the SQLite db file.
When using a SQLite database, no username or password needs to be provided.
SQLite is not supported in write mode. The local database should be a clone of a particular version of the master MySQL database at JLab.
ConditionsManager
Modifier and Type | Field and Description |
---|---|
private ConditionsRecord.ConditionsRecordCollection |
conditionsRecordCollection
The current set of conditions records for the run.
|
private ConditionsTag.ConditionsTagCollection |
conditionsTagCollection
The currently active conditions tag; an empty collection means that no tag is
active.
|
private Connection |
connection
The current database connection.
|
private ConverterRegistry |
converters
Create the global registry of conditions object converters.
|
private static String |
DEFAULT_PASSWORD
Password for default account 'hpsuser'.
|
private static String |
DEFAULT_URL
Default database URL.
|
private static String |
DEFAULT_USER
Default database user for read access.
|
private org.lcsim.conditions.ConditionsConverter |
ecalConverter
The converter for creating the combined ECAL conditions object.
|
private boolean |
isFrozen
True if the conditions system has been frozen and will ignore updates after
it is initialized.
|
private boolean |
isInitialized
True if the manager has been initialized, e.g.
|
private boolean |
isTestRun
True if current run number is from Test Run.
|
private static Logger |
LOG
Initialize the logger.
|
private static int |
MAX_ATTEMPTS
Number of connection retries allowed.
|
private static int |
RETRY_WAIT
Wait time (in millis) for the first retry.
|
private org.lcsim.conditions.ConditionsConverter |
svtConverter
The converter for creating the combined SVT conditions object.
|
private TableRegistry |
tableRegistry
Create the global registry of table meta data.
|
private Set<String> |
tags
The currently applied conditions tags.
|
private static int |
TEST_RUN_MAX_RUN
The max value for a run to be considered Test Run.
|
Constructor and Description |
---|
DatabaseConditionsManager()
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addTag(String tag)
Add a tag used to filter the accessible conditions records.
|
void |
addTags(Set<String> tags)
Add one or more tags for filtering records.
|
void |
clearTags()
Clear the tags used to filter the
ConditionsRecord s. |
void |
closeConnection()
Close the database connection.
|
boolean |
collectionExists(String tableName,
int collectionID)
This method will return
true if the given collection ID already
exists in the table. |
private Connection |
createConnection()
Get a connection to the conditions database, possibly using
properties from the command line for the database URL, username,
and password (otherwise the defaults are used to provide a
read only connection).
|
ConditionsRecord.ConditionsRecordCollection |
findConditionsRecords(String name)
Find a collection of conditions validity records by key name.
|
TableMetaData |
findTableMetaData(String name)
Find table information from the name.
|
void |
freeze()
This method can be called to "freeze" the conditions system so that any
subsequent updates to run number or detector name will be ignored.
|
Collection<String> |
getActiveTags()
Get the currently active conditions tags.
|
Set<String> |
getAvailableTags()
Get the set of available conditions tags from the conditions table
|
int |
getCollectionId(ConditionsObjectCollection<?> collection,
String description)
Add a row for a new collection and return the new collection ID assigned to
it.
|
ConditionsRecord.ConditionsRecordCollection |
getConditionsRecords()
Get the list of conditions records for the run, filtered by the current set
of active tags.
|
<ObjectType extends ConditionsObject,CollectionType extends ConditionsObjectCollection<ObjectType>> |
getConditionsSeries(Class<CollectionType> collectionType,
String tableName)
Get a conditions series with one or more collections.
|
Connection |
getConnection()
Get the JDBC connection.
|
org.lcsim.geometry.Detector |
getDetectorObject()
Get the current LCSim compact
Detector object with the geometry
and detector model. |
EcalConditions |
getEcalConditions()
Get the combined ECAL conditions for this run.
|
static DatabaseConditionsManager |
getInstance()
Get the static instance of this class.
|
SvtConditions |
getSvtConditions()
Get the combined SVT conditions for this run.
|
boolean |
hasConditionsRecord(String name)
True if there is a conditions record with the given name.
|
boolean |
isFrozen()
True if conditions system is frozen
|
boolean |
isInitialized()
True if conditions manager is properly initialized.
|
boolean |
isTestRun()
Return
true if Test Run configuration is active |
static boolean |
isTestRun(int runNumber)
Utility method to determine if a run number is from the 2012 Test Run.
|
<CollectionType extends ConditionsObjectCollection<?>> |
newCollection(Class<CollectionType> collectionType)
Create a new collection with the given type.
|
<CollectionType extends ConditionsObjectCollection<?>> |
newCollection(Class<CollectionType> collectionType,
String tableName)
Create a new collection with the given type and table name.
|
void |
openConnection()
Open the database connection.
|
private void |
registerConverters()
Register the conditions converters with the manager.
|
ResultSet |
selectQuery(String query)
This method can be used to perform a database SELECT query.
|
void |
setDetector(String detectorName,
int runNumber)
This method handles changes to the detector name and run number.
|
void |
unfreeze()
Un-freeze the conditions system so that updates will be received again.
|
addConditionsListener, clearCache, fireConditionsChanged, getCachedConditions, getConditions, getConditionsReader, getDetector, getRawConditions, getRun, open, registerConditionsConverter, removeConditionsConverter, removeConditionsListener, setConditionsReader, setRun
private static Logger LOG
private static final int TEST_RUN_MAX_RUN
private static String DEFAULT_URL
private static String DEFAULT_USER
private static String DEFAULT_PASSWORD
private static final int MAX_ATTEMPTS
private static final int RETRY_WAIT
private ConditionsRecord.ConditionsRecordCollection conditionsRecordCollection
private final ConditionsTag.ConditionsTagCollection conditionsTagCollection
private Connection connection
private final ConverterRegistry converters
private org.lcsim.conditions.ConditionsConverter ecalConverter
private boolean isFrozen
private boolean isInitialized
setDetector(String, int)
method was called.private boolean isTestRun
private org.lcsim.conditions.ConditionsConverter svtConverter
private final TableRegistry tableRegistry
public DatabaseConditionsManager()
private Connection createConnection()
public static DatabaseConditionsManager getInstance()
public static boolean isTestRun(int runNumber)
runNumber
- the run numbertrue
if run number is from the Test Runpublic void addTag(String tag)
Multiple tags are OR'd together.
tag
- the tag value used to filter returned conditions recordspublic void addTags(Set<String> tags)
tags
- the Set
of tags to addpublic void clearTags()
ConditionsRecord
s.public void closeConnection()
public boolean collectionExists(String tableName, int collectionID)
true
if the given collection ID already
exists in the table.tableName
- the name of the tablecollectionID
- the collection ID valuetrue
if collection existspublic ConditionsRecord.ConditionsRecordCollection findConditionsRecords(String name)
name
- the conditions key namepublic TableMetaData findTableMetaData(String name)
name
- the name of the tablenull
if does not existpublic void freeze()
public Collection<String> getActiveTags()
public Set<String> getAvailableTags()
public int getCollectionId(ConditionsObjectCollection<?> collection, String description) throws SQLException
collection
- the conditions object collectiondescription
- text description for the new collection ID record in the
databaseSQLException
public ConditionsRecord.ConditionsRecordCollection getConditionsRecords()
public <ObjectType extends ConditionsObject,CollectionType extends ConditionsObjectCollection<ObjectType>> ConditionsSeries<ObjectType,CollectionType> getConditionsSeries(Class<CollectionType> collectionType, String tableName)
ObjectType
- the type of the conditions objectCollectionType
- the type of the conditions collectioncollectionType
- the type of the collectiontableName
- the name of the data tablepublic Connection getConnection()
public org.lcsim.geometry.Detector getDetectorObject()
Detector
object with the geometry
and detector model.public EcalConditions getEcalConditions()
public SvtConditions getSvtConditions()
public boolean hasConditionsRecord(String name)
name
- the conditions record name (usually will match to table name)true
if a conditions record exists with the given namepublic boolean isFrozen()
true
if conditions system is currently frozenpublic boolean isInitialized()
true
if the manager is initializedpublic boolean isTestRun()
true
if Test Run configuration is activetrue
if Test Run configuration is activepublic <CollectionType extends ConditionsObjectCollection<?>> CollectionType newCollection(Class<CollectionType> collectionType)
collectionType
- the collection typepublic <CollectionType extends ConditionsObjectCollection<?>> CollectionType newCollection(Class<CollectionType> collectionType, String tableName)
collectionType
- the collection typetableName
- the table namepublic void openConnection()
private void registerConverters()
public ResultSet selectQuery(String query)
query
- the SQL query stringResultSet
from the queryRuntimeException
- if there is a query errorpublic void setDetector(String detectorName, int runNumber) throws org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException
setDetector
in class org.lcsim.conditions.ConditionsManagerImplementation
org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException
public void unfreeze()
Copyright © 2019. All rights reserved.