1 |
paus |
1.8 |
// $Id: setRootEnv.C,v 1.7 2010/03/12 13:44:53 bendavid Exp $
|
2 |
loizides |
1.1 |
#if !defined(__CINT__) || defined(__MAKECINT__)
|
3 |
|
|
#include <TEnv.h>
|
4 |
|
|
#include <TString.h>
|
5 |
|
|
#include <TSystem.h>
|
6 |
|
|
#include <TRegexp.h>
|
7 |
|
|
#include <TROOT.h>
|
8 |
|
|
#include <TFile.h>
|
9 |
|
|
#include <TClass.h>
|
10 |
|
|
#include <TClassTable.h>
|
11 |
|
|
#include <TInterpreter.h>
|
12 |
|
|
#include <TRandom3.h>
|
13 |
|
|
#include <TError.h>
|
14 |
|
|
#endif
|
15 |
|
|
|
16 |
paus |
1.8 |
void sayHello ();
|
17 |
|
|
void setIncludes ();
|
18 |
loizides |
1.5 |
void loadLibraries(const char *libpattern="libMitAna*.so");
|
19 |
paus |
1.8 |
void loadmylib (const char *name);
|
20 |
|
|
void loadmylib (const char *pkgname, const char *subpkgname);
|
21 |
loizides |
1.3 |
|
22 |
|
|
//__________________________________________________________________________________________________
|
23 |
paus |
1.2 |
|
24 |
loizides |
1.1 |
void setRootEnv()
|
25 |
|
|
{
|
26 |
paus |
1.2 |
// automatically restore gDirectory
|
27 |
|
|
TDirectory::TContext context(0);
|
28 |
|
|
|
29 |
|
|
// set a better default random generator
|
30 |
|
|
delete gRandom;
|
31 |
|
|
gRandom = new TRandom3;
|
32 |
|
|
gRandom->SetSeed(0);
|
33 |
|
|
|
34 |
|
|
// customizing the MIT analysis framework things
|
35 |
|
|
setIncludes();
|
36 |
|
|
loadLibraries();
|
37 |
loizides |
1.6 |
loadmylib("libMitCommonMathTools.so");
|
38 |
paus |
1.8 |
}
|
39 |
paus |
1.2 |
|
40 |
paus |
1.8 |
void sayHello()
|
41 |
|
|
{
|
42 |
loizides |
1.3 |
// have a friendly welcome message
|
43 |
paus |
1.2 |
if (gClassTable->GetID("mithep::Particle") >= 0) {
|
44 |
paus |
1.8 |
::Info("setRootEnv", "Welcome to MITROOT! Loaded default libraries.\n");
|
45 |
|
|
}
|
46 |
|
|
else {
|
47 |
|
|
::Info("setRootEnv", "Ooops, at least one essential library did not load....\n");
|
48 |
paus |
1.2 |
}
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
void setIncludes()
|
52 |
|
|
{
|
53 |
loizides |
1.3 |
if (gSystem->Getenv("CMSSW_VERSION")) {
|
54 |
|
|
TString str = gSystem->GetMakeSharedLib();
|
55 |
|
|
if (str.Contains("-m32")==0 && str.Contains("-m64")==0) {
|
56 |
|
|
str.ReplaceAll("g++", "g++ -m32");
|
57 |
|
|
gSystem->SetMakeSharedLib(str);
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
|
61 |
paus |
1.2 |
gSystem->AddIncludePath("-I$CMSSW_BASE/src/");
|
62 |
bendavid |
1.7 |
gSystem->AddIncludePath("-I$CMSSW_RELEASE_BASE/src/");
|
63 |
paus |
1.8 |
gSystem->AddIncludePath("-I$CMSSW_BASE/src/MitAna/TreeMod/interface");
|
64 |
loizides |
1.1 |
gSystem->AddIncludePath("-I$CMSSW_BASE/src/MitAna/macros");
|
65 |
|
|
gInterpreter->AddIncludePath(TString(gSystem->Getenv("CMSSW_BASE"))+"/src/");
|
66 |
bendavid |
1.7 |
gInterpreter->AddIncludePath(TString(gSystem->Getenv("CMSSW_RELEASE_BASE"))+"/src/");
|
67 |
paus |
1.4 |
gInterpreter->AddIncludePath(TString(gSystem->Getenv("CMSSW_BASE"))+
|
68 |
|
|
"/src/MitAna/TreeMod/interface");
|
69 |
loizides |
1.1 |
gInterpreter->AddIncludePath(TString(gSystem->Getenv("CMSSW_BASE"))+"/src/MitAna/macros");
|
70 |
|
|
gROOT->SetMacroPath(TString(gROOT->GetMacroPath())
|
71 |
paus |
1.2 |
+TString(gSystem->Getenv("CMSSW_BASE"))+"/src/MitAna/macros");
|
72 |
|
|
}
|
73 |
loizides |
1.1 |
|
74 |
loizides |
1.5 |
void loadLibraries(const char *libpattern)
|
75 |
paus |
1.2 |
{
|
76 |
|
|
TString libstr(Form("%s/lib/%s",gSystem->Getenv("CMSSW_BASE"),gSystem->Getenv("SCRAM_ARCH")));
|
77 |
|
|
|
78 |
|
|
void *dir = gSystem->OpenDirectory(libstr.Data());
|
79 |
loizides |
1.5 |
TRegexp re(libpattern, kTRUE);
|
80 |
paus |
1.2 |
TRegexp reignore("libMitAnalysis*.so", kTRUE);
|
81 |
|
|
while (const char *direntry=gSystem->GetDirEntry(dir) ) {
|
82 |
|
|
TString sdirentry(direntry);
|
83 |
|
|
if (sdirentry.Index(re) == kNPOS)
|
84 |
|
|
continue;
|
85 |
|
|
if (sdirentry.Index(reignore) != kNPOS)
|
86 |
|
|
continue;
|
87 |
|
|
Int_t len = strlen(direntry)-3;
|
88 |
|
|
if (len<=0)
|
89 |
|
|
continue;
|
90 |
|
|
char *tmpstr = new char[len+1];
|
91 |
|
|
for (Int_t i=0;i<len;i++)
|
92 |
|
|
tmpstr[i]=direntry[i];
|
93 |
|
|
tmpstr[len]='\0';
|
94 |
|
|
if (gInterpreter->IsLoaded(tmpstr)) {
|
95 |
|
|
if (gDebug)
|
96 |
|
|
Warning("setRootEnv","Trying to load \"%s\", but it is already loaded", tmpstr);
|
97 |
|
|
} else {
|
98 |
|
|
if (gSystem->Load(tmpstr)<0) {
|
99 |
|
|
gROOT->Error("setRootEnv", "could not load \"%s\" for use in ACLiC", tmpstr);
|
100 |
|
|
} else {
|
101 |
|
|
if (gDebug)
|
102 |
loizides |
1.3 |
Info("setRootEnv","Loaded \"%s\" for use in ACLiC", tmpstr);
|
103 |
loizides |
1.1 |
}
|
104 |
|
|
}
|
105 |
paus |
1.2 |
delete[] tmpstr;
|
106 |
loizides |
1.1 |
}
|
107 |
paus |
1.2 |
gSystem->FreeDirectory(dir);
|
108 |
loizides |
1.1 |
}
|
109 |
loizides |
1.3 |
|
110 |
|
|
void loadmylib(const char *name)
|
111 |
|
|
{
|
112 |
|
|
TString libstr(Form("%s/lib/%s/%s",
|
113 |
|
|
gSystem->Getenv("CMSSW_BASE"),
|
114 |
|
|
gSystem->Getenv("SCRAM_ARCH"),
|
115 |
|
|
name));
|
116 |
|
|
|
117 |
|
|
Int_t slevel=gErrorIgnoreLevel;
|
118 |
|
|
gErrorIgnoreLevel=kFatal;
|
119 |
|
|
Int_t suc = gSystem->Load(libstr);
|
120 |
|
|
gErrorIgnoreLevel=slevel;
|
121 |
|
|
|
122 |
|
|
if (suc<0) {
|
123 |
|
|
gROOT->Error("loadmylib", "could not load \"%s\" for use in ACLiC", libstr.Data());
|
124 |
|
|
} else {
|
125 |
|
|
if (gDebug)
|
126 |
|
|
Info("loadmylib","Loaded \"%s\" for use in ACLiC", name);
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
void loadmylib(const char *pkgname, const char *subpkgname)
|
131 |
|
|
{
|
132 |
|
|
loadmylib(Form("lib%s%s.so", pkgname, subpkgname));
|
133 |
|
|
}
|