All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
sbn.cxx File Reference
#include <fstream>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <vector>
#include <dlfcn.h>
#include <fhiclcpp/ParameterSet.h>
#include <core/ProcessorBase.hh>
#include <core/ProcessorBlock.hh>
#include <core/Loader.hh>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 13 of file sbn.cxx.

13  {
14  // Parse command line arguments
15  std::vector<char*> processors;
16  std::map<unsigned, char*> config_names;
17 
18  int c;
19  unsigned procindex = 0;
20  while ((c=getopt(argc, argv, "m:c:")) != -1) {
21  switch (c) {
22  case 'm':
23  processors.push_back(optarg);
24  procindex++;
25  break;
26  case 'c':
27  config_names[procindex-1] = optarg;
28  break;
29  case '?':
30  if (optopt == 'c' || optopt == 'm')
31  fprintf(stderr, "Option -%c requires an argument.\n", optopt);
32  else if (isprint(optopt))
33  fprintf(stderr, "Unknown option `-%c'.\n", optopt);
34  else
35  fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
36  return 1;
37  default:
38  abort();
39  }
40  }
41 
42  if (argc - optind < 1) {
43  std::cout << "Usage: " << argv[0] << " [-m PROCESSOR [-c CONFIG]] "
44  << "INPUTDEF [...]" << std::endl;
45  return 0;
46  }
47 
48  // Process input file definition
49  std::string filedef = argv[optind];
50  std::string list_suffix = ".list";
51  std::vector<std::string> filenames;
52 
53  if (std::equal(list_suffix.rbegin(), list_suffix.rend(), filedef.rbegin())) {
54  // File list
55  std::ifstream infile(filedef);
56  std::string filename;
57  while (infile >> filename) {
58  filenames.push_back(filename);
59  }
60  }
61  else {
62  // Files listed on command line
63  for (int i=optind; i<argc; i++) {
64  filenames.push_back(argv[i]);
65  }
66  }
67 
68  assert(!filenames.empty());
69 
70  // Setup
71  std::vector<core::ProcessorBase*> procs(processors.size());
72  std::vector<fhicl::ParameterSet*> configs(processors.size());
73 
74  std::cout << "Configuring... " << std::endl;
75  for (size_t i=0; i<procs.size(); i++) {
76  core::export_table* exp = core::LoadProcessor(processors[i]);
77  procs[i] = exp->create();
78  configs[i] = core::LoadConfig(config_names[i]);
79  }
80 
82  for (int i=0; i<procs.size(); i++) {
83  block.AddProcessor(procs[i], configs[i]);
84  }
85 
86  std::cout << "Running... " << std::endl;
87  block.ProcessFiles(filenames);
88 
89  block.DeleteProcessors();
90  std::cout << "Done!" << std::endl;
91 
92  return 0;
93 }
Struct containing (macro defined) creation/deletion operations.
Definition: Loader.hh:28
process_name WireCellLarsoft configs
BEGIN_PROLOG could also be dds filename
export_table * LoadProcessor(char *libname)
Definition: Loader.cxx:15
A set of Processors.
ProcessorBase *(* create)(void)
Definition: Loader.hh:30
virtual void DeleteProcessors()
bool equal(double a, double b)
Comparison tolerance, in centimeters.
fhicl::ParameterSet * LoadConfig(char *configfile)
Definition: Loader.cxx:80
virtual void ProcessFiles(std::vector< std::string > filenames)
virtual void AddProcessor(ProcessorBase *processor, fhicl::ParameterSet *config)
BEGIN_PROLOG could also be cout