Skip to content

Commit

Permalink
Factor Testing namespace and add interface to detectors.jsonnet content.
Browse files Browse the repository at this point in the history
  • Loading branch information
brettviren committed Feb 14, 2024
1 parent 444f7a0 commit 2cbba27
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 88 deletions.
13 changes: 2 additions & 11 deletions aux/inc/WireCellAux/Testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
#include <string>
#include <vector>

namespace WireCell::Aux::Testing {

// Load plugins. If empty, load "core" plugins.
void load_plugins(std::vector<std::string> list = {});
namespace WireCell::Testing {

// Return default-configured configurable interface.
template<typename IFACE>
Expand All @@ -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<std::string>& 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);

}

113 changes: 43 additions & 70 deletions aux/src/Testing.cxx
Original file line number Diff line number Diff line change
@@ -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 <algorithm> // find

using namespace WireCell;
using namespace WireCell::Aux;

void Testing::load_plugins(std::vector<std::string> 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<IDFT>("FftwDFT"); // not configurable
}

Expand All @@ -40,77 +31,59 @@ WireCell::IRandom::pointer Testing::get_random(const std::string& name)
}


static std::vector<std::string> knowndets = {"uboone", "pdsp"};
const std::vector<std::string>& 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<ValueError>("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<IConfigurable>(ws_tn);
auto cfg = icfg->default_configuration();
cfg["filename"] = kd["wires"];
icfg->configure(cfg);
}

{
auto icfg = Factory::lookup<IConfigurable>(fr_tn);
auto cfg = icfg->default_configuration();
cfg["filename"] = fr_fname;
icfg->configure(cfg);
}
{
auto icfg = Factory::lookup<IConfigurable>(ws_tn);
auto cfg = icfg->default_configuration();
cfg["filename"] = ws_fname;
icfg->configure(cfg);
}
const std::string fr_tn = "FieldResponse";
{
auto icfg = Factory::lookup<IConfigurable>(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<IWireSchema>(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<IConfigurable>(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<IAnodePlane>(tn));
ret.push_back(Factory::find_tn<IAnodePlane>(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");
// }
2 changes: 1 addition & 1 deletion aux/test/test_noisetools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 16 additions & 6 deletions util/inc/WireCellUtil/Testing.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
#ifndef WIRECELLUTIL_TESTING
#define WIRECELLUTIL_TESTING

#include "WireCellUtil/Configuration.h"

#define BOOST_ENABLE_ASSERT_HANDLER 1
#include <boost/assert.hpp>

#define Assert BOOST_ASSERT
#define AssertMsg BOOST_ASSERT_MSG

#include <string>
#include <vector>

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<std::string> list = {});

// Return the known detectors object from a given source.
Configuration detectors(const std::string& source="detectors.jsonnet");

}
} // namespace WireCell

#endif
20 changes: 20 additions & 0 deletions util/src/Testing.cxx
Original file line number Diff line number Diff line change
@@ -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 <sstream>

Expand Down Expand Up @@ -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<std::string> 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);
}

0 comments on commit 2cbba27

Please sign in to comment.