ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/macros/setRootEnv.C
Revision: 1.3
Committed: Wed Jun 11 13:26:05 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.2: +40 -2 lines
Log Message:
Added loadmylib for user libs.

File Contents

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