ATLAS Offline Software
Loading...
Searching...
No Matches
TrigGlobEffCorr::CheckConfig Class Reference

#include <CheckConfig.h>

Inheritance diagram for TrigGlobEffCorr::CheckConfig:
Collaboration diagram for TrigGlobEffCorr::CheckConfig:

Public Member Functions

 CheckConfig (TrigGlobalEfficiencyCorrectionTool &parent)
bool basicConfigChecks ()
bool advancedConfigChecks ()
void setLevel (MSG::Level lvl)
 Change the current logging level.
Functions providing the same interface as AthMessaging
bool msgLvl (const MSG::Level lvl) const
 Test the output level of the object.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc.

Static Private Member Functions

template<class CPTool>
static ToolHandle< CPTool > * findToolByName (ToolHandleArray< CPTool > &suppliedTools, const std::string &name)

Private Attributes

TrigGlobalEfficiencyCorrectionToolm_parent
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels).
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging).

Detailed Description

Definition at line 18 of file CheckConfig.h.

Constructor & Destructor Documentation

◆ CheckConfig()

CheckConfig::CheckConfig ( TrigGlobalEfficiencyCorrectionTool & parent)

Definition at line 20 of file CheckConfig.cxx.

21 : asg::AsgMessaging(&parent), m_parent(parent) {
22 msg().setLevel(parent.msg().level());
23}
TrigGlobalEfficiencyCorrectionTool & m_parent
Definition CheckConfig.h:26
MsgStream & msg() const
The standard message stream.
AsgMessaging(const std::string &name)
Constructor with a name.

Member Function Documentation

◆ advancedConfigChecks()

bool CheckConfig::advancedConfigChecks ( )

This method requires all (most) of TrigGlobalEfficiencyCorrectionTool internal variables to have been properly initialized already -> to be called as the last step of TrigGlobalEfficiencyCorrectionTool::initialize()

Check that for each electron/photon efficiency tool there is an associated scale factor tool with the same associated legs and tags. And vice versa.

A suitable CP tool must be available for each entry of 'ListOfLegsPerTag'

Periods don't overlap

Definition at line 243 of file CheckConfig.cxx.

243 {
248 bool success = true;
249
250 using ToolKey = TrigGlobalEfficiencyCorrectionTool::ToolKey;
251
254 auto checkConsistency = [this](auto& effToolIndex, auto& sfToolIndex,
255 const char* type) {
256 bool mismatch = (effToolIndex.size() != sfToolIndex.size());
257 if (!mismatch) {
258 for (auto& kv : sfToolIndex) {
259 auto itr = effToolIndex.find(kv.first);
260 if (itr != effToolIndex.end()) {
261 std::size_t index1 = kv.second, index2 = itr->second;
262 flat_set<ToolKey> pairs1, pairs2;
263 for (auto& kv : sfToolIndex)
264 if (kv.second == index1)
265 pairs1.insert(kv.first);
266 for (auto& kv : effToolIndex)
267 if (kv.second == index2)
268 pairs2.insert(kv.first);
269 if (pairs1 != pairs2)
270 mismatch = true;
271 } else
272 mismatch = true;
273 }
274 }
275 if (mismatch) {
277 "There must be a one-to-one correspondence between the "
278 << type
279 << " efficiency and scale factor tools "
280 "(including their associated trigger legs and selection tags)");
281 return false;
282 }
283 return true;
284 };
285 if (!checkConsistency(m_parent.m_electronEffToolIndex,
286 m_parent.m_electronSfToolIndex, "electron"))
287 return false;
288 if (!checkConsistency(m_parent.m_photonEffToolIndex,
289 m_parent.m_photonSfToolIndex, "photon"))
290 return false;
291
293 for (auto& kv : m_parent.m_legsPerTag) {
294 std::size_t tag = (kv.first != "*") ? m_parent.m_hasher(kv.first) : 0;
295 for (std::size_t leg :
296 m_parent.listNonOrderedCSValues(kv.second, success)) {
298 m_parent.m_dictionary[leg], success);
299 if (type == xAOD::Type::Electron) {
300 if (m_parent.m_electronEffToolIndex.find(ToolKey(leg, tag)) ==
301 m_parent.m_electronEffToolIndex.end()) {
303 "No electron tool provided for the combination of trigger leg '"
304 << m_parent.m_dictionary[leg] << "' and selection tag '"
305 << kv.first << "' mentioned in the property 'ListOfLegsPerTag'");
306 success = false;
307 }
308 } else if (type == xAOD::Type::Muon) {
309 if (m_parent.m_muonToolIndex.find(ToolKey(0, tag)) ==
310 m_parent.m_muonToolIndex.end()) {
312 "No muon tool provided for the combination of trigger leg '"
313 << m_parent.m_dictionary[leg] << "' and selection tag '"
314 << kv.first << "' mentioned in the property 'ListOfLegsPerTag'");
315 success = false;
316 }
317 } else if (type == xAOD::Type::Photon) {
318 if (m_parent.m_photonEffToolIndex.find(ToolKey(leg, tag)) ==
319 m_parent.m_photonEffToolIndex.end()) {
321 "No photon tool provided for the combination of trigger leg '"
322 << m_parent.m_dictionary[leg] << "' and selection tag '"
323 << kv.first << "' mentioned in the property 'ListOfLegsPerTag'");
324 success = false;
325 }
326 } else {
328 "Unable to determine which lepton flavour is associated to the "
329 "trigger leg '"
330 << m_parent.m_dictionary[leg]
331 << "' in the property 'ListOfLegsPerTag'");
332 success = false;
333 }
334 }
335 }
336 if (!success)
337 return false;
338
340 auto periods = m_parent.m_calculator->m_periods;
341 const auto periods_end = periods.end();
342 for (auto itr1 = periods.begin(); itr1 != periods_end; ++itr1) {
343 auto& x = itr1->m_boundaries;
344 if (x.second < x.first) {
346 "One of the periods specified in TriggerCombination has runMin ("
347 << x.first << ") > runMax (" << x.second << ")");
348 success = false;
349 }
350 for (auto itr2 = itr1 + 1; itr2 != periods_end; ++itr2) {
351 auto& y = itr2->m_boundaries;
352 if ((x.first >= y.first && x.first <= y.second) ||
353 (x.second >= y.first && x.second <= y.second)) {
354 ATH_MSG_ERROR("The periods specified in TriggerCombination overlap");
355 success = false;
356 }
357 }
358 }
359 if (!success)
360 return false;
361
362 return success;
363}
#define ATH_MSG_ERROR(x)
CxxUtils::flat_set< Key > flat_set
#define y
#define x
xAOD::Type::ObjectType associatedLeptonFlavour(std::size_t leg, bool &success)
@ Photon
The object is a photon.
Definition ObjectType.h:47
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ Electron
The object is an electron.
Definition ObjectType.h:46

