All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WCLS_tool.cc
Go to the documentation of this file.
1 #include "art/Utilities/ToolMacros.h"
2 #include "art/Utilities/ToolConfigTable.h"
3 
6 
7 #include "fhiclcpp/ParameterSet.h"
8 #include "fhiclcpp/types/Sequence.h"
9 #include "fhiclcpp/types/OptionalSequence.h"
10 #include "fhiclcpp/types/OptionalDelegatedParameter.h"
11 #include "fhiclcpp/types/Comment.h"
12 #include "fhiclcpp/types/Table.h"
13 
14 #include "WireCellApps/Main.h"
15 #include "WireCellUtil/String.h"
16 #include "WireCellUtil/Logging.h"
17 
18 #include "WireCellUtil/NamedFactory.h"
19 
20 #include <string>
21 
22 
23 namespace wcls {
24 
25 
26  // https://cdcvs.fnal.gov/redmine/projects/fhicl-cpp/wiki/Fhiclcpp_types_in_detail#TableltT-KeysToIgnoregt
28  std::set<std::string> operator()() {
29  // Ignore these for validation.
30  return {"params"};
31  }
32  };
33 
34  // https://cdcvs.fnal.gov/redmine/projects/art/wiki/Configuration_validation_and_description
35  struct WCLSConfig {
36  typedef fhicl::Sequence<std::string> string_list_t;
37  typedef fhicl::OptionalSequence<std::string> optional_string_list_t;
38  //typedef fhicl::OptionalTable<fhicl::ParameterSet> generic_pset_t;
39  typedef fhicl::OptionalDelegatedParameter generic_pset_t;
40 
41  // These are WCT config items to pass through
43  fhicl::Comment("List of one or more WCT configuration files."
44  "\nThey are located w.r.t. the WCT load path.") };
46  fhicl::Comment("List of one or more WCT application objects to execute.")};
48  fhicl::Comment("List of WCT component plugin libraries to load.\n"
49  "They are located w.r.t. the OS library load path")};
50 
52  fhicl::Comment("Optional list of file system paths to add to the WCT "
53  "configuration file load path."
54  "\nThis augments the WIRECELL_PATH environment variable.")};
56  fhicl::Comment("Optional table giving external variables to inject into WCT configuration.")};
58  fhicl::Comment("Optional table giving external Jsonnet code to inject into WCT configuration.")};
59 
60  // These are items needed by the tool
62  fhicl::Comment("List of WCT components which act as WCT sources.\n"
63  "They are called before WCT executes on each Art Event object") };
65  fhicl::Comment("List of WCT components which act as WCT sinks.\n"
66  "They are called after WCT executes on each Art Event object.") };
67 
69  fhicl::Comment("List of WCT log sinks.\n"
70  "Eg the strings 'stdout', 'stderr' or a file name.\n"
71  "An optional log level may be appended with ':<level>'.") };
73  fhicl::Comment("List of minimum WCT logger levels.\n"
74  "Specify as '<logger>:<level>' or as just '<level>' for default.") };
75 
76 
77  };
78 
79  class WCLS : public MainTool {
80  public:
81  using Parameters = art::ToolConfigTable<WCLSConfig, WCLSKeysToIgnore>;
82 
83  explicit WCLS(Parameters const& ps);
84  virtual ~WCLS() { }
85 
86  void produces(art::ProducesCollector& collector) {
87  for (auto iaev : m_outputers) {
88  iaev->produces(collector);
89  }
90  }
91  void process(art::Event& event);
92 
93  private:
94  WireCell::Main m_wcmain;
96  // for c2: m_prod is not used
97  // art::EDProducer* m_prod;
98  };
99 }
100 
101 
102 
104  : m_wcmain()
105 {
106  const auto& wclscfg = params();
107  WCLSConfig::optional_string_list_t::value_type slist;
108 
109  if (wclscfg.logsinks(slist)) {
110  for (auto logsink : slist) {
111  //std::cerr << "Log sink: \"" << logsink << "\"\n";
112  auto ls = WireCell::String::split(logsink, ":");
113  if (ls.size() == 2) {
114  m_wcmain.add_logsink(ls[0], ls[1]);
115  }
116  else {
117  m_wcmain.add_logsink(ls[0]);
118  }
119  }
120  }
121  slist.clear();
122  if (wclscfg.loglevels(slist)) {
123  for (auto loglevel : slist) {
124  //std::cerr << "Log level: \"" << loglevel << "\"\n";
125  auto ll = WireCell::String::split(loglevel, ":");
126  if (ll.size() == 2) {
127  m_wcmain.set_loglevel(ll[0], ll[1]);
128  }
129  else{
130  m_wcmain.set_loglevel("", ll[0]);
131  }
132  }
133  }
134  slist.clear();
135  WireCell::Log::set_pattern("[%H:%M:%S.%03e] %L [%^%=8n%$] %v");
136 
137  // transfer configuration
138 
139  // required
140 
141  for (auto cfg : wclscfg.configs()) {
142  m_wcmain.add_config(cfg);
143  }
144 
145  for (auto app : wclscfg.apps()) {
146  m_wcmain.add_app(app);
147  }
148 
149  for (auto plugin : wclscfg.plugins()) {
150  m_wcmain.add_plugin(plugin);
151  }
152 
153  // optional
154 
155  if (wclscfg.paths(slist)) {
156  for (auto path : slist) {
157  m_wcmain.add_path(path);
158  }
159  }
160  slist.clear();
161 
162 
163  {
164  fhicl::ParameterSet wcps;
165  if (wclscfg.params.get_if_present(wcps)) {
166  for (auto key : wcps.get_names()) {
167  auto value = wcps.get<std::string>(key);
168  m_wcmain.add_var(key, value);
169  }
170  }
171  }
172  {
173  fhicl::ParameterSet wcps;
174  if (wclscfg.structs.get_if_present(wcps)) {
175  for (auto key : wcps.get_names()) {
176  auto value = wcps.get<std::string>(key);
177  m_wcmain.add_code(key, value);
178  }
179  }
180  }
181 
182  //std::cerr << "Initialize Wire Cell\n";
183  try {
184  m_wcmain.initialize();
185  }
186  catch (WireCell::Exception& e) {
187  std::cerr << "Wire Cell Toolkit threw an exception\n";
188  auto msg = errstr(e);
189  std::cerr << msg << std::endl;
190  throw cet::exception("WireCellLArSoft") << msg;
191  }
192 
193 
194 
195  if (wclscfg.inputers(slist)) {
196  for (auto inputer : slist) {
197  auto iaev = WireCell::Factory::find_tn<IArtEventVisitor>(inputer);
198  m_inputers.push_back(iaev);
199  std::cerr << "Inputer: \"" << inputer << "\"\n";
200  }
201  }
202  slist.clear();
203  if (wclscfg.outputers(slist)) {
204  for (auto outputer : slist) {
205  auto iaev = WireCell::Factory::find_tn<IArtEventVisitor>(outputer);
206  m_outputers.push_back(iaev);
207  std::cerr << "Outputer: \"" << outputer << "\"\n";
208  }
209  }
210  slist.clear();
211 }
212 
213 void wcls::WCLS::process(art::Event& event)
214 {
215  for (auto iaev : m_inputers) {
216  //std::cerr << "pre visit\n";
217  iaev->visit(event);
218  }
219 
220  //std::cerr << "Running Wire Cell Toolkit...\n";
221  m_wcmain();
222  //std::cerr << "... Wire Cell Toolkit done\n";
223 
224  for (auto iaev : m_outputers) {
225  //std::cerr << "post visit\n";
226  iaev->visit(event);
227  }
228 }
229 
230 
231 DEFINE_ART_CLASS_TOOL(wcls::WCLS)
232 
233 // Local Variables:
234 // mode: c++
235 // c-basic-offset: 4
236 // End:
virtual ~WCLS()
Definition: WCLS_tool.cc:84
wcls::IArtEventVisitor::vector m_outputers
Definition: WCLS_tool.cc:95
fhicl::OptionalSequence< std::string > optional_string_list_t
Definition: WCLS_tool.cc:37
BEGIN_PROLOG could also be cerr
std::set< std::string > operator()()
Definition: WCLS_tool.cc:28
fhicl::Sequence< std::string > string_list_t
Definition: WCLS_tool.cc:36
generic_pset_t params
Definition: WCLS_tool.cc:55
then echo Invalid dCache scratch not copying back else ifdh ls
Definition: run_job.sh:111
void produces(art::ProducesCollector &collector)
Definition: WCLS_tool.cc:86
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
generic_pset_t structs
Definition: WCLS_tool.cc:57
art::ToolConfigTable< WCLSConfig, WCLSKeysToIgnore > Parameters
Definition: WCLS_tool.cc:81
WireCell::Main m_wcmain
Definition: WCLS_tool.cc:94
BEGIN_PROLOG vertical distance to the surface Name
fhicl::OptionalDelegatedParameter generic_pset_t
Definition: WCLS_tool.cc:39
optional_string_list_t loglevels
Definition: WCLS_tool.cc:72
void process(art::Event &event)
Accept an event to process.
Definition: WCLS_tool.cc:213
string_list_t apps
Definition: WCLS_tool.cc:45
wcls::IArtEventVisitor::vector m_inputers
Definition: WCLS_tool.cc:95
optional_string_list_t logsinks
Definition: WCLS_tool.cc:68
do i e
WCLS(Parameters const &ps)
Definition: WCLS_tool.cc:103
temporary value
string_list_t plugins
Definition: WCLS_tool.cc:47
string_list_t configs
Definition: WCLS_tool.cc:42
optional_string_list_t inputers
Definition: WCLS_tool.cc:61
optional_string_list_t outputers
Definition: WCLS_tool.cc:64
optional_string_list_t paths
Definition: WCLS_tool.cc:51