Manages handle trackers for an easy call of removeCachedProduct()
.
More...
#include <ArtHandleTrackerManager.h>
Classes | |
struct | Config_t |
Configuration record. More... | |
Public Types | |
using | Event_t = Event |
Type of data viewer object to operate with. More... | |
Public Member Functions | |
ArtHandleTrackerManager (Config_t config={}) | |
Constructs a handle manager. More... | |
ArtHandleTrackerManager (Event_t const &event, Config_t config={}) | |
Constructs a handle manager covering event . More... | |
template<typename Handle > | |
auto | registerHandle (Handle &&handle) -> decltype(auto) |
Queries | |
unsigned int | nTrackedHandles () const |
Returns the number of handles currently tracked. More... | |
bool | hasEvent () const |
Returns whether the object is associated to an event. More... | |
Registration of data products | |
template<typename T , typename... Args> | |
art::Handle< T > | getHandle (Args &&...args) |
Retrieves an handle from the event, and registers it. More... | |
template<typename T , typename... Args> | |
art::ValidHandle< T > | getValidHandle (Args &&...args) |
Retrieves a valid handle from the event, and registers it. More... | |
template<typename Handle > | |
decltype(auto) | registerHandle (Handle &&handle) |
Registers an existing handle. More... | |
Operations | |
void | useEvent (Event_t const &event) |
Changes the event being served. More... | |
unsigned int | removeCachedProducts () |
Clears the cached data products for all tracked handles. More... | |
void | forgetAllHandles () |
Stops tracking any handle, without removing their cache first. More... | |
unsigned int | doneWithEvent (bool removeCache=true, art::Event const *event=nullptr) |
Completes the work on the associated event . More... | |
Private Types | |
using | TrackerPtr = std::unique_ptr< util::ArtHandleTrackerInterface< Event_t >> |
Type of pointer to any handle tracker. More... | |
Private Member Functions | |
template<typename Handle > | |
Handle const * | findHandle (Handle const &like) const |
Returns the pointer to an handle equivalent to like . More... | |
void | canOperate (const char *where) const |
Static Private Member Functions | |
template<typename Handle > | |
static bool | handleSameProduct (TrackerPtr tracker, Handle const &handle) |
Returns whether tracker tracks the same product that handle handles. More... | |
Private Attributes | |
Event_t const * | fEvent = nullptr |
Event being manager. Must be present! More... | |
Config_t const | fConfig |
Configuration. More... | |
std::vector< TrackerPtr > | fTrackers |
List of managed handle trackers. More... | |
Manages handle trackers for an easy call of removeCachedProduct()
.
Event | the type of data product source (the "principal") to serve |
This handle manager is designed to simplify the usage of art::Event::removeCachedProduct()
on multiple data products.
The envisioned usage model in a single-thread module is the following:
produce()
, filter()
, analyze()
). Note that after an handle has its cached data removed, it's clear()
'ed.An handle manager can serve only one art event at a time. All handles come from that event (or are assumed to).
Example:
Or one can create the handle as preferred, and then register it:
Currently, both art::Handle
and art::ValidHandle
(and nothing else) can be created by ArtHandleTrackerManager
. The code can be extended to support any object that can be passed to art::Event::removeCachedProduct()
(e.g. art::ProductID
, if it will ever happen).
The current implementation is expected to be able to recognize handles pointing to the same data product even if they are of different type (e.g. art::Handle<T>
and art::ValidHandle<T>
). The manager stores a copy of the first type of handle registered for a given data product; then, if another handle of any type to the same data product is requested or registered, registerHandle()
will return the same handle in argument, and the getHandle()
family of functions will get and return a new handle. In both cases, no new registration will happen.
The current implementation is inherently not safe for art multithreading. While the inner data structure don't need global state, and the interface can easily be extended to allow for no global state as well, the operations are still performed on all the registered handles at once (meaning, when one thread asks for removeCachedProduct()
or forgetAllHandles()
, data from all events is affected). This can be overcome by changing the internal storage (to be reentrant and possibly by event) and a bit of the interface.
The object as it is now can be implemented on top of such object, preserving the current event information and delivering it to the new manager under the hood, with minimal overhead.
If such feature is needed, ask the author (and be prepared to test it).
Definition at line 32 of file ArtHandleTrackerManager.h.
using util::ArtHandleTrackerManager< Event >::Event_t = Event |
Type of data viewer object to operate with.
Definition at line 163 of file ArtHandleTrackerManager.h.
|
private |
Type of pointer to any handle tracker.
Definition at line 322 of file ArtHandleTrackerManager.h.
util::ArtHandleTrackerManager< Event >::ArtHandleTrackerManager | ( | Config_t | config = {} | ) |
Constructs a handle manager.
config | (optional) the configuration to be used |
useEvent()
An event must be later assigned to it (useEvent()
) to make it functional.
Definition at line 783 of file ArtHandleTrackerManager.h.
util::ArtHandleTrackerManager< Event >::ArtHandleTrackerManager | ( | Event_t const & | event, |
Config_t | config = {} |
||
) |
Constructs a handle manager covering event
.
event | the first data viewer (event) object to operate on |
Definition at line 791 of file ArtHandleTrackerManager.h.
|
private |
Checks that the object is in a state where it can perform operations.
where | identification of the calling function for error messages |
art::Exception | (code: art::errors::LogicError ) on failure |
Definition at line 981 of file ArtHandleTrackerManager.h.
unsigned int util::ArtHandleTrackerManager< Event >::doneWithEvent | ( | bool | removeCache = true , |
art::Event const * | event = nullptr |
||
) |
Completes the work on the associated event
.
removeCache | (default: true ) removes tracked data product caches |
event | if specified, only acts on cache from this event |
This is a shortcut for having optional release of cache in a single call, depending on the value of removeCache
:
true
, removeCachedProducts()
is called and its count is returned;false
, forgetAllHandles()
is called and 0
is returned.In addition, the object is disassociated from the event, and a call to useEvent()
will be needed before this object can be operative again.
If the event
parameter is not null, a check is done that the event being currently used matches event
, and if not no operation happens (0
is returned, but the object is not disassociated from its current event).
Definition at line 920 of file ArtHandleTrackerManager.h.
|
private |
Returns the pointer to an handle equivalent to like
.
Handle | the type of the handle being queried |
nullptr
if not foundThis is an half-assed method since it needs to know already the exact type of the handle being queried (it's not even agnostic to the difference between art::Handle
and art::ValidHandle
). For this reason, it's not really useful to the users, who would probably want to know if the data product is cached, via any mean.
Delegating the matching to util::ArtHandleTrackerInterface
is not possible (like
is a template parameter and can't be passed via virtual interface) and even working around that and finding the match, the returned value needs to be of type Handle
, which is not necessarily the type of handle stored in the tracker.
For the full functionality of knowing if a data product is tracked, a separate registry may be kept, still complicated by the fact that part of the registry entry is a C++ type (we may need to store a sanitized std::type_info
for that).
Definition at line 938 of file ArtHandleTrackerManager.h.
void util::ArtHandleTrackerManager< Event >::forgetAllHandles | ( | ) |
Stops tracking any handle, without removing their cache first.
Definition at line 911 of file ArtHandleTrackerManager.h.
art::Handle< T > util::ArtHandleTrackerManager< Event >::getHandle | ( | Args &&... | args | ) |
Retrieves an handle from the event, and registers it.
T | type of data product to retrieve |
Args | types of the arguments needed by art::getHandle() |
args | all the arguments that art::getHandle() requires |
getValidHandle()
, registerHandle()
This function wraps art::Event::getHandle()
, calling it to obtain the handle and then registering it (like with registerHandle()
).
Definition at line 818 of file ArtHandleTrackerManager.h.
art::ValidHandle< T > util::ArtHandleTrackerManager< Event >::getValidHandle | ( | Args &&... | args | ) |
Retrieves a valid handle from the event, and registers it.
T | type of data product to retrieve |
Args | types of the arguments needed by art::getValidHandle() |
args | all the arguments that art::getValidHandle() requires |
getHandle()
, registerHandle()
This is the art::ValidHandle
sibling of getHandle()
. See that one for details.
Definition at line 830 of file ArtHandleTrackerManager.h.
|
staticprivate |
Returns whether tracker
tracks the same product that handle
handles.
Definition at line 965 of file ArtHandleTrackerManager.h.
bool util::ArtHandleTrackerManager< Event >::hasEvent | ( | ) | const |
Returns whether the object is associated to an event.
Definition at line 889 of file ArtHandleTrackerManager.h.
unsigned int util::ArtHandleTrackerManager< Event >::nTrackedHandles | ( | ) | const |
Returns the number of handles currently tracked.
Definition at line 883 of file ArtHandleTrackerManager.h.
decltype(auto) util::ArtHandleTrackerManager< Event >::registerHandle | ( | Handle && | handle | ) |
Registers an existing handle.
Handle | the type of handle to register |
handle | the handle to be registered |
handle
(pass through)This method registers a copy of handle
into the manager.
auto util::ArtHandleTrackerManager< Event >::registerHandle | ( | Handle && | handle | ) | -> decltype(auto) |
Definition at line 842 of file ArtHandleTrackerManager.h.
unsigned int util::ArtHandleTrackerManager< Event >::removeCachedProducts | ( | ) |
Clears the cached data products for all tracked handles.
This method calls Event_t::removeCachedProduct()
for all tracked handles. This is the core functionality of the manager, which removes the cache of all tracked handles.
The art framework always makes the handles used to remove the cache invalid (Handle::clear()
). After the removal, the object stops tracking the handles (like with a call to forgetAllHandles()
).
Calling this method when there are no handles registered has no effect.
Definition at line 895 of file ArtHandleTrackerManager.h.
void util::ArtHandleTrackerManager< Event >::useEvent | ( | Event_t const & | event | ) |
Changes the event being served.
event | the new event being served |
art::Exception | (code: art::errors::LogicError ) if there are still registered handles |
The object starts tracking handles of a new event.
This method requires that any pending handle has been taken care of (even if the new event happens to be the same as the old one). Common options are removeCachedProductsAndForget()
if cache removal is desired, or forgetAllHandles()
if it's not.
Definition at line 798 of file ArtHandleTrackerManager.h.
|
private |
Configuration.
Definition at line 328 of file ArtHandleTrackerManager.h.
|
private |
Event being manager. Must be present!
Definition at line 326 of file ArtHandleTrackerManager.h.
|
private |
List of managed handle trackers.
Definition at line 331 of file ArtHandleTrackerManager.h.