◆ basicConfigChecks()

bool CheckConfig::basicConfigChecks ( )

All tools mentioned in 'ListOfLegsPerTool' must be in 'ElectronEfficiencyTools' or 'ElectronScaleFactorTools' (or equivalent photon tools)

All electron/photon tools must be associated to trigger legs (except when there's only one tool)

Additional checks when tags are used

All tools mentioned in 'ListOfTagsPerTool' must be known

Either all muon tools are associated to tags, either none

Either all electron tools are associated to tags, either none

Either all photon tools are associated to tags, either none

Definition at line 38 of file CheckConfig.cxx.

38 {
39 bool success = true;
40
41 if (m_parent.m_suppliedElectronEfficiencyTools.size() !=
42 m_parent.m_suppliedElectronScaleFactorTools.size()) {
44 "The numbers of electron tools supplied via the "
45 "'ElectronEfficiencyTools' and 'ElectronScaleFactorTools' properties "
46 "should be identical");
47 return false;
48 }
49
50 if (m_parent.m_suppliedPhotonEfficiencyTools.size() !=
51 m_parent.m_suppliedPhotonScaleFactorTools.size()) {
53 "The numbers of photon tools supplied via the 'PhotonEfficiencyTools' "
54 "and 'PhotonScaleFactorTools' properties should be identical");
55 return false;
56 }
57
61 for (auto& kv : m_parent.m_legsPerTool) {
62 auto& name = kv.first;
63 if (name ==
65 continue;
66 if (findToolByName(m_parent.m_suppliedElectronEfficiencyTools, name) ||
67 findToolByName(m_parent.m_suppliedElectronScaleFactorTools, name) ||
68 findToolByName(m_parent.m_suppliedPhotonEfficiencyTools, name) ||
69 findToolByName(m_parent.m_suppliedPhotonScaleFactorTools, name))
70 continue;
71 success = false;
72 if (findToolByName(m_parent.m_suppliedMuonTools, name)) {
73 ATH_MSG_ERROR("Muon tool "
74 << name
75 << " mentioned in property 'ListOfLegsPerTool', which is "
76 "only aimed at electron and photon tools");
77 } else {
78 std::string known_tools = "; the known tools are";
79 for (auto& tool : m_parent.m_suppliedElectronEfficiencyTools)
80 known_tools += " " + tool.name();
81 for (auto& tool : m_parent.m_suppliedElectronScaleFactorTools)
82 known_tools += " " + tool.name();
83 for (auto& tool : m_parent.m_suppliedPhotonEfficiencyTools)
84 known_tools += " " + tool.name();
85 for (auto& tool : m_parent.m_suppliedPhotonScaleFactorTools)
86 known_tools += " " + tool.name();
87 ATH_MSG_ERROR("Unknown tool "
88 << name << " mentioned in property 'ListOfLegsPerTool'"
89 << known_tools);
90 }
91 }
92 if (!success)
93 return false;
94
97 auto toolsHaveLegInfo = [this](auto& effTools, auto& sfTools,
98 const char* type) {
99 if (effTools.size() < 2)
100 return true;
101 bool success = true;
102 for (int i = 0; i < 2; ++i) {
103 for (auto& tool : (i ? effTools : sfTools)) {
104 const std::string& name = tool.name();
105 if (m_parent.m_legsPerTool.find(name) == m_parent.m_legsPerTool.end()) {
106 ATH_MSG_ERROR(type
107 << " tool " << name
108 << " associated trigger legs are not indicated in "
109 "'ListOfLegsPerTool', "
110 "doing so is mandatory when several tools are used");
111 success = false;
112 }
113 }
114 }
115 return success;
116 };
117 success &=
118 toolsHaveLegInfo(m_parent.m_suppliedElectronEfficiencyTools,
119 m_parent.m_suppliedElectronScaleFactorTools, "Electron");
120 success &=
121 toolsHaveLegInfo(m_parent.m_suppliedPhotonEfficiencyTools,
122 m_parent.m_suppliedPhotonScaleFactorTools, "Photon");
123 if (!success)
124 return false;
125
129
130 if (m_parent.m_leptonTagDecorations == "") {
131 if (m_parent.m_muonLegsPerTag.size() ||
132 m_parent.m_electronLegsPerTag.size() || m_parent.m_legsPerTag.size() ||
133 m_parent.m_tagsPerTool.size()) {
135 "the property 'LeptonTagDecorations' must be filled when any of "
136 "'ListOfTagsPerTool'"
137 " / 'ListOfLegsPerTag' / 'MuonLegsPerTag' / 'ElectronLegsPerTag' "
138 "is.");
139 return false;
140 }
141 return true;
142 }
143
145 unsigned nElectronToolsWithTags = 0, nMuonToolsWithTags = 0,
146 nPhotonToolsWithTags = 0;
147 for (auto& kv : m_parent.m_tagsPerTool) {
148 auto& name = kv.first;
149 if (findToolByName(m_parent.m_suppliedElectronEfficiencyTools, name) ||
150 findToolByName(m_parent.m_suppliedElectronScaleFactorTools, name))
151 ++nElectronToolsWithTags;
152 else if (findToolByName(m_parent.m_suppliedMuonTools, name))
153 ++nMuonToolsWithTags;
154 else if (findToolByName(m_parent.m_suppliedPhotonEfficiencyTools, name) ||
155 findToolByName(m_parent.m_suppliedPhotonScaleFactorTools, name))
156 ++nPhotonToolsWithTags;
157 else {
158 success = false;
159 std::string all_tools = "; the known tools are";
160 for (auto& tool : m_parent.m_suppliedElectronEfficiencyTools)
161 all_tools += " " + tool.name();
162 for (auto& tool : m_parent.m_suppliedElectronScaleFactorTools)
163 all_tools += " " + tool.name();
164 for (auto& tool : m_parent.m_suppliedPhotonEfficiencyTools)
165 all_tools += " " + tool.name();
166 for (auto& tool : m_parent.m_suppliedPhotonScaleFactorTools)
167 all_tools += " " + tool.name();
168 ATH_MSG_ERROR("Unknown tool "
169 << name << " mentioned in property 'ListOfTagsPerTool'");
170 }
171 }
173 if (nMuonToolsWithTags &&
174 (nMuonToolsWithTags != m_parent.m_suppliedMuonTools.size())) {
176 "Not all muon tools have been associated with tags in the "
177 "'ListOfTagsPerTool' property");
178 success = false;
179 }
181 unsigned nSupplied = m_parent.m_suppliedElectronEfficiencyTools.size() +
182 m_parent.m_suppliedElectronScaleFactorTools.size();
183 if (nElectronToolsWithTags && (nElectronToolsWithTags != nSupplied)) {
185 "Not all electron tools have been associated with tags in the "
186 "'ListOfTagsPerTool' property");
187 success = false;
188 }
189 if (!success)
190 return false;
192 nSupplied = m_parent.m_suppliedPhotonEfficiencyTools.size() +
193 m_parent.m_suppliedPhotonScaleFactorTools.size();
194 if (nPhotonToolsWithTags && (nPhotonToolsWithTags != nSupplied)) {
196 "Not all photon tools have been associated with tags in the "
197 "'ListOfTagsPerTool' property");
198 success = false;
199 }
200 if (!success)
201 return false;
202
203 /*
204 * More checks that are done in other places (or still need to be
205 * implemented!):
206 *
207 * - [advancedConfigChecks()] for each entry in ListOfLegsPerTag there must be
208 * a suitable tool for that tag and leg(s)
209 * - [enumerateTools()] no two electron/photon tools share the same {leg,tag}
210 * combination
211 * - [enumerateTools()] no two muon tools share the same tag
212 * - [advancedConfigChecks()] electron efficiency and scale factors have
213 * identical configurations: for each eff. tool leg/tag we must find a SF
214 * tool, and the other leg/tag pairs associated to those tools must be
215 * identical.
216 * - [UNCHECKED] if tags are used with electron (resp. muon, photon) tools,
217 * then all electron (muon, photon) tools must have an entry in
218 * ListOfTagsPerTool. Done partially in this function, but the case where no
219 * tools are tagged (yet tags are used, according to ListOfLegsPerTag or
220 * LeptonTagDecorations) escapes detection.
221 * - [loadTagsConfiguration()] each entry of ListOfLegsPerTag can be matched
222 * to a suitable tool
223 * - [UNCHECKED] suffixed tag read from a lepton must correspond to a know tag
224 * - [enumerateTools()] list of legs associated to each tool contains only
225 * known legs
226 * - [UNCHECKED TrigGlobEffCorrImportData import* functions] various
227 * consistency checks of the configuration files
228 * - [advancedConfigChecks()] user-specified periods are orthogonal
229 * - [ImportData::parseTriggerString()] no duplicated triggers in the
230 * combination
231 * - [UNCHECKED] for each configured electron/photon tool there is at least
232 * one associated tag^leg pair in 'ListOfLegsPerTag' (unless no
233 * electron/photon tags used)
234 * - [UNCHECKED] for each configured muon tool there is at least one
235 * associated tag in 'MuonLegsPerTag' (unless empty)
236 * - [enumerateTools()] electron tools can't be associated to photon legs; and
237 * reciprocally
238 */
239
240 return success;
241}
static std::string toolnameForDefaultScaleFactor()
To be used with the ListOfLegsPerTool property:
static ToolHandle< CPTool > * findToolByName(ToolHandleArray< CPTool > &suppliedTools, const std::string &name)

