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-mtd
is requested. Need to configure ssh adding a lineControlPath ~/.ssh/control-%h-%p-%r
to.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 usegetopt
to 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 filefilename
todbloader-mtd.cern.ch
usingssh
on portport
, unlessdryrun
isTrue
. 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 namename
and valuevalue
to theparent
XML. -
addDataSet(parent, dataset)
Add a dataset to theparent
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
andvalue
.name
should correspond to the column name in the corresponding table in the DB, whilevalue
is 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.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 isbarcode
of typekind_of_part
. When registering a part one can specify itsbatch
,manufacturer
name,serial
number, andattributes
, if any. The part is assumed to be inlocation
. The person who registered the part is assumed to be who ran the code, unlessuser
is provided. All parameters are in the form of a string, butattributes
that must be passed as a list of dictionaries. Each dictionary in the list must have two keys:NAME
andVALUE
. -
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-XX
whereXX
is 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.cmntroot
can beNone
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 (seenewrun
above.
Software created by Giovanni Organtini INFN-Sez. di Roma ([email protected])