Keeps a record of all registered events and their source. More...
#include <EventRegistry.h>
Classes | |
struct | EventRecord_t |
Element of the registry for an event. More... | |
Public Types | |
using | EventID_t = art::EventID |
Type used to identify an event. More... | |
using | FileID_t = std::size_t |
Type used to identify a source file. More... | |
using | EventIDandRecord_t = std::pair< EventID_t, EventRecord_t > |
Type with event ID (first ) and event record information (second ). More... | |
Public Member Functions | |
Source interface | |
FileID_t | recordSource (std::string const &fileName) |
Registers a source file and returns its ID in the registry. More... | |
bool | hasSource (FileID_t const &fileID) const |
Returns whether the specified file ID is registered as a source. More... | |
bool | hasSource (std::string const &fileName) const |
Returns whether the specified file name is registered as a source. More... | |
std::optional< FileID_t > | sourceID (std::string const &fileName) const |
std::optional< std::string > | sourceName (FileID_t const &fileID) const |
std::string | sourceNameOr (FileID_t const &fileID, std::string const &defName) const |
Event interface | |
std::vector< EventIDandRecord_t > | records () const |
Returns a copy of all event records. More... | |
std::optional< EventRecord_t > | eventRecord (art::EventID const &event) const |
EventRecord_t | recordEvent (EventID_t const &event, FileID_t sourceFileID) |
Registers an event and returns a copy of its record. More... | |
Static Public Attributes | |
static constexpr FileID_t | NoFileID = std::numeric_limits<FileID_t>::max() |
Mnemonic for no file ID. More... | |
Private Types | |
using | FileRegistry_t = std::vector< std::string > |
Type for source file registry. More... | |
Private Member Functions | |
void | copyEventRecordsInto (std::vector< EventIDandRecord_t > &recordCopy) const |
Copies all event records into recordCopy . More... | |
std::lock_guard< std::mutex > | lockEventRegistry () const |
Returns a lock guard around fEventRegistry . More... | |
FileRegistry_t::iterator | findSource (std::string const &fileName) |
Returns an iterator pointing to the specified file registry entry. More... | |
FileRegistry_t::const_iterator | findSource (std::string const &fileName) const |
Static Private Member Functions | |
static FileID_t | indexToFileID (std::size_t index) |
Converts an internal index in file source registry into a FileID_t . More... | |
static std::size_t | fileIDtoIndex (FileID_t fileID) |
Converts a FileID_t into an internal index in file source registry. More... | |
Private Attributes | |
std::vector< std::string > | fSourceFiles |
Registered source file, by file ID key. More... | |
std::unordered_map< EventID_t, EventRecord_t > | fEventRegistry |
Registry of all events. More... | |
std::mutex | fEventRegistryLock |
Lock for fEventRegistry . More... | |
Keeps a record of all registered events and their source.
This registry object will keep track of every time an event is "registered". An event is represented by its ID (art::EventID
), and it is associated to the input file(s) it is stored in.
Input files can be registered separately by file name, or at the same time with the event.
Registration of events can happen concurrently (thread-safe). Registration of source files, instead, is not protected.
It is guaranteed that the source file records are never modified once registered (i.e. neither removed from the registry, nor the path of a source record changed).
Definition at line 77 of file EventRegistry.h.
using sbn::EventRegistry::EventID_t = art::EventID |
Type used to identify an event.
Definition at line 81 of file EventRegistry.h.
using sbn::EventRegistry::EventIDandRecord_t = std::pair<EventID_t, EventRecord_t> |
Type with event ID (first
) and event record information (second
).
Definition at line 93 of file EventRegistry.h.
using sbn::EventRegistry::FileID_t = std::size_t |
Type used to identify a source file.
Definition at line 83 of file EventRegistry.h.
|
private |
Type for source file registry.
Definition at line 174 of file EventRegistry.h.
|
private |
Copies all event records into recordCopy
.
Definition at line 122 of file EventRegistry.cxx.
auto sbn::EventRegistry::eventRecord | ( | art::EventID const & | event | ) | const |
Returns a copy of the specified event record.
event
, or unset if event
is not registered Definition at line 82 of file EventRegistry.cxx.
|
staticprivate |
Converts a FileID_t
into an internal index in file source registry.
Definition at line 145 of file EventRegistry.cxx.
|
private |
Returns an iterator pointing to the specified file registry entry.
Definition at line 111 of file EventRegistry.cxx.
|
private |
Definition at line 115 of file EventRegistry.cxx.
bool sbn::EventRegistry::hasSource | ( | FileID_t const & | fileID | ) | const |
Returns whether the specified file ID is registered as a source.
Definition at line 35 of file EventRegistry.cxx.
bool sbn::EventRegistry::hasSource | ( | std::string const & | fileName | ) | const |
Returns whether the specified file name is registered as a source.
Definition at line 40 of file EventRegistry.cxx.
|
staticprivate |
Converts an internal index in file source registry into a FileID_t
.
Definition at line 140 of file EventRegistry.cxx.
|
private |
Returns a lock guard around fEventRegistry
.
Definition at line 135 of file EventRegistry.cxx.
Registers an event and returns a copy of its record.
event | ID of the event to be registered |
sourceFileID | ID of the source file to be associated with the event |
event
cet::exception | (category: "sbn::EventRegistry" ) if sourceFileID dose not match a registered source file |
recordEvent(EventID_t const&, std::string const&)
The record of the specified event
is updated adding sourceFileID
among its sources. A single sourceFileID
can appear multiple times for the same event, indicating a duplicate event in the same source file.
A source with sourceFileID
must have been registered already (recordSource()
).
Definition at line 98 of file EventRegistry.cxx.
auto sbn::EventRegistry::records | ( | ) | const |
Returns a copy of all event records.
Definition at line 72 of file EventRegistry.cxx.
auto sbn::EventRegistry::recordSource | ( | std::string const & | fileName | ) |
Registers a source file and returns its ID in the registry.
fileName | the name of the source file to be registered |
fileName
withIf fileName
has already been registered, the existing ID is returned and no other action is performed.
Definition at line 23 of file EventRegistry.cxx.
auto sbn::EventRegistry::sourceID | ( | std::string const & | fileName | ) | const |
Returns the ID of the source with the specified file name (slow!).
fileID
is not registered Definition at line 45 of file EventRegistry.cxx.
std::optional< std::string > sbn::EventRegistry::sourceName | ( | FileID_t const & | fileID | ) | const |
Returns the name of the source associated to the specified file ID.
fileID
is not registered Definition at line 58 of file EventRegistry.cxx.
std::string sbn::EventRegistry::sourceNameOr | ( | FileID_t const & | fileID, |
std::string const & | defName | ||
) | const |
Returns the name of the source associated to the specified file ID.
defName
if fileID
is not registered Definition at line 67 of file EventRegistry.cxx.
|
private |
Registry of all events.
Definition at line 180 of file EventRegistry.h.
|
mutableprivate |
Lock for fEventRegistry
.
Definition at line 182 of file EventRegistry.h.
|
private |
Registered source file, by file ID key.
Definition at line 177 of file EventRegistry.h.
Mnemonic for no file ID.
Definition at line 97 of file EventRegistry.h.