ATLAS Offline Software
JsonFileWriterHLT.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <iomanip>
8 #include <fstream>
9 #include <algorithm>
10 
11 #include <nlohmann/json.hpp>
13 
14 using namespace std;
15 
17  TrigConfMessaging( "JsonFileWriterHLT")
18 {}
19 
20 
22 template<typename T>
23 std::vector<T> ToVector(const TrigConf::DataStructure& ds, const std::string& child){
25  std::vector<T> return_vector;
26  for( const ptree::value_type& entry : ds.data().get_child(child) ) {
27  return_vector.push_back( entry.second.get_value<T>() );
28  }
29  return return_vector;
30 }
31 
33 template<typename T>
34 std::vector<std::vector<T>> ToVectorVector(const TrigConf::DataStructure& ds, const std::string& child){
36  std::vector<std::vector<T>> return_vector;
37  for( const ptree::value_type& outer : ds.data().get_child(child) ) {
38  return_vector.push_back(std::vector<T>());
39  for (const ptree::value_type& inner : outer.second) {
40  return_vector.back().push_back( inner.second.get_value<T>() );
41  }
42  }
43  return return_vector;
44 }
45 
46 
47 bool
49 {
50  json chains({});
51  for ( const auto & chain : menu ) {
52  json jChain({});
53  jChain["counter"] = chain.counter();
54  jChain["nameHash"] = chain.namehash();
55  jChain["l1item"] = chain.l1item();
56  jChain["legMultiplicities"] = chain.legMultiplicities();
57  jChain["l1thresholds"] = chain.l1thresholds();
58  jChain["groups"] = chain.groups();
59  jChain["streams"] = chain.streams();
60  jChain["seqeuncers"] = chain.sequencers();
61 
62  // Optional Run2 payload
63  if (chain.hasChild("signature")) {
64  json jSig({});
65  jSig["counters"] = ToVector<uint32_t>(chain, "signature.counters");
66  jSig["logics"] = ToVector<int>(chain, "signature.logics");
67  jSig["labels"] = ToVector<std::string>(chain, "signature.labels");
68  jSig["outputTEs"] = ToVectorVector<std::string>(chain, "signature.outputTEs");
69  jChain["signature"] = jSig;
70  }
71 
72  chains[chain.name()] = jChain;
73  }
74 
75  json sequencers({});
76  for ( const auto& [seqName, algsList]: menu.sequencers() ) {
77  json jSeq( algsList );
78  sequencers[seqName] = jSeq;
79  }
80  json streams({});
81  for ( const auto& stream: menu.streams() ) {
82  json jStream({});
83  jStream["name"] = stream["name"];
84  jStream["type"] = stream["type"];
85  jStream["obeyLB"] = stream.getAttribute<bool>("obeyLB");
86  jStream["forceFullEventBuilding"] = stream.getAttribute<bool>("forceFullEventBuilding");
87  streams[stream["name"]] = jStream;
88  }
89 
90 
91  json j({});
92  j["filetype"] = "hltmenu";
93  j["name"] = menu.name();
94  j["chains"] = chains;
95  j["sequencers"] = sequencers;
96  j["streams"] = streams;
97 
98  // Optional Run2 payload
99  if (menu.hasChild("sequence_run2")) {
100  json jSequence({});
101  jSequence["outputTEs"] = ToVector<std::string>(menu, "sequence_run2.outputTEs");
102  jSequence["inputTEs"] = ToVectorVector<std::string>(menu, "sequence_run2.inputTEs");
103  jSequence["algorithms"] = ToVectorVector<std::string>(menu, "sequence_run2.algorithms");
104  j["sequence_run2"] = jSequence;
105  }
106 
107  std::ofstream outfile(filename);
108  outfile << std::setw(4) << j << std::endl;
109 
110  TRG_MSG_INFO("Saved file " << filename);
111  return true;
112 }
113 bool
114 TrigConf::JsonFileWriterHLT::writeJsonFile(const std::string & filename, const HLTMenu & menu, const HLTPrescalesSet & ps) const
115 {
116  json chains({});
117  for ( const auto & chain : menu ) {
118  json jChain({});
119  jChain["name"] = chain.name();
120  jChain["counter"] = chain.counter();
121  jChain["hash"] = chain.namehash();
122  jChain["prescale"] = ps.prescale(chain.name()).prescale;
123  jChain["enabled"] = ps.prescale(chain.name()).enabled;
124  chains[chain.name()] = jChain;
125  }
126  json j({});
127  j["filetype"] = "hltprescale";
128  j["name"] = ps.name();
129  j["prescales"] = chains;
130  std::ofstream outfile(filename);
131  outfile << std::setw(4) << j << std::endl;
132 
133  TRG_MSG_INFO("Saved file " << filename);
134  return true;
135 }
checkxAOD.ds
ds
Definition: Tools/PyUtils/bin/checkxAOD.py:258
TrigConf::JsonFileWriterHLT::JsonFileWriterHLT
JsonFileWriterHLT()
Constructor.
Definition: JsonFileWriterHLT.cxx:16
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
TrigConf::HLTMenu
HLT menu configuration.
Definition: HLTMenu.h:21
json
nlohmann::json json
Definition: HistogramDef.cxx:9
python.outputTest_v2.streams
streams
Definition: outputTest_v2.py:55
json
nlohmann::json json
Definition: JsonFileWriterHLT.cxx:12
TrigConf::DataStructure::name
virtual const std::string & name() const final
Definition: DataStructure.cxx:109
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
JsonFileWriterHLT.h
menu
make the sidebar many part of the config
Definition: hcg.cxx:551
TrigConf::HLTPrescalesSet::prescale
const HLTPrescale & prescale(const std::string &chainName) const
HLT prescales by chain names.
Definition: HLTPrescalesSet.cxx:85
TrigConf::JsonFileWriterHLT::writeJsonFile
bool writeJsonFile(const std::string &filename, const HLTMenu &menu) const
Definition: JsonFileWriterHLT.cxx:48
TrigConf::ToVectorVector
std::vector< std::vector< T > > ToVectorVector(const TrigConf::DataStructure &ds, const std::string &child)
Helper function ptree key->[[]] to std::vector<std::vector<T>>
Definition: prepareTriggerMenu.cxx:276
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
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
TrigConf::TrigConfMessaging
Class to provide easy access to TrigConf::MsgStream for TrigConf classes.
Definition: TrigConfMessaging.h:28
python.copyTCTOutput.chains
chains
Definition: copyTCTOutput.py:81
TrigConf::ToVector
std::vector< T > ToVector(const TrigConf::DataStructure &ds, const std::string &child)
Helper function ptree key->[] to std::vector<T>
Definition: prepareTriggerMenu.cxx:265
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
TrigConf::HLTPrescale::prescale
float prescale() const
Definition: HLTPrescale.h:52
TrigConf::HLTPrescalesSet
HLT menu configuration.
Definition: HLTPrescalesSet.h:19
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42