From ed83cb4ec7de3c3b7987d6be013fc3eae8b79acb Mon Sep 17 00:00:00 2001 From: benanator77 Date: Tue, 30 Jan 2024 12:56:07 -0800 Subject: [PATCH 01/11] Making Ben version of DataCutPort branch, branched from Nymph2_2/Develop --- .gitignore | 3 + Cpp/Library/Data/CutResult.hh | 43 +++++ Cpp/Library/Data/CutStatus.cc | 118 +++++++++++++ Cpp/Library/Data/CutStatus.hh | 306 ++++++++++++++++++++++++++++++++++ Testing/Cpp/TestCutBen.cc | 83 +++++++++ 5 files changed, 553 insertions(+) create mode 100644 Cpp/Library/Data/CutResult.hh create mode 100644 Cpp/Library/Data/CutStatus.cc create mode 100644 Cpp/Library/Data/CutStatus.hh create mode 100644 Testing/Cpp/TestCutBen.cc diff --git a/.gitignore b/.gitignore index df5fd5ce..2567bd0a 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,6 @@ build*/ dist*/ Python/*.egg-info __pycache__ + +# untracked directory +untracked*/ diff --git a/Cpp/Library/Data/CutResult.hh b/Cpp/Library/Data/CutResult.hh new file mode 100644 index 00000000..62818ff2 --- /dev/null +++ b/Cpp/Library/Data/CutResult.hh @@ -0,0 +1,43 @@ +/* + * CutResult.hh + * + * Created on: Sept 19, 2014 + * Author: nsoblath + */ + +#ifndef CUTRESULT_HH_ +#define CUTRESULT_HH_ + +#include +#include + +namespace Nymph +{ + typedef std::map< std::string, bool > CutResult; + typedef CutResult::value_type fCutVal; + // This might be enough. gives key fName to return bool of if cut + // ::value_type is just the pair value type def used to initiate the map + // so give fCutVal( fName, value) and then insert into CutResult + +/* struct CutResult + { + std::string fName; + bool fState; + bool fAssigned; + CutResult() : fName(), fState( false ), fAssigned( false ) {} + CutResult( const std::string& name, bool state ) : fName( name ), fState( state ), fAssigned( true ) {} + }; + + struct CheckCutResultName + { + std::string fName; + CheckCutResultName( const std::string& name ) : fName( name ) {} + bool operator()( const CutResult& result ) + { + return result.fName == fName; + } + }; +*/ +} /* namespace Nymph */ + +#endif /* CUTRESULT_HH_ */ diff --git a/Cpp/Library/Data/CutStatus.cc b/Cpp/Library/Data/CutStatus.cc new file mode 100644 index 00000000..9b50cb43 --- /dev/null +++ b/Cpp/Library/Data/CutStatus.cc @@ -0,0 +1,118 @@ +/* + * CutStatus.cc + * + * Created on: Aug 24, 2012 + * Author: nsoblath + */ + +#include "CutStatus.hh" + +//#include "KTExtensibleStructFactory.hh" +#include "Logger.hh" + +namespace Nymph +{ + LOGGER(cutlog, "Cut"); + + CutStatus::CutStatus() : + fCutResults(), + fSummary() + { + } + + CutStatus::CutStatus(const CutStatus& orig) : + fCutResults(orig.fCutResults), + fSummary() + { + UpdateStatus(); + } + + CutStatus::~CutStatus() + {} + + CutStatus& CutStatus::operator=(const CutStatus& rhs) + { + fCutResults = rhs.fCutResults; + UpdateStatus(); + return *this; + } + + // Ben: above is constructors for different argument cases (empty, const cutstatus, reference). Shouldn't need to change. + + // Ben: This one needs to change. shouldn't need mask with maps. +/* void CutStatus::AssignCutResult(unsigned maskPos, const std::string& name, bool state, bool doUpdateStatus) + { + LDEBUG(cutlog, "Assigning cut result <" << name << "> to position <" << maskPos << "> with state <" << state << ">"); + if( maskPos >= fCutResults.size() ) + { + fCutResults.resize( maskPos + 1 ); + } + LDEBUG(cutlog, "Cut result size is now <" << fCutResults.size() << ">"); + if( fCutResults[maskPos].fAssigned ) + { + throw Exception() << "Mask position <" << maskPos << "> has already been assigned"; + } + fCutResults[maskPos].fName = name; + fCutResults[maskPos].fState = state; + fCutResults[maskPos].fAssigned = true; + if( doUpdateStatus ) UpdateStatus(); + return; + } +*/ + // Ben: map version. Not sure if need the doUpdateStatus part tho + void CutStatus::AssignCutResult(const std::string& name, bool state, bool doUpdateStatus) + { + LDEBUG(cutlog, "Assigning cut result <" << name << "> with state <" << state << ">"); + // Ben: don't think I need the resize stuff, happens automatically with maps + if( fCutResults.find(name) != fCutResults.end()) + { + throw Exception() << "Cut with name: " << name << " has already been assigned"; + } + fCutResults.insert(make_pair(name,state)); + LDEBUG(cutlog, "Cut result size is now: " << fCutResults.size() ); + if( doUpdateStatus ) UpdateStatus(); + return; + } // Ben: Should be fully adjusted, might need fixing for the update status stuff + + // Ben: displays map keys and vals with ostream. + void CutStatus::UpdateStatus() + { + LDEBUG(cutlog, "Updating cut summary"); + unsigned nCuts = fCutResults.size(); + //fSummary.resize(nCuts, false); // now just a string + + // loop through to set cuts + LDEBUG(cutlog, "nCuts: " << nCuts); + for (unsigned iCut = 0; iCut < nCuts; ++iCut) // I think this still works for map. I believe map[iterator] bring up ith key/value + { + //fSummary[iCut] = fCutResults[iCut].fName && fCutResults[iCut].fState; + if(fCutResults[iCut]->second == 1) // may need to change iCut to iterator type + { + fSummary.append(fCutResults[iCut]->first; + } + } + LDEBUG(cutlog, "Cut summary: " << fSummary); + return; + } + + std::string CutStatus::CutResultsPresent() const + { + std::string cutsPresent; + for (auto cutIt = fCutResults.cbegin(); cutIt != fCutResults.cend(); ++cutIt) + { + if ((! cutIt->first.empty()) && (cutIt->second == 1)) + { + cutsPresent = cutIt->first + " " + cutsPresent; // TODO still need to change this to using vector of strings? + } + } + return cutsPresent; + } + + std::ostream& operator<<(std::ostream& out, const CutStatus& status) + { + out << "Cut summary: " << status.fSummary << '\n'; + return out; + } + + +} /* namespace Nymph */ diff --git a/Cpp/Library/Data/CutStatus.hh b/Cpp/Library/Data/CutStatus.hh new file mode 100644 index 00000000..2b54dc94 --- /dev/null +++ b/Cpp/Library/Data/CutStatus.hh @@ -0,0 +1,306 @@ +/* + * CutStatus.hh + * + * Created on: Sept 19, 2014 + * Author: nsoblath + */ + +#ifndef CUTSTATUS_HH_ +#define CUTSTATUS_HH_ + + +#include "CutResult.hh" + +#include "Exception.hh" + +//#include "cereal/access.hpp" +//#include "cereal/types/string.hpp" +//#include "cereal/types/vector.hpp" + +#include + +#include +#include +#include + +namespace Nymph +{ + /*! + @class CutStatus + @author N. S. Oblath + + @brief Provides easy access to cut result information. + + @details + The cut results can be imagined as an array of booleans, specifying whether the cut was passed: [true, false, false, true, . . . ]. + + Cuts are assigned both an array position (non-negative integer) and a name (string) before or when the results are set. + + CutStatus is typically used as a member variable of CoreData, the top-level data object. + + CutStatus owns the set of CutResults that have been added to a data object. + It also owns a summary of those cuts (implemented with boost::dynamic_bitset). + + You can check if the data has been cut with the IsCut functions. + - IsCut() returns true if any cut results are true; + - IsCut(const bitset_type& mask), IsCut(unsigned int mask), and IsCut(const std::string& mask) allow you to specify + a cut mask, and return true if any of the cut results specified by the mask are true. + + When specifying a cut mask, bits set to true specify cuts that should be used: + - bitset_type is boost::dynamic_bitset; + - unsigned integer masks use the bits of the integer; + - std::string masks are strings with each character either a 0 or 1. + + With CutStatus you can interact with individual cut results in the following ways: + - Get the number of cut results with size(), + - Get a reference to the cut results with CutResults(), + - If you need to manually update the cut status bitset, use UpdateStatus(), + - Add cut results to a data object 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(), and + - Set the value of a cut result with SetCutState(), + + Cut results can typically be accessed by either name or mask position. + */ + + class CutStatus + { + public: + //typedef boost::dynamic_bitset< > bitset_type; + + //typedef std::vector< CutResult > CutResults_t; + + //typedef CutResults_t::iterator CutResultsIt; + //typedef CutResults_t::const_iterator CutResultsCIt; + + // Ben: With CutResult map, shouldn't need to mess with the vector ? + typedef CutResult::iterator CutResultIt; // map iterator + typedef CutResult::const_iterator CutResultCIt; // map const iterator + + public: // Ben: Below initiates operators, shouldn't need to mess with this, just in the actual operator defns how they interact with the maps. + CutStatus(); + CutStatus(const CutStatus& orig); + ~CutStatus(); + + CutStatus& operator=(const CutStatus& rhs); + + /// Returns the size of the cut results vector + size_t size() const; + + /// Returns a reference to the cut results vector + const CutResults_t& CutResults() const; + + /// Updates the summary bitset from the cut results vector + void UpdateStatus(); + + /// Adds a new cut result with the specified name; throws Exception if a cut with that name already exists + void AssignCutResult(const std::string& name, bool state=false, bool doUpdateStatus=true); + + /// Removes the cut by erasing the name and setting the state to false + void RemoveCutResult(const std::string& cutName, bool doUpdateStatus=true); + /// Removes the cut by erasing the name and setting the state to false + //void RemoveCutResult(unsigned maskPos, bool doUpdateStatus=true); + + 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 whether or not the specified cut is present (whether or not it has been explicitly assigned) + //bool HasCutResult(unsigned maskPos) const; + + /// Returns the state of the named cut; throws Exception if it doesn't exist + bool GetCutState(const std::string& cutName) const; + /// Returns the state of the specified cut; throws Exception if it doesn't exist + //bool GetCutState(unsigned maskPos) const; + + /// Sets the state of the specified cut; throws Exception if it doesn't exist + void SetCutState(const std::string& cutName, bool state, bool doUpdateStatus=true); + /// Sets the state of the specified cut; throws Exception if it doesn't exist + //void SetCutState(unsigned maskPos, bool state, bool doUpdateStatus=true); + + /// Returns a string with the names of the cuts that are present in bitset order + std::string CutResultsPresent() const; + + private: + friend std::ostream& operator<<(std::ostream& out, const CutStatus& status); + + CutResults_t fCutResults; + + //bitset_type fSummary; // Need to change from bitset to vector of strings or similar. Can potentially skip and directly cout map vals + std::string fSummary; // string containing names of only cuts that have been applied, separated by _ + + public: + bool IsCut() const; + //bool IsCut(const bitset_type& mask) const; + //bool IsCut(unsigned long long mask) const; + bool IsCut(const std::string& mask) const; + + //bitset_type ToBitset(unsigned long long mask) const; + //bitset_type ToBitset(const std::string& mask) const; + + private: +//------SerialRemoved--------- +/* + friend class cereal::access; + + template< class Archive > + void save( Archive& ar ) const; + + template< class Archive > + void load( Archive& ar ); +*/ + }; + + std::ostream& operator<<(std::ostream& out, const CutStatus& status); + + // Ben: TODO Likely need to edit below lines + + inline const CutStatus::CutResults_t& CutStatus::CutResults() const + { + return fCutResults; + } + + inline CutStatus::CutResultsIt CutStatus::FindCutResult( const std::string& name ) + { + if( name.empty() ) return fCutResults.end(); + //return std::find_if( fCutResults.begin(), fCutResults.end(), CheckCutResultName(name) ); + return fCutResults.at(name); + } + + inline CutStatus::CutResultsCIt CutStatus::FindCutResultC( const std::string& name ) const + { + if( name.empty() ) return fCutResults.cend(); + //return std::find_if( fCutResults.cbegin(), fCutResults.cend(), CheckCutResultName(name) ); + return fCutResults.at(name); + } + + inline CutStatus::CutResultsIt CutStatus::CutResultsEnd() + { + return fCutResults.end(); + } + + inline CutStatus::CutResultsCIt CutStatus::CutResultsEndC() const + { + return fCutResults.cend(); + } + + inline bool CutStatus::HasCutResult( const std::string& name ) const + { + //return FindCutResultC(name) != std::end(fCutResults); + return fCutResults.find(name) != fCutResults.end(); + } +/* + inline bool CutStatus::HasCutResult( unsigned maskPos ) const + { + return maskPos < fCutResults.size() && fCutResults[maskPos].fAssigned; + } +*/ + inline bool CutStatus::GetCutState( const std::string& name ) const + { + //CutResultsCIt cutIt = FindCutResultC(name); + if (fCutResults.find(name) != fCutResults.end()) + { + return fCutResults.at(name); + } + throw Exception() << "Unable to find cut <" << name << ">"; + } +/* + inline bool CutStatus::GetCutState( unsigned maskPos ) const + { + if (maskPos < fCutResults.size()) + { + return fCutResults[maskPos].fState; + } + throw Exception() << "Mask position <" << maskPos << "> is out of range (only " << size() << " cuts are present)"; + } +*/ + inline void CutStatus::SetCutState(const std::string& name, bool state, bool doUpdateStatus) + { + //CutResultsIt cutIt = FindCutResult(name); + if (fCutResults.find(name) != fCutResults.end()) + { + fCutResults.insert(make_pair(name,state)); + if (doUpdateStatus) UpdateStatus(); + return; + } + throw Exception() << "Unable to find cut <" << name << ">"; + } + + inline void CutStatus::SetCutState(unsigned maskPos, bool state, bool doUpdateStatus) + { + if (maskPos < fCutResults.size()) + { + fCutResults[maskPos].fState = state; + if (doUpdateStatus) UpdateStatus(); + return; + } + throw Exception() << "Mask position <" << maskPos << "> is out of range (only "<< size() << " cuts are present)"; + } + + inline void CutStatus::RemoveCutResult(const std::string& name, bool doUpdateStatus) + { + if (fCutResults.find(name) == fCutResults.end()) + { + fCutResults.erase(name); + } + if (doUpdateStatus) UpdateStatus(); + return; + } + // Ben: think I have to require removal by key name +/* + inline void CutStatus::RemoveCutResult(unsigned maskPos, bool doUpdateStatus) + { + if (maskPos < fCutResults.size()) + { + fCutResults[maskPos].fName = ""; + fCutResults[maskPos].fState = false; + } + if (doUpdateStatus) UpdateStatus(); + return; + } +*/ + inline size_t CutStatus::size() const + { + //return fSummary.size(); // This won't work with fSummary now a string + return fCutResults.size(); + } + + inline bool CutStatus::IsCut() const + { + return !fSummary.empty(); // This still works with fSummary now a string + } +// dont think i need anything with mask anymore +/* + inline bool CutStatus::IsCut(const bitset_type& mask) const + { + return (fSummary & mask).any(); + } + + inline bool CutStatus::IsCut(unsigned long long mask) const + { + return IsCut(ToBitset(mask)); + } + + inline bool CutStatus::IsCut(const std::string& mask) const + { + return IsCut(ToBitset(mask)); + } + + inline CutStatus::bitset_type CutStatus::ToBitset(unsigned long long mask) const + { + return bitset_type(fSummary.size(), mask); + } + + inline CutStatus::bitset_type CutStatus::ToBitset(const std::string& mask) const + { + return bitset_type(mask); + } +*/ +} /* namespace Nymph */ + +#endif /* CUTSTATUS_HH_ */ diff --git a/Testing/Cpp/TestCutBen.cc b/Testing/Cpp/TestCutBen.cc new file mode 100644 index 00000000..66ed3d8d --- /dev/null +++ b/Testing/Cpp/TestCutBen.cc @@ -0,0 +1,83 @@ +/* + * TestCut.cc + * + * Created on: Sep 29, 2014 + * Author: nsoblath + */ + +#include "TestCuts.hh" + +#include "Logger.hh" +#include "TestData.hh" + +LOGGER(testlog, "TestCut"); + +using namespace Nymph; +using namespace std; + +int main() +{ + try + { + ExtCoreData data; + TestDataExt testData("test"); + + CutStatus& cutStatus = data.GetCutStatus(); + + LINFO(testlog, "Assigning awesome-cut"); + //unsigned awesomeCutPos = 0; + string awesomeCutName("awesome-cut"); + //cutStatus.AssignCutResult(awesomeCutPos, awesomeCutName); + cutStatus.AssignCutResult(awesomeCutName,1,1); + + LINFO(testlog, "Initial cut state: " << cutStatus.IsCut()); + + LINFO(testlog, "Applying awesome cut"); + AwesomeCut cut(awesomeCutName); + cut.Apply(data, testData); + + LINFO(testlog, "Cuts present: " << cutStatus.CutResultsPresent()) + LINFO(testlog, "Has cut result <" << awesomeCutName << ">? " << cutStatus.HasCutResult(awesomeCutName)); + //LINFO(testlog, "Has cut result at " << awesomeCutPos << "? " << cutStatus.HasCutResult(awesomeCutPos)); + LINFO(testlog, "Cut state of <" << awesomeCutName << ">is: " << cutStatus.GetCutState(awesomeCutName)); + //LINFO(testlog, "Cut state at " << awesomeCutPos << " is: " << cutStatus.GetCutState(awesomeCutPos)); + LINFO(testlog, "Is cut (all results)? " << cutStatus.IsCut()); + LINFO(testlog, "Current cut status: " << cutStatus); + //LINFO(testlog, "Is cut (with mask \"0\")? " << cutStatus.IsCut("0")); + + LINFO(testlog, "Assigning not-awesome-cut"); + //unsigned notAwesomeCutPos = 1; + string notAwesomeCutName("not-awesome-cut"); + //cutStatus.AssignCutResult(notAwesomeCutPos, notAwesomeCutName); + cutStatus.AssignCutResult(notAwesomeCutName,1,1); + + LINFO(testlog, "Applying not-awesome cut"); + NotAwesomeCut naCut(notAwesomeCutName); + naCut.Apply(data, testData); + + LINFO(testlog, "Cuts present: " << cutStatus.CutResultsPresent()) + LINFO(testlog, "Has cut result <" << awesomeCutName << ">? " << cutStatus.HasCutResult(awesomeCutName)); + //LINFO(testlog, "Has cut result at " << awesomeCutPos << "? " << cutStatus.HasCutResult(awesomeCutPos)); + LINFO(testlog, "Cut state of <" << awesomeCutName << "> is: " << cutStatus.GetCutState(awesomeCutName)); + //LINFO(testlog, "Cut state at " << awesomeCutPos << " is: " << cutStatus.GetCutState(awesomeCutPos)); + LINFO(testlog, "Has cut result <" << notAwesomeCutName << ">? " << cutStatus.HasCutResult(notAwesomeCutName)); + //LINFO(testlog, "Has cut result at " << notAwesomeCutPos << "? " << cutStatus.HasCutResult(notAwesomeCutPos)); + LINFO(testlog, "Cut state of <" << notAwesomeCutName << "> is: " << cutStatus.GetCutState(notAwesomeCutName)); + LINFO(testlog, "Cut state at " << notAwesomeCutPos << " is: " << cutStatus.GetCutState(notAwesomeCutPos)); + LINFO(testlog, "Is cut (all results)? " << cutStatus.IsCut()); + //LINFO(testlog, "Is cut with mask \"00\"? " << cutStatus.IsCut("00")); + //LINFO(testlog, "Is cut with mask \"01\"? " << cutStatus.IsCut("01")); + //LINFO(testlog, "Is cut with mask \"10\"? " << cutStatus.IsCut("10")); + //LINFO(testlog, "Is cut with mask \"11\"? " << cutStatus.IsCut("11")); + //LINFO(testlog, "Is cut with mask 0? " << cutStatus.IsCut(0)); + //LINFO(testlog, "Is cut with mask 1? " << cutStatus.IsCut(1)); + //LINFO(testlog, "Is cut with mask 2? " << cutStatus.IsCut(2)); + //LINFO(testlog, "Is cut with mask 3? " << cutStatus.IsCut(3)); + } + catch(std::exception& e) + { + LERROR(testlog, "Exception caught: " << e.what()); + } + + return 0; +} From b5ffa164a6d0c5c8f29b4bf84cb8e02246af5326 Mon Sep 17 00:00:00 2001 From: benanator77 Date: Tue, 13 Feb 2024 14:41:34 -0800 Subject: [PATCH 02/11] Revamped CutStatus, nearly able to compile to run tests. CutResult incorporated into CutStatus. --- Cpp/Library/Data/CutResult.hh | 4 +- Cpp/Library/Data/CutStatus.cc | 41 +++++----- Cpp/Library/Data/CutStatus.hh | 144 +++++++++++++--------------------- Testing/CMakeLists.txt | 2 + Testing/Cpp/TestCutBen.cc | 83 -------------------- 5 files changed, 81 insertions(+), 193 deletions(-) delete mode 100644 Testing/Cpp/TestCutBen.cc diff --git a/Cpp/Library/Data/CutResult.hh b/Cpp/Library/Data/CutResult.hh index 62818ff2..32d73fed 100644 --- a/Cpp/Library/Data/CutResult.hh +++ b/Cpp/Library/Data/CutResult.hh @@ -13,8 +13,8 @@ namespace Nymph { - typedef std::map< std::string, bool > CutResult; - typedef CutResult::value_type fCutVal; + typedef std::map< std::string, bool > CutResult_t; + typedef CutResult_t::value_type fCutVal; // This might be enough. gives key fName to return bool of if cut // ::value_type is just the pair value type def used to initiate the map // so give fCutVal( fName, value) and then insert into CutResult diff --git a/Cpp/Library/Data/CutStatus.cc b/Cpp/Library/Data/CutStatus.cc index 9b50cb43..c4472e9f 100644 --- a/Cpp/Library/Data/CutStatus.cc +++ b/Cpp/Library/Data/CutStatus.cc @@ -6,7 +6,6 @@ */ #include "CutStatus.hh" - //#include "KTExtensibleStructFactory.hh" #include "Logger.hh" @@ -15,16 +14,13 @@ namespace Nymph LOGGER(cutlog, "Cut"); CutStatus::CutStatus() : - fCutResults(), - fSummary() + CutResults(), { } CutStatus::CutStatus(const CutStatus& orig) : - fCutResults(orig.fCutResults), - fSummary() + CutResults(orig.CutResults), { - UpdateStatus(); } CutStatus::~CutStatus() @@ -33,7 +29,6 @@ namespace Nymph CutStatus& CutStatus::operator=(const CutStatus& rhs) { fCutResults = rhs.fCutResults; - UpdateStatus(); return *this; } @@ -60,22 +55,21 @@ namespace Nymph } */ // Ben: map version. Not sure if need the doUpdateStatus part tho - void CutStatus::AssignCutResult(const std::string& name, bool state, bool doUpdateStatus) + void CutStatus::AssignCutResult(const std::string& cutName, bool state) { - LDEBUG(cutlog, "Assigning cut result <" << name << "> with state <" << state << ">"); + LDEBUG(cutlog, "Assigning cut result <" << cutName << "> with state <" << state << ">"); // Ben: don't think I need the resize stuff, happens automatically with maps - if( fCutResults.find(name) != fCutResults.end()) + if( fCutResults.find(cutName) != fCutResults.end()) { - throw Exception() << "Cut with name: " << name << " has already been assigned"; + throw Exception() << "Cut with name: " << cutName << " has already been assigned"; } - fCutResults.insert(make_pair(name,state)); + fCutResults.insert(make_pair(cutName,state)); LDEBUG(cutlog, "Cut result size is now: " << fCutResults.size() ); - if( doUpdateStatus ) UpdateStatus(); return; - } // Ben: Should be fully adjusted, might need fixing for the update status stuff + } // Ben: displays map keys and vals with ostream. - void CutStatus::UpdateStatus() +/* void CutStatus::UpdateStatus() { LDEBUG(cutlog, "Updating cut summary"); unsigned nCuts = fCutResults.size(); @@ -93,16 +87,17 @@ namespace Nymph } LDEBUG(cutlog, "Cut summary: " << fSummary); return; - } + }*/ - std::string CutStatus::CutResultsPresent() const + std::vector< std::string > CutStatus::CutResultsPresent() const { - std::string cutsPresent; + std::vector< std::string > cutsPresent; for (auto cutIt = fCutResults.cbegin(); cutIt != fCutResults.cend(); ++cutIt) { if ((! cutIt->first.empty()) && (cutIt->second == 1)) { - cutsPresent = cutIt->first + " " + cutsPresent; // TODO still need to change this to using vector of strings? + //cutsPresent = cutIt->first + " " + cutsPresent; // TODO still need to change this to using vector of strings? + cutsPresent.push_back(cutIt->first); } } return cutsPresent; @@ -110,7 +105,13 @@ namespace Nymph std::ostream& operator<<(std::ostream& out, const CutStatus& status) { - out << "Cut summary: " << status.fSummary << '\n'; + out << "Cut summary: " << '\n'; + std::vector< std::string > cuts = status.CutResultsPresent(); + for (auto cutIt = cuts.cbegin(); cutIt != cuts.cend(); ++cutIt) + { + out << cuts[cutIt] << "; "; + } + out << '\n'; return out; } diff --git a/Cpp/Library/Data/CutStatus.hh b/Cpp/Library/Data/CutStatus.hh index 2b54dc94..d68bcad0 100644 --- a/Cpp/Library/Data/CutStatus.hh +++ b/Cpp/Library/Data/CutStatus.hh @@ -8,8 +8,11 @@ #ifndef CUTSTATUS_HH_ #define CUTSTATUS_HH_ +#include +#include +#include -#include "CutResult.hh" +//#include "CutResult.hh" #include "Exception.hh" @@ -17,12 +20,6 @@ //#include "cereal/types/string.hpp" //#include "cereal/types/vector.hpp" -#include - -#include -#include -#include - namespace Nymph { /*! @@ -67,16 +64,13 @@ namespace Nymph class CutStatus { public: - //typedef boost::dynamic_bitset< > bitset_type; - - //typedef std::vector< CutResult > CutResults_t; - - //typedef CutResults_t::iterator CutResultsIt; - //typedef CutResults_t::const_iterator CutResultsCIt; - - // Ben: With CutResult map, shouldn't need to mess with the vector ? - typedef CutResult::iterator CutResultIt; // map iterator - typedef CutResult::const_iterator CutResultCIt; // map const iterator + //CutStatus() : CutResults(); + typedef std::map< std::string, bool > CutResults_t; + typedef CutResults_t::iterator CutResultsIt; + typedef CutResults_t::const_iterator CutResultsCIt; + + //private: + //std::map< std::string, bool > CutResults; public: // Ben: Below initiates operators, shouldn't need to mess with this, just in the actual operator defns how they interact with the maps. CutStatus(); @@ -85,22 +79,17 @@ namespace Nymph CutStatus& operator=(const CutStatus& rhs); - /// Returns the size of the cut results vector + /// Returns the size of the cut results map size_t size() const; - /// Returns a reference to the cut results vector - const CutResults_t& CutResults() const; - - /// Updates the summary bitset from the cut results vector - void UpdateStatus(); + /// 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& name, bool state=false, bool doUpdateStatus=true); + 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, bool doUpdateStatus=true); - /// Removes the cut by erasing the name and setting the state to false - //void RemoveCutResult(unsigned maskPos, bool doUpdateStatus=true); + void RemoveCutResult(const std::string& cutName); CutResultsIt FindCutResult(const std::string& cutName); CutResultsCIt FindCutResultC(const std::string& cutName) const; @@ -110,18 +99,12 @@ namespace Nymph /// Returns whether or not the specified cut is present bool HasCutResult(const std::string& cutName) const; - /// Returns whether or not the specified cut is present (whether or not it has been explicitly assigned) - //bool HasCutResult(unsigned maskPos) const; /// Returns the state of the named cut; throws Exception if it doesn't exist bool GetCutState(const std::string& cutName) const; - /// Returns the state of the specified cut; throws Exception if it doesn't exist - //bool GetCutState(unsigned maskPos) const; /// Sets the state of the specified cut; throws Exception if it doesn't exist - void SetCutState(const std::string& cutName, bool state, bool doUpdateStatus=true); - /// Sets the state of the specified cut; throws Exception if it doesn't exist - //void SetCutState(unsigned maskPos, bool state, bool doUpdateStatus=true); + void SetCutState(const std::string& cutName, bool state); /// Returns a string with the names of the cuts that are present in bitset order std::string CutResultsPresent() const; @@ -129,54 +112,37 @@ namespace Nymph private: friend std::ostream& operator<<(std::ostream& out, const CutStatus& status); + //CutResults_t CutResults; // TODO might need a map fCutResult to replace this vector defn CutResults_t fCutResults; //bitset_type fSummary; // Need to change from bitset to vector of strings or similar. Can potentially skip and directly cout map vals - std::string fSummary; // string containing names of only cuts that have been applied, separated by _ + //std::string fSummary; // string containing names of only cuts that have been applied, separated by _ public: bool IsCut() const; - //bool IsCut(const bitset_type& mask) const; - //bool IsCut(unsigned long long mask) const; bool IsCut(const std::string& mask) const; + int NumCuts() const; - //bitset_type ToBitset(unsigned long long mask) const; - //bitset_type ToBitset(const std::string& mask) const; - - private: -//------SerialRemoved--------- -/* - friend class cereal::access; - - template< class Archive > - void save( Archive& ar ) const; - - template< class Archive > - void load( Archive& ar ); -*/ }; std::ostream& operator<<(std::ostream& out, const CutStatus& status); // Ben: TODO Likely need to edit below lines - inline const CutStatus::CutResults_t& CutStatus::CutResults() const + 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& name ) + inline CutStatus::CutResultsIt CutStatus::FindCutResult( const std::string& cutName ) { - if( name.empty() ) return fCutResults.end(); - //return std::find_if( fCutResults.begin(), fCutResults.end(), CheckCutResultName(name) ); - return fCutResults.at(name); + //if( cutName.empty() ) return CutResults.end(); // Don't think I need this, map::find should return map::end if empty + return fCutResults.find(cutName); } - inline CutStatus::CutResultsCIt CutStatus::FindCutResultC( const std::string& name ) const + inline CutStatus::CutResultsCIt CutStatus::FindCutResultC( const std::string& cutName ) const { - if( name.empty() ) return fCutResults.cend(); - //return std::find_if( fCutResults.cbegin(), fCutResults.cend(), CheckCutResultName(name) ); - return fCutResults.at(name); + return fCutResults.find(cutName); } inline CutStatus::CutResultsIt CutStatus::CutResultsEnd() @@ -189,25 +155,24 @@ namespace Nymph return fCutResults.cend(); } - inline bool CutStatus::HasCutResult( const std::string& name ) const + inline bool CutStatus::HasCutResult( const std::string& cutName ) const { - //return FindCutResultC(name) != std::end(fCutResults); - return fCutResults.find(name) != fCutResults.end(); + return fCutResults.count(cutName); } -/* - inline bool CutStatus::HasCutResult( unsigned maskPos ) const + + /*inline bool CutStatus::HasCutResult( unsigned mapPos ) const { - return maskPos < fCutResults.size() && fCutResults[maskPos].fAssigned; - } -*/ - inline bool CutStatus::GetCutState( const std::string& name ) const + //return maskPos < fCutResults.size() && fCutResults[maskPos].fAssigned; + return mapPos < fCutResults.end() && fCutResults + }*/ + + inline bool CutStatus::GetCutState( const std::string& cutName ) const { - //CutResultsCIt cutIt = FindCutResultC(name); - if (fCutResults.find(name) != fCutResults.end()) + if (fCutResults.find(cutName) != fCutResults.end()) { - return fCutResults.at(name); + return fCutResults.at(cutName); } - throw Exception() << "Unable to find cut <" << name << ">"; + throw Exception() << "Unable to find cut <" << cutName << ">"; } /* inline bool CutStatus::GetCutState( unsigned maskPos ) const @@ -219,19 +184,17 @@ namespace Nymph throw Exception() << "Mask position <" << maskPos << "> is out of range (only " << size() << " cuts are present)"; } */ - inline void CutStatus::SetCutState(const std::string& name, bool state, bool doUpdateStatus) + inline void CutStatus::SetCutState(const std::string& cutName, bool state) { - //CutResultsIt cutIt = FindCutResult(name); - if (fCutResults.find(name) != fCutResults.end()) + if (fCutResults.find(cutName) != fCutResults.end()) { - fCutResults.insert(make_pair(name,state)); - if (doUpdateStatus) UpdateStatus(); + fCutResults.insert(make_pair(cutName,state)); return; } - throw Exception() << "Unable to find cut <" << name << ">"; + throw Exception() << "Unable to find cut <" << cutName << ">"; } - inline void CutStatus::SetCutState(unsigned maskPos, bool state, bool doUpdateStatus) +/* inline void CutStatus::SetCutState(unsigned maskPos, bool state, bool doUpdateStatus) { if (maskPos < fCutResults.size()) { @@ -241,17 +204,16 @@ namespace Nymph } throw Exception() << "Mask position <" << maskPos << "> is out of range (only "<< size() << " cuts are present)"; } - - inline void CutStatus::RemoveCutResult(const std::string& name, bool doUpdateStatus) +*/ + inline void CutStatus::RemoveCutResult(const std::string& cutName) { - if (fCutResults.find(name) == fCutResults.end()) + if (fCutResults.find(cutName) == fCutResults.end()) { - fCutResults.erase(name); + fCutResults.erase(cutName); } - if (doUpdateStatus) UpdateStatus(); return; } - // Ben: think I have to require removal by key name + // Ben: can remove by iterator position, but won't for consistency /* inline void CutStatus::RemoveCutResult(unsigned maskPos, bool doUpdateStatus) { @@ -266,13 +228,19 @@ namespace Nymph */ inline size_t CutStatus::size() const { - //return fSummary.size(); // This won't work with fSummary now a string return fCutResults.size(); } inline bool CutStatus::IsCut() const { - return !fSummary.empty(); // This still works with fSummary now a string + 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; } // dont think i need anything with mask anymore /* diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index e883ad9e..b167b43e 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -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 diff --git a/Testing/Cpp/TestCutBen.cc b/Testing/Cpp/TestCutBen.cc deleted file mode 100644 index 66ed3d8d..00000000 --- a/Testing/Cpp/TestCutBen.cc +++ /dev/null @@ -1,83 +0,0 @@ -/* - * TestCut.cc - * - * Created on: Sep 29, 2014 - * Author: nsoblath - */ - -#include "TestCuts.hh" - -#include "Logger.hh" -#include "TestData.hh" - -LOGGER(testlog, "TestCut"); - -using namespace Nymph; -using namespace std; - -int main() -{ - try - { - ExtCoreData data; - TestDataExt testData("test"); - - CutStatus& cutStatus = data.GetCutStatus(); - - LINFO(testlog, "Assigning awesome-cut"); - //unsigned awesomeCutPos = 0; - string awesomeCutName("awesome-cut"); - //cutStatus.AssignCutResult(awesomeCutPos, awesomeCutName); - cutStatus.AssignCutResult(awesomeCutName,1,1); - - LINFO(testlog, "Initial cut state: " << cutStatus.IsCut()); - - LINFO(testlog, "Applying awesome cut"); - AwesomeCut cut(awesomeCutName); - cut.Apply(data, testData); - - LINFO(testlog, "Cuts present: " << cutStatus.CutResultsPresent()) - LINFO(testlog, "Has cut result <" << awesomeCutName << ">? " << cutStatus.HasCutResult(awesomeCutName)); - //LINFO(testlog, "Has cut result at " << awesomeCutPos << "? " << cutStatus.HasCutResult(awesomeCutPos)); - LINFO(testlog, "Cut state of <" << awesomeCutName << ">is: " << cutStatus.GetCutState(awesomeCutName)); - //LINFO(testlog, "Cut state at " << awesomeCutPos << " is: " << cutStatus.GetCutState(awesomeCutPos)); - LINFO(testlog, "Is cut (all results)? " << cutStatus.IsCut()); - LINFO(testlog, "Current cut status: " << cutStatus); - //LINFO(testlog, "Is cut (with mask \"0\")? " << cutStatus.IsCut("0")); - - LINFO(testlog, "Assigning not-awesome-cut"); - //unsigned notAwesomeCutPos = 1; - string notAwesomeCutName("not-awesome-cut"); - //cutStatus.AssignCutResult(notAwesomeCutPos, notAwesomeCutName); - cutStatus.AssignCutResult(notAwesomeCutName,1,1); - - LINFO(testlog, "Applying not-awesome cut"); - NotAwesomeCut naCut(notAwesomeCutName); - naCut.Apply(data, testData); - - LINFO(testlog, "Cuts present: " << cutStatus.CutResultsPresent()) - LINFO(testlog, "Has cut result <" << awesomeCutName << ">? " << cutStatus.HasCutResult(awesomeCutName)); - //LINFO(testlog, "Has cut result at " << awesomeCutPos << "? " << cutStatus.HasCutResult(awesomeCutPos)); - LINFO(testlog, "Cut state of <" << awesomeCutName << "> is: " << cutStatus.GetCutState(awesomeCutName)); - //LINFO(testlog, "Cut state at " << awesomeCutPos << " is: " << cutStatus.GetCutState(awesomeCutPos)); - LINFO(testlog, "Has cut result <" << notAwesomeCutName << ">? " << cutStatus.HasCutResult(notAwesomeCutName)); - //LINFO(testlog, "Has cut result at " << notAwesomeCutPos << "? " << cutStatus.HasCutResult(notAwesomeCutPos)); - LINFO(testlog, "Cut state of <" << notAwesomeCutName << "> is: " << cutStatus.GetCutState(notAwesomeCutName)); - LINFO(testlog, "Cut state at " << notAwesomeCutPos << " is: " << cutStatus.GetCutState(notAwesomeCutPos)); - LINFO(testlog, "Is cut (all results)? " << cutStatus.IsCut()); - //LINFO(testlog, "Is cut with mask \"00\"? " << cutStatus.IsCut("00")); - //LINFO(testlog, "Is cut with mask \"01\"? " << cutStatus.IsCut("01")); - //LINFO(testlog, "Is cut with mask \"10\"? " << cutStatus.IsCut("10")); - //LINFO(testlog, "Is cut with mask \"11\"? " << cutStatus.IsCut("11")); - //LINFO(testlog, "Is cut with mask 0? " << cutStatus.IsCut(0)); - //LINFO(testlog, "Is cut with mask 1? " << cutStatus.IsCut(1)); - //LINFO(testlog, "Is cut with mask 2? " << cutStatus.IsCut(2)); - //LINFO(testlog, "Is cut with mask 3? " << cutStatus.IsCut(3)); - } - catch(std::exception& e) - { - LERROR(testlog, "Exception caught: " << e.what()); - } - - return 0; -} From 2859544aca6a31a305454a713e54bf4bf9fe886e Mon Sep 17 00:00:00 2001 From: benanator77 Date: Tue, 13 Feb 2024 14:44:08 -0800 Subject: [PATCH 03/11] Added tracking to the TestCut.cc file --- Testing/Cpp/TestCut.cc | 104 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Testing/Cpp/TestCut.cc diff --git a/Testing/Cpp/TestCut.cc b/Testing/Cpp/TestCut.cc new file mode 100644 index 00000000..6be23781 --- /dev/null +++ b/Testing/Cpp/TestCut.cc @@ -0,0 +1,104 @@ +/* + * TestCut.cc + * + * Created on: Sep 29, 2014 + * Author: nsoblath + */ + +//#include "TestCuts.hh" + +//#include "CutResult.hh" +#include "CutStatus.hh" + +#include "catch.hpp" + +TEST_CASE( "cut_present", "[cut]" ) +{ + using namespace Nymph; + //using namespace NymphTesting; + + // Do i need to define a cut status class object here? Define one in .hh? + // I think define one in TestCut.hh and use here? + + // just defining here for now + CutStatus testCutStatus; + testCutStatus.AssignCutResult("fTestCut", 1); + + // check fTestCut applied + REQUIRE ( testCutStatus.size() == 1 ); + //REQUIRE( testCutStatus.FindCutResult("fTestCut") == 0 ); // This returns position of cut in map, not state + // check fTestCut state + //REQUIRE( testCutStatus["fTestCut"] ) +} + +// Old Style +/* +using namespace Nymph; +using namespace std; + +int main() +{ + try + { + ExtCoreData data; + TestDataExt testData("test"); + + CutStatus& cutStatus = data.GetCutStatus(); + + LINFO(testlog, "Assigning awesome-cut"); + //unsigned awesomeCutPos = 0; + string awesomeCutName("awesome-cut"); + //cutStatus.AssignCutResult(awesomeCutPos, awesomeCutName); + cutStatus.AssignCutResult(awesomeCutName,1,1); + + LINFO(testlog, "Initial cut state: " << cutStatus.IsCut()); + + LINFO(testlog, "Applying awesome cut"); + AwesomeCut cut(awesomeCutName); + cut.Apply(data, testData); + + LINFO(testlog, "Cuts present: " << cutStatus.CutResultsPresent()) + LINFO(testlog, "Has cut result <" << awesomeCutName << ">? " << cutStatus.HasCutResult(awesomeCutName)); + //LINFO(testlog, "Has cut result at " << awesomeCutPos << "? " << cutStatus.HasCutResult(awesomeCutPos)); + LINFO(testlog, "Cut state of <" << awesomeCutName << ">is: " << cutStatus.GetCutState(awesomeCutName)); + //LINFO(testlog, "Cut state at " << awesomeCutPos << " is: " << cutStatus.GetCutState(awesomeCutPos)); + LINFO(testlog, "Is cut (all results)? " << cutStatus.IsCut()); + LINFO(testlog, "Current cut status: " << cutStatus); + //LINFO(testlog, "Is cut (with mask \"0\")? " << cutStatus.IsCut("0")); + + LINFO(testlog, "Assigning not-awesome-cut"); + //unsigned notAwesomeCutPos = 1; + string notAwesomeCutName("not-awesome-cut"); + //cutStatus.AssignCutResult(notAwesomeCutPos, notAwesomeCutName); + cutStatus.AssignCutResult(notAwesomeCutName,1,1); + + LINFO(testlog, "Applying not-awesome cut"); + NotAwesomeCut naCut(notAwesomeCutName); + naCut.Apply(data, testData); + + LINFO(testlog, "Cuts present: " << cutStatus.CutResultsPresent()) + LINFO(testlog, "Has cut result <" << awesomeCutName << ">? " << cutStatus.HasCutResult(awesomeCutName)); + //LINFO(testlog, "Has cut result at " << awesomeCutPos << "? " << cutStatus.HasCutResult(awesomeCutPos)); + LINFO(testlog, "Cut state of <" << awesomeCutName << "> is: " << cutStatus.GetCutState(awesomeCutName)); + //LINFO(testlog, "Cut state at " << awesomeCutPos << " is: " << cutStatus.GetCutState(awesomeCutPos)); + LINFO(testlog, "Has cut result <" << notAwesomeCutName << ">? " << cutStatus.HasCutResult(notAwesomeCutName)); + //LINFO(testlog, "Has cut result at " << notAwesomeCutPos << "? " << cutStatus.HasCutResult(notAwesomeCutPos)); + LINFO(testlog, "Cut state of <" << notAwesomeCutName << "> is: " << cutStatus.GetCutState(notAwesomeCutName)); + LINFO(testlog, "Cut state at " << notAwesomeCutPos << " is: " << cutStatus.GetCutState(notAwesomeCutPos)); + LINFO(testlog, "Is cut (all results)? " << cutStatus.IsCut()); + //LINFO(testlog, "Is cut with mask \"00\"? " << cutStatus.IsCut("00")); + //LINFO(testlog, "Is cut with mask \"01\"? " << cutStatus.IsCut("01")); + //LINFO(testlog, "Is cut with mask \"10\"? " << cutStatus.IsCut("10")); + //LINFO(testlog, "Is cut with mask \"11\"? " << cutStatus.IsCut("11")); + //LINFO(testlog, "Is cut with mask 0? " << cutStatus.IsCut(0)); + //LINFO(testlog, "Is cut with mask 1? " << cutStatus.IsCut(1)); + //LINFO(testlog, "Is cut with mask 2? " << cutStatus.IsCut(2)); + //LINFO(testlog, "Is cut with mask 3? " << cutStatus.IsCut(3)); + } + catch(std::exception& e) + { + LERROR(testlog, "Exception caught: " << e.what()); + } + + return 0; +}*/ From 8fbc958e3a1d670b28c5d8b441ab64297d519823 Mon Sep 17 00:00:00 2001 From: benanator77 Date: Wed, 21 Feb 2024 08:50:41 -0800 Subject: [PATCH 04/11] Fixed some more issues in CutStatus.cc --- Cpp/Library/CMakeLists.txt | 2 ++ Cpp/Library/Data/CutStatus.cc | 21 +++++++++++---------- Cpp/Library/Data/CutStatus.hh | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Cpp/Library/CMakeLists.txt b/Cpp/Library/CMakeLists.txt index c99c80ca..44f4a7b3 100644 --- a/Cpp/Library/CMakeLists.txt +++ b/Cpp/Library/CMakeLists.txt @@ -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 @@ -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 diff --git a/Cpp/Library/Data/CutStatus.cc b/Cpp/Library/Data/CutStatus.cc index c4472e9f..3c39a5fa 100644 --- a/Cpp/Library/Data/CutStatus.cc +++ b/Cpp/Library/Data/CutStatus.cc @@ -7,21 +7,21 @@ #include "CutStatus.hh" //#include "KTExtensibleStructFactory.hh" -#include "Logger.hh" +#include "logger.hh" namespace Nymph { LOGGER(cutlog, "Cut"); - CutStatus::CutStatus() : - CutResults(), - { - } +// CutStatus::CutStatus() : +// CutResults(), +// { +// } - CutStatus::CutStatus(const CutStatus& orig) : - CutResults(orig.CutResults), - { - } +// CutStatus::CutStatus(const CutStatus& orig) : +// CutResults(orig.CutResults), +// { +// } CutStatus::~CutStatus() {} @@ -109,7 +109,8 @@ namespace Nymph std::vector< std::string > cuts = status.CutResultsPresent(); for (auto cutIt = cuts.cbegin(); cutIt != cuts.cend(); ++cutIt) { - out << cuts[cutIt] << "; "; + //out << cuts[cutIt] << "; "; + out << *cutIt << "; "; } out << '\n'; return out; diff --git a/Cpp/Library/Data/CutStatus.hh b/Cpp/Library/Data/CutStatus.hh index d68bcad0..efa7e78e 100644 --- a/Cpp/Library/Data/CutStatus.hh +++ b/Cpp/Library/Data/CutStatus.hh @@ -107,7 +107,7 @@ namespace Nymph void SetCutState(const std::string& cutName, bool state); /// Returns a string with the names of the cuts that are present in bitset order - std::string CutResultsPresent() const; + std::vector< std::string > CutResultsPresent() const; private: friend std::ostream& operator<<(std::ostream& out, const CutStatus& status); From 8364bc3c5fd7a36f282e6f28712828aba499c589 Mon Sep 17 00:00:00 2001 From: benanator77 Date: Wed, 21 Feb 2024 16:57:27 -0800 Subject: [PATCH 05/11] Got TestCuts running, fixed some minor issues in CutStatus, all functions now working as expected\! --- Cpp/Library/Data/CutStatus.cc | 54 ++---------------------------- Cpp/Library/Data/CutStatus.hh | 63 ++--------------------------------- Testing/Cpp/TestCut.cc | 31 ++++++++++++++++- 3 files changed, 36 insertions(+), 112 deletions(-) diff --git a/Cpp/Library/Data/CutStatus.cc b/Cpp/Library/Data/CutStatus.cc index 3c39a5fa..2c1e9eb2 100644 --- a/Cpp/Library/Data/CutStatus.cc +++ b/Cpp/Library/Data/CutStatus.cc @@ -13,10 +13,9 @@ namespace Nymph { LOGGER(cutlog, "Cut"); -// CutStatus::CutStatus() : -// CutResults(), -// { -// } + CutStatus::CutStatus() + { + } // CutStatus::CutStatus(const CutStatus& orig) : // CutResults(orig.CutResults), @@ -32,33 +31,9 @@ namespace Nymph return *this; } - // Ben: above is constructors for different argument cases (empty, const cutstatus, reference). Shouldn't need to change. - - // Ben: This one needs to change. shouldn't need mask with maps. -/* void CutStatus::AssignCutResult(unsigned maskPos, const std::string& name, bool state, bool doUpdateStatus) - { - LDEBUG(cutlog, "Assigning cut result <" << name << "> to position <" << maskPos << "> with state <" << state << ">"); - if( maskPos >= fCutResults.size() ) - { - fCutResults.resize( maskPos + 1 ); - } - LDEBUG(cutlog, "Cut result size is now <" << fCutResults.size() << ">"); - if( fCutResults[maskPos].fAssigned ) - { - throw Exception() << "Mask position <" << maskPos << "> has already been assigned"; - } - fCutResults[maskPos].fName = name; - fCutResults[maskPos].fState = state; - fCutResults[maskPos].fAssigned = true; - if( doUpdateStatus ) UpdateStatus(); - return; - } -*/ - // Ben: map version. Not sure if need the doUpdateStatus part tho void CutStatus::AssignCutResult(const std::string& cutName, bool state) { LDEBUG(cutlog, "Assigning cut result <" << cutName << "> with state <" << state << ">"); - // Ben: don't think I need the resize stuff, happens automatically with maps if( fCutResults.find(cutName) != fCutResults.end()) { throw Exception() << "Cut with name: " << cutName << " has already been assigned"; @@ -68,27 +43,6 @@ namespace Nymph return; } - // Ben: displays map keys and vals with ostream. -/* void CutStatus::UpdateStatus() - { - LDEBUG(cutlog, "Updating cut summary"); - unsigned nCuts = fCutResults.size(); - //fSummary.resize(nCuts, false); // now just a string - - // loop through to set cuts - LDEBUG(cutlog, "nCuts: " << nCuts); - for (unsigned iCut = 0; iCut < nCuts; ++iCut) // I think this still works for map. I believe map[iterator] bring up ith key/value - { - //fSummary[iCut] = fCutResults[iCut].fName && fCutResults[iCut].fState; - if(fCutResults[iCut]->second == 1) // may need to change iCut to iterator type - { - fSummary.append(fCutResults[iCut]->first; - } - } - LDEBUG(cutlog, "Cut summary: " << fSummary); - return; - }*/ - std::vector< std::string > CutStatus::CutResultsPresent() const { std::vector< std::string > cutsPresent; @@ -96,7 +50,6 @@ namespace Nymph { if ((! cutIt->first.empty()) && (cutIt->second == 1)) { - //cutsPresent = cutIt->first + " " + cutsPresent; // TODO still need to change this to using vector of strings? cutsPresent.push_back(cutIt->first); } } @@ -109,7 +62,6 @@ namespace Nymph std::vector< std::string > cuts = status.CutResultsPresent(); for (auto cutIt = cuts.cbegin(); cutIt != cuts.cend(); ++cutIt) { - //out << cuts[cutIt] << "; "; out << *cutIt << "; "; } out << '\n'; diff --git a/Cpp/Library/Data/CutStatus.hh b/Cpp/Library/Data/CutStatus.hh index efa7e78e..bc3049cd 100644 --- a/Cpp/Library/Data/CutStatus.hh +++ b/Cpp/Library/Data/CutStatus.hh @@ -112,7 +112,6 @@ namespace Nymph private: friend std::ostream& operator<<(std::ostream& out, const CutStatus& status); - //CutResults_t CutResults; // TODO might need a map fCutResult to replace this vector defn CutResults_t fCutResults; //bitset_type fSummary; // Need to change from bitset to vector of strings or similar. Can potentially skip and directly cout map vals @@ -127,8 +126,6 @@ namespace Nymph std::ostream& operator<<(std::ostream& out, const CutStatus& status); - // Ben: TODO Likely need to edit below lines - inline std::map< std::string, bool > CutStatus::CutResults() const // get a const of the map { return fCutResults; @@ -136,7 +133,6 @@ namespace Nymph inline CutStatus::CutResultsIt CutStatus::FindCutResult( const std::string& cutName ) { - //if( cutName.empty() ) return CutResults.end(); // Don't think I need this, map::find should return map::end if empty return fCutResults.find(cutName); } @@ -160,12 +156,6 @@ namespace Nymph return fCutResults.count(cutName); } - /*inline bool CutStatus::HasCutResult( unsigned mapPos ) const - { - //return maskPos < fCutResults.size() && fCutResults[maskPos].fAssigned; - return mapPos < fCutResults.end() && fCutResults - }*/ - inline bool CutStatus::GetCutState( const std::string& cutName ) const { if (fCutResults.find(cutName) != fCutResults.end()) @@ -174,40 +164,20 @@ namespace Nymph } throw Exception() << "Unable to find cut <" << cutName << ">"; } -/* - inline bool CutStatus::GetCutState( unsigned maskPos ) const - { - if (maskPos < fCutResults.size()) - { - return fCutResults[maskPos].fState; - } - throw Exception() << "Mask position <" << maskPos << "> is out of range (only " << size() << " cuts are present)"; - } -*/ + inline void CutStatus::SetCutState(const std::string& cutName, bool state) { if (fCutResults.find(cutName) != fCutResults.end()) { - fCutResults.insert(make_pair(cutName,state)); + fCutResults[cutName] = state; return; } throw Exception() << "Unable to find cut <" << cutName << ">"; } -/* inline void CutStatus::SetCutState(unsigned maskPos, bool state, bool doUpdateStatus) - { - if (maskPos < fCutResults.size()) - { - fCutResults[maskPos].fState = state; - if (doUpdateStatus) UpdateStatus(); - return; - } - throw Exception() << "Mask position <" << maskPos << "> is out of range (only "<< size() << " cuts are present)"; - } -*/ inline void CutStatus::RemoveCutResult(const std::string& cutName) { - if (fCutResults.find(cutName) == fCutResults.end()) + if (fCutResults.find(cutName) != fCutResults.end()) { fCutResults.erase(cutName); } @@ -242,33 +212,6 @@ namespace Nymph int stateSum = boost::accumulate(fCutResults | boost::adaptors::map_values, 0); return stateSum; } -// dont think i need anything with mask anymore -/* - inline bool CutStatus::IsCut(const bitset_type& mask) const - { - return (fSummary & mask).any(); - } - - inline bool CutStatus::IsCut(unsigned long long mask) const - { - return IsCut(ToBitset(mask)); - } - - inline bool CutStatus::IsCut(const std::string& mask) const - { - return IsCut(ToBitset(mask)); - } - - inline CutStatus::bitset_type CutStatus::ToBitset(unsigned long long mask) const - { - return bitset_type(fSummary.size(), mask); - } - - inline CutStatus::bitset_type CutStatus::ToBitset(const std::string& mask) const - { - return bitset_type(mask); - } -*/ } /* namespace Nymph */ #endif /* CUTSTATUS_HH_ */ diff --git a/Testing/Cpp/TestCut.cc b/Testing/Cpp/TestCut.cc index 6be23781..0d1f99ca 100644 --- a/Testing/Cpp/TestCut.cc +++ b/Testing/Cpp/TestCut.cc @@ -28,7 +28,36 @@ TEST_CASE( "cut_present", "[cut]" ) REQUIRE ( testCutStatus.size() == 1 ); //REQUIRE( testCutStatus.FindCutResult("fTestCut") == 0 ); // This returns position of cut in map, not state // check fTestCut state - //REQUIRE( testCutStatus["fTestCut"] ) + REQUIRE( testCutStatus.GetCutState("fTestCut") == 1 ); + + // check default is to assign cut status FALSE + testCutStatus.AssignCutResult("fNotCut"); + REQUIRE ( testCutStatus.size() == 2 ); + REQUIRE ( testCutStatus.GetCutState("fNotCut") == 0 ); + + // Test Readout + UNSCOPED_INFO ( testCutStatus ); + //CHECK ( false ); // Force readout even if no fails + + // Check IsCut() + REQUIRE ( testCutStatus.IsCut() == true ); + + // Check Num Cuts (size but only for cuts that are true) + REQUIRE ( testCutStatus.NumCuts() == 1 ); + + // Change Cut State + testCutStatus.SetCutState("fTestCut",0); + REQUIRE ( testCutStatus.GetCutState("fTestCut") == 0); + + // Check throw if set/check state for non-existant cut + REQUIRE_THROWS ( testCutStatus.SetCutState("fMissingCut",1) ); + REQUIRE_THROWS ( testCutStatus.GetCutState("fMissingCut") ); + + // Remove cuts + testCutStatus.RemoveCutResult("fTestCut"); + testCutStatus.RemoveCutResult("fNotCut"); + REQUIRE ( testCutStatus.size() == 0 ); + } // Old Style From 8e09d0d5fa6ba24ae46139f6e707e0687cfe5dca Mon Sep 17 00:00:00 2001 From: benanator77 Date: Thu, 22 Feb 2024 16:10:33 -0800 Subject: [PATCH 06/11] Fixed CutStatus assignment and copy operators --- Cpp/Library/Data/CutResult.hh | 43 ---------------- Cpp/Library/Data/CutStatus.cc | 18 ++++--- Cpp/Library/Data/CutStatus.hh | 31 ++++------- Testing/Cpp/TestCut.cc | 96 ++++++----------------------------- 4 files changed, 36 insertions(+), 152 deletions(-) delete mode 100644 Cpp/Library/Data/CutResult.hh diff --git a/Cpp/Library/Data/CutResult.hh b/Cpp/Library/Data/CutResult.hh deleted file mode 100644 index 32d73fed..00000000 --- a/Cpp/Library/Data/CutResult.hh +++ /dev/null @@ -1,43 +0,0 @@ -/* - * CutResult.hh - * - * Created on: Sept 19, 2014 - * Author: nsoblath - */ - -#ifndef CUTRESULT_HH_ -#define CUTRESULT_HH_ - -#include -#include - -namespace Nymph -{ - typedef std::map< std::string, bool > CutResult_t; - typedef CutResult_t::value_type fCutVal; - // This might be enough. gives key fName to return bool of if cut - // ::value_type is just the pair value type def used to initiate the map - // so give fCutVal( fName, value) and then insert into CutResult - -/* struct CutResult - { - std::string fName; - bool fState; - bool fAssigned; - CutResult() : fName(), fState( false ), fAssigned( false ) {} - CutResult( const std::string& name, bool state ) : fName( name ), fState( state ), fAssigned( true ) {} - }; - - struct CheckCutResultName - { - std::string fName; - CheckCutResultName( const std::string& name ) : fName( name ) {} - bool operator()( const CutResult& result ) - { - return result.fName == fName; - } - }; -*/ -} /* namespace Nymph */ - -#endif /* CUTRESULT_HH_ */ diff --git a/Cpp/Library/Data/CutStatus.cc b/Cpp/Library/Data/CutStatus.cc index 2c1e9eb2..c2a8a342 100644 --- a/Cpp/Library/Data/CutStatus.cc +++ b/Cpp/Library/Data/CutStatus.cc @@ -6,7 +6,6 @@ */ #include "CutStatus.hh" -//#include "KTExtensibleStructFactory.hh" #include "logger.hh" namespace Nymph @@ -17,20 +16,27 @@ namespace Nymph { } -// CutStatus::CutStatus(const CutStatus& orig) : -// CutResults(orig.CutResults), -// { -// } + CutStatus::CutStatus(const CutStatus& orig) + { + fCutResults = orig.fCutResults; + } CutStatus::~CutStatus() {} CutStatus& CutStatus::operator=(const CutStatus& rhs) { + //delete[] fCutResults; fCutResults = rhs.fCutResults; return *this; } - +/* + CutStatus CutStatus::operator=(const CutStatus rhs) + { + fCutResults = rhs.fCutResults; + return *this; + } +*/ void CutStatus::AssignCutResult(const std::string& cutName, bool state) { LDEBUG(cutlog, "Assigning cut result <" << cutName << "> with state <" << state << ">"); diff --git a/Cpp/Library/Data/CutStatus.hh b/Cpp/Library/Data/CutStatus.hh index bc3049cd..2afec6df 100644 --- a/Cpp/Library/Data/CutStatus.hh +++ b/Cpp/Library/Data/CutStatus.hh @@ -12,13 +12,8 @@ #include #include -//#include "CutResult.hh" - #include "Exception.hh" -//#include "cereal/access.hpp" -//#include "cereal/types/string.hpp" -//#include "cereal/types/vector.hpp" namespace Nymph { @@ -29,29 +24,23 @@ namespace Nymph @brief Provides easy access to cut result information. @details - The cut results can be imagined as an array of booleans, specifying whether the cut was passed: [true, false, false, true, . . . ]. - - Cuts are assigned both an array position (non-negative integer) and a name (string) before or when the results are set. + 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 CoreData, the top-level data object. CutStatus owns the set of CutResults that have been added to a data object. - It also owns a summary of those cuts (implemented with boost::dynamic_bitset). + It also owns a summary of those cuts. You can check if the data has been cut with the IsCut functions. - IsCut() returns true if any cut results are true; - - IsCut(const bitset_type& mask), IsCut(unsigned int mask), and IsCut(const std::string& mask) allow you to specify - a cut mask, and return true if any of the cut results specified by the mask are true. - When specifying a cut mask, bits set to true specify cuts that should be used: - - bitset_type is boost::dynamic_bitset; - - unsigned integer masks use the bits of the integer; - - std::string masks are strings with each character either a 0 or 1. + When specifying a cut, bools set to true specify cuts that should be used. 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 a reference to the cut results with CutResults(), - - If you need to manually update the cut status bitset, use UpdateStatus(), + - Get the number of cut results with value true with NumCuts(), + - Get a reference to the cut results with CutResults(), TODO; not currently implemented - Add cut results to a data object with AssignCutResult(), - Remove a cut result with RemoveCutResult(), - Check to see if a particular cut result is present using HasCutResult(), @@ -64,21 +53,19 @@ namespace Nymph class CutStatus { public: - //CutStatus() : CutResults(); typedef std::map< std::string, bool > CutResults_t; typedef CutResults_t::iterator CutResultsIt; typedef CutResults_t::const_iterator CutResultsCIt; - //private: - //std::map< std::string, bool > CutResults; - - public: // Ben: Below initiates operators, shouldn't need to mess with this, just in the actual operator defns how they interact with the maps. + public: CutStatus(); CutStatus(const CutStatus& orig); ~CutStatus(); CutStatus& operator=(const CutStatus& rhs); + //CutStatus operator=(const CutStatus rhs); + /// Returns the size of the cut results map size_t size() const; diff --git a/Testing/Cpp/TestCut.cc b/Testing/Cpp/TestCut.cc index 0d1f99ca..923bf7e6 100644 --- a/Testing/Cpp/TestCut.cc +++ b/Testing/Cpp/TestCut.cc @@ -1,13 +1,10 @@ /* * TestCut.cc * - * Created on: Sep 29, 2014 - * Author: nsoblath + * Created on: Jan 6, 2024 + * Author: btfoust */ -//#include "TestCuts.hh" - -//#include "CutResult.hh" #include "CutStatus.hh" #include "catch.hpp" @@ -17,10 +14,6 @@ TEST_CASE( "cut_present", "[cut]" ) using namespace Nymph; //using namespace NymphTesting; - // Do i need to define a cut status class object here? Define one in .hh? - // I think define one in TestCut.hh and use here? - - // just defining here for now CutStatus testCutStatus; testCutStatus.AssignCutResult("fTestCut", 1); @@ -53,81 +46,22 @@ TEST_CASE( "cut_present", "[cut]" ) REQUIRE_THROWS ( testCutStatus.SetCutState("fMissingCut",1) ); REQUIRE_THROWS ( testCutStatus.GetCutState("fMissingCut") ); + // Check initialize from other cut status + CutStatus testCutStatus2(testCutStatus); + REQUIRE ( testCutStatus2.size() == 2 ); + REQUIRE ( testCutStatus2.GetCutState("fTestCut") == 0); + + // Check assignment operator + testCutStatus2.SetCutState("fNotCut",1); + testCutStatus2 = testCutStatus; + REQUIRE ( testCutStatus2.GetCutState("fNotCut") == 0); + // Remove cuts testCutStatus.RemoveCutResult("fTestCut"); testCutStatus.RemoveCutResult("fNotCut"); REQUIRE ( testCutStatus.size() == 0 ); + testCutStatus2.RemoveCutResult("fTestCut"); + testCutStatus2.RemoveCutResult("fNotCut"); + REQUIRE ( testCutStatus2.size() == 0 ); } - -// Old Style -/* -using namespace Nymph; -using namespace std; - -int main() -{ - try - { - ExtCoreData data; - TestDataExt testData("test"); - - CutStatus& cutStatus = data.GetCutStatus(); - - LINFO(testlog, "Assigning awesome-cut"); - //unsigned awesomeCutPos = 0; - string awesomeCutName("awesome-cut"); - //cutStatus.AssignCutResult(awesomeCutPos, awesomeCutName); - cutStatus.AssignCutResult(awesomeCutName,1,1); - - LINFO(testlog, "Initial cut state: " << cutStatus.IsCut()); - - LINFO(testlog, "Applying awesome cut"); - AwesomeCut cut(awesomeCutName); - cut.Apply(data, testData); - - LINFO(testlog, "Cuts present: " << cutStatus.CutResultsPresent()) - LINFO(testlog, "Has cut result <" << awesomeCutName << ">? " << cutStatus.HasCutResult(awesomeCutName)); - //LINFO(testlog, "Has cut result at " << awesomeCutPos << "? " << cutStatus.HasCutResult(awesomeCutPos)); - LINFO(testlog, "Cut state of <" << awesomeCutName << ">is: " << cutStatus.GetCutState(awesomeCutName)); - //LINFO(testlog, "Cut state at " << awesomeCutPos << " is: " << cutStatus.GetCutState(awesomeCutPos)); - LINFO(testlog, "Is cut (all results)? " << cutStatus.IsCut()); - LINFO(testlog, "Current cut status: " << cutStatus); - //LINFO(testlog, "Is cut (with mask \"0\")? " << cutStatus.IsCut("0")); - - LINFO(testlog, "Assigning not-awesome-cut"); - //unsigned notAwesomeCutPos = 1; - string notAwesomeCutName("not-awesome-cut"); - //cutStatus.AssignCutResult(notAwesomeCutPos, notAwesomeCutName); - cutStatus.AssignCutResult(notAwesomeCutName,1,1); - - LINFO(testlog, "Applying not-awesome cut"); - NotAwesomeCut naCut(notAwesomeCutName); - naCut.Apply(data, testData); - - LINFO(testlog, "Cuts present: " << cutStatus.CutResultsPresent()) - LINFO(testlog, "Has cut result <" << awesomeCutName << ">? " << cutStatus.HasCutResult(awesomeCutName)); - //LINFO(testlog, "Has cut result at " << awesomeCutPos << "? " << cutStatus.HasCutResult(awesomeCutPos)); - LINFO(testlog, "Cut state of <" << awesomeCutName << "> is: " << cutStatus.GetCutState(awesomeCutName)); - //LINFO(testlog, "Cut state at " << awesomeCutPos << " is: " << cutStatus.GetCutState(awesomeCutPos)); - LINFO(testlog, "Has cut result <" << notAwesomeCutName << ">? " << cutStatus.HasCutResult(notAwesomeCutName)); - //LINFO(testlog, "Has cut result at " << notAwesomeCutPos << "? " << cutStatus.HasCutResult(notAwesomeCutPos)); - LINFO(testlog, "Cut state of <" << notAwesomeCutName << "> is: " << cutStatus.GetCutState(notAwesomeCutName)); - LINFO(testlog, "Cut state at " << notAwesomeCutPos << " is: " << cutStatus.GetCutState(notAwesomeCutPos)); - LINFO(testlog, "Is cut (all results)? " << cutStatus.IsCut()); - //LINFO(testlog, "Is cut with mask \"00\"? " << cutStatus.IsCut("00")); - //LINFO(testlog, "Is cut with mask \"01\"? " << cutStatus.IsCut("01")); - //LINFO(testlog, "Is cut with mask \"10\"? " << cutStatus.IsCut("10")); - //LINFO(testlog, "Is cut with mask \"11\"? " << cutStatus.IsCut("11")); - //LINFO(testlog, "Is cut with mask 0? " << cutStatus.IsCut(0)); - //LINFO(testlog, "Is cut with mask 1? " << cutStatus.IsCut(1)); - //LINFO(testlog, "Is cut with mask 2? " << cutStatus.IsCut(2)); - //LINFO(testlog, "Is cut with mask 3? " << cutStatus.IsCut(3)); - } - catch(std::exception& e) - { - LERROR(testlog, "Exception caught: " << e.what()); - } - - return 0; -}*/ From 9c845aed6cd048093f4e4fc975b19a1f2bc696d1 Mon Sep 17 00:00:00 2001 From: benanator77 Date: Tue, 12 Mar 2024 11:15:57 -0700 Subject: [PATCH 07/11] Added CutStatus member to DataFrame, passes test of adding a cut in TestDataFrame.cc --- Cpp/Library/Data/DataFrame.cc | 3 ++- Cpp/Library/Data/DataFrame.hh | 4 ++++ Testing/Cpp/TestDataFrame.cc | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cpp/Library/Data/DataFrame.cc b/Cpp/Library/Data/DataFrame.cc index 12240592..e1cfadc6 100644 --- a/Cpp/Library/Data/DataFrame.cc +++ b/Cpp/Library/Data/DataFrame.cc @@ -10,7 +10,8 @@ namespace Nymph { DataFrame::DataFrame() : - fDataObjects() + fDataObjects(), + fCuts() {} DataFrame::~DataFrame() diff --git a/Cpp/Library/Data/DataFrame.hh b/Cpp/Library/Data/DataFrame.hh index 4e8d4631..157d903c 100644 --- a/Cpp/Library/Data/DataFrame.hh +++ b/Cpp/Library/Data/DataFrame.hh @@ -10,6 +10,7 @@ #define NYMPH_DATAFRAME_HH_ #include "Data.hh" +#include "CutStatus.hh" #include "Exception.hh" #include "MemberVariable.hh" @@ -95,6 +96,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 > DataMap; MEMVAR_REF( DataMap, DataObjects ); + + // CutStatus object for storing cut information + CutStatus fCuts; }; diff --git a/Testing/Cpp/TestDataFrame.cc b/Testing/Cpp/TestDataFrame.cc index 100ca626..1d8ad6c7 100644 --- a/Testing/Cpp/TestDataFrame.cc +++ b/Testing/Cpp/TestDataFrame.cc @@ -24,6 +24,10 @@ TEST_CASE( "data_frame", "[data]" ) REQUIRE_FALSE( frame.Has< TestData1 >() ); REQUIRE_FALSE( frame.Has< TestData2 >() ); + // check Cut Status functioning + frame.fCuts.AssignCutResult("fTestCut", 1); + REQUIRE ( frame.fCuts.GetCutState("fTestCut") == 1); + // create a data object with Get() TestData1& data1 = frame.Get< TestData1 >(); REQUIRE( frame.Has< TestData1 >() ); From 6cefd0134e8f45cfd88fb574de43d6ccd10f7bd3 Mon Sep 17 00:00:00 2001 From: benanator77 Date: Tue, 12 Mar 2024 11:37:26 -0700 Subject: [PATCH 08/11] Updated details of CutStatus --- Cpp/Library/Data/CutStatus.hh | 34 +++++++--------------------------- Cpp/Library/Data/DataFrame.hh | 4 +++- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/Cpp/Library/Data/CutStatus.hh b/Cpp/Library/Data/CutStatus.hh index 2afec6df..d105b9b6 100644 --- a/Cpp/Library/Data/CutStatus.hh +++ b/Cpp/Library/Data/CutStatus.hh @@ -26,28 +26,26 @@ namespace Nymph @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 CoreData, the top-level data object. - - CutStatus owns the set of CutResults that have been added to a data object. - It also owns a summary of those cuts. + 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 should be used. + 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(), TODO; not currently implemented - - Add cut results to a data object with AssignCutResult(), + - 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(), and + - 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, - Cut results can typically be accessed by either name or mask position. */ class CutStatus @@ -64,8 +62,6 @@ namespace Nymph CutStatus& operator=(const CutStatus& rhs); - //CutStatus operator=(const CutStatus rhs); - /// Returns the size of the cut results map size_t size() const; @@ -101,9 +97,6 @@ namespace Nymph CutResults_t fCutResults; - //bitset_type fSummary; // Need to change from bitset to vector of strings or similar. Can potentially skip and directly cout map vals - //std::string fSummary; // string containing names of only cuts that have been applied, separated by _ - public: bool IsCut() const; bool IsCut(const std::string& mask) const; @@ -170,19 +163,6 @@ namespace Nymph } return; } - // Ben: can remove by iterator position, but won't for consistency -/* - inline void CutStatus::RemoveCutResult(unsigned maskPos, bool doUpdateStatus) - { - if (maskPos < fCutResults.size()) - { - fCutResults[maskPos].fName = ""; - fCutResults[maskPos].fState = false; - } - if (doUpdateStatus) UpdateStatus(); - return; - } -*/ inline size_t CutStatus::size() const { return fCutResults.size(); diff --git a/Cpp/Library/Data/DataFrame.hh b/Cpp/Library/Data/DataFrame.hh index 157d903c..c20895d9 100644 --- a/Cpp/Library/Data/DataFrame.hh +++ b/Cpp/Library/Data/DataFrame.hh @@ -41,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 From 57c8a03b6cb8abf8fef6924912040bb8677b895d Mon Sep 17 00:00:00 2001 From: benanator77 Date: Tue, 12 Mar 2024 11:38:21 -0700 Subject: [PATCH 09/11] Cleaning up stuff --- Cpp/Library/Data/CutStatus.cc | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Cpp/Library/Data/CutStatus.cc b/Cpp/Library/Data/CutStatus.cc index c2a8a342..a8eaca6b 100644 --- a/Cpp/Library/Data/CutStatus.cc +++ b/Cpp/Library/Data/CutStatus.cc @@ -30,13 +30,7 @@ namespace Nymph fCutResults = rhs.fCutResults; return *this; } -/* - CutStatus CutStatus::operator=(const CutStatus rhs) - { - fCutResults = rhs.fCutResults; - return *this; - } -*/ + void CutStatus::AssignCutResult(const std::string& cutName, bool state) { LDEBUG(cutlog, "Assigning cut result <" << cutName << "> with state <" << state << ">"); From 807aaf2408d9e732014ba225f2bea5434579ae88 Mon Sep 17 00:00:00 2001 From: benanator77 Date: Tue, 12 Mar 2024 14:12:21 -0700 Subject: [PATCH 10/11] Changed cut list function and << operator to show all cuts regardless of bool value --- Cpp/Library/Data/CutStatus.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cpp/Library/Data/CutStatus.cc b/Cpp/Library/Data/CutStatus.cc index a8eaca6b..54aad68a 100644 --- a/Cpp/Library/Data/CutStatus.cc +++ b/Cpp/Library/Data/CutStatus.cc @@ -48,7 +48,7 @@ namespace Nymph std::vector< std::string > cutsPresent; for (auto cutIt = fCutResults.cbegin(); cutIt != fCutResults.cend(); ++cutIt) { - if ((! cutIt->first.empty()) && (cutIt->second == 1)) + if (! cutIt->first.empty()) { cutsPresent.push_back(cutIt->first); } From 5e9597fc061f87a690028b6b711c8ef4f01466cd Mon Sep 17 00:00:00 2001 From: benanator77 Date: Tue, 12 Mar 2024 17:48:54 -0700 Subject: [PATCH 11/11] Added a README in Cpp/Library/Data/ for future work on cut updates --- Cpp/Library/Data/README_future_work.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Cpp/Library/Data/README_future_work.txt diff --git a/Cpp/Library/Data/README_future_work.txt b/Cpp/Library/Data/README_future_work.txt new file mode 100644 index 00000000..3b9ea7fe --- /dev/null +++ b/Cpp/Library/Data/README_future_work.txt @@ -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 +