Skip to content

JSON-formatted Histogram Definition

I've rewritten the Python/C++ interface to use JSON-formatted strings. This will allow for slightly more sophisticated configurations of histograms. This also necessitated re-writing a number of the unit tests.

The defineHistogram() function in GenericMonitoringTool now creates a Python dictionary of histgram attributes, dumps them into a JSON string, which is then passed to the C++ GenericMonitoringTool's histograms member. The HistogramDef struct is now a pretty trivial step, unpacking the variables into the struct. The essential logic has therefore been moved to the Python side.

An example string passed to C++ would be the following.

{
    "alias": "var",
    "allvars": [
        "var"
    ],
    "convention": "",
    "opt": "",
    "path": "",
    "title": "var",
    "type": "TH1F",
    "weight": "",
    "xarray": [],
    "xbins": 100,
    "xlabels": [],
    "xmax": 1,
    "xmin": 0,
    "xvar": "var",
    "yarray": [],
    "ybins": 0.0,
    "ylabels": [],
    "ymax": 0.0,
    "ymin": 0.0,
    "yvar": "",
    "zlabels": [],
    "zmax": 0.0,
    "zmin": 0.0,
    "zvar": ""
}

Also included:

  • changes to HistogramFactory that allows one to set y labels but not x labels.
  • in two places, managed to combine two redundant unit tests into one

There's a lot of diff, but a good portion of it was just moving code from C++ to Python, and rewriting a lot of strings in the unit tests, so the logic should be pretty similar. Please let me know any thoughts.

Todo:

  • some cleanup. Some #include statements can be removed.
  • check for TrigGenericMonitoringTool dependencies on the change.
  • add specific support for k____ histogram options. For example, a HistogramDef member called kAddBinsDynamically. This will be done in a future MR.

People: @ponyisi @tbold @fwinkl @pisarna

Edited by Charles Burton

Merge request reports