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#include "TGridJDL.h"
14#include "TObjString.h"
15
16////////////////////////////////////////////////////////////////////////////////
17/// Cleanup.
18
20{
21 Clear();
22}
23
24////////////////////////////////////////////////////////////////////////////////
25/// Clears the JDL information.
26
28{
30}
31
32////////////////////////////////////////////////////////////////////////////////
33/// Sets a value. If the entry already exists the old one is replaced.
34
35void TGridJDL::SetValue(const char *key, const char *value)
36{
37 TObject *object = fMap.FindObject(key);
38 TPair *pair = dynamic_cast<TPair*>(object);
39 if (pair) {
40 TObject *oldObject = pair->Key();
41 if (oldObject) {
42 TObject *oldValue = pair->Value();
43
45 delete oldObject;
46 oldObject = 0;
47
48 if (oldValue) {
49 delete oldValue;
50 oldValue = 0;
51 }
52 }
53 }
54
55 fMap.Add(new TObjString(key), new TObjString(value));
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Returns the value corresponding to the provided key. Return 0 in case
60/// key is not found.
61
62const char *TGridJDL::GetValue(const char *key)
63{
64 if (!key)
65 return 0;
66
67 TObject *object = fMap.FindObject(key);
68 if (!object)
69 return 0;
70
71 TPair *pair = dynamic_cast<TPair*>(object);
72 if (!pair)
73 return 0;
74
75 TObject *value = pair->Value();
76 if (!value)
77 return 0;
78
79 TObjString *string = dynamic_cast<TObjString*>(value);
80 if (!string)
81 return 0;
82
83 return string->GetName();
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Sets a value. If the entry already exists the old one is replaced.
88
89void TGridJDL::SetDescription(const char *key, const char* description)
90{
91 TObject *object = fDescriptionMap.FindObject(key);
92 TPair *pair = dynamic_cast<TPair*>(object);
93 if (pair) {
94 TObject *oldObject = pair->Key();
95 if (oldObject) {
96 TObject *oldValue = pair->Value();
97
99 delete oldObject;
100 oldObject = 0;
101
102 if (oldValue) {
103 delete oldValue;
104 oldValue = 0;
105 }
106 }
107 }
108
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Returns the value corresponding to the provided key. Return 0 in case
114/// key is not found.
115
116const char *TGridJDL::GetDescription(const char *key)
117{
118 if (!key)
119 return 0;
120
121 TObject *object = fDescriptionMap.FindObject(key);
122 if (!object)
123 return 0;
124
125 TPair *pair = dynamic_cast<TPair*>(object);
126 if (!pair)
127 return 0;
128
129 TObject *value = pair->Value();
130 if (!value)
131 return 0;
132
133 TObjString *string = dynamic_cast<TObjString*>(value);
134 if (!string)
135 return 0;
136
137 return string->GetName();
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Adds quotes to the provided string.
142/// E.g. Value --> "Value"
143
145{
146 TString temp = TString("\"");
147 temp += value;
148 temp += "\"";
149
150 return temp;
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Adds a value to a key value which hosts a set of values.
155/// E.g. InputSandbox: {"file1","file2"}
156
157void TGridJDL::AddToSet(const char *key, const char *value)
158{
159 const char *oldValue = GetValue(key);
161 if (oldValue)
163 if (newString.IsNull()) {
164 newString = "{";
165 } else {
166 newString.Remove(newString.Length()-1);
167 newString += ",";
168 }
169
171 newString += "}";
172
173 SetValue(key, newString);
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Adds a value to a key value which hosts a set of values.
178/// E.g. InputSandbox: {"file1","file2"}
179
180void TGridJDL::AddToSetDescription(const char *key, const char *description)
181{
182 const char *oldValue = GetDescription(key);
184 if (oldValue)
187
189}
190////////////////////////////////////////////////////////////////////////////////
191/// Generates the JDL snippet.
192
194{
195 TString output("");
196
197 TIter next(&fMap);
199 TObject *object = 0;
200 TObject *objectD = 0;
201 while ((object = next())) {
202 TObjString *key = dynamic_cast<TObjString*>(object);
203 if (key) {
204 TObject *value = fMap.GetValue(object);
205 TObjString *valueobj = dynamic_cast<TObjString*>(value);
206
207 if (valueobj) {
208 nextDescription.Reset();
209 while ((objectD = nextDescription())) {
210 TObjString *keyD = dynamic_cast<TObjString*>(objectD);
211 if (keyD) {
213 TObjString *valueobjD = dynamic_cast<TObjString*>(valueD);
214 if (valueobjD && !strcmp(key->GetName(), keyD->GetName())){
215 //Info("",Form("%s %s",key->GetString().Data(),keyD->GetString().Data()));
216 output += "# ";
217 output += valueobjD->GetName();
218 output += "\n";
219 }
220 }
221 }
222 output += key->GetName();
223 output += " = ";
224 output += valueobj->GetName();
225 output += ";\n\n";
226 }
227 }
228 }
229
230 return output;
231}
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
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:19
void SetValue(const char *key, const char *value)
Sets a value. If the entry already exists the old one is replaced.
Definition TGridJDL.cxx:35
const char * GetDescription(const char *key)
Returns the value corresponding to the provided key.
Definition TGridJDL.cxx:116
void AddToSetDescription(const char *key, const char *description)
Adds a value to a key value which hosts a set of values.
Definition TGridJDL.cxx:180
virtual TString Generate()
Generates the JDL snippet.
Definition TGridJDL.cxx:193
TMap fDescriptionMap
Definition TGridJDL.h:33
TMap fMap
Definition TGridJDL.h:32
TString AddQuotes(const char *value)
Adds quotes to the provided string.
Definition TGridJDL.cxx:144
void AddToSet(const char *key, const char *value)
Adds a value to a key value which hosts a set of values.
Definition TGridJDL.cxx:157
void SetDescription(const char *key, const char *description)
Sets a value. If the entry already exists the old one is replaced.
Definition TGridJDL.cxx:89
const char * GetValue(const char *key)
Returns the value corresponding to the provided key.
Definition TGridJDL.cxx:62
void Clear(const Option_t *="") override
Clears the JDL information.
Definition TGridJDL.cxx:27
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:42
Class used by TMap to store (key,value) pairs.
Definition TMap.h:103
TObject * Value() const
Definition TMap.h:122
TObject * Key() const
Definition TMap.h:121
Basic string class.
Definition TString.h:137