ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
TrigConf::JsonFileLoader Class Reference

Loader of trigger configurations from Json files. More...

#include <JsonFileLoader.h>

Inheritance diagram for TrigConf::JsonFileLoader:
Collaboration diagram for TrigConf::JsonFileLoader:

Public Member Functions

 JsonFileLoader ()
 Constructor. More...
 
virtual ~JsonFileLoader () override=default
 Destructor. More...
 
bool loadFile (const std::string &filename, boost::property_tree::ptree &data, const std::string &pathToChild="") const
 Load content of json file into a ptree. More...
 
bool loadFile (const std::string &filename, DataStructure &data, const std::string &pathToChild="") const
 Load content of json file into a ptree. More...
 
bool saveFile (const std::string &filename, const DataStructure &data) const
 Save content of DataStructure (underlying ptree) to a file. More...
 
std::string getFileType (const std::string &filename) const
 Checks the trigger level of a given json file. More...
 
bool checkTriggerLevel (const std::string &filename, std::string &level) const
 Checks the trigger level of a given json file. More...
 
void setLevel (MSGTC::Level lvl)
 
MSGTC::Level outputLevel () const
 
bool msgLvl (const MSGTC::Level lvl) const
 Test the output level. More...
 
MsgStreamTCmsg () const
 The standard message stream. More...
 
MsgStreamTCmsg (const MSGTC::Level lvl) const
 The standard message stream. More...
 

Private Member Functions

std::string findFile (const std::string &filename) const
 

Private Attributes

boost::thread_specific_ptr< MsgStreamTCm_msg_tls
 MsgStreamTC instance (a std::cout like with print-out levels) More...
 
std::string m_name
 

Detailed Description

Loader of trigger configurations from Json files.

Definition at line 25 of file JsonFileLoader.h.

Constructor & Destructor Documentation

◆ JsonFileLoader()

TrigConf::JsonFileLoader::JsonFileLoader ( )

Constructor.

Definition at line 19 of file JsonFileLoader.cxx.

19  :
20  TrigConfMessaging( "JsonFileLoader")
21 {}

◆ ~JsonFileLoader()

virtual TrigConf::JsonFileLoader::~JsonFileLoader ( )
overridevirtualdefault

Destructor.

Member Function Documentation

◆ checkTriggerLevel()

bool TrigConf::JsonFileLoader::checkTriggerLevel ( const std::string &  filename,
std::string &  level 
) const

Checks the trigger level of a given json file.

Parameters
filename[in] Name of the json file
level[out] either "L1", "HLT" or "UNKNOWN"

Definition at line 128 of file JsonFileLoader.cxx.

130 {
131  level = "UNKNOWN";
132 
133  DataStructure data;
134 
135  bool succeeded = this -> loadFile ( filename, data );
136 
137  if ( succeeded ) {
138  if (data.hasChild("chains")) {
139  level = "HLT";
140  } else if (data.hasChild("items")) {
141  level = "L1";
142  }
143  }
144 
145  return succeeded;
146 }

◆ findFile()

std::string TrigConf::JsonFileLoader::findFile ( const std::string &  filename) const
private

Definition at line 28 of file JsonFileLoader.cxx.

28  {
29 
30  // check for the file as specified
32  return filename;
33  }
34 
35  // check if absolute location has been specified
36  if (!filename.empty() && filename[0] == '/') {
37  TRG_MSG_WARNING("Can not find file with absolute location " << filename);
38  return {};
39  }
40 
41  return {};
42 }

◆ getFileType()

std::string TrigConf::JsonFileLoader::getFileType ( const std::string &  filename) const

Checks the trigger level of a given json file.

Parameters
filename[in] Name of the json file

Definition at line 114 of file JsonFileLoader.cxx.

115 {
116  std::string ft = "UNKNOWN";
117 
118  DataStructure data;
119  if ( loadFile ( filename, data ) ) {
120  ft = data.getAttribute("filetype", /*ignoreIfMissing*/ true, ft);
121  }
122 
123  return ft;
124 }

◆ loadFile() [1/2]

bool TrigConf::JsonFileLoader::loadFile ( const std::string &  filename,
boost::property_tree::ptree data,
const std::string &  pathToChild = "" 
) const

Load content of json file into a ptree.

Parameters
filename[in] Name of the json file
data[out]
pathToChild[in] Path to a sub structure for partial loading of data

If the optional parameter pathToChild is specified, one can load parts if the configuration from the file.

const std::string l1_filename = "TriggerMenuXML/LVL1config_Physics_pp_v7.json";
TrigConf::DataStructure metSignificance;
fileLoader.loadFile( l1_filename, metSignificance, "CaloInfo.METSignificance");

Definition at line 45 of file JsonFileLoader.cxx.

48 {
49 
50  std::string file = findFile(filename); // resolved file name
51  if ( file.empty() ) {
52  return false;
53  }
54  TRG_MSG_INFO("Reading information from " << file);
55 
56  // Load the json file
57  try {
58  boost::property_tree::read_json(file, data);
59  }
60  catch (const boost::property_tree::json_parser_error& e) {
61  TRG_MSG_WARNING("Could either not locate or parse the file " << file);
62  return false;
63  }
64 
65  if( ! pathToChild.empty() ) {
66  // the user has specified that s/he wants to access a certain part of the file
67  // the pathToChild is specified like this "a.b.c"
68  boost::optional<ptree&> subtree = data.get_child_optional(pathToChild);
69  if(subtree) {
70  data = *subtree;
71  } else {
72  TRG_MSG_WARNING("Did not find element '" << pathToChild << "' in the file " << file);
73  data.clear();
74  }
75  }
76 
77  return true;
78 }

