ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/macros/setRootEnv.C
(Generate patch)

Comparing UserCode/MitAna/macros/setRootEnv.C (file contents):
Revision 1.1 by loizides, Tue May 27 19:59:54 2008 UTC vs.
Revision 1.4 by paus, Thu Jul 3 10:27:52 2008 UTC

# Line 1 | Line 1
1   // $Id$
2  
3   #if !defined(__CINT__) || defined(__MAKECINT__)
4 #include <Riostream.h>
4   #include <TEnv.h>
5   #include <TString.h>
6   #include <TSystem.h>
# Line 13 | Line 12
12   #include <TInterpreter.h>
13   #include <TRandom3.h>
14   #include <TError.h>
16 #include <TStyle.h>
15   #endif
16  
17 + void setIncludes();
18 + void loadLibraries();
19 + void loadmylib(const char *name);
20 + void loadmylib(const char *pkgname, const char *subpkgname);
21 +
22 + //__________________________________________________________________________________________________
23 +
24   void setRootEnv()
25   {
26 <  gSystem->AddIncludePath("-I$CMSSW_BASE/src/ -I$CMSSW_BASE/src/MitAna/TreeMod/inc");
26 >  // 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 >  // have a friendly welcome message
39 >  if (gClassTable->GetID("mithep::Particle") >= 0) {
40 >    ::Info("setRootEnv", "Welcome to MITROOT!\n");
41 >  }
42 > }
43 >
44 > void setIncludes()
45 > {
46 >  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 >  gSystem->AddIncludePath("-I$CMSSW_BASE/src/");
55 >  gSystem->AddIncludePath("-I$CMSSW_BASE/src/MitAna/TreeMod/inc");
56    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");
58 >  gInterpreter->AddIncludePath(TString(gSystem->Getenv("CMSSW_BASE"))+
59 >                               "/src/MitAna/TreeMod/interface");
60    gInterpreter->AddIncludePath(TString(gSystem->Getenv("CMSSW_BASE"))+"/src/MitAna/macros");
61    gROOT->SetMacroPath(TString(gROOT->GetMacroPath())
62 <                       +TString(gSystem->Getenv("CMSSW_BASE"))+"/src/MitAna/macros");
63 <
29 <  if (1) { // load libs
30 <    TDirectory::TContext context(0); // automatically restore gDirectory
31 <    if(1) {
32 <
33 <      TString libstr(Form("%s/lib/%s",
34 <                          gSystem->Getenv("CMSSW_BASE"),
35 <                          gSystem->Getenv("SCRAM_ARCH")));
36 <
37 <      void *dir = gSystem->OpenDirectory(libstr.Data());
38 <      if(1) {
39 <        TRegexp re("libMitAna*.so", kTRUE);
40 <        TRegexp reignore("libMitAnalysis*.so", kTRUE);
41 <        while(const char *direntry=gSystem->GetDirEntry(dir) ) {
42 <          TString sdirentry(direntry);
43 <          if (sdirentry.Index(re) == kNPOS) {
44 <            continue;
45 <          }
46 <          if (sdirentry.Index(reignore) != kNPOS) {
47 <            continue;
48 <          }
49 <          Int_t len=strlen(direntry)-3;
50 <          if(len<=0) continue;
51 <          char *tmpstr = new char[len+1];
52 <          for(Int_t i=0;i<len;i++) tmpstr[i]=direntry[i];
53 <          tmpstr[len]='\0';
54 <          if (gInterpreter->IsLoaded(tmpstr))  {
55 <            if (gDebug) Warning("setRootEnv","Trying to load \"%s\", but it is already loaded", tmpstr);
56 <          } else {
57 <            if(gSystem->Load(tmpstr)<0) {
58 <              gROOT->Error("setRootEnv", "could not load \"%s\" for use in ACLiC", tmpstr);
59 <            } else {
60 <              if(gDebug) Info("setRootEnv","Loaded \"%s\" and its dependencies", tmpstr);
61 <            }
62 <          }
63 <          delete[] tmpstr;
64 <        }
65 <        gSystem->FreeDirectory(dir);
66 <      }
67 <    }
68 <
69 <    if(0) { // set some common gStyle settings
70 <      gStyle->SetPalette(1,0);
62 >                      +TString(gSystem->Getenv("CMSSW_BASE"))+"/src/MitAna/macros");
63 > }
64  
65 <      gStyle->SetPadColor(0);
66 <      gStyle->SetPadBorderSize(0);
67 <      gStyle->SetPadBorderMode(0);
75 <      gStyle->SetCanvasColor(0);
76 <      gStyle->SetCanvasBorderMode(0);
77 <      gStyle->SetCanvasBorderSize(0);
78 <      gStyle->SetFrameBorderMode(0);
79 <      gStyle->SetFrameLineColor(0);
80 <      gStyle->SetTitleColor(0);
81 <      gStyle->SetTitleBorderSize(0);
82 <    }
65 > void loadLibraries()
66 > {
67 >  TString libstr(Form("%s/lib/%s",gSystem->Getenv("CMSSW_BASE"),gSystem->Getenv("SCRAM_ARCH")));
68  
69 <    if(1) { // set a better default random generator
70 <      delete gRandom;
71 <      gRandom = new TRandom3;
72 <      gRandom->SetSeed(0);
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 >          Info("setRootEnv","Loaded \"%s\" for use in ACLiC", tmpstr);
94 >      }
95      }
96 +    delete[] tmpstr;
97 +  }
98 +  gSystem->FreeDirectory(dir);
99 + }
100  
101 <    if (gClassTable->GetID("mithep::Particle") >= 0) {
102 <      ::Info("setRootEnv", "Welcome to MITROOT!\n");
103 <    }
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 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines