Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema based configuration #105

Draft
wants to merge 140 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
a328d01
update with new naming
HaiwangYu Apr 26, 2021
6006cb2
add json cfg
HaiwangYu Apr 26, 2021
aeab056
use pcbro for now
HaiwangYu Apr 27, 2021
e7f1ecf
response_plane as parameter
HaiwangYu Jun 8, 2021
a2a271f
add nf-sp for VD
HaiwangYu Jun 8, 2021
8718436
G4RefTime as parameter
HaiwangYu Jun 8, 2021
8e4917f
config. response_plane
HaiwangYu Jun 10, 2021
26721c1
offset fix
HaiwangYu Jun 10, 2021
6ecbfdb
ch_per_plane and other configurations
HaiwangYu Jun 10, 2021
946b1ca
init wcls-sim-drift-simchannel.fcl
HaiwangYu Jun 14, 2021
d47a145
Very first step of schema based configuration.
brettviren Jun 21, 2021
db59ef0
Break each schema into its own pair of headers
brettviren Jun 21, 2021
22728e1
Convert TrackDepos to schema based configuration
brettviren Jun 22, 2021
8a4bab3
fix code and string miss-use
HaiwangYu Jun 23, 2021
a8cb14d
json -> jsonnet
HaiwangYu Jun 23, 2021
ad6f91b
Add generation of Jsonnet constructor functions
brettviren Jun 24, 2021
6909b91
Fix regressions in TrackDepos and convert Ductor and DepoSplat
brettviren Jun 25, 2021
ad43503
Add codegen to wscript, needing a naming convention change
brettviren Jun 25, 2021
b84a807
Remove now undeeded manual script, update readme to match
brettviren Jun 25, 2021
be06c9e
add fcl param
HaiwangYu Jun 30, 2021
834f900
fix typo
HaiwangYu Jun 30, 2021
a969fbb
Drop C++ jsonnet and use C API
brettviren Jul 1, 2021
a04641a
Merge pull request #107 from brettviren/cgojsonnet
HaiwangYu Jul 7, 2021
04210fc
merge master
HaiwangYu Jul 8, 2021
8f1fe93
More conversion to schema
brettviren Jul 15, 2021
635fa23
Fix #109.
brettviren Jul 16, 2021
aa91137
Merge pull request #110 from brettviren/add-back-mt
brettviren Jul 23, 2021
d577b97
Fix #113 by making ImpactResponse::spectrum() thread safe.
brettviren Jul 23, 2021
baa313e
Merge pull request #114 from WireCell/fix-ii-mt-race
brettviren Jul 26, 2021
9fe1184
Fix #115 array ordering mismatch and deal with Numpy dynamically chos…
brettviren Jul 26, 2021
e516ac9
Merge pull request #116 from WireCell/fix115
brettviren Jul 26, 2021
1d06dbd
Make parent directory for output npz if it doesn't exist. Fix #117
brettviren Jul 29, 2021
34d36a4
Do not try to make the parent directory if it is not located
brettviren Aug 3, 2021
f7a3ed1
This test came back, it should be disabled
brettviren Aug 3, 2021
adb19ef
Make tagging of Ductor configurable
brettviren Aug 3, 2021
2912486
Break DepoSplat away from using Ductor as base to reduce confusion ab…
brettviren Aug 3, 2021
a13a04d
More consistent frame tagging, add fluctuation to DepoSplat
brettviren Aug 4, 2021
ddeee20
Add cluster file sink and clean up the nodes graph dot
brettviren Aug 10, 2021
7a05eb8
git subrepo clone git@github.com:brettviren/custard.git sio/src/custard
brettviren Aug 10, 2021
701b707
Move private cluster helpers to aux, get basic sink written
brettviren Aug 10, 2021
9dd7861
Get numpy writing initially tested
brettviren Aug 11, 2021
8faf80f
Add start of frame file sink and make 'Aux' namespace consistently ca…
brettviren Aug 11, 2021
9d3758c
Rename files, add make and test and more docs
brettviren Aug 12, 2021
483ed78
Move nljs, custard finishes/fixes
brettviren Aug 12, 2021
d337b9e
git subrepo push sio/src/custard
brettviren Aug 12, 2021
82784b1
Remove custard subrepo in prep to move it to better spot
brettviren Aug 12, 2021
1f4b162
git subrepo clone git@github.com:brettviren/custard.git util/inc/custard
brettviren Aug 12, 2021
0935c92
Test and fix vector writing.
brettviren Aug 12, 2021
a1190f6
git subrepo push util/inc/custard
brettviren Aug 12, 2021
5c165f5
Add a 'tap' construction pattern for pgrapher
brettviren Aug 12, 2021
6664a02
Check for EOS and protect against empty frames
brettviren Aug 12, 2021
d264fa4
Use correct file ext
brettviren Aug 13, 2021
06777e0
Use only unity concurrence. Fix #121.
brettviren Aug 13, 2021
666c358
Logging cleanup and improvements made along the way to fixing #121.
brettviren Aug 13, 2021
b3ee9a8
Pop and do not flush at EOS.
brettviren Aug 13, 2021
028e9ea
Fix more bad logging
brettviren Aug 13, 2021
83007c9
Fix ordering of filters and add tests for compression/decompress
brettviren Aug 13, 2021
4c75841
Assure output directory
brettviren Aug 14, 2021
41656c8
Make frame file sink an ITerminal so it may close the file at exit
brettviren Aug 14, 2021
4756db5
git subrepo push util/inc/custard
brettviren Aug 14, 2021
7952064
Fix typos in .npy file name pattern
brettviren Aug 16, 2021
d6c4c62
git subrepo pull util/inc/custard
brettviren Aug 16, 2021
61b8f93
Again move these 'private' vendored headers to a spot less likely to …
brettviren Aug 17, 2021
5e968b5
git subrepo clone git@github.com:brettviren/custard.git util/src/custard
brettviren Aug 17, 2021
ed66508
Add nljs directly
brettviren Aug 17, 2021
07e0e35
git subrepo push util/src/custard
brettviren Aug 17, 2021
d9878f9
Build pedantic clean
brettviren Aug 17, 2021
b2bdf15
git subrepo push util/src/custard
brettviren Aug 17, 2021
92bfc35
Again with the moving
brettviren Aug 17, 2021
e873b22
git subrepo clone git@github.com:brettviren/custard.git util/inc/custard
brettviren Aug 17, 2021
41ac979
Integrate custard
brettviren Aug 17, 2021
0245b05
Quiet missed cerr
brettviren Aug 17, 2021
458166b
git subrepo push util/inc/custard
brettviren Aug 17, 2021
bd24940
Finish integrating custard/pigenc
brettviren Aug 17, 2021
5e3b017
A test relevant to #122 about boost deprecated warnings
brettviren Aug 17, 2021
2bd197e
Cherry pick 'option for skipping the roi refinement'
wenqiang-gu Aug 3, 2021
fa10162
Merge pull request #119 from WireCell/fixes-and-additions
HaiwangYu Aug 17, 2021
cd69626
Merge pull request #108 from HaiwangYu/dune-vd
HaiwangYu Aug 17, 2021
4878f9b
merge
HaiwangYu Aug 18, 2021
8d5cde0
add IDepoSetFilter and IDepoSetSource.h
HaiwangYu Aug 20, 2021
364a367
update
HaiwangYu Aug 20, 2021
1e28e02
to be complete
HaiwangYu Aug 20, 2021
31e7580
to be complete
HaiwangYu Aug 20, 2021
c4e465f
Merge pull request #123 from HaiwangYu/dev
brettviren Aug 20, 2021
7879dbb
Logging tweaks while chasing some imaging bug
brettviren Aug 20, 2021
0ed7199
Merge branch 'master' of github.com:wirecell/wire-cell-toolkit
brettviren Aug 20, 2021
90ad049
Improve logging and let components know their name.
brettviren Aug 23, 2021
9f5dc5e
Replace ignored and unactionable cerr with a return of the
brettviren Aug 23, 2021
c77c8a6
Add a version string.
brettviren Aug 23, 2021
79d7ff1
Remove vestigial python/ sub package.
brettviren Aug 23, 2021
7e147b0
Possibly fix the out-of-order problem with split_node
brettviren Aug 24, 2021
a9f336b
Maybe for real fix the out-of-order problem.
brettviren Aug 25, 2021
9c1e05b
Fix template specializations to be inline
brettviren Aug 26, 2021
b5cc10c
Add frame file source for #111. Needs testing
brettviren Aug 26, 2021
8c6d7ae
Clean and test frame file source. Fix #111.
brettviren Aug 26, 2021
fa04dd3
Simplest DepoSetDrifter using a Drifter
brettviren Aug 26, 2021
f5e48bf
Add depo set loader and fix depo set drifter
brettviren Aug 26, 2021
462511e
Merge pull request #127 from WireCell/fixes-and-additions2
brettviren Aug 27, 2021
5ba97af
Merge remote-tracking branch 'origin/master'
brettviren Aug 27, 2021
40dc839
Merge pull request #129 from WireCell/fixes-and-additions3
brettviren Aug 27, 2021
4a77094
Adjust C-API calling code according to go-jsonnet's C bindings.
knoepfel Sep 8, 2021
e348f27
Merge pull request #130 from knoepfel/c-api-adjustments
brettviren Sep 8, 2021
3ba1002
Add depo set file source/sink using tar stream of numpy files
brettviren Oct 7, 2021
21015dc
Add depo set file source/sink using tar stream of numpy files
brettviren Oct 7, 2021
9395cd5
Merge branch 'hybrid-wcls' of github.com:WireCell/wire-cell-toolkit i…
brettviren Oct 11, 2021
d3d94b6
Add test for load failures and update wcb/waf-tools to handle new lib…
brettviren Oct 12, 2021
f7afb12
Only do special linking if torch_cuda is used
brettviren Oct 12, 2021
bf53e7b
Convert to logger, fix timing measurements
brettviren Oct 15, 2021
06c5933
Some flailing to avoid torch error about data on both cpu and cuda.
brettviren Oct 16, 2021
47e13aa
Checkpoint
brettviren Oct 16, 2021
27327f5
Merge branch 'hybrid-wcls' of github.com:WireCell/wire-cell-toolkit i…
brettviren Oct 16, 2021
4e93222
Add torch service currently with DRF using it or optionally the old t…
brettviren Oct 16, 2021
cb608c8
Semaphore and torch device cleanups
brettviren Oct 18, 2021
5c1fa11
Make threshold configurable
brettviren Oct 18, 2021
9c08877
Add scale setting intended to allow charge sign flipping. See #133 f…
brettviren Oct 20, 2021
4bdbe66
Give 'trivial' mode where full frame is fanned without tag fules
brettviren Oct 20, 2021
afa2b63
Clarify log/error message and improve the temporary debug dependency …
brettviren Oct 20, 2021
7cdbb04
Add options to save frames as 'dense'.
brettviren Oct 20, 2021
7d11aa4
Quiet some output
brettviren Oct 20, 2021
79d42d6
Logging cleanups and give channel selector optional tag rules
brettviren Oct 21, 2021
625e7f1
Clarify cbeg and cend as being relative to the smallest channel ID in…
brettviren Oct 22, 2021
e86d1c6
Add ability to select traces by plane.
brettviren Oct 26, 2021
21cf05e
Improve tag handling in plane selector, add message if non-unity outp…
brettviren Oct 28, 2021
90eb3d0
Make it an Aux::Logger
brettviren Oct 28, 2021
ad74e14
Add test of pdsp sim sp dnnroi and a suite of new 'helper' configurat…
brettviren Oct 28, 2021
a966fcb
Merge pull request #131 from WireCell/hybrid-wcls
HaiwangYu Nov 11, 2021
551840d
Make test executable
brettviren Dec 6, 2021
2cb4a17
Very first step of schema based configuration.
brettviren Jun 21, 2021
b9b53c0
Break each schema into its own pair of headers
brettviren Jun 21, 2021
ec8d88f
Merge fixes after rebase cfgschema branch on top of recent master
brettviren Dec 6, 2021
77c5cb1
Add generation of Jsonnet constructor functions
brettviren Jun 24, 2021
2fba70c
Fix regressions in TrackDepos and convert Ductor and DepoSplat
brettviren Jun 25, 2021
980f8b4
Add codegen to wscript, needing a naming convention change
brettviren Jun 25, 2021
b967cc7
Remove now undeeded manual script, update readme to match
brettviren Jun 25, 2021
898f355
More conversion to schema
brettviren Jul 15, 2021
a9382cd
Merge fixes
brettviren Dec 6, 2021
083a081
Get config schema branch building again after rebase and add Aux::Con…
brettviren Dec 7, 2021
78bb231
Make single header for each schema which combines structs and nljs
brettviren Dec 7, 2021
ff7874c
Schema-based config, back on track
brettviren Dec 7, 2021
bde5e82
Edits
brettviren Dec 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ calgrind.*
*.hdf
wct-deps.dot


