ROOT  6.06/09
Reference Guide
TGridJDL.cxx
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Jan Fiete Grosse-Oetringhaus 28/9/2004
3 // Jancurova.lucia@cern.ch Slovakia 29/9/2008
4 
5 /*************************************************************************
6  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 //////////////////////////////////////////////////////////////////////////
14 // //
15 // TGridJDL //
16 // //
17 // Abstract base class to generate JDL files for job submission to the //
18 // Grid. //
19 // //
20 // Related classes are TGLiteJDL. //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TGridJDL.h"
25 #include "TObjString.h"
26 #include "Riostream.h"
27 
28 
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 /// Cleanup.
33 
35 {
36  Clear();
37 }
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Clears the JDL information.
41 
43 {
44  fMap.DeleteAll();
45 }
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Sets a value. If the entry already exists the old one is replaced.
49 
50 void TGridJDL::SetValue(const char *key, const char *value)
51 {
52  TObject *object = fMap.FindObject(key);
53  TPair *pair = dynamic_cast<TPair*>(object);
54  if (pair) {
55  TObject *oldObject = pair->Key();
56  if (oldObject) {
57  TObject *oldValue = pair->Value();
58 
59  fMap.Remove(oldObject);
60  delete oldObject;
61  oldObject = 0;
62 
63  if (oldValue) {
64  delete oldValue;
65  oldValue = 0;
66  }
67  }
68  }
69 
70  fMap.Add(new TObjString(key), new TObjString(value));
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Returns the value corresponding to the provided key. Return 0 in case
75 /// key is not found.
76 
77 const char *TGridJDL::GetValue(const char *key)
78 {
79  if (!key)
80  return 0;
81 
82  TObject *object = fMap.FindObject(key);
83  if (!object)
84  return 0;
85 
86  TPair *pair = dynamic_cast<TPair*>(object);
87  if (!pair)
88  return 0;
89 
90  TObject *value = pair->Value();
91  if (!value)
92  return 0;
93 
94  TObjString *string = dynamic_cast<TObjString*>(value);
95  if (!string)
96  return 0;
97 
98  return string->GetName();
99 }
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Sets a value. If the entry already exists the old one is replaced.
103 
104 void TGridJDL::SetDescription(const char *key, const char* description)
105 {
106  TObject *object = fDescriptionMap.FindObject(key);
107  TPair *pair = dynamic_cast<TPair*>(object);
108  if (pair) {
109  TObject *oldObject = pair->Key();
110  if (oldObject) {
111  TObject *oldValue = pair->Value();
112 
113  fDescriptionMap.Remove(oldObject);
114  delete oldObject;
115  oldObject = 0;
116 
117  if (oldValue) {
118  delete oldValue;
119  oldValue = 0;
120  }
121  }
122  }
123 
124  fDescriptionMap.Add(new TObjString(key), new TObjString(description));
125 }
126 
127 ////////////////////////////////////////////////////////////////////////////////
128 /// Returns the value corresponding to the provided key. Return 0 in case
129 /// key is not found.
130 
131 const char *TGridJDL::GetDescription(const char *key)
132 {
133  if (!key)
134  return 0;
135 
136  TObject *object = fDescriptionMap.FindObject(key);
137  if (!object)
138  return 0;
139 
140  TPair *pair = dynamic_cast<TPair*>(object);
141  if (!pair)
142  return 0;
143 
144  TObject *value = pair->Value();
145  if (!value)
146  return 0;
147 
148  TObjString *string = dynamic_cast<TObjString*>(value);
149  if (!string)
150  return 0;
151 
152  return string->GetName();
153 }
154 
155 ////////////////////////////////////////////////////////////////////////////////
156 /// Adds quotes to the provided string.
157 /// E.g. Value --> "Value"
158 
160 {
161  TString temp = TString("\"");
162  temp += value;
163  temp += "\"";
164 
165  return temp;
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Adds a value to a key value which hosts a set of values.
170 /// E.g. InputSandbox: {"file1","file2"}
171 
172 void TGridJDL::AddToSet(const char *key, const char *value)
173 {
174  const char *oldValue = GetValue(key);
175  TString newString;
176  if (oldValue)
177  newString = oldValue;
178  if (newString.IsNull()) {
179  newString = "{";
180  } else {
181  newString.Remove(newString.Length()-1);
182  newString += ",";
183  }
184 
185  newString += AddQuotes(value);
186  newString += "}";
187 
188  SetValue(key, newString);
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Adds a value to a key value which hosts a set of values.
193 /// E.g. InputSandbox: {"file1","file2"}
194 
195 void TGridJDL::AddToSetDescription(const char *key, const char *description)
196 {
197  const char *oldValue = GetDescription(key);
198  TString newString;
199  if (oldValue)
200  newString = oldValue;
201  newString += description;
202 
203  SetDescription(key, newString);
204 }
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Generates the JDL snippet.
207 
209 {
210  TString output("");
211 
212  TIter next(&fMap);
213  TIter nextDescription(&fDescriptionMap);
214  TObject *object = 0;
215  TObject *objectD = 0;
216  while ((object = next())) {
217  TObjString *key = dynamic_cast<TObjString*>(object);
218  if (key) {
219  TObject *value = fMap.GetValue(object);
220  TObjString *valueobj = dynamic_cast<TObjString*>(value);
221 
222  if (valueobj) {
223  nextDescription.Reset();
224  while ((objectD = nextDescription())) {
225  TObjString *keyD = dynamic_cast<TObjString*>(objectD);
226  if (keyD) {
227  TObject *valueD = fDescriptionMap.GetValue(objectD);
228  TObjString *valueobjD = dynamic_cast<TObjString*>(valueD);
229  if (valueobjD && !strcmp(key->GetName(), keyD->GetName())){
230  //Info("",Form("%s %s",key->GetString().Data(),keyD->GetString().Data()));
231  output += "# ";
232  output += valueobjD->GetName();
233  output += "\n";
234  }
235  }
236  }
237  output += key->GetName();
238  output += " = ";
239  output += valueobj->GetName();
240  output += ";\n\n";
241  }
242  }
243  }
244 
245  return output;
246 }
const char * GetName() const
Returns name of object.
Definition: TObjString.h:42
TString AddQuotes(const char *value)
Adds quotes to the provided string.
Definition: TGridJDL.cxx:159
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Ssiz_t Length() const
Definition: TString.h:390
Collectable string class.
Definition: TObjString.h:32
void SetValue(const char *key, const char *value)
Sets a value. If the entry already exists the old one is replaced.
Definition: TGridJDL.cxx:50
const char Option_t
Definition: RtypesCore.h:62
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
Definition: TMap.cxx:52
Basic string class.
Definition: TString.h:137
void Reset()
Definition: TCollection.h:161
ClassImp(TGridJDL) TGridJDL
Cleanup.
Definition: TGridJDL.cxx:29
void AddToSet(const char *key, const char *value)
Adds a value to a key value which hosts a set of values.
Definition: TGridJDL.cxx:172
void DeleteAll()
Remove all (key,value) pairs from the map AND delete the keys AND values when they are allocated on t...
Definition: TMap.cxx:166
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition: TMap.cxx:234
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition: TMap.cxx:213
void AddToSetDescription(const char *key, const char *description)
Adds a value to a key value which hosts a set of values.
Definition: TGridJDL.cxx:195
TObject * Remove(TObject *key)
Remove the (key,value) pair with key from the map.
Definition: TMap.cxx:294
TObject * Value() const
Definition: TMap.h:125
TMap fDescriptionMap
Definition: TGridJDL.h:41
Bool_t IsNull() const
Definition: TString.h:387
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:106
void SetDescription(const char *key, const char *description)
Sets a value. If the entry already exists the old one is replaced.
Definition: TGridJDL.cxx:104
const char * GetValue(const char *key)
Returns the value corresponding to the provided key.
Definition: TGridJDL.cxx:77
TObject * Key() const
Definition: TMap.h:124
const char * GetDescription(const char *key)
Returns the value corresponding to the provided key.
Definition: TGridJDL.cxx:131
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void Clear(const Option_t *=0)
Clears the JDL information.
Definition: TGridJDL.cxx:42
virtual TString Generate()
Generates the JDL snippet.
Definition: TGridJDL.cxx:208
static void output(int code)
Definition: gifencode.c:226
float value
Definition: math.cpp:443
TMap fMap
Definition: TGridJDL.h:40