All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Attributes | List of all members
util::LocalArtHandleTrackerManager< Event > Class Template Reference

Variant of util::ArtHandleTrackerManager in local scope. More...

#include <ArtHandleTrackerManager.h>

Public Types

using Event_t = typename ArtHandleTrackerManager< Event >::Event_t
 Type of the art event. More...
 

Public Member Functions

 LocalArtHandleTrackerManager (Event const &event, bool removeCache=true)
 Constructor: operates on the specified event. More...
 
 ~LocalArtHandleTrackerManager ()
 Destructor; will implement the RAII pattern (i.e. call doneWithEvent()). More...
 
template<typename Handle >
auto registerHandle (Handle &&handle) -> decltype(auto)
 
Queries
unsigned int nTrackedHandles () const
 Returns the number of handles currently tracked. More...
 
bool willRemoveCachedProducts () const
 
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 setRemoveCachedProducts (bool removeCache)
 Sets whether to remove tracked data caches on destruction or not. 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)
 Completes the work on the associated event. More...
 
unsigned int doneWithEvent ()
 Completes the work on the associated event. More...
 

Private Attributes

ArtHandleTrackerManager< Event > fManager
 The actual manager doing the work. More...
 
bool fRemoveCache
 Whether to remove cache on destructor. More...
 

Detailed Description

template<typename Event>
class util::LocalArtHandleTrackerManager< Event >

Variant of util::ArtHandleTrackerManager in local scope.

Template Parameters
Eventthe type of data product source (the "principal") to serve

This class allows the removal of data products cached in an event. The general functionality is described in util::ArtHandleTrackerManager.

This class in particular offers a tuned interface for the case where the object is local (which is convenient for multithreading and if all the reading and usage happens in the same scope):

Whether the object will actually remove the caches can be decided on construction (by default it does), and then changed with setRemoveCachedProducts(). The removal can also be anticipated by explicitly calling doneWithEvent() (no event parameter is supported), after which the destruction will not do anything.

Example:

void MyModule::analyze(art::Event const & event) override {
util::LocalArtHandleTrackerManager dataCacheRemover{ event };
auto const& handle = dataCacheRemover.getHandle<MyDataProduct>(fTag);
auto results = processData(*handle); // ... or whatever
results.Write(); // ... or another portion of whatever
}

Definition at line 33 of file ArtHandleTrackerManager.h.

Member Typedef Documentation

template<typename Event >
using util::LocalArtHandleTrackerManager< Event >::Event_t = typename ArtHandleTrackerManager<Event>::Event_t

Type of the art event.

Definition at line 429 of file ArtHandleTrackerManager.h.

Constructor & Destructor Documentation

template<typename Event >
util::LocalArtHandleTrackerManager< Event >::LocalArtHandleTrackerManager ( Event const &  event,
bool  removeCache = true 
)

Constructor: operates on the specified event.

Parameters
eventthe event this object will operate on
removeCache(default: true) remove tracked data caches when done

The parameter removeCache controls whether the data caches are removed on destruction. It may be changed along the way with setRemoveCachedProducts().

Definition at line 997 of file ArtHandleTrackerManager.h.

998  : fManager{ event }, fRemoveCache{ removeCache }
999  {}
bool fRemoveCache
Whether to remove cache on destructor.
ArtHandleTrackerManager< Event > fManager
The actual manager doing the work.
template<typename Event >
util::LocalArtHandleTrackerManager< Event >::~LocalArtHandleTrackerManager ( )

Destructor; will implement the RAII pattern (i.e. call doneWithEvent()).

Definition at line 1004 of file ArtHandleTrackerManager.h.

1005  { doneWithEvent(); }
unsigned int doneWithEvent()
Completes the work on the associated event.

Member Function Documentation

template<typename Event >
unsigned int util::LocalArtHandleTrackerManager< Event >::doneWithEvent ( bool  removeCache)

Completes the work on the associated event.

Parameters
removeCache(default: true) removes tracked data product caches
Returns
the number of cleared data product caches
See Also
doneWithEvent()

This is a shortcut for having optional release of cache in a single call, depending on the value of removeCache:

