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