ATLAS Offline Software
|
helper class to cache systematics varied calibration constants inside a ISystematicsTool or IRentrantSystematicsTool More...
#include <SystematicsCache.h>
Public Member Functions | |
template<typename T2 > | |
SystematicsCache (T2 *val_parent) | |
void | initialize (CP::SystematicSet val_affectingSystematics, std::function< StatusCode(const CP::SystematicSet &sys, CalibData &result)> val_calc) noexcept |
initialize with the list of affecting systematics and a function to calculate the calibration data for each systematic More... | |
const CP::SystematicSet & | affectingSystematics () const noexcept |
the list of affecting systematics More... | |
bool | isAffectedBySystematic (const SystematicVariation &systematic) const |
whether we are affected by the given systematic variation More... | |
StatusCode | get (const CP::SystematicSet &sys, const CalibData *&result) const |
get the pointer to the cached calibration data for the given systematic, calculating it if necessary More... | |
StatusCode | add (const CP::SystematicSet &sys, CalibData value) |
add an individual systematic variation More... | |
StatusCode | add (const SystematicVariation &variation, CalibData value) |
bool | msgLvl (const MSG::Level lvl) const |
Test the output level of the object. More... | |
MsgStream & | msg () const |
The standard message stream. More... | |
MsgStream & | msg (const MSG::Level lvl) const |
The standard message stream. More... | |
Private Attributes | |
CP::SystematicSet | m_affectingSystematics |
the list of affecting systematics More... | |
std::function< StatusCode(const CP::SystematicSet &sys, CalibData &result)> | m_calc |
the function to calculate the calibration data for a given systematics More... | |
tbb::concurrent_unordered_map< CP::SystematicSet, std::shared_ptr< const CalibData >, SystematicSetHash > m_cache | ATLAS_THREAD_SAFE |
the cache of previously calculated calibration data More... | |
std::mutex | m_calcMutex |
a mutex to protext against concurrent execution of m_calc More... | |
std::function< MsgStream &()> | m_msg |
the message stream we use More... | |
helper class to cache systematics varied calibration constants inside a ISystematicsTool or IRentrantSystematicsTool
The general pattern for how systematics are supposed to be implemented inside systematics tools is that the first time a specific systematic variation is requested the tool should calculate the calibration constants for that particular systematic, store it in an (unordered) map and look it up from that map in all subsequent uses. This class tries to implement that particular logic in a thread-safe and (reasonably) fool-proof way.
The basic way to use this class is:
There are not too many constraints on the structure and lambda function, just make sure the structure is default constructable and the lambda function is safe to execute while a lock is held (i.e. if you acquire a lock make sure not to create a dead-lock). It is currently not anticipated that this lambda function needs to be thread-safe itself (even if multiple threads use the same tool, they would still just run through the same systematics in the same order). It is guaranteed that the function is called exactly once for each unique set of affecting systematics, and that only a single copy of the calibration data is stored for each unique set of affecting systematics.
Note that while the above example uses a lambda function it is probably a good idea to write this as a separate helper function and have the lambda function wrap that helper. The rationale for that recommendation is that this is usually a rather long function with tedious logic and making it part of initialize can affect the readability of either one.
Definition at line 84 of file SystematicsCache.h.
CP::SystematicsCache< CalibData >::SystematicsCache | ( | T2 * | val_parent | ) |
StatusCode CP::SystematicsCache< CalibData >::add | ( | const CP::SystematicSet & | sys, |
CalibData | value | ||
) |
StatusCode CP::SystematicsCache< CalibData >::add | ( | const SystematicVariation & | variation, |
CalibData | value | ||
) |
|
noexcept |
the list of affecting systematics
Definition at line 169 of file SystematicsCache.h.
StatusCode CP::SystematicsCache< CalibData >::get | ( | const CP::SystematicSet & | sys, |
const CalibData *& | result | ||
) | const |
get the pointer to the cached calibration data for the given systematic, calculating it if necessary
Definition at line 188 of file SystematicsCache.h.
|
noexcept |
initialize with the list of affecting systematics and a function to calculate the calibration data for each systematic
Definition at line 157 of file SystematicsCache.h.
bool CP::SystematicsCache< CalibData >::isAffectedBySystematic | ( | const SystematicVariation & | systematic | ) | const |
whether we are affected by the given systematic variation
this is mostly for implementing the ISystematicsTool interface and should probably not be used by anyone.
Definition at line 178 of file SystematicsCache.h.
|
inherited |
The standard message stream.
Definition at line 24 of file AsgMessagingForward.cxx.
|
inherited |
|
inherited |
Test the output level of the object.
lvl | The message level to test against |
true
If messages at level "lvl" will be printed Definition at line 11 of file AsgMessagingForward.cxx.
|
mutableprivate |
the cache of previously calculated calibration data
Definition at line 135 of file SystematicsCache.h.
|
private |
the list of affecting systematics
Definition at line 128 of file SystematicsCache.h.
|
private |
the function to calculate the calibration data for a given systematics
Definition at line 132 of file SystematicsCache.h.
|
mutableprivate |
a mutex to protext against concurrent execution of m_calc
see the comment inside get for a detailed explanation of why this is used/needed.
Definition at line 141 of file SystematicsCache.h.
|
privateinherited |
the message stream we use
This used to be a simple pointer to the MsgStream
itself, but in AthenaMT the actual object used is local to the thread. So instead of pointing to it directly we are now using a function to look it up, which will get the thread-local object.
Definition at line 77 of file AsgMessagingForward.h.