Skip to content

Integrating into your code

Giovanni Organtini edited this page Jan 12, 2022 · 2 revisions

The mtdConstructionDBTools library can be integrated into you own software for data processing, such that, one you have got your data, you can seamlessly transfer them to the dbloader immediately. The library can be easily integrated into your code using

from mtdConstructionDBTools import mtdcdb

The transfer requires an ssh tunnel to be created. You can provide the secure connection when you launch the run that collects the data. To establish the connection you add the following line to your script:

mtdcdb.initiateSession()

To illustrate the process, we take an example in which we measure the LY on an array using the TOFPET bench in Roma.

Data are collected within a run, which brings some info with it that must be recorded in the database. More dataset can be associated to the same run. Then, when you start a run, you first create a dictionary containing information from the run, as follows:

    run_dict = { 'name': `IRR0_0H_T0M`,
                 'type': 'TOFPET',
                 'number': -1,
                 'comment': '',
                 'location': 'Roma/TOFPET'
        }

In the above example, a run is created of type TOFPET, with an id IRR0_0H_T0M. A run may have a number, too (in this case, it does not, so we assign it a -1 value). All the fields are free format strings.

Once you got the data for a part with a given barcode, you create a list of dictionaries with the corresponding data. To do that, you need to know the table structure for the corresponding conditions. In the case of the TOFPET bench, the corresponding condition table has been created as follows:

CREATE TABLE CMS_MTD_TMING_COND.LY_XTALK
(
  RECORD_ID             NUMBER(38) NOT NULL,
  CONDITION_DATA_SET_ID NUMBER(38) NOT NULL,
  CTR                   NUMBER  NOT NULL,
  SIGMA_T               NUMBER  NOT NULL,
  TEMPERATURE           NUMBER  NOT NULL,
  XTLEFT                NUMBER  NOT NULL,
  XTRIGHT               NUMBER  NOT NULL,
  LY_NORM               NUMBER  NOT NULL
)

Data is represented as a list, whose elements are dictionaries with two keys: NAME and VALUE. There are as many entries in the list as much data column in the table. The value of NAME must be identical to the corresponding column name in the table, while the value of VALUE is set to its value for the record that will be created. The example follows.

xtalk = [{'NAME': 'CTR',         'VALUE': ctr},
         {'NAME': 'SIGMA_T',     'VALUE': sigma_t},
         {'NAME': 'TEMPERATURE', 'VALUE': temperature},
         {'NAME': 'XTLEFT',      'VALUE': xtLeft},
         {'NAME': 'XTRIGHT',     'VALUE': xtRight},
         {'NAME': 'LY_NORM',     'VALUE': lyNorm}]

You create such a list for each barcode, then you collect all the lists into a list as

xdataset[barcode] = xdata

Once you have collected the data for all the barcodes, you just create the corresponding conditions:

root = mtdcdb.root()
condition = mtdcdb.newCondition(root, 'LY XTALK', xtalkdataset, run = run_dict,
                                runBegin = run_begin)

where run_begin is the timestamp of the run in the format YYYY-MM-DD HH24:MM:SS. See the full documentation to know all the possible parameters.

Then, transfer data to the dbloader using

mtdcdb.transfer(condition) At the end, close the tunnel with

mtdcdb.terminateSession()

Clone this wiki locally