SND@LHC Software
|
Public Member Functions | |
__init__ (self, connection_dict) | |
list_detectors (self, parent_id=None) | |
Returns a list with all the detector names in the database. | |
get_detector (self, detector_id) | |
Returns a detector dictionary. | |
add_detector (self, name, parent_id=None) | |
Adds a new detector to the database. | |
remove_detector (self, detector_id) | |
Removes a detector from the database. | |
add_condition (self, detector_id, name, tag, values, type=None, collected_at=datetime.now(), valid_since=datetime.now(), valid_until=datetime.max) | |
Adds a condition to a detector. | |
get_conditions (self, detector_id) | |
Returns a list with all condition dictionaries associated with a detector. | |
get_conditions_by_name (self, detector_id, name) | |
Returns a list with condition dictionaries having a specific name for a given detector. | |
get_conditions_by_tag (self, detector_id, tag) | |
Returns a list with condition dictionaries having a specific tag for a given detector. | |
get_conditions_by_name_and_validity (self, detector_id, name, start_date, end_date=None) | |
Returns a list with condition dictionaries associated with a detector that are valid on the specified date. | |
get_condition_by_name_and_tag (self, detector_id, name, tag) | |
Returns a condition dictionary of a specific condition belonging to a detector, identified by condition name and tag. | |
get_condition_by_name_and_collection_date (self, detector_id, name, collected_at) | |
Returns a condition dictionary of a specific condition belonging to a detector, identified by condition name and collection date/time. | |
update_condition_by_name_and_tag (self, detector_id, name, tag, type=None, valid_since=None, valid_until=None) | |
Updates the type, valid_since and valid_until values of a specific condition belonging to a detector, identified by condition name and tag. | |
Private Member Functions | |
__get_connection (self, connection_dict) | |
__delete_db (self, db_name) | |
__validate_str (self, input_string) | |
__validate_datetime (self, input_datetime) | |
__validate_path (self, input_path) | |
__validate_interval_parameters (self, input_date) | |
__sanitize_str (self, input_string) | |
__sanitize_path (self, input_path) | |
__convert_date (self, input_date_string) | |
__split_name (self, detector_id) | |
__get_wrapper (self, wrapper_id) | |
__get_subdetector (self, detector, sub_name) | |
__get_detector (self, detector_wrapper, detector_id) | |
__add_wrapper (self, name) | |
__remove_wrapper (self, wrapper_id) | |
Static Private Attributes | |
__db_connection = None | |
Adapter class for a MongoDB back-end that implements the CDB interface.
Definition at line 28 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.__init__ | ( | self, | |
connection_dict | |||
) |
This constructor makes a connection to the MongoDB conditions DB. :param connection_dict: The mongoDB configuration for making the connection to the Conditions Database.
Definition at line 35 of file mongodbadapter.py.
|
private |
Creates a new DetectorWrapper object and stores it in the DB. Returns this new wrapper or None if a detector with that name already exists. :param name: (String) uniquely identifying the wrapper.
Definition at line 245 of file mongodbadapter.py.
|
private |
This method converts a date string to a datetime Object. :param input_date_string: String representing a date Accepted String formats: "Year", "Year-Month", "Year-Month-Day", "Year-Month-Day Hours", "Year-Month-Day Hours-Minutes", "Year-Month-Day Hours-Minutes-Seconds". :throw ValueError: If input_date_string is not as specified.
Definition at line 131 of file mongodbadapter.py.
|
private |
Delete the specified database. :param db_name: The name of the DB that needs to be deleted.
Definition at line 60 of file mongodbadapter.py.
|
private |
Create a connection to a MongoDB server and return the connection handle.
Definition at line 44 of file mongodbadapter.py.
|
private |
Returns a Detector object identified by detector_id. It raises ValueError if the detector_id could not be found. :param detector_wrapper: DetectorWrapper object that contains a detector tree. :param detector_id: (String) The ID (i.e. path) to the detector that must be retrieved.
Definition at line 215 of file mongodbadapter.py.
|
private |
Returns a subdetector with name sub_name under the specified parent detector. :param detector: Detector object. :param sub_name: (String) name of the subdetector that should be returned.
Definition at line 201 of file mongodbadapter.py.
|
private |
Returns a DetectorWrapper object. Otherwise it raises a ValueError exception if the wrapper_id could not be found. :param wrapper_id: String specifying the ID for the wrapper to be returned. Must be unique. Must not contain a forward slash (i.e. /).
Definition at line 172 of file mongodbadapter.py.
|
private |
Removes a detector wrapper and its contents from the database. :param wrapper_id: (String) identifying the wrapper to remove.
Definition at line 259 of file mongodbadapter.py.
|
private |
This method removes slashes and spaces at the beginning and at the end of the parameter input_path. :param input_path: string that will be sanitized.
Definition at line 121 of file mongodbadapter.py.
|
private |
This method removes spaces at the beginning and at the end of the string and returns the String without spaces. :param input_string: string that will be sanitized.
Definition at line 112 of file mongodbadapter.py.
|
private |
Splits the detector_id string using '/' and returns a list of detector names. Otherwise raises an exception if detector_id is not a valid path / id. :param detector_id: path to a detector (e.g. detect_name/subdetector_name/...).
Definition at line 159 of file mongodbadapter.py.
|
private |
This method validates if input_datetime is of datetime type. If it is not of datetime type it returns False. :param input_datetime: value that needs to be tested.
Definition at line 79 of file mongodbadapter.py.
|
private |
This method validates if input_date is a datetime type or string. If yes, it returns True. Otherwise it returns False. :param input_date: It could be String or datetime type.
Definition at line 101 of file mongodbadapter.py.
|
private |
This method validates if input_path is a valid path. If it is not of String type it returns False. :param input_path: value that needs to be tested.
Definition at line 90 of file mongodbadapter.py.
|
private |
This method validates if input_string is of string type. If it is not of String type it returns False. :param input_string: value that needs to be tested.
Definition at line 68 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.add_condition | ( | self, | |
detector_id, | |||
name, | |||
tag, | |||
values, | |||
type = None , |
|||
collected_at = datetime.now() , |
|||
valid_since = datetime.now() , |
|||
valid_until = datetime.max |
|||
) |
Adds a condition to a detector.
detector_id | String identifying the detector to which the condition will be added (i.e. 'muonflux/driftTubes'). |
name | String specifying the name of the condition (e.g. 'strawPositions'). |
tag | String specifying a tag for the condition. Must be unique for the same condition name. |
values | The values of the condition. Can be any data type. |
type | (optional) String specifying the type of condition (e.g. 'calibration'). |
collected_at | (optional) Timestamp specifying the date/time the condition was acquired. Must be unique w.r.t. the condition name. Can be of type String or datetime. This timestamp will be stored with an accuracy up to seconds. If unspecified, this value will be set to 'datetime.now'. |
valid_since | (optional) Timestamp specifying the date/time as of when the condition is valid. Can be of type String or datetime. This timestamp will be stored with an accuracy up to seconds. If unspecified, this value will be set to 'datetime.now'. |
valid_until | (optional) Timestamp specifying the date/time up until the condition is valid. Can be of type String or datetime. If unspecified, this value will be set to 'datetime.max'. This timestamp will be stored with an accuracy up to seconds. |
TypeError | If input type is not as specified. |
ValueError | If detector_id does not exist. |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 462 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.add_detector | ( | self, | |
name, | |||
parent_id = None |
|||
) |
Adds a new detector to the database.
name | String specifying the name for the new detector. Must be unique. Must not contain a forward slash (i.e. /). |
parent_id | (optional) String identifying the parent detector the new detector should be added to as subdetector. |
TypeError | If input type is not as specified. |
ValueError | If parent_id does not exist. |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 340 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.get_condition_by_name_and_collection_date | ( | self, | |
detector_id, | |||
name, | |||
collected_at | |||
) |
Returns a condition dictionary of a specific condition belonging to a detector, identified by condition name and collection date/time.
This combination must be unique.
detector_id | String identifying the detector for which the condition must be retrieved (i.e. 'muonflux/driftTubes'). |
name | String specifying the name of the conditions to be retrieved (e.g. 'strawPositions'). |
collected_at | Timestamp specifying the moment on which the condition was collected/measured. Can be of type String or datetime. Collection dates are stored with accuracy up to seconds. |
TypeError | If input type is not as specified. |
ValueError | If detector_id does not exist. |
Dict | A dictionary adhering to the following specification: Condition = { 'name': String, 'tag': String, 'type': String, 'collected_at': datetime, 'valid_since': datetime, 'valid_until': datetime, 'values': mixed } |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 769 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.get_condition_by_name_and_tag | ( | self, | |
detector_id, | |||
name, | |||
tag | |||
) |
Returns a condition dictionary of a specific condition belonging to a detector, identified by condition name and tag.
This combination must be unique.
detector_id | String identifying the detector for which the condition must be retrieved (i.e. 'muonflux/driftTubes'). |
name | String specifying the name of the conditions to be retrieved (e.g. 'strawPositions'). |
tag | String specifying the tag of the condition to be retrieved. |
TypeError | If input type is not as specified. |
ValueError | If detector_id does not exist. |
Dict | A dictionary adhering to the following specification: Condition = { 'name': String, 'tag': String, 'type': String, 'collected_at': datetime, 'valid_since': datetime, 'valid_until': datetime, 'values': mixed } |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 732 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.get_conditions | ( | self, | |
detector_id | |||
) |
Returns a list with all condition dictionaries associated with a detector.
detector_id | String identifying the detector for which the conditions must be retrieved (i.e. 'muonflux/driftTubes'). |
TypeError | If input type is not as specified. |
ValueError | If detector_id does not exist. |
List | A list with condition dictionaries adhering to the following specification: Condition = { 'name': String, 'tag': String, 'type': String, 'collected_at': datetime, 'valid_since': datetime, 'valid_until': datetime, 'values': mixed } |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 546 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.get_conditions_by_name | ( | self, | |
detector_id, | |||
name | |||
) |
Returns a list with condition dictionaries having a specific name for a given detector.
detector_id | String identifying the detector for which the conditions must be retrieved (i.e. 'muonflux/driftTubes'). |
name | String specifying the name of the conditions to be retrieved (e.g. 'strawPositions'). |
TypeError | If input type is not as specified. |
ValueError | If detector_id does not exist. |
List | A list with condition dictionaries adhering to the following specification: Condition = { 'name': String, 'tag': String, 'type': String, 'collected_at': datetime, 'valid_since': datetime, 'valid_until': datetime, 'values': mixed } |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 580 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.get_conditions_by_name_and_validity | ( | self, | |
detector_id, | |||
name, | |||
start_date, | |||
end_date = None |
|||
) |
Returns a list with condition dictionaries associated with a detector that are valid on the specified date.
detector_id | String identifying the detector for which the condition must be retrieved (i.e. 'muonflux/driftTubes'). |
name | String specifying the name of the conditions to be retrieved (e.g. 'strawPositions'). |
start_date | Timestamp specifying a start of a date/time range for which conditions must be valid. Can be of type String or datetime. |
end_date | (optional) Timestamp specifying the end of a date/time range for which conditions must be valid. If not specified then we will query for validity on the start_date. Can be of type String or datetime |
TypeError | If input type is not as specified. |
ValueError | If detector_id does not exist. |
List | A list with condition dictionaries adhering to the following specification: Condition = { 'name': String, 'tag': String, 'type': String, 'collected_at': datetime, 'valid_since': datetime, 'valid_until': datetime, 'values': mixed } |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 660 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.get_conditions_by_tag | ( | self, | |
detector_id, | |||
tag | |||
) |
Returns a list with condition dictionaries having a specific tag for a given detector.
detector_id | String identifying the detector for which the condition must be retrieved (i.e. 'muonflux/driftTubes'). |
tag | String specifying the tag of the condition to be retrieved. |
TypeError | If input type is not as specified. |
ValueError | If detector_id does not exist. |
List | A list with condition dictionaries adhering to the following specification: Condition = { 'name': String, 'tag': String, 'type': String, 'collected_at': datetime, 'valid_since': datetime, 'valid_until': datetime, 'values': mixed } |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 620 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.get_detector | ( | self, | |
detector_id | |||
) |
Returns a detector dictionary.
detector_id | String identifying the detector to retrieve (i.e. 'muonflux/driftTubes'). |
TypeError | If input type is not as specified. |
ValueError | If detector_id does not exist. |
Dict | A dictionary adhering to the following specification: Detector = { 'name': String, 'subdetectors': List of Detector, 'conditions': List of Condition } |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 315 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.list_detectors | ( | self, | |
parent_id = None |
|||
) |
Returns a list with all the detector names in the database.
detector_id | (optional) String identifying the parent detector to retrieve the (sub)detector names for (i.e. 'muonflux/driftTubes'). |
TypeError | If input type is not as specified. |
ValueError | If parent_id does not exist. |
List | A list with (string) names of detectors under the specified parent. |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 279 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.remove_detector | ( | self, | |
detector_id | |||
) |
Removes a detector from the database.
Caution: all conditions associated with this detector will be permanently removed as well!
detector_id | String identifying the detector to remove (i.e. 'muonflux/driftTubes'). |
TypeError | If input type is not as specified. |
ValueError | If detector_id does not exist. |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 405 of file mongodbadapter.py.
conditionsDatabase.databases.mongodb.mongodbadapter.MongoToCDBAPIAdapter.update_condition_by_name_and_tag | ( | self, | |
detector_id, | |||
name, | |||
tag, | |||
type = None , |
|||
valid_since = None , |
|||
valid_until = None |
|||
) |
Updates the type, valid_since and valid_until values of a specific condition belonging to a detector, identified by condition name and tag.
detector_id | String identifying the detector for which the condition must be updated (i.e. 'muonflux/driftTubes'). |
name | String specifying the name of the conditions to be updated (e.g. 'strawPositions'). |
tag | String specifying the tag of the condition to be updated. |
type | (optional) String specifying the type of condition (e.g. 'calibration'). |
valid_since | (optional) Timestamp specifying the date/time as of when the condition is valid. Can be of type String or datetime. |
valid_until | (optional) Timestamp specifying the date/time up until the condition is valid. Can be of type String or datetime. |
TypeError | If input type is not as specified. |
ValueError | If detector_id does not exist. |
Reimplemented from conditionsDatabase.interface.APIInterface.
Definition at line 814 of file mongodbadapter.py.
|
staticprivate |
Definition at line 33 of file mongodbadapter.py.