ATLAS Offline Software
JsonPlotsDefReadTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "JsonPlotsDefReadTool.h"
12 #include "SinglePlotDefinition.h"
13 
15 #include <nlohmann/json.hpp>
16 
17 
22 {
23  ATH_MSG_INFO( "Initializing " << name() );
25  return StatusCode::SUCCESS;
26 }
27 
28 
32 std::vector< IDTPM::SinglePlotDefinition >
34 {
35  using json = nlohmann::json;
36  using cstr_t = const std::string&;
37 
38  std::vector< SinglePlotDefinition > plotDefVec;
39 
41  for( cstr_t plotDefStr : m_plotsDefs ) {
42 
43  ATH_MSG_DEBUG( "Reading plot definition : " << plotDefStr );
44 
46  const json& plotDef = json::parse( plotDefStr );
47 
49  cstr_t name = plotDef.contains( "name" ) ?
50  plotDef.at( "name" ).get_ref< cstr_t >() : "";
51 
53  cstr_t type = plotDef.contains( "type" ) ?
54  plotDef.at( "type" ).get_ref< cstr_t >() : "";
55 
57  cstr_t folder = plotDef.contains( "folder" ) ?
58  plotDef.at( "folder" ).get_ref< cstr_t >() : "";
59 
61  cstr_t title = plotDef.contains( "title" ) ?
62  plotDef.at( "title" ).get_ref< cstr_t >() : "";
63 
65  unsigned int nBinsX = plotDef.contains( "xAxis_nBins" ) ?
66  ( unsigned int )std::stoi(
67  plotDef.at( "xAxis_nBins" ).get_ref< cstr_t >() ) : 0;
68 
70  unsigned int nBinsY = plotDef.contains( "yAxis_nBins" ) ?
71  ( unsigned int )std::stoi(
72  plotDef.at( "yAxis_nBins" ).get_ref< cstr_t >() ) : 0;
73 
75  unsigned int nBinsZ = plotDef.contains( "zAxis_nBins" ) ?
76  ( unsigned int )std::stoi(
77  plotDef.at( "zAxis_nBins" ).get_ref< cstr_t >() ) : 0;
78 
80  float xLow = plotDef.contains( "xAxis_low" ) ?
81  std::stof( plotDef.at( "xAxis_low" ).get_ref< cstr_t >() ) : 0.;
82  float xHigh = plotDef.contains( "xAxis_high" ) ?
83  std::stof( plotDef.at( "xAxis_high" ).get_ref< cstr_t >() ) : 0.;
84 
86  float yLow = plotDef.contains( "yAxis_low" ) ?
87  std::stof( plotDef.at( "yAxis_low" ).get_ref< cstr_t >() ) : 0.;
88  float yHigh = plotDef.contains( "yAxis_high" ) ?
89  std::stof( plotDef.at( "yAxis_high" ).get_ref< cstr_t >() ) : 0.;
90 
92  float zLow = plotDef.contains( "zAxis_low" ) ?
93  std::stof( plotDef.at( "zAxis_low" ).get_ref< cstr_t >() ) : 0.;
94  float zHigh = plotDef.contains( "zAxis_high" ) ?
95  std::stof( plotDef.at( "zAxis_high" ).get_ref< cstr_t >() ) : 0.;
96 
98  cstr_t xTitle = plotDef.contains( "xAxis_title" ) ?
99  plotDef.at( "xAxis_title" ).get_ref< cstr_t >() : "";
100 
102  cstr_t yTitle = plotDef.contains( "yAxis_title" ) ?
103  plotDef.at( "yAxis_title" ).get_ref< cstr_t >() : "";
104 
106  cstr_t zTitle = plotDef.contains( "zAxis_title" ) ?
107  plotDef.at( "zAxis_title" ).get_ref< cstr_t >() : "";
108 
110  plotDefVec.emplace_back(
111  name, type, title,
112  xTitle, nBinsX, xLow, xHigh,
113  yTitle, nBinsY, yLow, yHigh,
114  zTitle, nBinsZ, zLow, zHigh,
115  folder );
116 
118  if( not plotDefVec.back().isValid() ) {
119  ATH_MSG_WARNING( "Tried to add invalid plot : " <<
120  plotDefVec.back().plotDigest() );
121  plotDefVec.pop_back(); // removing from vector
122  }
123 
124  } // close m_plotDefs loop
125 
126  return plotDefVec;
127 }
SinglePlotDefinition.h
Class to store (internally) each plot definition in this package (originally based on the SingleHisto...
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
json
nlohmann::json json
Definition: HistogramDef.cxx:9
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:983
plotBeamSpotVert.plotDef
dictionary plotDef
Definition: plotBeamSpotVert.py:55
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
covarianceTool.title
title
Definition: covarianceTool.py:542
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
JsonPlotsDefReadTool.h
Tool to read/parse plots definitions from Json input format.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
IDTPM::JsonPlotsDefReadTool::initialize
virtual StatusCode initialize() override
Initialize.
Definition: JsonPlotsDefReadTool.cxx:21
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
IDTPM::JsonPlotsDefReadTool::getPlotsDefinitions
virtual std::vector< SinglePlotDefinition > getPlotsDefinitions() const override
Parse input pltos defnitions and returns vector of SinglePlotDefinition.
Definition: JsonPlotsDefReadTool.cxx:33
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
asg::AsgTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: AsgTool.h:133