All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Loader.cxx
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 #include <fstream>
4 #include <string>
5 #include <vector>
6 #include <dlfcn.h>
7 #include <cetlib/filepath_maker.h>
8 #include <fhiclcpp/make_ParameterSet.h>
9 #include <fhiclcpp/ParameterSet.h>
10 #include <core/ProcessorBase.hh>
11 #include <core/ProcessorBlock.hh>
12 
13 namespace core {
14 
15 export_table* LoadProcessor(char* libname) {
16  std::cout << "Loading processor: " << libname << "... ";
17 
18  char* libdir = getenv("SBN_LIB_DIR");
19  char libpath[1000];
20  snprintf(libpath, 1000, "%s/libsbnanalysis_%s.so", libdir, libname);
21 
22  void* handle = dlopen(libpath, RTLD_NOW);
23  if (!handle) {
24  std::cout << "ERROR" << std::endl;
25  std::cerr << "Error loading processor " << libname << ": \n\n"
26  << dlerror()
27  << "\n\nSBN_LIB_DIR = " << libdir
28  << std::endl;
29  exit(1);
30  }
31 
32  export_table* exports = (export_table*) dlsym(handle, "exports");
33 
34  if (exports) {
35  std::cout << "OK" << std::endl;
36  }
37  else {
38  std::cout << "ERROR" << std::endl;
39  std::cerr << "Invalid library " << libpath << ". "
40  << "Not a Processor?" << std::endl;
41  exit(1);
42  }
43 
44  return exports;
45 }
46 
48  std::cout << "Loading post-processor: " << libname << "... ";
49 
50  char* libdir = getenv("SBN_LIB_DIR");
51  char libpath[1000];
52  snprintf(libpath, 1000, "%s/libsbnanalysis_%s.so", libdir, libname);
53 
54  void* handle = dlopen(libpath, RTLD_NOW);
55  if (!handle) {
56  std::cout << "ERROR" << std::endl;
57  std::cerr << "Error loading post-processor " << libname << ": \n\n"
58  << dlerror()
59  << "\n\nSBN_LIB_DIR = " << libdir
60  << std::endl;
61  exit(1);
62  }
63 
64  export_table_postprocess* exports = (export_table_postprocess*) dlsym(handle, "exports");
65 
66  if (exports) {
67  std::cout << "OK" << std::endl;
68  }
69  else {
70  std::cout << "ERROR" << std::endl;
71  std::cerr << "Invalid library " << libpath << ". "
72  << "Not a PostProcessor?" << std::endl;
73  exit(1);
74  }
75 
76  return exports;
77 }
78 
79 
80 fhicl::ParameterSet* LoadConfig(char* configfile) {
81  fhicl::ParameterSet* config = NULL;
82 
83  if (configfile) {
84  std::cout << "Loading configuration: " << configfile << "... ";
85  config = new fhicl::ParameterSet;
86  cet::filepath_lookup_nonabsolute maker("FHICL_FILE_PATH");
87  fhicl::make_ParameterSet(configfile, maker, *config);
88  std::cout << "OK" << std::endl;
89  }
90 
91  return config;
92 }
93 
94 } // namespace core
95 
Struct containing (macro defined) creation/deletion operations.
Definition: Loader.hh:28
BEGIN_PROLOG could also be cerr
export_table * LoadProcessor(char *libname)
Definition: Loader.cxx:15
export_table_postprocess * LoadPostProcessor(char *libname)
Definition: Loader.cxx:47
struct core::export_table exports
fhicl::ParameterSet * LoadConfig(char *configfile)
Definition: Loader.cxx:80
Struct containing (macro defined) creation/deletion operations.
Definition: Loader.hh:40
BEGIN_PROLOG could also be cout