mtdConstructionDBTools - CMSROMA/MTDDB GitHub Wiki

mtdcdb

from mtdConstructionDBTools import mtdcdb

mtdcdb is intended to help in building the XML structures needed to upload data to the MTD construction database

general services

xml elements management

  • attribute(parent, name, value) Append an attribute with name name and value value to the parent XML.

  • addDataSet(parent, dataset) Add a dataset to the parent XML. A dataset is a dictionary with barcodes as keys and a list of dictionaries as value. The dictionaries in the list contains two elements each: name and value. name should correspond to the column name in the corresponding table in the DB, while value is its content. The example shows how to build the dataset. This function is used internally in newCondition() to attach the dataset to each part.

creating objects in DB

  • newrun(condition, run = {}, begin = None, end = None) Used internally to create a run when creating conditions obtained during that run. run is a dictionary with the following keys: type, name, number, comment, location, user. If the latter is empty, it is automatically set to the current user.

  • part(barcode, kind_of_part, batch = None, attributes = None, manufacturer = None, user = None, location = 'testLab', serial = None) Returns the XML to define a part whose barcode is barcode of type kind_of_part. When registering a part one can specify its batch, manufacturer name, serial number, and attributes, if any. The part is assumed to be in location. The person who registered the part is assumed to be who ran the code, unless user is provided. All parameters are in the form of a string, but attributes that must be passed as a list of dictionaries. Each dictionary in the list must have two keys: NAME and VALUE.

  • mtdcreateMatrix(parts, barcode, Xtaltype, manufacturer, batchIngot, laboratory, serial = 'None', user = None, multiplicity = 16) Returns the XML structure for a LYSO array (aka a matrix). Its children are automatically created whose barcode is barcode-XX where XX is a number between 0 and 15. To create the corresponding XML structure for a single crystal use multiplicity = 1.

  • newCondition(cmntroot, condition_name, condition_dataset, run, runBegin = None, runEnd = None) Returns the XML structure for conditions. Conditions are the results of a measurement. A condition, which may be composed of many fields, is associated to a run. cmntroot can be None or any other XML structure: the resulting condition will be a child of it. You must provide a condition dataset in the form of a dictionary whose keys are the barcodes of the measured parts, and whose values are lists of dictionaries. The latter have two entries each: a NAME and a VALUE. NAME is associated to the corresponding column name in the db table, while VALUE will be used to insert a row in this table. run details must be provided in the form of a run dictionary (see newrun above.


Software created by Giovanni Organtini INFN-Sez. di Roma ([email protected])