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