ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/macros/setRootEnv.C
Revision: 1.4
Committed: Thu Jul 3 10:27:52 2008 UTC (16 years, 10 months ago) by paus
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_006, Mit_005, Mit_004, MITHEP_2_0_x
Changes since 1.3: +3 -2 lines
Log Message:
Little slip from 'inc' to 'interface'.

File Contents

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