diff --git a/aux/inc/WireCellAux/Testing.h b/aux/inc/WireCellAux/Testing.h index d12ced5b..cac39015 100644 --- a/aux/inc/WireCellAux/Testing.h +++ b/aux/inc/WireCellAux/Testing.h @@ -21,10 +21,7 @@ #include #include -namespace WireCell::Aux::Testing { - - // Load plugins. If empty, load "core" plugins. - void load_plugins(std::vector list = {}); +namespace WireCell::Testing { // Return default-configured configurable interface. template @@ -43,14 +40,8 @@ namespace WireCell::Aux::Testing { // Return named Random IRandom::pointer get_random(const std::string& name="default"); - // A number of named detectors are 'known' here. - const std::vector& known_detectors(); - - // Return some configured anodes for a known detector. + // Return configured anodes for a known detector. IAnodePlane::vector anodes(const std::string detector); - // Initialize WCT logging with argv[0]. - // void loginit(const char* argv0); - } diff --git a/aux/src/Testing.cxx b/aux/src/Testing.cxx index f026a5b5..105d4364 100644 --- a/aux/src/Testing.cxx +++ b/aux/src/Testing.cxx @@ -1,29 +1,20 @@ #include "WireCellAux/Testing.h" -#include "WireCellUtil/PluginManager.h" +#include "WireCellUtil/Testing.h" #include "WireCellUtil/NamedFactory.h" -#include "WireCellIface/IConfigurable.h" + +#include "WireCellIface/IWireSchema.h" #include // find using namespace WireCell; using namespace WireCell::Aux; -void Testing::load_plugins(std::vector list) -{ - PluginManager& pm = PluginManager::instance(); - - if (list.empty()) { - list = {"WireCellAux", "WireCellGen", "WireCellSigProc", "WireCellPgraph", "WireCellImg", "WireCellSio", "WireCellApps"}; - } - for (const auto& one : list) { - pm.add(one); - } -} - WireCell::IDFT::pointer Testing::get_dft() { - load_plugins({"WireCellAux"}); + // load_plugins({"WireCellAux"}); + // we are in Aux, so no need to load! + return Factory::lookup("FftwDFT"); // not configurable } @@ -40,77 +31,59 @@ WireCell::IRandom::pointer Testing::get_random(const std::string& name) } -static std::vector knowndets = {"uboone", "pdsp"}; -const std::vector& Testing::known_detectors() +IAnodePlane::vector Testing::anodes(std::string detector) { - return knowndets; -} + // Probably should move WSF and FR to aux.... + Testing::load_plugins({"WireCellGen", "WireCellSigProc"}); -static void assert_known_det(const std::string& det) -{ - if (std::find(knowndets.begin(), knowndets.end(), det) == knowndets.end()) { - THROW(ValueError() << errmsg{"unknown detector: " + det}); - } -} + auto kds = detectors(); + const auto& kd = kds[detector]; + if (kd.isNull()) { + raise("unknown detector \"%s\"", detector); + } -IAnodePlane::vector Testing::anodes(std::string detector) -{ - assert_known_det(detector); - load_plugins({"WireCellGen", "WireCellSigProc"}); - IAnodePlane::vector anodes; + const std::string ws_tn = "WireSchemaFile"; { - int nanodes = 1; - // Note: these files must be located via WIRECELL_PATH - std::string ws_fname = "microboone-celltree-wires-v2.1.json.bz2"; - std::string fr_fname = "ub-10-half.json.bz2"; - if (detector == "uboone") { - ws_fname = "microboone-celltree-wires-v2.1.json.bz2"; - fr_fname = "ub-10-half.json.bz2"; - } - if (detector == "pdsp") { - ws_fname = "protodune-wires-larsoft-v4.json.bz2"; - fr_fname = "garfield-1d-3planes-21wires-6impacts-dune-v1.json.bz2"; - nanodes = 6; - } - - const std::string fr_tn = "FieldResponse"; - const std::string ws_tn = "WireSchemaFile"; + auto icfg = Factory::lookup(ws_tn); + auto cfg = icfg->default_configuration(); + cfg["filename"] = kd["wires"]; + icfg->configure(cfg); + } - { - auto icfg = Factory::lookup(fr_tn); - auto cfg = icfg->default_configuration(); - cfg["filename"] = fr_fname; - icfg->configure(cfg); - } - { - auto icfg = Factory::lookup(ws_tn); - auto cfg = icfg->default_configuration(); - cfg["filename"] = ws_fname; - icfg->configure(cfg); - } + const std::string fr_tn = "FieldResponse"; + { + auto icfg = Factory::lookup(fr_tn); + auto cfg = icfg->default_configuration(); + cfg["filename"] = kd["fields"]; + icfg->configure(cfg); + } - for (int ianode = 0; ianode < nanodes; ++ianode) { + auto iwsf = Factory::lookup_tn(ws_tn); + const auto& wstore = iwsf->wire_schema_store(); + const auto& wdets = wstore.detectors(); + const auto& wanodes = wstore.detectors(); + + IAnodePlane::vector ret; + for (const auto& det : wdets) { + for (const auto& anode_index : det.anodes) { + const auto& anode = wanodes[anode_index]; + const int ianode = anode.ident; + std::string tn = String::format("AnodePlane:%d", ianode); auto icfg = Factory::lookup_tn(tn); auto cfg = icfg->default_configuration(); cfg["ident"] = ianode; cfg["wire_schema"] = ws_tn; + + // FIXME: this is NOT general and needs to be retrieved from detectors.jsonnet somehow!!!! cfg["faces"][0]["response"] = 10 * units::cm - 6 * units::mm; cfg["faces"][0]["cathode"] = 2.5604 * units::m; + icfg->configure(cfg); - anodes.push_back(Factory::find_tn(tn)); + ret.push_back(Factory::find_tn(tn)); } } - return anodes; + return ret; } -// void Testing::loginit(const char* argv0) -// { -// std::string name = argv0; -// name += ".log"; -// Log::add_stderr(true, "trace"); -// Log::add_file(name, "trace"); -// Log::set_level("trace"); -// Log::set_pattern("[%H:%M:%S.%03e] %L [%^%=8n%$] %v"); -// } diff --git a/aux/test/test_noisetools.cxx b/aux/test/test_noisetools.cxx index 030af3d9..65e6b88d 100644 --- a/aux/test/test_noisetools.cxx +++ b/aux/test/test_noisetools.cxx @@ -16,7 +16,7 @@ using namespace WireCell; using namespace WireCell::Spectrum; using namespace WireCell::String; -using namespace WireCell::Aux::Testing; +using namespace WireCell::Testing; using namespace WireCell::Aux::RandTools; using namespace WireCell::Aux::DftTools; using namespace WireCell::Aux::NoiseTools; diff --git a/util/inc/WireCellUtil/Testing.h b/util/inc/WireCellUtil/Testing.h index f52a5e82..fb87533d 100644 --- a/util/inc/WireCellUtil/Testing.h +++ b/util/inc/WireCellUtil/Testing.h @@ -1,24 +1,34 @@ #ifndef WIRECELLUTIL_TESTING #define WIRECELLUTIL_TESTING +#include "WireCellUtil/Configuration.h" + #define BOOST_ENABLE_ASSERT_HANDLER 1 #include #define Assert BOOST_ASSERT #define AssertMsg BOOST_ASSERT_MSG +#include +#include + namespace boost { void assertion_failed(char const* expr, char const* function, char const* file, long line); void assertion_failed_msg(char const* expr, char const* msg, char const* function, char const* file, long line); } // namespace boost -namespace WireCell { - namespace Testing { - // Add a stderr and file log sink based on the argv[0] name. - // Bare calls, eg, spdlog::debug() may then be issued. - void log(const char* argv0); +namespace WireCell::Testing { + + // Add a stderr and file log sink based on the argv[0] name. + // Bare calls, eg, spdlog::debug() may then be issued. + void log(const char* argv0); + + // Load plugins. If empty, load "core" plugins. + void load_plugins(std::vector list = {}); + + // Return the known detectors object from a given source. + Configuration detectors(const std::string& source="detectors.jsonnet"); - } } // namespace WireCell #endif diff --git a/util/src/Testing.cxx b/util/src/Testing.cxx index 9a9cc490..242cf31a 100644 --- a/util/src/Testing.cxx +++ b/util/src/Testing.cxx @@ -1,6 +1,8 @@ #include "WireCellUtil/Testing.h" #include "WireCellUtil/Exceptions.h" #include "WireCellUtil/Logging.h" +#include "WireCellUtil/PluginManager.h" +#include "WireCellUtil/Persist.h" #include @@ -30,3 +32,21 @@ void Testing::log(const char* argv0) Log::add_stderr(true, "trace"); Log::add_file(name, "trace"); } + +void Testing::load_plugins(std::vector list) +{ + PluginManager& pm = PluginManager::instance(); + + if (list.empty()) { + list = {"WireCellAux", "WireCellGen", "WireCellSigProc", "WireCellPgraph", "WireCellImg", "WireCellSio", "WireCellApps"}; + } + for (const auto& one : list) { + pm.add(one); + } +} + +Configuration Testing::detectors(const std::string& filename) +{ + return Persist::load(filename); +} +