Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
29
30////////////////////////////////////////////////////////////////////////////////
31/// Cleanup.
32
34{
35 Clear();
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// Clears the JDL information.
40
42{
44}
45
46////////////////////////////////////////////////////////////////////////////////
47/// Sets a value. If the entry already exists the old one is replaced.
48
49void TGridJDL::SetValue(const char *key, const char *value)
50{
51 TObject *object = fMap.FindObject(key);
52 TPair *pair = dynamic_cast<TPair*>(object);
53 if (pair) {
54 TObject *oldObject = pair->Key();
55 if (oldObject) {
56 TObject *oldValue = pair->Value();
57
59 delete oldObject;
60 oldObject = 0;
61
62 if (oldValue) {
63 delete oldValue;
64 oldValue = 0;
65 }
66 }
67 }
68
69 fMap.Add(new TObjString(key), new TObjString(value));
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Returns the value corresponding to the provided key. Return 0 in case
74/// key is not found.
75
76const char *TGridJDL::GetValue(const char *key)
77{
78 if (!key)
79 return 0;
80
81 TObject *object = fMap.FindObject(key);
82 if (!object)
83 return 0;
84
85 TPair *pair = dynamic_cast<TPair*>(object);
86 if (!pair)
87 return 0;
88
89 TObject *value = pair->Value();
90 if (!value)
91 return 0;
92
93 TObjString *string = dynamic_cast<TObjString*>(value);
94 if (!string)
95 return 0;
96
97 return string->GetName();
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Sets a value. If the entry already exists the old one is replaced.
102
103void TGridJDL::SetDescription(const char *key, const char* description)
104{
105 TObject *object = fDescriptionMap.FindObject(key);
106 TPair *pair = dynamic_cast<TPair*>(object);
107 if (pair) {
108 TObject *oldObject = pair->Key();
109 if (oldObject) {
110 TObject *oldValue = pair->Value();
111
113 delete oldObject;
114 oldObject = 0;
115
116 if (oldValue) {
117 delete oldValue;
118 oldValue = 0;
119 }
120 }
121 }
122
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// Returns the value corresponding to the provided key. Return 0 in case
128/// key is not found.
129
130const char *TGridJDL::GetDescription(const char *key)
131{
132 if (!key)
133 return 0;
134
135 TObject *object = fDescriptionMap.FindObject(key);
136 if (!object)
137 return 0;
138
139 TPair *pair = dynamic_cast<TPair*>(object);
140 if (!pair)
141 return 0;
142
143 TObject *value = pair->Value();
144 if (!value)
145 return 0;
146
147 TObjString *string = dynamic_cast<TObjString*>(value);
148 if (!string)
149 return 0;
150
151 return string->GetName();
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Adds quotes to the provided string.
156/// E.g. Value --> "Value"
157
159{
160 TString temp = TString("\"");
161 temp += value;
162 temp += "\"";
163
164 return temp;
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Adds a value to a key value which hosts a set of values.
169/// E.g. InputSandbox: {"file1","file2"}
170
171void TGridJDL::AddToSet(const char *key, const char *value)
172{
173 const char *oldValue = GetValue(key);
175 if (oldValue)
177 if (newString.IsNull()) {
178 newString = "{";
179 } else {
180 newString.Remove(newString.Length()-1);
181 newString += ",";
182 }
183
185 newString += "}";
186
187 SetValue(key, newString);
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Adds a value to a key value which hosts a set of values.
192/// E.g. InputSandbox: {"file1","file2"}
193
194void TGridJDL::AddToSetDescription(const char *key, const char *description)
195{
196 const char *oldValue = GetDescription(key);
198 if (oldValue)
201
203}
204////////////////////////////////////////////////////////////////////////////////
205/// Generates the JDL snippet.
206
208{
209 TString output("");
210
211 TIter next(&fMap);
213 TObject *object = 0;
214 TObject *objectD = 0;
215 while ((object = next())) {
216 TObjString *key = dynamic_cast<TObjString*>(object);
217 if (key) {
218 TObject *value = fMap.GetValue(object);
219 TObjString *valueobj = dynamic_cast<TObjString*>(value);
220
221 if (valueobj) {
222 nextDescription.Reset();
223 while ((objectD = nextDescription())) {
224 TObjString *keyD = dynamic_cast<TObjString*>(objectD);
225 if (keyD) {
227 TObjString *valueobjD = dynamic_cast<TObjString*>(valueD);
228 if (valueobjD && !strcmp(key->GetName(), keyD->GetName())){
229 //Info("",Form("%s %s",key->GetString().Data(),keyD->GetString().Data()));
230 output += "# ";
231 output += valueobjD->GetName();
232 output += "\n";
233 }
234 }
235 }
236 output += key->GetName();
237 output += " = ";
238 output += valueobj->GetName();
239 output += ";\n\n";
240 }
241 }
242 }
243
244 return output;
245}
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
virtual ~TGridJDL()
Cleanup.
Definition TGridJDL.cxx:33
void SetValue(const char *key, const char *value)
Sets a value. If the entry already exists the old one is replaced.
Definition TGridJDL.cxx:49
const char * GetDescription(const char *key)
Returns the value corresponding to the provided key.
Definition TGridJDL.cxx:130
void AddToSetDescription(const char *key, const char *description)
Adds a value to a key value which hosts a set of values.
Definition TGridJDL.cxx:194
virtual TString Generate()
Generates the JDL snippet.
Definition TGridJDL.cxx:207
TMap fDescriptionMap
Definition TGridJDL.h:35
TMap fMap
Definition TGridJDL.h:34
TString AddQuotes(const char *value)
Adds quotes to the provided string.
Definition TGridJDL.cxx:158
void AddToSet(const char *key, const char *value)
Adds a value to a key value which hosts a set of values.
Definition TGridJDL.cxx:171
void SetDescription(const char *key, const char *description)
Sets a value. If the entry already exists the old one is replaced.
Definition TGridJDL.cxx:103
const char * GetValue(const char *key)
Returns the value corresponding to the provided key.
Definition TGridJDL.cxx:76
void Clear(const Option_t *="") override
Clears the JDL information.
Definition TGridJDL.cxx:41
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:167
void Add(TObject *obj) override
This function may not be used (but we need to provide it since it is a pure virtual in TCollection).
Definition TMap.cxx:53
TObject * FindObject(const char *keyname) const override
Check if a (key,value) pair exists with keyname as name of the key.
Definition TMap.cxx:214
TObject * Remove(TObject *key) override
Remove the (key,value) pair with key from the map.
Definition TMap.cxx:295
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition TMap.cxx:235
Collectable string class.
Definition TObjString.h:28
const char * GetName() const override
Returns name of object.
Definition TObjString.h:38
Mother of all ROOT objects.
Definition TObject.h:41
Class used by TMap to store (key,value) pairs.
Definition TMap.h:102
TObject * Value() const
Definition TMap.h:121
TObject * Key() const
Definition TMap.h:120
Basic string class.
Definition TString.h:138
static void output()