Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ build*/
dist*/
Python/*.egg-info
__pycache__

# untracked directory
untracked*/
2 changes: 2 additions & 0 deletions Cpp/Library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ set( NYMPH_HEADERFILES
${DATA_DIR}/DataPresent.hh
${DATA_DIR}/SignalData.hh
${DATA_DIR}/SlotData.hh
${DATA_DIR}/CutStatus.hh

${CONT_DIR}/ControlAccess.hh
${CONT_DIR}/Controller.hh
Expand All @@ -48,6 +49,7 @@ set( NYMPH_SOURCEFILES

${DATA_DIR}/Data.cc
${DATA_DIR}/DataFrame.cc
${DATA_DIR}/CutStatus.cc

${PROC_DIR}/PrimaryProcessor.cc
${PROC_DIR}/Processor.cc
Expand Down
72 changes: 72 additions & 0 deletions Cpp/Library/Data/CutStatus.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* CutStatus.cc
*
* Created on: Aug 24, 2012
* Author: nsoblath
*/

#include "CutStatus.hh"
#include "logger.hh"

namespace Nymph
{
LOGGER(cutlog, "Cut");

CutStatus::CutStatus()
{
}

CutStatus::CutStatus(const CutStatus& orig)
{
fCutResults = orig.fCutResults;
}

CutStatus::~CutStatus()
{}

CutStatus& CutStatus::operator=(const CutStatus& rhs)
{
//delete[] fCutResults;
fCutResults = rhs.fCutResults;
return *this;
}

void CutStatus::AssignCutResult(const std::string& cutName, bool state)
{
LDEBUG(cutlog, "Assigning cut result <" << cutName << "> with state <" << state << ">");
if( fCutResults.find(cutName) != fCutResults.end())
{
throw Exception() << "Cut with name: " << cutName << " has already been assigned";
}
fCutResults.insert(make_pair(cutName,state));
LDEBUG(cutlog, "Cut result size is now: " << fCutResults.size() );
return;
}

std::vector< std::string > CutStatus::CutResultsPresent() const
{
std::vector< std::string > cutsPresent;
for (auto cutIt = fCutResults.cbegin(); cutIt != fCutResults.cend(); ++cutIt)
{
if (! cutIt->first.empty())
{
cutsPresent.push_back(cutIt->first);
}
}
return cutsPresent;
}

std::ostream& operator<<(std::ostream& out, const CutStatus& status)
{
out << "Cut summary: " << '\n';
std::vector< std::string > cuts = status.CutResultsPresent();
for (auto cutIt = cuts.cbegin(); cutIt != cuts.cend(); ++cutIt)
{
out << *cutIt << "; ";
}
out << '\n';
return out;
}


} /* namespace Nymph */
184 changes: 184 additions & 0 deletions Cpp/Library/Data/CutStatus.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
* CutStatus.hh
*
* Created on: Sept 19, 2014
* Author: nsoblath
*/

#ifndef CUTSTATUS_HH_
#define CUTSTATUS_HH_

#include <map>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptor/map.hpp>

#include "Exception.hh"


namespace Nymph
{
/*!
@class CutStatus
@author N. S. Oblath

@brief Provides easy access to cut result information.

@details
The cut results are stored as a map with cut name as key, with value of bool of whether the cut is applied or not.

CutStatus is typically used as a member variable of DataFrame.

You can check if the data has been cut with the IsCut functions.
- IsCut() returns true if any cut results are true;

When specifying a cut, bools set to true specify cuts that are applied.

With CutStatus you can interact with individual cut results in the following ways:
- Check whether any cut results are set to true with IsCut(),
- Get the number of cut results with size(),
- Get the number of cut results with value true with NumCuts(),
- Get a reference to the cut results with CutResults(),
- Add cut results to a dataframe with AssignCutResult(),
- Remove a cut result with RemoveCutResult(),
- Check to see if a particular cut result is present using HasCutResult(),
- Get the value of a cut result with GetCutState(),
- Set the value of a cut result with SetCutState(),
- Get a vector of cut names for cuts with value==True with CutResultsPresent(), and
- Output a text summary of applied cuts with the << operator,

*/

class CutStatus
{
public:
typedef std::map< std::string, bool > CutResults_t;
typedef CutResults_t::iterator CutResultsIt;
typedef CutResults_t::const_iterator CutResultsCIt;

public:
CutStatus();
CutStatus(const CutStatus& orig);
~CutStatus();

CutStatus& operator=(const CutStatus& rhs);

/// Returns the size of the cut results map
size_t size() const;

/// Returns a reference to the cut results map
std::map< std::string, bool > CutResults() const;

/// Adds a new cut result with the specified name; throws Exception if a cut with that name already exists
void AssignCutResult(const std::string& cutName, bool state=false);

/// Removes the cut by erasing the name and setting the state to false
void RemoveCutResult(const std::string& cutName);

CutResultsIt FindCutResult(const std::string& cutName);
CutResultsCIt FindCutResultC(const std::string& cutName) const;

CutResultsIt CutResultsEnd();
CutResultsCIt CutResultsEndC() const;

/// Returns whether or not the specified cut is present
bool HasCutResult(const std::string& cutName) const;

/// Returns the state of the named cut; throws Exception if it doesn't exist
bool GetCutState(const std::string& cutName) const;

/// Sets the state of the specified cut; throws Exception if it doesn't exist
void SetCutState(const std::string& cutName, bool state);

/// Returns a string with the names of the cuts that are present in bitset order
std::vector< std::string > CutResultsPresent() const;

private:
friend std::ostream& operator<<(std::ostream& out, const CutStatus& status);

CutResults_t fCutResults;

public:
bool IsCut() const;
bool IsCut(const std::string& mask) const;
int NumCuts() const;

};

std::ostream& operator<<(std::ostream& out, const CutStatus& status);

inline std::map< std::string, bool > CutStatus::CutResults() const // get a const of the map
{
return fCutResults;
}

inline CutStatus::CutResultsIt CutStatus::FindCutResult( const std::string& cutName )
{
return fCutResults.find(cutName);
}

inline CutStatus::CutResultsCIt CutStatus::FindCutResultC( const std::string& cutName ) const
{
return fCutResults.find(cutName);
}

inline CutStatus::CutResultsIt CutStatus::CutResultsEnd()
{
return fCutResults.end();
}

inline CutStatus::CutResultsCIt CutStatus::CutResultsEndC() const
{
return fCutResults.cend();
}

inline bool CutStatus::HasCutResult( const std::string& cutName ) const
{
return fCutResults.count(cutName);
}

inline bool CutStatus::GetCutState( const std::string& cutName ) const
{
if (fCutResults.find(cutName) != fCutResults.end())
{
return fCutResults.at(cutName);
}
throw Exception() << "Unable to find cut <" << cutName << ">";
}

inline void CutStatus::SetCutState(const std::string& cutName, bool state)
{
if (fCutResults.find(cutName) != fCutResults.end())
{
fCutResults[cutName] = state;
return;
}
throw Exception() << "Unable to find cut <" << cutName << ">";
}

inline void CutStatus::RemoveCutResult(const std::string& cutName)
{
if (fCutResults.find(cutName) != fCutResults.end())
{
fCutResults.erase(cutName);
}
return;
}
inline size_t CutStatus::size() const
{
return fCutResults.size();
}

inline bool CutStatus::IsCut() const
{
int stateSum = boost::accumulate(fCutResults | boost::adaptors::map_values, 0);
return stateSum > 0;
}

inline int CutStatus::NumCuts() const
{
int stateSum = boost::accumulate(fCutResults | boost::adaptors::map_values, 0);
return stateSum;
}
} /* namespace Nymph */

#endif /* CUTSTATUS_HH_ */
3 changes: 2 additions & 1 deletion Cpp/Library/Data/DataFrame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
namespace Nymph
{
DataFrame::DataFrame() :
fDataObjects()
fDataObjects(),
fCuts()
{}

DataFrame::~DataFrame()
Expand Down
8 changes: 7 additions & 1 deletion Cpp/Library/Data/DataFrame.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define NYMPH_DATAFRAME_HH_

#include "Data.hh"
#include "CutStatus.hh"
#include "Exception.hh"

#include "MemberVariable.hh"
Expand Down Expand Up @@ -40,10 +41,12 @@ namespace Nymph

@author N. S. Oblath

@brief Container for Data objects used during data processing
@brief Container for Data objects and their cut information used during data processing

@details
Individual Data objects are held in an unordered map, indexed by type.
A CutStatus object contains cut information in an ordered map, with keys of cut name.
The CutStatus describes the latest/most processed data object in the dataframe, and is updated as new data objects are added with more cuts.

*/
class DataFrame
Expand Down Expand Up @@ -95,6 +98,9 @@ namespace Nymph
// typedef used to avoid problems with the comma in the MEMVAR macro
typedef std::unordered_map< std::type_index, std::unique_ptr<Data> > DataMap;
MEMVAR_REF( DataMap, DataObjects );

// CutStatus object for storing cut information
CutStatus fCuts;
};


Expand Down
11 changes: 11 additions & 0 deletions Cpp/Library/Data/README_future_work.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This branch reworked CutStatus into an ordered map. CutResult is replaced with a map definition within CutStatus. CutStatus is stored as a member object in DataFrame.
Potential improvements:
- Replace the bool values of the CutStatus map with pair of (bool, string) so a description can be added.
- May need to restore CutResult.hh, and move the map definition there. Could be needed in future Cut.hh

Further Cut work to be done:
- CutFilter.hh and ApplyCut.hh should be updated next.
-- See Nymph/Cpp/Library_v1/Data/KTCutFilter.hh
-- and Nymph/Cpp/Library_v1/Data/KTApplyCut.hh
- Cut.hh may also need updating

2 changes: 2 additions & 0 deletions Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ set( testing_SOURCES
${CPP_DIR}/TestSingleRunController.cc
${CPP_DIR}/TestSlotData.cc
${CPP_DIR}/UseCatch.cc
# Ben adding tests
${CPP_DIR}/TestCut.cc
)

set( lib_dependencies
Expand Down
Loading