This repository has been archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a plugin to filter events based on a reminder of division of their
event number Also fix a bit of decoration in FilterEventIDPlugin.
- Loading branch information
1 parent
e309cce
commit d842ab1
Showing
4 changed files
with
183 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* \file FilterEventIDReminderPlugin.hpp | ||
* \author Andrey Popov | ||
* | ||
* Defines a class that filters event based on based on a reminder of division of their event number | ||
* by a specified denominator. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <Plugin.hpp> | ||
|
||
#include <PECReaderPlugin.hpp> | ||
#include <EventID.hpp> | ||
|
||
#include <string> | ||
#include <map> | ||
#include <vector> | ||
|
||
|
||
/** | ||
* \class FilterEventIDReminderPlugin | ||
* \brief Filters events on a reminder of division of their event number | ||
* | ||
* The plugin calculates a reminder of division of the event number part of event ID by a | ||
* configurable denominator. If this reminder is larger that the configurable maximal allowed value, | ||
* the event is rejected. If needed, this logic can be inverted by setting a dedicated flag. | ||
*/ | ||
class FilterEventIDReminderPlugin: public Plugin | ||
{ | ||
public: | ||
/** | ||
* \brief Constructor | ||
* | ||
* Consult the general documentation of the class for details. | ||
*/ | ||
FilterEventIDReminderPlugin(std::string const &name, unsigned maxReminder, | ||
unsigned denominator, bool isReversed = false); | ||
|
||
public: | ||
/** | ||
* \brief Creates a newly-initialised copy | ||
* | ||
* Consult documentation of the overriden method for details. | ||
*/ | ||
Plugin *Clone() const; | ||
|
||
/** | ||
* \brief Notifies this that a dataset has been opened | ||
* | ||
* Consult documentation of the overriden method for details. | ||
*/ | ||
void BeginRun(Dataset const &dataset); | ||
|
||
/** | ||
* \brief Notifies this that a dataset has been closed | ||
* | ||
* Consult documentation of the overriden method for details. | ||
*/ | ||
void EndRun(); | ||
|
||
/** | ||
* \brief Decides if the event should be kept or rejected based on its event number | ||
* | ||
* Consult documentation of the overriden method for details. | ||
*/ | ||
bool ProcessEvent(); | ||
|
||
private: | ||
/// Pointer to PECReaderPlugin | ||
PECReaderPlugin const *reader; | ||
|
||
/** | ||
* \brief Maximal allowed reminder of a division of an event number by the denominator | ||
* | ||
* If the reminder is larger, the event is rejected. | ||
*/ | ||
unsigned maxReminder; | ||
|
||
/// Denominator to divide the event number | ||
unsigned denominator; | ||
|
||
/// Indicates if the logic of the filter should be reversed | ||
bool isReversed; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <FilterEventIDReminderPlugin.hpp> | ||
|
||
#include <Processor.hpp> | ||
|
||
#include <stdexcept> | ||
#include <fstream> | ||
#include <sstream> | ||
|
||
|
||
using namespace std; | ||
|
||
|
||
FilterEventIDReminderPlugin::FilterEventIDReminderPlugin(string const &name_, | ||
unsigned maxReminder_, unsigned denominator_, bool isReversed_ /*=false*/): | ||
Plugin(name_), | ||
maxReminder(maxReminder_), denominator(denominator_), isReversed(isReversed_) | ||
{} | ||
|
||
|
||
Plugin *FilterEventIDReminderPlugin::Clone() const | ||
{ | ||
return new FilterEventIDReminderPlugin(name, maxReminder, denominator, isReversed); | ||
} | ||
|
||
|
||
void FilterEventIDReminderPlugin::BeginRun(Dataset const &) | ||
{ | ||
// Save pointer to the reader plugin | ||
reader = dynamic_cast<PECReaderPlugin const *>(processor->GetPluginBefore("Reader", name)); | ||
} | ||
|
||
|
||
void FilterEventIDReminderPlugin::EndRun() | ||
{} | ||
|
||
|
||
bool FilterEventIDReminderPlugin::ProcessEvent() | ||
{ | ||
auto const &id = (*reader)->GetEventID(); | ||
bool const res = ((id.Event() % denominator) <= maxReminder); | ||
|
||
return (isReversed) ? not res : res; | ||
} |