00001 #include <iostream>
00002
00003 void SetAliEnSettings()
00004 {
00005
00006
00007 ifstream fileIn;
00008 fileIn.open(Form("/tmp/gclient_env_%d",gSystem->GetUid()));
00009 if (gDebug>0) {printf("P010_TAlien.C: parsing /tmp/gclient_env_$UID\n");}
00010 TString lineS,tmp;
00011 char line[4096];
00012
00013 while (fileIn.good()){
00014 fileIn.getline(line,4096,'\n');
00015 lineS = line;
00016 if (lineS.IsNull()) continue;
00017 if (lineS.Contains("export ")) {
00018 lineS.ReplaceAll("export ","");
00019
00020 TObjArray* array = lineS.Tokenize("=");
00021
00022 if (array->GetEntries() == 2) {
00023 TObjString *strVar = (TObjString *) array->At(0);
00024 TObjString *strVal = (TObjString *) array->At(1);
00025
00026 if ((strVar)&&(strVal)) {
00027 tmp = strVal->GetString();
00028 tmp.ReplaceAll("\"","");
00029 tmp.ReplaceAll("$LD_LIBRARY_PATH",gSystem->Getenv("LD_LIBRARY_PATH"));
00030 tmp.ReplaceAll("$DYLD_LIBRARY_PATH",gSystem->Getenv("DYLD_LIBRARY_PATH"));
00031 tmp.ReplaceAll(" ","");
00032 gSystem->Unsetenv(strVar->GetString());
00033 gSystem->Setenv(strVar->GetString(), tmp);
00034 if (gDebug>0) {
00035 Info("P010_TAlien", "setting environment %s=\"%s\"", strVar->GetString().Data(), tmp.Data());
00036 }
00037 if (!strVar->GetString().CompareTo("GCLIENT_SERVER_LIST")) {
00038 gSystem->Unsetenv("alien_API_SERVER_LIST");
00039 gSystem->Setenv("alien_API_SERVER_LIST", tmp);
00040 }
00041 }
00042 if (array) {
00043 delete array;
00044 array = 0 ;
00045 }
00046 } else {
00047
00048 TObjArray* array = lineS.Tokenize("\" ");
00049 TString key="";
00050 TString val="";
00051 for (int i=0; i< array->GetEntries(); i++) {
00052 if ( ((TObjString*) array->At(i))->GetString().Contains("=")) {
00053 if (key.Length() && val.Length()) {
00054 val.Resize(val.Length()-1);
00055 if (gDebug>0) {
00056 Info("P010_TAlien", "setting environment %s=\"%s\"", key.Data(), val.Data());
00057 }
00058 gSystem->Unsetenv(key);
00059 gSystem->Setenv(key, val);
00060 key="";
00061 val="";
00062 }
00063 key = ((TObjString*) array->At(i))->GetString();
00064 key.ReplaceAll("=","");
00065 } else {
00066 val+=((TObjString*) array->At(i))->GetString();
00067 val+=" ";
00068 }
00069 }
00070 if (key.Length() && val.Length()) {
00071 if (gDebug>0) {
00072 Info("P010_TAlien", "setting environment %s=\"%s\"", key.Data(), val.Data());
00073 }
00074 gSystem->Unsetenv(key);
00075 gSystem->Setenv(key, val);
00076 }
00077 }
00078 }
00079 }
00080 }
00081
00082 void P010_TAlien()
00083 {
00084 TString configfeatures = gROOT->GetConfigFeatures();
00085 TString ralienpath = gSystem->Getenv("ROOTSYS");
00086 ralienpath += "/lib/"; ralienpath += "libRAliEn.so";
00087
00088
00089 if ((!gSystem->AccessPathName(ralienpath))) || (configfeatures.contains("alien"))) {
00090
00091 if ((!gSystem->Getenv("GBBOX_ENVFILE")) ||
00092 ( gSystem->Getenv("ALIEN_SOURCE_GCLIENT_ENV")) ||
00093 (!gSystem->Getenv("ALIEN_SKIP_GCLIENT_ENV")) ) {
00094 SetAliEnSettings();
00095 }
00096
00097 if ( ((gSystem->Load("libgapiUI.so")>=0) && (gSystem->Load("libRAliEn.so")>=0))) {
00098 gPluginMgr->AddHandler("TGrid", "^alien", "TAlien",
00099 "RAliEn", "TAlien(const char*,const char*,const char*,const char*)");
00100 } else {
00101 Error("P010_TAlien","Please fix your loader path environment variable to be able to load libRAliEn.so");
00102 }
00103 }
00104 }