Skip to content
Draft
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
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cmake_minimum_required (VERSION 3.1)
#########

cmake_policy( SET CMP0048 NEW ) # version in project()
project( Nymph VERSION 1.4.7 )
project( Nymph VERSION 1.4.10 )

list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/Scarab/cmake )
include( PackageBuilder )
Expand All @@ -25,8 +25,8 @@ include( Nymph )
# Nymph options #
#################

# require C++11
set_option( USE_CPP11 TRUE )
# require C++17
set_option( USE_CPP17 TRUE )

# Build the Nymph executable (also requires Nymph_ENABLE_EXECUTABLES)
option( Nymph_BUILD_NYMPH_EXE "Flag to build the Nymph executable; also requires Nymph_ENABLE_EXECUTABLES" ON )
Expand Down
1 change: 1 addition & 0 deletions Executables/Validation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ if (Nymph_ENABLE_TESTING)
TestApplication
TestApplyCut
TestCacheDirectory
TestContext
TestCut
TestCutFilter
TestLogger
Expand Down
10 changes: 7 additions & 3 deletions Executables/Validation/KTTestProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ namespace Nymph
{
KTLOGGER(testsiglog, "KTTestProcessor")

KTTestProcessorA::KTTestProcessorA() :
KT_REGISTER_PROCESSOR(KTTestProcessorA, "test-proc-a");

KTTestProcessorA::KTTestProcessorA(const std::string& name) :
KTProcessor(name),
fTheSignal()
{
RegisterSignal("the_signal", &fTheSignal);
Expand All @@ -35,9 +38,10 @@ namespace Nymph
}


KT_REGISTER_PROCESSOR(KTTestProcessorB, "test-proc-b");


KTTestProcessorB::KTTestProcessorB()
KTTestProcessorB::KTTestProcessorB(const std::string& name) :
KTProcessor(name)
{
RegisterSlot("first_slot", this, &KTTestProcessorB::Slot1);
RegisterSlot("second_slot", this, &KTTestProcessorB::Slot2);
Expand Down
4 changes: 2 additions & 2 deletions Executables/Validation/KTTestProcessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Nymph
typedef KTSignalConcept< void (int) >::signal TheSignal;

public:
KTTestProcessorA();
KTTestProcessorA(const std::string& name = "test-proc-a");
virtual ~KTTestProcessorA();

bool Configure(const scarab::param_node* node);
Expand All @@ -34,7 +34,7 @@ namespace Nymph
class KTTestProcessorB : public KTProcessor
{
public:
KTTestProcessorB();
KTTestProcessorB(const std::string& name = "test-proc-b");
virtual ~KTTestProcessorB();

bool Configure(const scarab::param_node* node);
Expand Down
55 changes: 55 additions & 0 deletions Executables/Validation/TestContext.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* TestContext.cc
*
* Created on: Aug 9, 2024
* Author: N.S. Oblath
*
* Usage: > ./TestContext
*
* Purpose: Test access to context from multiple processors
*
*/

#include "KTTestProcessor.hh"

#include "KTContext.hh"
#include "KTLogger.hh"
#include "KTProcessorToolbox.hh"

using namespace Nymph;

KTLOGGER(testlog, "TestContext");

int main()
{
KTTestProcessorA procA;
KTTestProcessorB procB;

KTINFO(testlog, "Contexts belonging to procA and procB should be independent\n&procA.Context() == &procB.Context(): " << (&procA.Context() == &procB.Context()));

KTProcessorToolbox toolbox;

if (! toolbox.AddProcessor("test-proc-a", "tpa"))
{
KTERROR(testlog, "Unable to create test proc A with the Processor Toolbox");
return 1;
}
if (! toolbox.AddProcessor("test-proc-b", "tpb"))
{
KTERROR(testlog, "Unable to create test proc B with the Processor Toolbox");
return 1;
}

KTProcessor& procAtb = *toolbox.GetProcessor("tpa");
KTProcessor& procBtb = *toolbox.GetProcessor("tpb");

KTINFO(testlog, "Contexts belonging to procAtb and procBtb should be identical\n&procAtb.Context() == &procBtb.Context(): " << (&procAtb.Context() == &procBtb.Context()));

toolbox.Context().Add("test", scarab::param_value(5));
KTINFO(testlog, "toolbox has context \"test\"? (expect \"1\") " << toolbox.Context().Has("test"));
KTINFO(testlog, "procAtb has context \"test\"? (expect \"1\") " << procAtb.Context().Has("test"));
KTINFO(testlog, "procBtb has context \"test\"? (expect \"1\") " << procBtb.Context().Has("test"));
KTINFO(testlog, "Values are all equal? (expect \"1 1\") " << (toolbox.Context().Get("test")().as_int() == procAtb.Context().Get("test")().as_int()) << " " << (toolbox.Context().Get("test")().as_int() == procBtb.Context().Get("test")().as_int()));

return 0;
}
4 changes: 4 additions & 0 deletions Library/Application/KTProcessorToolbox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace Nymph

KTProcessorToolbox::KTProcessorToolbox(const std::string& name) :
KTConfigurable(name),
KTHasContext(),
fProcFactory(scarab::factory< KTProcessor, const std::string& >::get_instance()),
fRunQueue(),
fProcMap()
Expand Down Expand Up @@ -318,6 +319,9 @@ namespace Nymph
ProcMapIt it = fProcMap.find(procName);
if (it == fProcMap.end())
{
// share the context
proc->SetContext(fContext);

ProcessorInfo pInfo;
pInfo.fProc = proc;
fProcMap.insert(ProcMapValue(procName, pInfo));
Expand Down
5 changes: 2 additions & 3 deletions Library/Application/KTProcessorToolbox.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define KTPROCESSORTOOLBOX_HH_

#include "KTConfigurable.hh"
#include "KTContext.hh"
//#include "KTNOFactory.hh"

#include "factory.hh"
Expand Down Expand Up @@ -71,7 +72,7 @@ namespace Nymph
</li>
</ul>
*/
class KTProcessorToolbox : public KTConfigurable
class KTProcessorToolbox : public KTConfigurable, public KTHasContext
{
public:
KTProcessorToolbox(const std::string& name = "processor-toolbox");
Expand Down Expand Up @@ -199,7 +200,5 @@ namespace Nymph
return;
}



} /* namespace Nymph */
#endif /* KTPROCESSORTOOLBOX_HH_ */
2 changes: 2 additions & 0 deletions Library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set( NYMPH_HEADERFILES
${DATA_DIR}/KTCutStatus.hh
${DATA_DIR}/KTData.hh
${PROC_DIR}/KTConnection.hh
${PROC_DIR}/KTContext.hh
${PROC_DIR}/KTPrimaryProcessor.hh
${PROC_DIR}/KTProcessor.hh
${PROC_DIR}/KTSignal.hh
Expand Down Expand Up @@ -62,6 +63,7 @@ set( NYMPH_SOURCEFILES
${DATA_DIR}/KTCutFilter.cc
${DATA_DIR}/KTCutStatus.cc
${DATA_DIR}/KTData.cc
${PROC_DIR}/KTContext.cc
${PROC_DIR}/KTPrimaryProcessor.cc
${PROC_DIR}/KTProcessor.cc
${PROC_DIR}/KTSignal.cc
Expand Down
54 changes: 54 additions & 0 deletions Library/Processor/KTContext.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* KTContext.cc
*
* Created on: Aug 7, 2024
* Author: N.S. Oblath
*/

#include "KTContext.hh"

#include "KTLogger.hh"

#include <memory>

namespace Nymph
{

KTLOGGER(proclog, "KTContext.hh");

KTContext::KTContext() :
fData()
{}

KTContext::~KTContext()
{}

bool KTContext::Has(const std::string& name) const
{
return fData.has(name);
}

scarab::param& KTContext::Get(const std::string& name)
{
return fData[name];
}

const scarab::param& KTContext::Get(const std::string& name) const
{
return fData[name];
}

void KTContext::Add(const std::string& name, const scarab::param& data)
{
fData.add(name, data);
return;
}


KTHasContext::KTHasContext() :
fContext(std::make_shared< KTContext >())
{}

KTHasContext::~KTHasContext()
{}
} /* namespace Nymph */
68 changes: 68 additions & 0 deletions Library/Processor/KTContext.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
@file KTContext.hh
@brief Contains KTContext
@details KTContext contains the run context that's available to all processors
@author: N. S. Oblath
@date: Aug 7, 2024
*/

#ifndef KTCONTEXT_HH_
#define KTCONTEXT_HH_

#include "param.hh"

namespace Nymph
{

class KTContext
{
public:
KTContext();
virtual ~KTContext();

bool Has(const std::string& name) const;

scarab::param& Get(const std::string& name);
const scarab::param& Get(const std::string& name) const;

void Add(const std::string& name, const scarab::param& data);

protected:
scarab::param_node fData;
};

class KTHasContext
{
public:
KTHasContext();
virtual ~KTHasContext();

KTContext& Context();
const KTContext& Context() const;

void SetContext(const std::shared_ptr< KTContext > context);

protected:
std::shared_ptr< KTContext > fContext;

};

inline KTContext& KTHasContext::Context()
{
return *fContext;
}

inline const KTContext& KTHasContext::Context() const
{
return *fContext;
}

inline void KTHasContext::SetContext(std::shared_ptr< KTContext > context)
{
fContext = context;
return;
}

} /* namespace Nymph */

#endif /* KTCONTEXT_HH_ */
5 changes: 3 additions & 2 deletions Library/Processor/KTProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "KTProcessor.hh"

#include "KTContext.hh"
//#include "KTLogger.hh"

#include <boost/foreach.hpp>
Expand All @@ -26,10 +27,10 @@ namespace Nymph

KTProcessor::KTProcessor(const string& name) :
KTConfigurable(name),
KTHasContext(),
fSignalMap(),
fSlotMap()
{
}
{}

KTProcessor::~KTProcessor()
{
Expand Down
5 changes: 4 additions & 1 deletion Library/Processor/KTProcessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define KTPROCESSOR_HH_

#include "KTConfigurable.hh"
#include "KTContext.hh"

#include "KTConnection.hh"
#include "KTLogger.hh"
Expand All @@ -24,20 +25,22 @@

#include <exception>
#include <map>
#include <memory>
#include <sstream>
#include <string>

namespace Nymph
{
KTLOGGER(processorlog, "KTProcessor.hh");


class ProcessorException : public std::logic_error
{
public:
ProcessorException(std::string const& why);
};

class KTProcessor : public KTConfigurable
class KTProcessor : public KTConfigurable, public KTHasContext
{
protected:
typedef std::map< std::string, KTSignalWrapper* > SignalMap;
Expand Down
4 changes: 2 additions & 2 deletions Library/Utility/KTLogger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ namespace Nymph
fPrivate->fLogger = logName;
}
fPrivate->fColored = true;
sprintf(KTLogger::Private::sDateTimeFormat, "%%T");
snprintf(KTLogger::Private::sDateTimeFormat, 16, "%%T");
SetLevel(eDebug);
}

KTLogger::KTLogger(const std::string& name) : fPrivate(new Private())
{
fPrivate->fLogger = name.c_str();
fPrivate->fColored = true;
sprintf(KTLogger::Private::sDateTimeFormat, "%%T");
snprintf(KTLogger::Private::sDateTimeFormat, 16, "%%T");
SetLevel(eDebug);
}

Expand Down