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
-
initiateSession(user = None, port = 50022)Initiate a multiplexed ssh session, such that the password is requested only once for the user, when a transfer todbloader-mtdis requested. Need to configure ssh adding a lineControlPath ~/.ssh/control-%h-%p-%rto.ssh/config. -
terminateSession(user = None, port = 50022)Terminate the session started withinitiateSession(). -
mtdhelp(shrtOpts = '', longOpts = '', helpOpts = '', err = 0, hlp = '')Used in scripts to provide help about their usage. It assumes that you usegetoptto define short and long options to the script. It prints a generic help message passed ashlp. Passing short and long options, together with a list of strings, each of which contains a short help message for the corresponding option, prints a well formatted help message. It returnserr. -
writeToDB(port = 50022, filename = 'registerMatrixBatch.xml', dryrun = False, user = None)Actually upload filefilenametodbloader-mtd.cern.chusingsshon portport, unlessdryrunisTrue. The user is set to the username of the person running it, unless provided visuser. -
transfer(xml, filename = None, dryrun = False, user = None)Transfer the XML structure to thedblaoder. A session must be previously initiated withinitiateSession(). Internally callswriteToDB(). -
root()Creates the root element in the XML structure. -
mtdxml(root)Returnsroot(an XML structure) as a string.
xml elements management
-
attribute(parent, name, value)Append an attribute with namenameand valuevalueto theparentXML. -
addDataSet(parent, dataset)Add a dataset to theparentXML. 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:nameandvalue.nameshould correspond to the column name in the corresponding table in the DB, whilevalueis its content. The example shows how to build thedataset. This function is used internally innewCondition()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.runis 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 isbarcodeof typekind_of_part. When registering a part one can specify itsbatch,manufacturername,serialnumber, andattributes, if any. The part is assumed to be inlocation. The person who registered the part is assumed to be who ran the code, unlessuseris provided. All parameters are in the form of a string, butattributesthat must be passed as a list of dictionaries. Each dictionary in the list must have two keys:NAMEandVALUE. -
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 isbarcode-XXwhereXXis a number between 0 and 15. To create the corresponding XML structure for a single crystal usemultiplicity = 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.cmntrootcan beNoneor 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.rundetails must be provided in the form of a run dictionary (seenewrunabove.
Software created by Giovanni Organtini INFN-Sez. di Roma ([email protected])