ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/macros/setRootEnv.C
Revision: 1.6
Committed: Thu Jun 11 19:37:00 2009 UTC (15 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_011, Mit_010a, Mit_010, Mit_009c, Mit_009b, Mit_009a
Changes since 1.5: +2 -1 lines
Log Message:
Load mathtools.

File Contents

# User Rev Content
1 loizides 1.6 // $Id: setRootEnv.C,v 1.5 2008/11/18 16:55:49 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     gSystem->AddIncludePath("-I$CMSSW_BASE/src/MitAna/TreeMod/inc");
57 loizides 1.1 gSystem->AddIncludePath("-I$CMSSW_BASE/src/MitAna/macros");
58     gInterpreter->AddIncludePath(TString(gSystem->Getenv("CMSSW_BASE"))+"/src/");
59 paus 1.4 gInterpreter->AddIncludePath(TString(gSystem->Getenv("CMSSW_BASE"))+
60     "/src/MitAna/TreeMod/interface");
61 loizides 1.1 gInterpreter->AddIncludePath(TString(gSystem->Getenv("CMSSW_BASE"))+"/src/MitAna/macros");
62     gROOT->SetMacroPath(TString(gROOT->GetMacroPath())
63 paus 1.2 +TString(gSystem->Getenv("CMSSW_BASE"))+"/src/MitAna/macros");
64     }
65 loizides 1.1
66 loizides 1.5 void loadLibraries(const char *libpattern)
67 paus 1.2 {
68     TString libstr(Form("%s/lib/%s",gSystem->Getenv("CMSSW_BASE"),gSystem->Getenv("SCRAM_ARCH")));
69    
70     void *dir = gSystem->OpenDirectory(libstr.Data());
71 loizides 1.5 TRegexp re(libpattern, kTRUE);
72 paus 1.2 TRegexp reignore("libMitAnalysis*.so", kTRUE);
73     while (const char *direntry=gSystem->GetDirEntry(dir) ) {
74     TString sdirentry(direntry);
75     if (sdirentry.Index(re) == kNPOS)
76     continue;
77     if (sdirentry.Index(reignore) != kNPOS)
78     continue;
79     Int_t len = strlen(direntry)-3;
80     if (len<=0)
81     continue;
82     char *tmpstr = new char[len+1];
83     for (Int_t i=0;i<len;i++)
84     tmpstr[i]=direntry[i];
85     tmpstr[len]='\0';
86     if (gInterpreter->IsLoaded(tmpstr)) {
87     if (gDebug)
88     Warning("setRootEnv","Trying to load \"%s\", but it is already loaded", tmpstr);
89     } else {
90     if (gSystem->Load(tmpstr)<0) {
91     gROOT->Error("setRootEnv", "could not load \"%s\" for use in ACLiC", tmpstr);
92     } else {
93     if (gDebug)
94 loizides 1.3 Info("setRootEnv","Loaded \"%s\" for use in ACLiC", tmpstr);
95 loizides 1.1 }
96     }
97 paus 1.2 delete[] tmpstr;
98 loizides 1.1 }
99 paus 1.2 gSystem->FreeDirectory(dir);
100 loizides 1.1 }
101 loizides 1.3
102     void loadmylib(const char *name)
103     {
104     TString libstr(Form("%s/lib/%s/%s",
105     gSystem->Getenv("CMSSW_BASE"),
106     gSystem->Getenv("SCRAM_ARCH"),
107     name));
108    
109     Int_t slevel=gErrorIgnoreLevel;
110     gErrorIgnoreLevel=kFatal;
111     Int_t suc = gSystem->Load(libstr);
112     gErrorIgnoreLevel=slevel;
113    
114     if (suc<0) {
115     gROOT->Error("loadmylib", "could not load \"%s\" for use in ACLiC", libstr.Data());
116     } else {
117     if (gDebug)
118     Info("loadmylib","Loaded \"%s\" for use in ACLiC", name);
119     }
120     }
121    
122     void loadmylib(const char *pkgname, const char *subpkgname)
123     {
124     loadmylib(Form("lib%s%s.so", pkgname, subpkgname));
125     }