Differently from util::ArtHandleTrackerManager, the object is not disassociated from the event: new handles can be registered and the clearing settings are preserved as they are. To be really done with the event, setRemoveCachedProducts() needs to be set to false, and users should refrain from calling `removeCachedProducts().

This method ignores and overrides the value set by setRemoveCachedProducts() and the one at construction.

Definition at line 1068 of file ArtHandleTrackerManager.h.

1069 {
1070  assert(fManager.hasEvent());
1071 
1072  if (removeCache) return removeCachedProducts();
1073 
1074  forgetAllHandles();
1075  return 0;
1076 } // util::LocalArtHandleTrackerManager<Event>::doneWithEvent()
unsigned int removeCachedProducts()
Clears the cached data products for all tracked handles.
void forgetAllHandles()
Stops tracking any handle, without removing their cache first.
ArtHandleTrackerManager< Event > fManager
The actual manager doing the work.
template<typename Event >
unsigned int util::LocalArtHandleTrackerManager< Event >::doneWithEvent ( )

Completes the work on the associated event.

Returns
the number of cleared data product caches
See Also
doneWithEvent(bool), setRemoveCachedProducts()

This is a shortcut for having optional release of cache in a single call, depending on the value of willRemoveCachedProducts():

In addition, the object is disassociated from the event, and the object will not be available for use any more.

Definition at line 1081 of file ArtHandleTrackerManager.h.

unsigned int doneWithEvent()
Completes the work on the associated event.
template<typename Event >
void util::LocalArtHandleTrackerManager< Event >::forgetAllHandles ( )

Stops tracking any handle, without removing their cache first.

Definition at line 1061 of file ArtHandleTrackerManager.h.

1062  { return fManager.forgetAllHandles(); }
ArtHandleTrackerManager< Event > fManager
The actual manager doing the work.
template<typename Event >
template<typename T , typename... Args>
art::Handle< T > util::LocalArtHandleTrackerManager< Event >::getHandle ( Args &&...  args)

Retrieves an handle from the event, and registers it.

Template Parameters
Ttype of data product to retrieve
Argstypes of the arguments needed by art::getHandle()
Parameters
argsall the arguments that art::getHandle() requires
Returns
the handle just read and being managed
See Also
getValidHandle(), registerHandle()

This function wraps art::Event::getHandle(), calling it to obtain the handle and then registering it (like with registerHandle()).

Definition at line 1024 of file ArtHandleTrackerManager.h.

1025  { return fManager.template getHandle<T>(std::forward<Args>(args)...); }
ArtHandleTrackerManager< Event > fManager
The actual manager doing the work.
template<typename Event >
template<typename T , typename... Args>
art::ValidHandle< T > util::LocalArtHandleTrackerManager< Event >::getValidHandle ( Args &&...  args)

Retrieves a valid handle from the event, and registers it.

Template Parameters
Ttype of data product to retrieve
Argstypes of the arguments needed by art::getValidHandle()
Parameters
argsall the arguments that art::getValidHandle() requires
Returns
the handle just read and being managed
See Also
getHandle(), registerHandle()

This is the art::ValidHandle sibling of getHandle(). See that one for details.

Definition at line 1032 of file ArtHandleTrackerManager.h.

1033  { return fManager.template getValidHandle<T>(std::forward<Args>(args)...); }
ArtHandleTrackerManager< Event > fManager
The actual manager doing the work.
template<typename Event >
unsigned int util::LocalArtHandleTrackerManager< Event >::nTrackedHandles ( ) const

Returns the number of handles currently tracked.

Definition at line 1010 of file ArtHandleTrackerManager.h.

1011  {return fManager.nTrackedHandles(); }
ArtHandleTrackerManager< Event > fManager
The actual manager doing the work.
template<typename Event >
template<typename Handle >
decltype(auto) util::LocalArtHandleTrackerManager< Event >::registerHandle ( Handle &&  handle)

Registers an existing handle.

Template Parameters
Handlethe type of handle to register
Parameters
handlethe handle to be registered
Returns
the same handle is passed through

This method registers a copy of handle into the manager.

template<typename Event >
template<typename Handle >
auto util::LocalArtHandleTrackerManager< Event >::registerHandle ( Handle &&  handle) -> decltype(auto)

Definition at line 1040 of file ArtHandleTrackerManager.h.

1041 {
1042  return fManager.template registerHandle<Handle>(std::forward<Handle>(handle));
1043 }
ArtHandleTrackerManager< Event > fManager
The actual manager doing the work.
template<typename Event >
unsigned int util::LocalArtHandleTrackerManager< Event >::removeCachedProducts ( )

Clears the cached data products for all tracked handles.

Returns
the number of tracked handles which had their cache removed

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 1055 of file ArtHandleTrackerManager.h.

1056  { return fManager.removeCachedProducts(); }
ArtHandleTrackerManager< Event > fManager
The actual manager doing the work.
template<typename Event >
void util::LocalArtHandleTrackerManager< Event >::setRemoveCachedProducts ( bool  removeCache)

Sets whether to remove tracked data caches on destruction or not.

Parameters
removeCacheif true, data caches will be removed on destruction

Definition at line 1049 of file ArtHandleTrackerManager.h.

1050  { fRemoveCache = removeCache; }
bool fRemoveCache
Whether to remove cache on destructor.
template<typename Event >
bool util::LocalArtHandleTrackerManager< Event >::willRemoveCachedProducts ( ) const

Returns whether caches will be removed on destruction.

See Also
setRemoveCachedProducts()

Definition at line 1016 of file ArtHandleTrackerManager.h.

1017  { return fRemoveCache; }
bool fRemoveCache
Whether to remove cache on destructor.

Member Data Documentation

template<typename Event >
ArtHandleTrackerManager<Event> util::LocalArtHandleTrackerManager< Event >::fManager
private

The actual manager doing the work.

Definition at line 422 of file ArtHandleTrackerManager.h.

template<typename Event >
bool util::LocalArtHandleTrackerManager< Event >::fRemoveCache
private

Whether to remove cache on destructor.

Definition at line 424 of file ArtHandleTrackerManager.h.


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