.direnv
.envrc
7 changes: 7 additions & 0 deletions apps/inc/WireCellApps/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,18 @@ namespace WireCell {
/// Call to finalize any terminal components.
void finalize();

/// Return the compiled version string
std::string version() const;

private:
ConfigManager m_cfgmgr;
std::vector<std::string> m_plugins, m_apps, m_cfgfiles, m_load_path;
Persist::externalvars_t m_extvars, m_extcode, m_tlavars, m_tlacode;
Log::logptr_t l;

// Limit number of threads. 0 means set no limit. This is
// only relevant if we are built with TBB support
int m_threads{0};
};

} // namespace WireCell
Expand Down
76 changes: 70 additions & 6 deletions apps/src/Main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

#include "WireCellApps/Main.h"

#include "WireCellUtil/Version.h"
#include "WireCellUtil/NamedFactory.h"
#include "WireCellUtil/String.h"
#include "WireCellUtil/Point.h"

#include "WireCellIface/IConfigurable.h"
#include "WireCellIface/ITerminal.h"
#include "WireCellIface/IApplication.h"
#include "WireCellIface/INamed.h"

#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
Expand All @@ -25,6 +27,10 @@
#include <fftw3.h>
#endif

#if HAVE_TBB_LIB
#include <tbb/global_control.h>
#endif