◆ findToolByName()

template<class CPTool>
ToolHandle< CPTool > * CheckConfig::findToolByName ( ToolHandleArray< CPTool > & suppliedTools,
const std::string & name )
staticprivate

Definition at line 26 of file CheckConfig.cxx.

27 {
28 for (auto& tool : suppliedTools) {
29 if (tool.name() == name ||
30 tool->name() == name) // athena: not always the same
31 {
32 return &tool;
33 }
34 }
35 return nullptr;
36}

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ msg() [1/2]

MsgStream & asg::AsgMessaging::msg ( ) const
inherited

The standard message stream.

Returns
A reference to the default message stream of this object.

Definition at line 49 of file AsgMessaging.cxx.

49 {
50#ifndef XAOD_STANDALONE
51 return ::AthMessaging::msg();
52#else // not XAOD_STANDALONE
53 return m_msg;
54#endif // not XAOD_STANDALONE
55 }

◆ msg() [2/2]

MsgStream & asg::AsgMessaging::msg ( const MSG::Level lvl) const
inherited

The standard message stream.

Parameters
lvlThe message level to set the stream to
Returns
A reference to the default message stream, set to level "lvl"

Definition at line 57 of file AsgMessaging.cxx.

57 {
58#ifndef XAOD_STANDALONE
59 return ::AthMessaging::msg( lvl );
60#else // not XAOD_STANDALONE
61 m_msg << lvl;
62 return m_msg;
63#endif // not XAOD_STANDALONE
64 }

◆ msgLvl()

bool asg::AsgMessaging::msgLvl ( const MSG::Level lvl) const
inherited

Test the output level of the object.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
true If messages at level "lvl" will be printed

Definition at line 41 of file AsgMessaging.cxx.

41 {
42#ifndef XAOD_STANDALONE
43 return ::AthMessaging::msgLvl( lvl );
44#else // not XAOD_STANDALONE
45 return m_msg.msgLevel( lvl );
46#endif // not XAOD_STANDALONE
47 }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging).

Definition at line 141 of file AthMessaging.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

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

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_parent

TrigGlobalEfficiencyCorrectionTool& TrigGlobEffCorr::CheckConfig::m_parent
private

Definition at line 26 of file CheckConfig.h.


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