ATLAS Offline Software
Run2toRun3ConvertersHLT.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <numeric>
6 #include "TrigConfData/HLTMenu.h"
9 #define BOOST_BIND_GLOBAL_PLACEHOLDERS // Needed to silence Boost pragma message
10 #include <boost/property_tree/json_parser.hpp>
19 
20 
21 template<typename COLL>
24  ptree array;
25  for ( const auto& el: data ) {
26  ptree one;
27  one.put("", el);
28  array.push_back(std::make_pair("", one));
29  }
30  return array;
31 }
32 
33 std::vector<int> legMult(const TrigConf::HLTChain* cptr) {
35 }
36 
37 std::vector<std::string> l1thresholds(const TrigConf::HLTFrame* frame, const TrigConf::HLTChain* cptr) {
38  std::set<std::string> names;
39  for ( const auto sig: cptr->signatures() ) {
40  for ( const auto te: sig->outputTEs() ) {
41  auto sequence = frame->getHLTSequenceList().getSequence(te->name());
42  for ( const auto inTE: sequence->inputTEs() ) {
43  if ( not ( inTE->name().find("L2_") == 0 or inTE->name().find("EF_") == 0 or inTE->name().find("HLT_") == 0 ) ) {
44  names.insert(inTE->name());
45  }
46  }
47  }
48  }
49  return std::vector<std::string>( names.begin(), names.end() );
50 }
51 
53  // this code is useful to debug JSON before it is pushed to menu objects expecting certain structure in place
54  std::stringstream ss;
55  boost::property_tree::json_parser::write_json(ss, p);
56  std::cout << ss.str() << std::endl;
57 }
58 
61  ptree top;
62  top.put("filetype", "hltmenu");
63  top.put("name", frame->name());
64  ptree pChains;
65 
66  std::map<std::string, const TrigConf::HLTStreamTag*> allStreams;
67 
68  for ( auto cptr : frame->getHLTChainList() ) {
69  ptree pChain;
70  pChain.put("counter", cptr->chain_counter());
71  pChain.put("nameHash", cptr->chain_hash_id());
72  pChain.put("l1item", cptr->lower_chain_name());
73  pChain.add_child("l1thresholds", asArray(l1thresholds(frame, cptr)));
74  pChain.add_child("legMultiplicities", asArray(legMult(cptr)) );
75  pChain.add_child("sequencers", asArray(std::vector<std::string>({"missing"})));
76 
77  std::vector<std::string> strNames;
78  for ( const auto st: cptr->streams()) {
79  strNames.push_back(st->stream());
80  allStreams[st->stream()] = st;
81  }
82  pChain.add_child("streams", asArray(strNames));
83 
84  pChain.add_child("groups", asArray(cptr->groups()));
85 
86  // Signature data
87  // Note: This is run-2 only.
88  // It is propagated here to allow legacy trigger feature access.
89  std::vector<uint32_t> counters;
90  std::vector<int> logics;
91  std::vector<std::string> labels;
92  ptree outputTEs_outerArray; // outputTEs is a std::vector<std::vector<std::string>>
93 
94  for(auto& signature : cptr->signatureList() ){
95  uint32_t cntr = signature->signature_counter();
96  counters.push_back(cntr);
97  logics.push_back(signature->logic());
98  labels.push_back(signature->label());
99  ptree outputTEs_innerArray;
100  for(auto& outputTE : signature->outputTEs()){
101  outputTEs_innerArray.push_back( ptree::value_type("", outputTE->name()) );
102  }
103  outputTEs_outerArray.push_back( ptree::value_type("", outputTEs_innerArray) );
104  }
105 
106  ptree pSig;
107  pSig.add_child("counters", asArray(counters));
108  pSig.add_child("logics", asArray(logics));
109  pSig.add_child("outputTEs", outputTEs_outerArray);
110  pSig.add_child("labels", asArray(labels));
111 
112  pChain.add_child("signature", pSig);
113  // End of signature data
114 
115  pChains.push_back(std::make_pair(cptr->chain_name(), pChain));
116  }
117  ptree pStreams;
118  for ( auto [sname, stream]: allStreams ) {
119  ptree pStream;
120  pStream.put("name", sname);
121  pStream.put("type", stream->type());
122  pStream.put("obeyLB", stream->obeyLB());
123  pStream.put("forceFullEventBuilding", true); // TODO understand how to get this information from old menu
124  pStreams.push_back(std::make_pair(sname, pStream));
125  }
126 
127  top.add_child("chains", pChains);
128 
129  top.add_child("streams", pStreams);
130  ptree pSequencers;
131  pSequencers.add_child("missing", asArray(std::vector<std::string>({""})));
132  top.add_child("sequencers", pSequencers);
133 
134  // Set run2 sequence information:
135  const TrigConf::HLTSequenceList& sequenceList = frame->getHLTSequenceList();
136  std::vector<std::string> outputTEs;
137  ptree inputTEs_outerArray; // sequenceInputTEs is a std::vector<std::vector<std::string>>
138  ptree algorithms_outerArray; // sequenceAlgorithms is a std::vector<std::vector<std::string>>
139  for(auto& seq : sequenceList){
140  outputTEs.push_back(seq->outputTE()->name());
141 
142  ptree inputTEs_innerArray;
143  for(auto& input : seq->inputTEs()) {
144  inputTEs_innerArray.push_back( ptree::value_type("", input->name()) );
145  }
146  inputTEs_outerArray.push_back( ptree::value_type("", inputTEs_innerArray) );
147 
148  ptree algorithms_innerArray;
149  for(const std::string& alg : seq->algorithms()) {
150  algorithms_innerArray.push_back( ptree::value_type("", alg) );
151  }
152  algorithms_outerArray.push_back( ptree::value_type("", algorithms_innerArray) );
153  }
154  ptree pSequence;
155  pSequence.add_child("outputTEs", asArray(outputTEs));
156  pSequence.add_child("inputTEs", inputTEs_outerArray);
157  pSequence.add_child("algorithms", algorithms_outerArray);
158  top.add_child("sequence_run2", pSequence);
159 
160  menu.setData(std::move(top));
161  menu.setSMK(frame->smk());
162  return true;
163 }
164 
165 void convertRun2HLTMenuToRun3(const TrigConf::HLTFrame* frame, const std::string& filename) {
167  convertHLTMenu(frame, menu);
168 
170  writer.writeJsonFile(filename, menu);
171 
172 }
173 
174 void convertRun2HLTPrescalesToRun3(const TrigConf::HLTFrame* frame, const std::string& filename) {
176  ptree top;
177  top.put("filetype", "hltprescale");
178  top.put("name", frame->name());
179  ptree pChains;
180  for ( auto cptr : frame->getHLTChainList() ) {
181  ptree pChain;
182  pChain.put("name", cptr->chain_name());
183  pChain.put("counter", cptr->chain_counter());
184  pChain.put("hash", cptr->chain_hash_id());
185  pChain.put("prescale", cptr->prescale());
186  pChain.put("enabled", (cptr->prescale()>0 ? true: false));
187 
188  pChains.push_back(std::make_pair(cptr->chain_name(), pChain));
189  }
190  top.add_child("prescales", pChains);
191  TrigConf::HLTPrescalesSet psk(std::move(top));
192 
194  convertHLTMenu(frame, menu);
195 
197  writer.writeJsonFile(filename, menu, psk);
198 }
199 
test_athena_ntuple_filter.seq
seq
filter configuration ## -> we use the special sequence 'AthMasterSeq' which is run before any other a...
Definition: test_athena_ntuple_filter.py:18
TrigConf::JsonFileWriterHLT
Loader of trigger configurations from Json files.
Definition: JsonFileWriterHLT.h:23
HLTPrescalesSet.h
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
TrigConf::TrigConfData::name
const std::string & name() const
Definition: TrigConfData.h:22
ChainNameParser.h
SGout2dot.alg
alg
Definition: SGout2dot.py:243
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
TrigConf::HLTMenu
HLT menu configuration.
Definition: HLTMenu.h:21
TrigConf::HLTChain::chain_name
const std::string & chain_name() const
Definition: TrigConfHLTData/TrigConfHLTData/HLTChain.h:72
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
convertRun2HLTPrescalesToRun3
void convertRun2HLTPrescalesToRun3(const TrigConf::HLTFrame *frame, const std::string &filename)
Definition: Run2toRun3ConvertersHLT.cxx:174
convertHLTMenu
bool convertHLTMenu(const TrigConf::HLTFrame *frame, TrigConf::HLTMenu &menu)
Definition: Run2toRun3ConvertersHLT.cxx:59
TrigConf::HLTSequenceList::getSequence
HLTSequence * getSequence(unsigned int id) const
counts the number of sequences in the menu
Definition: HLTSequenceList.cxx:45
HLTChain.h
python.TriggerConfig.menu
menu
Definition: TriggerConfig.py:842
Trk::one
@ one
Definition: TrkDetDescr/TrkSurfaces/TrkSurfaces/RealQuadraticEquation.h:22
printJSON
void printJSON(boost::property_tree::ptree &p)
Definition: Run2toRun3ConvertersHLT.cxx:52
TrigConf::HLTChain::signatures
const std::vector< HLTSignature * > & signatures() const
Definition: TrigConfHLTData/TrigConfHLTData/HLTChain.h:109
TrigConf::HLTChain
HLT chain configuration information.
Definition: TrigConfHLTData/TrigConfHLTData/HLTChain.h:35
TrigConf::HLTFrame::getHLTSequenceList
const HLTSequenceList & getHLTSequenceList() const
const accessor to the list of HLT sequences
Definition: HLTFrame.h:50
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
JsonFileWriterHLT.h
menu
make the sidebar many part of the config
Definition: hcg.cxx:551
beamspotnt.labels
list labels
Definition: bin/beamspotnt.py:1447
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
legMult
std::vector< int > legMult(const TrigConf::HLTChain *cptr)
Definition: Run2toRun3ConvertersHLT.cxx:33
HLTStreamTag.h
python.subdetectors.mmg.names
names
Definition: mmg.py:8
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
HLTSignature.h
python.BuildSignatureFlags.sig
sig
Definition: BuildSignatureFlags.py:218
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
asArray
boost::property_tree::ptree asArray(const COLL &data)
Definition: Run2toRun3ConvertersHLT.cxx:22
lumiFormat.array
array
Definition: lumiFormat.py:91
TrigConf::TrigConfData::smk
unsigned int smk() const
Definition: TrigConfData.h:20
ptree
boost::property_tree::ptree ptree
Definition: JsonFileLoader.cxx:16
ChainNameParser::multiplicities
std::vector< int > multiplicities(const std::string &chain)
Definition: ChainNameParser.cxx:202
HLTFrame.h
HLTTriggerElement.h
convertRun2HLTMenuToRun3
void convertRun2HLTMenuToRun3(const TrigConf::HLTFrame *frame, const std::string &filename)
Definition: Run2toRun3ConvertersHLT.cxx:165
TrigConf::HLTFrame
The HLT trigger menu,.
Definition: HLTFrame.h:33
TrigConf::HLTFrame::getHLTChainList
const HLTChainList & getHLTChainList() const
const accessor to the list of HLT chains
Definition: HLTFrame.h:49
HLTIdentifier.h
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
HLTMenu.h
top
@ top
Definition: TruthClasses.h:64
l1thresholds
std::vector< std::string > l1thresholds(const TrigConf::HLTFrame *frame, const TrigConf::HLTChain *cptr)
Definition: Run2toRun3ConvertersHLT.cxx:37
TrigConf::HLTPrescalesSet
HLT menu configuration.
Definition: HLTPrescalesSet.h:19
DataStructure.h
example.writer
writer
show summary of content
Definition: example.py:36
TrigConf::HLTSequenceList
list of HLT sequences
Definition: HLTSequenceList.h:40