Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
Add a plugin to filter events based on a reminder of division of their
Browse files Browse the repository at this point in the history
event number

Also fix a bit of decoration in FilterEventIDPlugin.
  • Loading branch information
andrey-popov committed Feb 24, 2014
1 parent e309cce commit d842ab1
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 54 deletions.
106 changes: 53 additions & 53 deletions extensions/include/FilterEventIDPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,60 +28,60 @@
*/
class FilterEventIDPlugin: public Plugin
{
public:
/// Constructor
FilterEventIDPlugin(std::string const &name, std::string const &eventIDsFileName,
bool rejectKnownEvent = true);
public:
/// Constructor
FilterEventIDPlugin(std::string const &name, std::string const &eventIDsFileName,
bool rejectKnownEvent = true);

private:
/// A private constructor to be used in method Clone
FilterEventIDPlugin(std::string const &name, std::map<std::string,
std::vector<EventID>> const &eventIDsAllFiles, bool rejectKnownEvent);

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);

private:
/// A private constructor to be used in method Clone
FilterEventIDPlugin(std::string const &name, std::map<std::string,
std::vector<EventID>> const &eventIDsAllFiles, bool rejectKnownEvent);
/**
* \brief Notifies this that a dataset has been closed
*
* Consult documentation of the overriden method for details.
*/
void EndRun();

/**
* \brief Processes the current event
*
* Consult documentation of the overriden method for details.
*/
bool ProcessEvent();

public:
/**
* \brief Creates a newly-initialized 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 Processes the current event
*
* Consult documentation of the overriden method for details.
*/
bool ProcessEvent();
private:
/// Pointer to PECReaderPlugin
PECReaderPlugin const *reader;

/**
* \brief Switch defining the logic of filtering
*
* If set to true, the plugin rejects events whose IDs are mentioned in the provided file.
* If set to false, it keeps only events with IDs written in the file.
*/
bool rejectKnownEvent;

/// Map to store event IDs. The key of the map is a short name of corresponding ROOT file
std::map<std::string, std::vector<EventID>> eventIDsAllFiles;

private:
/// Pointer to PECReaderPlugin
PECReaderPlugin const *reader;

/**
* \brief Switch defining the logic of filtering
*
* If set to true, the plugin rejects events whose IDs are mentioned in the provided file.
* If set to false, it keeps only events with IDs written in the file.
*/
bool rejectKnownEvent;

/// Map to store event IDs. The key of the map is a short name of corresponding ROOT file
std::map<std::string, std::vector<EventID>> eventIDsAllFiles;

/// Pointer to vector of event IDs for the current ROOT file (note it might be null)
std::vector<EventID> const *eventIDsCurFile;
/// Pointer to vector of event IDs for the current ROOT file (note it might be null)
std::vector<EventID> const *eventIDsCurFile;
};
85 changes: 85 additions & 0 deletions extensions/include/FilterEventIDReminderPlugin.hpp
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;
};
3 changes: 2 additions & 1 deletion extensions/src/FilterEventIDPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ void FilterEventIDPlugin::BeginRun(Dataset const &dataset)
// Lists of event IDs are provided on per-file basis. Since the plugin is not notified when
//a new file in the current dataset is started, it makes sense only to filer atomic datasets
if (dataset.GetFiles().size() not_eq 1)
throw logic_error("TTbarRecoPlugin::BeginRun: The plugin can filter atomic datasets only.");
throw logic_error("FilterEventIDPlugin::BeginRun: The plugin can filter atomic "
"datasets only.");


// Save pointer to the reader plugin
Expand Down
43 changes: 43 additions & 0 deletions extensions/src/FilterEventIDReminderPlugin.cpp
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;
}

0 comments on commit d842ab1

Please sign in to comment.