ATLAS Offline Software
Loading...
Searching...
No Matches
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.
virtual ~JsonFileLoader () override=default
 Destructor.
bool loadFile (const std::string &filename, boost::property_tree::ptree &data, const std::string &pathToChild="") const
 Load content of json file into a ptree.
bool loadFile (const std::string &filename, DataStructure &data, const std::string &pathToChild="") const
 Load content of json file into a ptree.
bool saveFile (const std::string &filename, const DataStructure &data) const
 Save content of DataStructure (underlying ptree) to a file.
std::string getFileType (const std::string &filename) const
 Checks the trigger level of a given json file.
bool checkTriggerLevel (const std::string &filename, std::string &level) const
 Checks the trigger level of a given json file.
void setLevel (MSGTC::Level lvl)
MSGTC::Level outputLevel () const
bool msgLvl (const MSGTC::Level lvl) const
 Test the output level.
MsgStreamTCmsg () const
 The standard message stream.
MsgStreamTCmsg (const MSGTC::Level lvl) const
 The standard message stream.
const std::string & getName () const
 name accessor

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)
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}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
bool loadFile(const std::string &filename, boost::property_tree::ptree &data, const std::string &pathToChild="") const
Load content of json file into a ptree.

◆ 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
31 if( std::filesystem::exists( filename ) ) {
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}

◆ getName()

const std::string & TrigConf::TrigConfMessaging::getName ( ) const
inlineinherited

name accessor

Returns
the name

Definition at line 101 of file TrigConfMessaging.h.

101 {
102 return m_name;
103 }

◆ 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");
Base class for Trigger configuration data and wrapper around underlying representation.
Loader of trigger configurations from Json files.

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}
std::string findFile(const std::string &filename) const
TFile * file

◆ 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{
86 boost::property_tree::ptree pt;
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 86 of file TrigConfMessaging.h.

87 {
88 MsgStreamTC* ms = m_msg_tls.get();
89 if (!ms) {
90 ms = new MsgStreamTC(m_name);
91 m_msg_tls.reset(ms);
92 }
93 return *ms;
94 }
boost::thread_specific_ptr< MsgStreamTC > m_msg_tls
MsgStreamTC instance (a std::cout like with print-out levels)

◆ 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 96 of file TrigConfMessaging.h.

97 {
98 return msg() << lvl;
99 }
MsgStreamTC & msg() const
The standard message stream.

◆ 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 75 of file TrigConfMessaging.h.

76 {
77 if (msg().level() <= lvl) {
78 msg() << lvl;
79 return true;
80 }
81 else {
82 return false;
83 }
84 }

◆ 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); }
void setLevel(MSGTC::Level lvl)
Set message level of stream.

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 71 of file TrigConfMessaging.h.

◆ m_name

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

Definition at line 72 of file TrigConfMessaging.h.


The documentation for this class was generated from the following files: