Functions
load_libs.C File Reference

Go to the source code of this file.

Functions

void load (std::string lib)
 
void load_libs ()
 

Function Documentation

void load ( std::string  lib)

Definition at line 3 of file load_libs.C.

References om::cout, allTimeWatchdog::endl, exit(), and runNovaSAM::ret.

Referenced by load_libs().

4 {
5  std::cout << "." << std::flush;
6 
7  /*
8  // Temporary special-case for NOvARwgt, which currently triggers an obnoxious
9  // GENIE banner when you load it.
10  if(lib == "NOvARwgt"){
11  fflush(stdout);
12  int bak = dup(1);
13  int nul = open("/dev/null", O_WRONLY);
14  dup2(nul, 1);
15  close(nul);
16 
17  int ret = gSystem->Load(("lib"+lib).c_str());
18 
19  fflush(stdout);
20  dup2(bak, 1);
21  close(bak);
22 
23  if(ret != 0){
24  std::cout << "Failed to load libNOvARwgt" << std::endl;
25  exit(1);
26  }
27  return;
28  }
29  */
30 
31  int ret = gSystem->Load(("lib"+lib).c_str());
32  // In case of error, exit immediately with the error clearly showing, instead
33  // of with a confusing secondary error about a page of output later.
34  if(ret != 0){
35  std::cout << "Failed to load lib" << lib << std::endl;
36  exit(1);
37  }
38 }
Definition: __init__.py:1
OStream cout
Definition: OStream.cxx:6
exit(0)
void load_libs ( )

Definition at line 40 of file load_libs.C.

References om::cout, allTimeWatchdog::endl, cet::getenv(), and load().

41 {
42  // under no circumstances should Cling be digging around in the dictionary for missing symbols.
43  // we just want those missing symbols to be reported and cafe to fail so we can find them.
44  ::gCling->UnloadLibraryMap("libCAFAna_dict");
45 
46  // All the CINT exception handler does is obfuscate the stack. With this,
47  // uncaught exceptions immediately show a useful backtrace under gdb.
48  //G__SetCatchException(0);
49 
50  TString qsrt = gSystem->Getenv("SRT_QUAL");
51  TString qmrb = gSystem->Getenv("MRB_QUALS");
52  // Mirror the optimization settings in use elsewhere
53  if( qsrt.Contains("debug") || qmrb.Contains("debug") ) {
54  gSystem->SetAclicMode(TSystem::kDebug);
55  }
56  else{
57  gSystem->SetAclicMode(TSystem::kOpt);
58  }
59 
60  // This magic incantation prevents ROOT doing slow cleanup work in
61  // TList::RecursiveRemove() under ~TH1(). But it's historically led to
62  // various crashes. Right now it's commented out again for causing crashes
63  // when trying to zoom into a plot. Potentially this will make the
64  // destruction of the TFile in PredictionSystJoint2018 very slow.
65  // We set it there.
66  // gROOT->SetMustClean(false);
67 
68  // Colorize error messages. Would be better if we could just pick up the
69  // flags novasoft uses, but they don't seem to be in any env var.
70  gSystem->SetFlagsDebug(TString(gSystem->GetFlagsDebug())+" -fdiagnostics-color=auto");
71  gSystem->SetFlagsOpt(TString(gSystem->GetFlagsOpt())+" -fdiagnostics-color=auto -UNDEBUG"); // match gcc's maxopt behaviour of retaining assert()
72 
73 
74  if(qmrb == "") { // This is the SRT build
75  // List of libraries to load. Dependency order.
76  const std::vector<std::string> libs =
77  {
78  "Minuit2",
79  "StandardRecord",
80  "StandardRecord_dict",
81  "StandardRecordProxy",
82  "NOvARwgt",
83  "StandardRecordNOvARwgt",
84  "CAFAnaCore",
85  "CAFAnaVars", "CAFAnaCuts", "CAFAnaSysts",
86  "CAFAnaUnfold", "CAFAnaDecomp",
87  "CAFAnaExtrap", "CAFAnaPrediction",
88  "CAFAnaExperiment", "CAFAnaFC",
89  "CAFAnaFit", "CAFAnaAnalysis", "CAFAnaXSec",
90  "CAFAna"
91  };
92 
93  // Actually load the libraries
94  std::cout << "Loading libraries";
95  for(const std::string& lib: libs) load(lib);
97  }
98  else { // This is the MRB build
99  // List of libraries to load. Dependency order.
100  const std::vector<std::string> libs =
101  {
102  "Geom", "Tree", "Minuit2", // CAFReweight pulls in Genie which pulls in ROOT geometry
103  "StandardRecord", "StandardRecord_dict", "StandardRecordProxy",
104  "NOvARwgt",
105  "CAFAna",
106  //"OscLibFunc",
107  //"MCReweightFunc",
108  //"ifdh",
109  "NDAnanumucc_inc"
110  //"NumuEnergyFunc"
111  };
112 
113  // Actually load the libraries
114  std::cout << "Loading libraries (mrb)";
115  for(const std::string& lib: libs) load(lib);
116  std::cout << std::endl;
117  }
118 
119  // Pick up standard NOvA style
120  gROOT->Macro("$SRT_PUBLIC_CONTEXT/Utilities/rootlogon.C");
121  gROOT->ForceStyle();
122 
123  TRint* rint = dynamic_cast<TRint*>(gApplication);
124  if(rint) rint->SetPrompt("cafe [%d] ");
125 
126 
127  // Do this last so that the profiler library is unloaded before our main
128  // libraries, meaning that the code in ProfilerSupport runs at the right time
129  // (after the profile file is made). This does mean that we aren't able to
130  // profile library loading/startup. The ideal solution would be to make a
131  // mini-library for just ProfilerSupport.
132  if(gSystem->Getenv("CPUPROFILE")){
133  // We were passed the --prof option
134  const std::string cpuprof = gSystem->Getenv("CPUPROFILE");
135 
136  std::cout << "Profiling enabled." << std::endl;
137 
138  if(!qsrt.Contains("debug") && !qmrb.Contains("debug")){
139  std::cout << "Note: profiling works much better in debug mode." << std::endl;
140  }
141 
142  const char* pd = getenv("GPERFTOOLS_DIR");
143  if(pd){
144  gSystem->Load((std::string(pd)+"/lib/libprofiler.so").c_str());
145  // Apparently the library load manages to corrupt the env var? Put it
146  // back.
147  gSystem->Setenv("CPUPROFILE", cpuprof.c_str());
148  }
149  else{
150  std::cout << "Couldn't find gperftools library" << std::endl;
151  }
152  }
153 }
void load(std::string lib)
Definition: load_libs.C:3
Definition: __init__.py:1
std::string getenv(std::string const &name)
Definition: __init__.py:1
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154