All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
sbn-postprocess.cxx File Reference
#include <fstream>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <vector>
#include <dlfcn.h>
#include <core/PostProcessorBase.hh>
#include <core/Loader.hh>
#include "TROOT.h"

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 12 of file sbn-postprocess.cxx.

12  {
13  // Parse command line arguments
14  char *post_processor = NULL;
15  char *config_name = NULL; // optional
16  std::string output_fname = "";
17 
18  int c;
19  unsigned procindex = 0;
20  unsigned n_workers = 1;
21  while ((c=getopt(argc, argv, "m:c:o:w:")) != -1) {
22  switch (c) {
23  case 'w':
24  n_workers = std::stoi(std::string(optarg));
25  break;
26  case 'm':
27  if (post_processor != NULL) {
28  fprintf(stderr, "Only specify one post-processor.\n");
29  return 1;
30  }
31  post_processor = optarg;
32  break;
33  case 'c':
34  if (config_name != NULL) {
35  fprintf(stderr, "Only specify one post-processor configuration.\n");
36  return 1;
37  }
38  config_name = optarg;
39  break;
40  case 'o':
41  output_fname = optarg;
42  break;
43  case '?':
44  if (optopt == 'c' || optopt == 'm' || optopt == 'o')
45  fprintf(stderr, "Option -%c requires an argument.\n", optopt);
46  else if (isprint(optopt))
47  fprintf(stderr, "Unknown option `-%c'.\n", optopt);
48  else
49  fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
50  return 1;
51  default:
52  abort();
53  }
54  }
55 
56  if (argc - optind < 1) {
57  std::cout << "Usage: " << argv[0] << " -m POSTPROCESSOR [-c CONFIG] "
58  << "INPUTDEF [...]" << std::endl;
59  return 0;
60  }
61 
62  // Process input file definition
63  std::string filedef = argv[optind];
64  std::string list_suffix = ".list";
65  std::vector<std::string> filenames;
66 
67  if (std::equal(list_suffix.rbegin(), list_suffix.rend(), filedef.rbegin())) {
68  // File list
69  std::ifstream infile(filedef);
70  std::string filename;
71  while (infile >> filename) {
72  filenames.push_back(filename);
73  }
74  }
75  else {
76  // Files listed on command line
77  for (int i=optind; i<argc; i++) {
78  filenames.push_back(argv[i]);
79  }
80  }
81 
82  assert(!filenames.empty());
83  assert(post_processor != NULL);
84 
85  // enable multiple threads if needed
86  if (n_workers > 1) {
87  ROOT::EnableThreadSafety();
88  }
89 
90  // Setup
91  std::cout << "Configuring... " << std::endl;
94  proc->Initialize(config_name, output_fname, n_workers);
95 
96  // Run
97  std::cout << "Running... " << std::endl;
98  proc->Run(filenames);
99  std::cout << "Done!" << std::endl;
100 
101  return 0;
102 }
PostProcessorBase *(* create)(void)
Definition: Loader.hh:42
BEGIN_PROLOG could also be dds filename
void Initialize(char *config=NULL, const std::string &output_fname="", unsigned n_workers=1)
export_table_postprocess * LoadPostProcessor(char *libname)
Definition: Loader.cxx:47
void Run(std::vector< std::string > filelist)
bool equal(double a, double b)
Comparison tolerance, in centimeters.
A generic tree-reading event-by-event processor.
Struct containing (macro defined) creation/deletion operations.
Definition: Loader.hh:40
BEGIN_PROLOG could also be cout