-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from DUNE-DAQ/aeoranday/refactoring
Trigger Activity Factory Refactorization
- Loading branch information
Showing
21 changed files
with
180 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* @file: TriggerActivityFactory.hpp | ||
* | ||
* This is part of the DUNE DAQ Application Framework, copyright 2023. | ||
* Licensing/copyright details are in the COPYING file that you should have | ||
* received with this code. | ||
*/ | ||
|
||
#ifndef TRIGGERALGS_TRIGGER_ACTIVITY_FACTORY_HPP_ | ||
#define TRIGGERALGS_TRIGGER_ACTIVITY_FACTORY_HPP_ | ||
|
||
#include "triggeralgs/TriggerActivityMaker.hpp" | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <functional> | ||
|
||
#define REGISTER_TRIGGER_ACTIVITY_MAKER(tam_name, tam_class) \ | ||
static struct tam_class##Registrar { \ | ||
tam_class##Registrar() { \ | ||
TriggerActivityFactory::registerCreator(tam_name, []() -> std::shared_ptr<TriggerActivityMaker> {return std::make_shared<tam_class>();}); \ | ||
} \ | ||
} tam_class##_registrar; | ||
|
||
namespace triggeralgs { | ||
|
||
class TriggerActivityFactory | ||
{ | ||
public: | ||
using TAMakerCreator = std::function<std::shared_ptr<TriggerActivityMaker>()>; | ||
using TAMakerMap = std::unordered_map<std::string, TAMakerCreator>; | ||
|
||
public: | ||
TriggerActivityFactory(const TriggerActivityFactory&) = delete; | ||
TriggerActivityFactory& operator=(const TriggerActivityFactory&) = delete; | ||
virtual ~TriggerActivityFactory() {} | ||
|
||
static std::shared_ptr<TriggerActivityMaker> makeTAMaker(const std::string& algName); | ||
|
||
static void registerCreator(const std::string algName, TAMakerCreator creator); | ||
|
||
private: | ||
static TAMakerMap& getTAMakers(); | ||
}; | ||
|
||
} /* namespace triggeralgs */ | ||
|
||
// TODO: Define ers exceptions | ||
#endif // TRIGGERALGS_TRIGGER_ACTIVITY_FACTORY_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* @file: TriggerActivityFactory.cpp | ||
* | ||
* This is part of the DUNE DAQ Application Framework, copyright 2023. | ||
* Licensing/copyright details are in the COPYING file that you should have | ||
* received with this code. | ||
*/ | ||
#include <iostream> | ||
|
||
#include "triggeralgs/TriggerActivityFactory.hpp" | ||
#include "TRACE/trace.h" | ||
#define TRACE_NAME "TriggerActivityFactory" | ||
|
||
using namespace triggeralgs; | ||
|
||
TriggerActivityFactory::TAMakerMap& TriggerActivityFactory::getTAMakers() { | ||
static TAMakerMap s_makers; | ||
return s_makers; | ||
} | ||
|
||
void TriggerActivityFactory::registerCreator(const std::string algName, TAMakerCreator creator) | ||
{ | ||
TAMakerMap& makers = getTAMakers(); | ||
|
||
auto it = makers.find(algName); | ||
if (it == makers.end()) { | ||
makers[algName] = creator; | ||
} | ||
} | ||
|
||
std::shared_ptr<TriggerActivityMaker> TriggerActivityFactory::makeTAMaker(const std::string& algName) | ||
{ | ||
TAMakerMap& makers = getTAMakers(); | ||
|
||
auto it = makers.find(algName); | ||
if (it != makers.end()) { | ||
return it->second(); | ||
} | ||
|
||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
|
||
add_executable(test_trivial test_trivial.cxx) | ||
target_include_directories(test_trivial PRIVATE ${BOOST_INCLUDE_DIRS}) | ||
add_test(NAME trivial COMMAND test_trivial) | ||
|
||
add_executable(test_supernova test_supernova.cxx) | ||
target_include_directories(test_supernova PRIVATE ${BOOST_INCLUDE_DIRS}) | ||
add_test(NAME supernova COMMAND test_supernova) | ||
add_executable(test_factory test_factory.cxx) | ||
target_link_libraries(test_factory PRIVATE triggeralgs trgdataformats::trgdataformats) | ||
target_include_directories(test_factory PRIVATE ${BOOST_INCLUDE_DIRS}) | ||
add_test(NAME factory COMMAND test_factory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @file test_factory.cxx | ||
* | ||
* This is part of the DUNE DAQ Application Framework, copyright 2023. | ||
* Licensing/copyright details are in the COPYING file that you should have | ||
* received with this code. | ||
*/ | ||
|
||
// NOLINTNEXTLINE(build/define_used) | ||
#define BOOST_TEST_MODULE boost_test_macro_overview | ||
|
||
#include "triggeralgs/TriggerActivityFactory.hpp" | ||
#include "triggeralgs/TriggerActivityMaker.hpp" | ||
|
||
#include <boost/test/included/unit_test.hpp> | ||
|
||
#include <iostream> | ||
#include <vector> | ||
|
||
using namespace dunedaq; | ||
|
||
namespace triggeralgs { | ||
|
||
BOOST_AUTO_TEST_CASE(test_macro_overview) | ||
{ | ||
std::shared_ptr<TriggerActivityMaker> prescale_maker = TriggerActivityFactory::makeTAMaker("TriggerActivityMakerPrescalePlugin"); | ||
|
||
std::vector<TriggerActivity> prescale_ta; | ||
TriggerPrimitive some_tp; | ||
for (int idx = 0; idx < 10; idx++) { | ||
some_tp.type = TriggerPrimitive::Type::kTPC; | ||
some_tp.algorithm = TriggerPrimitive::Algorithm::kTPCDefault; | ||
some_tp.time_start = idx; | ||
some_tp.time_peak = 1+idx; | ||
some_tp.time_over_threshold = 2; | ||
some_tp.adc_integral = 1000+idx; | ||
some_tp.adc_peak = 1000+idx; | ||
some_tp.channel = 0+idx; | ||
some_tp.detid = 0; | ||
(*prescale_maker)(some_tp, prescale_ta); | ||
} | ||
|
||
bool same_alg = (prescale_ta[0].algorithm == TriggerActivity::Algorithm::kPrescale); | ||
|
||
BOOST_TEST(same_alg); | ||
} | ||
|
||
} /* namespace triggeralgs */ |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.