◆ loadFile() [2/2]

bool TrigConf::JsonFileLoader::loadFile ( const std::string &  filename,
DataStructure data,
const std::string &  pathToChild = "" 
) const

Load content of json file into a ptree.

Parameters
filename[in] Name of the json file
data[out]
pathToChild[in] Path to a sub structure for partial loading of data

Definition at line 82 of file JsonFileLoader.cxx.

85 {
87 
88  if( ! loadFile( filename, pt, pathToChild) )
89  return false;
90 
91  data.setData(std::move(pt));
92 
93  return true;
94 }

◆ msg() [1/2]

MsgStreamTC & TrigConf::TrigConfMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 81 of file TrigConfMessaging.h.

82  {
83  MsgStreamTC* ms = m_msg_tls.get();
84  if (!ms) {
85  ms = new MsgStreamTC(m_name);
86  m_msg_tls.reset(ms);
87  }
88  return *ms;
89  }

◆ msg() [2/2]

MsgStreamTC & TrigConf::TrigConfMessaging::msg ( const MSGTC::Level  lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 91 of file TrigConfMessaging.h.

92  {
93  return msg() << lvl;
94  }

◆ msgLvl()

bool TrigConf::TrigConfMessaging::msgLvl ( const MSGTC::Level  lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 70 of file TrigConfMessaging.h.

71  {
72  if (msg().level() <= lvl) {
73  msg() << lvl;
74  return true;
75  }
76  else {
77  return false;
78  }
79  }

◆ outputLevel()

MSGTC::Level TrigConf::JsonFileLoader::outputLevel ( ) const
inline

Definition at line 88 of file JsonFileLoader.h.

88 { return msg().level(); }

◆ saveFile()

bool TrigConf::JsonFileLoader::saveFile ( const std::string &  filename,
const DataStructure data 
) const

Save content of DataStructure (underlying ptree) to a file.

Parameters
filename[in] Name of the json file
data[in]

Definition at line 99 of file JsonFileLoader.cxx.

101 {
102  if ( filename == "" ) {
103  TRG_MSG_ERROR("Could not save to file, as specified filename is empty");
104  return false;
105  }
106  boost::property_tree::write_json(filename, data.data());
107  TRG_MSG_INFO("Saved file " << filename);
108 
109  return true;
110 }

◆ setLevel()

void TrigConf::JsonFileLoader::setLevel ( MSGTC::Level  lvl)
inline

Definition at line 86 of file JsonFileLoader.h.

86 { msg().setLevel(lvl); }

Member Data Documentation

◆ m_msg_tls

boost::thread_specific_ptr<MsgStreamTC> TrigConf::TrigConfMessaging::m_msg_tls
mutableprivateinherited

MsgStreamTC instance (a std::cout like with print-out levels)

Definition at line 66 of file TrigConfMessaging.h.

◆ m_name

std::string TrigConf::TrigConfMessaging::m_name
privateinherited

Definition at line 67 of file TrigConfMessaging.h.


The documentation for this class was generated from the following files:
TRG_MSG_ERROR
#define TRG_MSG_ERROR(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:29
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
PlotCalibFromCool.ft
ft
Definition: PlotCalibFromCool.py:329
TrigConf::TrigConfMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStreamTC > m_msg_tls
MsgStreamTC instance (a std::cout like with print-out levels)
Definition: TrigConfMessaging.h:66
TrigConf::JsonFileLoader::findFile
std::string findFile(const std::string &filename) const
Definition: JsonFileLoader.cxx:28
TrigConf::JsonFileLoader::loadFile
bool loadFile(const std::string &filename, boost::property_tree::ptree &data, const std::string &pathToChild="") const
Load content of json file into a ptree.
Definition: JsonFileLoader.cxx:45
test_pyathena.pt
pt
Definition: test_pyathena.py:11
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
TrigConf::TrigConfMessaging::m_name
std::string m_name
Definition: TrigConfMessaging.h:67
TrigConf::TrigConfMessaging::msg
MsgStreamTC & msg() const
The standard message stream.
Definition: TrigConfMessaging.h:81
TrigConf::TrigConfMessaging::TrigConfMessaging
TrigConfMessaging()=delete
file
TFile * file
Definition: tile_monitor.h:29
TrigConf::MsgStreamTC::level
MSGTC::Level level()
Return message level of stream.
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:53
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
TRG_MSG_WARNING
#define TRG_MSG_WARNING(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:28
ptree
boost::property_tree::ptree ptree
Definition: JsonFileLoader.cxx:16
TrigConf::DataStructure
Base class for Trigger configuration data and wrapper around underlying representation.
Definition: DataStructure.h:37
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
TrigConf::JsonFileLoader
Loader of trigger configurations from Json files.
Definition: JsonFileLoader.h:25
TrigConf::MsgStreamTC::setLevel
void setLevel(MSGTC::Level lvl)
Set message level of stream.
Definition: Trigger/TrigConfiguration/TrigConfBase/Root/MsgStream.cxx:52
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9