load_libs.C
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset: 2; -*-
2 
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 }
39 
40 void load_libs()
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  "CAFAnaCoreExt",
85  "CAFAnaCore",
86  "CAFAnaVars", "CAFAnaCuts", "CAFAnaSysts",
87  "CAFAnaUnfold", "CAFAnaDecomp",
88  "CAFAnaExtrap", "CAFAnaPrediction",
89  "CAFAnaExperiment", "CAFAnaFC",
90  "CAFAnaFit", "CAFAnaAnalysis", "CAFAnaXSec",
91  "CAFAna"
92  };
93 
94  // Actually load the libraries
95  std::cout << "Loading libraries";
96  for(const std::string& lib: libs) load(lib);
98  }
99  else { // This is the MRB build
100  // List of libraries to load. Dependency order.
101  const std::vector<std::string> libs =
102  {
103  "Geom", "Tree", "Minuit2", // CAFReweight pulls in Genie which pulls in ROOT geometry
104  "StandardRecord", "StandardRecord_dict", "StandardRecordProxy",
105  "NOvARwgt",
106  "CAFAna",
107  //"OscLibFunc",
108  //"MCReweightFunc",
109  //"ifdh",
110  "NDAnanumucc_inc"
111  //"NumuEnergyFunc"
112  };
113 
114  // Actually load the libraries
115  std::cout << "Loading libraries (mrb)";
116  for(const std::string& lib: libs) load(lib);
117  std::cout << std::endl;
118  }
119 
120  // Pick up standard NOvA style
121  gROOT->Macro("$SRT_PUBLIC_CONTEXT/Utilities/rootlogon.C");
122  gROOT->ForceStyle();
123 
124  TRint* rint = dynamic_cast<TRint*>(gApplication);
125  if(rint) rint->SetPrompt("cafe [%d] ");
126 
127 
128  // Do this last so that the profiler library is unloaded before our main
129  // libraries, meaning that the code in ProfilerSupport runs at the right time
130  // (after the profile file is made). This does mean that we aren't able to
131  // profile library loading/startup. The ideal solution would be to make a
132  // mini-library for just ProfilerSupport.
133  if(gSystem->Getenv("CPUPROFILE")){
134  // We were passed the --prof option
135  const std::string cpuprof = gSystem->Getenv("CPUPROFILE");
136 
137  std::cout << "Profiling enabled." << std::endl;
138 
139  if(!qsrt.Contains("debug") && !qmrb.Contains("debug")){
140  std::cout << "Note: profiling works much better in debug mode." << std::endl;
141  }
142 
143  const char* pd = getenv("GPERFTOOLS_DIR");
144  if(pd){
145  gSystem->Load((std::string(pd)+"/lib/libprofiler.so").c_str());
146  // Apparently the library load manages to corrupt the env var? Put it
147  // back.
148  gSystem->Setenv("CPUPROFILE", cpuprof.c_str());
149  }
150  else{
151  std::cout << "Couldn't find gperftools library" << std::endl;
152  }
153  }
154 }
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
exit(0)
void load_libs()
Definition: load_libs.C:40
enum BeamMode string