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