using namespace WireCell;
using namespace std;
namespace po = boost::program_options;
Expand Down Expand Up @@ -79,7 +85,16 @@ int Main::cmdline(int argc, char* argv[])
"specify a Jsonnet top level arguments variable=<code>")

("path,P", po::value<vector<string> >(),
"add to JSON/Jsonnet search path");
"add to JSON/Jsonnet search path")
#if HAVE_TBB_LIB
("threads,t", po::value<int>(),
"limit number of threads used")
#endif

("version,v",
"print the compiled version to stdout")

;
// clang-format on

po::variables_map opts;
Expand Down Expand Up @@ -171,13 +186,28 @@ int Main::cmdline(int argc, char* argv[])
}
}

#ifdef HAVE_TBB_LIB
if (opts.count("threads")) {
m_threads = opts["threads"].as<int>();
}
#endif

if (opts.count("version")) {
std::cout << version() << std::endl;
}

// Maybe make this cmdline configurable. For now, set all
// backends the same.
Log::set_pattern("[%H:%M:%S.%03e] %L [%^%=8n%$] %v");

return 0;
}

std::string Main::version() const
{
return WireCell::version;
}

void Main::add_plugin(const std::string& libname) { m_plugins.push_back(libname); }

void Main::add_app(const std::string& tn) { m_apps.push_back(tn); }
Expand Down Expand Up @@ -209,6 +239,9 @@ void Main::add_path(const std::string& dirname) { m_load_path.push_back(dirname)

void Main::initialize()
{
// Here we got thought the boot-up sequence steps.

// Load configuration files
for (auto filename : m_cfgfiles) {
l->info("loading config file {} ...", filename);
Persist::Parser p(m_load_path, m_extvars, m_extcode, m_tlavars, m_tlacode);
Expand All @@ -217,7 +250,7 @@ void Main::initialize()
l->info("...done");
}

// Find if we have our special configuration entry
// Find if we have our own special configuration entry
int ind = m_cfgmgr.index("wire-cell");
Configuration main_cfg = m_cfgmgr.pop(ind);
if (!main_cfg.isNull()) {
Expand All @@ -243,11 +276,9 @@ void Main::initialize()
pm.add(pname, lname);
}

// Apply any user configuration. This is a two step. First, just
// assure all the components referenced in the configuration
// sequence can be instantiated. Then, find them again and
// actually configure them. This way, any problems fails fast.
// Apply any component configuration sequence.

// Instantiation
for (auto c : m_cfgmgr.all()) {
if (c.isNull()) {
continue; // allow and ignore any totally empty configurations
Expand All @@ -265,6 +296,23 @@ void Main::initialize()
l->info("constructing app: \"{}\"", c);
Factory::lookup_tn<IApplication>(c);
}

// Give any named components their name.
for (auto c : m_cfgmgr.all()) {
if (c.isNull()) {
continue; // allow and ignore any totally empty configurations
}
string type = get<string>(c, "type");
string name = get<string>(c, "name");
auto namobj = Factory::find_maybe<INamed>(type, name); // doesn't throw.
if (!namobj) {
continue;
}
namobj->set_name(name);
}

// Finally, ask any configurables for their default, merge with
// user config and give back.
for (auto c : m_cfgmgr.all()) {
if (c.isNull()) {
continue; // allow and ignore any totally empty configurations
Expand Down Expand Up @@ -295,12 +343,28 @@ void Main::operator()()
auto a = Factory::find<IApplication>(type, name); // throws
app_objs.push_back(a);
}
l->debug("executing {} apps, thread limit {}:",
m_apps.size(), m_threads);

#if HAVE_TBB_LIB
std::unique_ptr<tbb::global_control> gc;
if (m_threads) {
gc = std::make_unique<tbb::global_control>(
tbb::global_control::max_allowed_parallelism,
m_threads);
}
l->debug("executing {} apps, thread limit {}:",
m_apps.size(), m_threads);
#else
l->debug("executing {} apps:", m_apps.size());
#endif

for (size_t ind = 0; ind < m_apps.size(); ++ind) {
auto aobj = app_objs[ind];
l->debug("executing app: \"{}\"", m_apps[ind]);
aobj->execute(); // throws
}

}

void Main::finalize()
Expand Down
7 changes: 6 additions & 1 deletion apps/wscript_build
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
bld.smplpkg('WireCellApps', use='WireCellIface FFTWTHREADS')
if 'HAVE_TBB' in bld.env:
bld.smplpkg('WireCellApps', use='WireCellIface FFTWTHREADS TBB')
else:
bld.smplpkg('WireCellApps', use='WireCellIface FFTWTHREADS')


# app_use='WireCellUtil JSONNET',
# test_use='WireCellUtil DYNAMO BOOST JSONCPP JSONNET')
33 changes: 33 additions & 0 deletions aux/inc/WireCellAux/ClusterHelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Provide some helper functions for working with ICluster

#ifndef WIRECELLAUX_CLUSTERJSONIFY
#define WIRECELLAUX_CLUSTERJSONIFY

#include "WireCellUtil/Configuration.h"
#include "WireCellIface/IFrame.h"
#include "WireCellIface/ISlice.h"
#include "WireCellIface/ICluster.h"

#include <string>

namespace WireCell::Aux {
/// Return JSON representation of the cluster.
Json::Value jsonify(const ICluster::pointer& cluster,
double drift_speed);

/// Return name for the cluster in a canonical form suitable for
/// use as a file name. It only includes info related directly to
/// the cluster (the ident).
std::string name(const ICluster::pointer& cluster);

/// Return the slices in the cluster.
ISlice::vector find_slices(const ICluster::pointer& cluster);

/// Return the frame of the first slice in the cluster. Note, in
/// principle, clusters can span frames.
IFrame::pointer find_frame(const ICluster::pointer& cluster);

}

#endif

64 changes: 64 additions & 0 deletions aux/inc/WireCellAux/Configurable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/** A base class providing auto-configuration.

This works in conjunction with a config struct which is produced
via shema codegen.

To use

1) Inherit your MyConfigurable class from
Configurable<Cfg::MyConfigurable> instead of directly
IConfigurable.

2) If migrating from old, remove configure() and
default_configure() methods.

3) If you configure() method held non-configuration related
initialization, it may move into configured().

4) Use the protected m_cfg object to access the configuration
struct including any "service" type components "used" by yours.

*/


#ifndef WIRECELLAUX_CONFIGURABLE
#define WIRECELLAUX_CONFIGURABLE

#include "WireCellUtil/nljs2jcpp.hpp" // remove when ditch JsonCPP

#include "WireCellIface/IConfigurable.h"

namespace WireCell::Aux {

template<typename CfgStruct>
class Configurable : public IConfigurable {
public:
using cfg_type = CfgStruct;

// Subclass may implement in order to get post-config entry.
virtual void configured() { }

// Subclass need not but MAY overide IF it also calls.
virtual void configure(const WireCell::Configuration& jcfg)
{
nljs_t nljs = jcfg;
m_cfg = nljs.get<cfg_type>();
configured();
}

// Subclass need not but MAY overide IF it also calls.
virtual WireCell::Configuration default_configuration() const
{
const nljs_t nljs = m_cfg;
return nljs.get<Json::Value>();
}

protected:
// Subclass should use m_cfg directly.
cfg_type m_cfg;
};

}


#endif
29 changes: 29 additions & 0 deletions aux/inc/WireCellAux/DepoTools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
Some helper functions operating on IDepo
*/
#ifndef WIRECELLAUX_DEPOTOOLS
#define WIRECELLAUX_DEPOTOOLS

#include "WireCellIface/IDepo.h"
#include "WireCellUtil/Array.h"

namespace WireCell::Aux {

/** Fill data and info arrays from IDepoSet.

The "data" array will be shaped (ndepos,7) and each
7-tuple holds: (time, charge, x, y, z, long, tran).

The "info" array is integer and shaped (nedpos, 4). Each
4-tuple holds: (id, pdg, gen, child).

If "priors" is true, then run the depos through flatten() in
order to save them and give non-zero gen and child. O.w.,
only those depos in pass directly in the vector are saved.
*/
void fill(Array::array_xxf& data, Array::array_xxi& info,
const IDepo::vector& depos, bool priors = true);

}

#endif
15 changes: 11 additions & 4 deletions aux/inc/WireCellAux/FrameTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@

#include "WireCellIface/IFrame.h"
#include "WireCellUtil/Array.h"
#include "WireCellUtil/Logging.h"

namespace WireCell {
namespace aux {
namespace Aux {

// Print some info to cerr about frame
void dump_frame(WireCell::IFrame::pointer frame);
/// Return a canonical name for the frame.
std::string name(const WireCell::IFrame::pointer& frame);

/// Print some info to cerr about frame. If log is null, use stderr.
void dump_frame(WireCell::IFrame::pointer frame, Log::logptr_t log = nullptr);

/// Return brief info string summarizing frame and trace tag.
std::string taginfo(const WireCell::IFrame::pointer& frame);

/// Return a vector of traces which have no trace tags. Here,
/// any frame tags are ignored. Returned vector of traces has
Expand Down Expand Up @@ -106,7 +113,7 @@ namespace WireCell {
/// outside of any individual trace.
IFrame::pointer sum(std::vector<IFrame::pointer> frames, int ident);

} // namespace aux
} // namespace Aux
} // namespace WireCell

#endif
Loading