TGridJDL.cxx

Go to the documentation of this file.
00001 // @(#)root/net:$Id: TGridJDL.cxx 35776 2010-09-27 08:25:59Z rdm $
00002 // Author: Jan Fiete Grosse-Oetringhaus   28/9/2004
00003 //         Jancurova.lucia@cern.ch Slovakia  29/9/2008
00004 
00005 /*************************************************************************
00006  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00007  * All rights reserved.                                                  *
00008  *                                                                       *
00009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00011  *************************************************************************/
00012 
00013 //////////////////////////////////////////////////////////////////////////
00014 //                                                                      //
00015 // TGridJDL                                                             //
00016 //                                                                      //
00017 // Abstract base class to generate JDL files for job submission to the  //
00018 // Grid.                                                                //
00019 //                                                                      //
00020 // Related classes are TGLiteJDL.                                       //
00021 //                                                                      //
00022 //////////////////////////////////////////////////////////////////////////
00023 
00024 #include "TGridJDL.h"
00025 #include "TObjString.h"
00026 #include "Riostream.h"
00027 
00028 
00029 ClassImp(TGridJDL)
00030 
00031 //______________________________________________________________________________
00032 TGridJDL::~TGridJDL()
00033 {
00034    // Cleanup.
00035 
00036    Clear();
00037 }
00038 
00039 //______________________________________________________________________________
00040 void TGridJDL::Clear(const Option_t*)
00041 {
00042    // Clears the JDL information.
00043 
00044    fMap.DeleteAll();
00045 }
00046 
00047 //______________________________________________________________________________
00048 void TGridJDL::SetValue(const char *key, const char *value)
00049 {
00050    // Sets a value. If the entry already exists the old one is replaced.
00051 
00052    TObject *object = fMap.FindObject(TString(key));
00053    TPair *pair = dynamic_cast<TPair*>(object);
00054    if (pair) {
00055       TObject *oldObject = pair->Key();
00056       if (oldObject) {
00057          TObject *oldValue = pair->Value();
00058 
00059          fMap.Remove(oldObject);
00060          delete oldObject;
00061          oldObject = 0;
00062 
00063          if (oldValue) {
00064             delete oldValue;
00065             oldValue = 0;
00066          }
00067       }
00068    }
00069 
00070    fMap.Add(new TObjString(key), new TObjString(value));
00071 }
00072 
00073 //______________________________________________________________________________
00074 const char *TGridJDL::GetValue(const char *key)
00075 {
00076    // Returns the value corresponding to the provided key. Return 0 in case
00077    // key is not found.
00078 
00079    if (!key)
00080       return 0;
00081 
00082    TObject *object = fMap.FindObject(TString(key));
00083    if (!object)
00084       return 0;
00085 
00086    TPair *pair = dynamic_cast<TPair*>(object);
00087    if (!pair)
00088       return 0;
00089 
00090    TObject *value = pair->Value();
00091    if (!value)
00092       return 0;
00093 
00094    TObjString *string = dynamic_cast<TObjString*>(value);
00095    if (!string)
00096       return 0;
00097 
00098    return string->GetString();
00099 }
00100 
00101 //______________________________________________________________________________
00102 void TGridJDL::SetDescription(const char *key, const char* description)
00103 {
00104    // Sets a value. If the entry already exists the old one is replaced.
00105 
00106    TObject *object = fDescriptionMap.FindObject(TString(key));
00107    TPair *pair = dynamic_cast<TPair*>(object);
00108    if (pair) {
00109       TObject *oldObject = pair->Key();
00110       if (oldObject) {
00111          TObject *oldValue = pair->Value();
00112 
00113          fDescriptionMap.Remove(oldObject);
00114          delete oldObject;
00115          oldObject = 0;
00116 
00117          if (oldValue) {
00118             delete oldValue;
00119             oldValue = 0;
00120          }
00121       }
00122    }
00123 
00124    fDescriptionMap.Add(new TObjString(key), new TObjString(description));
00125 }
00126 
00127 //______________________________________________________________________________
00128 const char *TGridJDL::GetDescription(const char *key)
00129 {
00130    // Returns the value corresponding to the provided key. Return 0 in case
00131    // key is not found.
00132 
00133    if (!key)
00134       return 0;
00135 
00136    TObject *object = fDescriptionMap.FindObject(TString(key));
00137    if (!object)
00138       return 0;
00139 
00140    TPair *pair = dynamic_cast<TPair*>(object);
00141    if (!pair)
00142       return 0;
00143 
00144    TObject *value = pair->Value();
00145    if (!value)
00146       return 0;
00147 
00148    TObjString *string = dynamic_cast<TObjString*>(value);
00149    if (!string)
00150       return 0;
00151 
00152    return string->GetString();
00153 }
00154 
00155 //______________________________________________________________________________
00156 TString TGridJDL::AddQuotes(const char *value)
00157 {
00158    // Adds quotes to the provided string.
00159    //  E.g. Value --> "Value"
00160 
00161    TString temp = TString("\"");
00162    temp += value;
00163    temp += "\"";
00164 
00165    return temp;
00166 }
00167 
00168 //______________________________________________________________________________
00169 void TGridJDL::AddToSet(const char *key, const char *value)
00170 {
00171    // Adds a value to a key value which hosts a set of values.
00172    // E.g. InputSandbox: {"file1","file2"}
00173 
00174    const char *oldValue = GetValue(key);
00175    TString newString;
00176    if (oldValue)
00177       newString = oldValue;
00178    if (newString.IsNull()) {
00179       newString = "{";
00180    } else {
00181       newString.Remove(newString.Length()-1);
00182       newString += ",";
00183    }
00184 
00185    newString += AddQuotes(value);
00186    newString += "}";
00187 
00188    SetValue(key, newString);
00189 }
00190 
00191 //______________________________________________________________________________
00192 void TGridJDL::AddToSetDescription(const char *key, const char *description)
00193 {
00194    // Adds a value to a key value which hosts a set of values.
00195    // E.g. InputSandbox: {"file1","file2"}
00196 
00197    const char *oldValue = GetDescription(key);
00198    TString newString;
00199    if (oldValue)
00200       newString = oldValue;
00201    newString += description;
00202 
00203    SetDescription(key, newString);
00204 }
00205 //______________________________________________________________________________
00206 TString TGridJDL::Generate()
00207 {
00208    // Generates the JDL snippet.
00209 
00210    TString output("");
00211 
00212    TIter next(&fMap);
00213    TIter nextDescription(&fDescriptionMap);
00214    TObject *object = 0;
00215    TObject *objectD = 0;
00216    while ((object = next())) {
00217       TObjString *key = dynamic_cast<TObjString*>(object);
00218       if (key) {
00219          TObject *value = fMap.GetValue(object);
00220          TObjString *valueobj = dynamic_cast<TObjString*>(value);
00221 
00222          if (valueobj) {
00223             nextDescription.Reset();
00224             while ((objectD = nextDescription())) {
00225                TObjString *keyD = dynamic_cast<TObjString*>(objectD);
00226                if (keyD) {
00227                   TObject *valueD = fDescriptionMap.GetValue(objectD);
00228                   TObjString *valueobjD = dynamic_cast<TObjString*>(valueD);
00229                   if (valueobjD && !key->GetString().CompareTo(keyD->GetString())){
00230                      //Info("",Form("%s %s",key->GetString().Data(),keyD->GetString().Data()));
00231                      output += "# ";
00232                      output += valueobjD->GetString();
00233                      output += "\n";
00234                   }
00235                }
00236             }
00237             output += key->GetString();
00238             output += " = ";
00239             output += valueobj->GetString();
00240             output += ";\n\n";
00241          }
00242       }
00243    }
00244 
00245    return output;
00246 }

Generated on Tue Jul 5 14:46:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1