Logo ROOT  
Reference Guide
TAlienJDL.cxx
Go to the documentation of this file.
1// @(#)root/alien:$Id$
2// Author: Jan Fiete Grosse-Oetringhaus 28/9/2004
3// Lucia.Jancurova@cern.ch Slovakia 2007
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// TAlienJDL //
16// //
17// Class which creates JDL files for the alien middleware //
18// //
19//////////////////////////////////////////////////////////////////////////
20
21#include "TAlienJDL.h"
22#include "TGrid.h"
23#include "TGridJob.h"
24#include "Riostream.h"
25#include "TSystem.h"
26#include "TObjString.h"
27#include "TObjArray.h"
28
30
31////////////////////////////////////////////////////////////////////////////////
32/// Sets the executable.
33
34void TAlienJDL::SetExecutable(const char *value, const char *description)
35{
36 if (value)
37 SetValue("Executable", AddQuotes(value));
38 if (description)
39 SetDescription("Executable", description);
40}
41
42////////////////////////////////////////////////////////////////////////////////
43/// Sets the arguments.
44
45void TAlienJDL::SetArguments(const char *value, const char *description)
46{
47 if (value)
48 SetValue("Arguments", AddQuotes(value));
49 if (description)
50 SetDescription("Arguments", description);
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Sets eMail address.
55
56void TAlienJDL::SetEMail(const char *value, const char *description)
57{
58 if (value)
59 SetValue("Email", AddQuotes(value));
60 if (description)
61 SetDescription("Email", description);
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Sets OutputDirectory.
66
67void TAlienJDL::SetOutputDirectory(const char *value, const char *description)
68{
69 if (value)
70 SetValue ("OutputDir", AddQuotes(value));
71 if (description)
72 SetDescription("OutputDir", description);
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Sets merged OutputDirectory.
77
78void TAlienJDL::SetMergedOutputDirectory ( const char * value,const char* description)
79{
80 if (value)
81 SetValue ("MergeOutputDir", AddQuotes(value));
82 if (description)
83 SetDescription("MergeOutputDir", description);
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Sets OutputDirectory.
88
89void TAlienJDL:: SetPrice(UInt_t price,const char* description)
90{
91 TString pricestring(Form("%d",price));
92 SetValue("Price", AddQuotes(pricestring.Data()));
93
94 if (description)
95 SetDescription("Price", description);
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// To inform AliEn master about estimated Time-To-Live of included nodes.
100
101void TAlienJDL:: SetTTL(UInt_t ttl, const char *description)
102{
103 TString ttlstring;
104 ttlstring+= ttl;
105 SetValue("TTL", ttlstring.Data());
106
107 if (description)
108 SetDescription("TTL", description);
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Sets Job Tag
113
114void TAlienJDL::SetJobTag(const char* value,const char* description)
115{
116 if (value)
117 SetValue("JobTag", AddQuotes(value));
118 if (description)
119 SetDescription("JobTag", description);
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Sets InputDataListFormat - can be "xml-single" or "xml-multi"
124
125void TAlienJDL::SetInputDataListFormat(const char* value,const char* description)
126{
127 if (value)
128 SetValue("InputDataListFormat", AddQuotes(value));
129 if (description)
130 SetDescription("InputDataListFormat", description);
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Sets InputDataList name
135
136void TAlienJDL::SetInputDataList(const char* value,const char* description)
137{
138 if (value)
139 SetValue("InputDataList", AddQuotes(value));
140 if (description)
141 SetDescription("InputDataList", description);
142}
143
144
145////////////////////////////////////////////////////////////////////////////////
146/// Sets the split mode.
147
148void TAlienJDL::SetSplitMode(const char *value, UInt_t maxnumberofinputfiles,
149 UInt_t maxinputfilesize, const char *d1, const char *d2,
150 const char *d3)
151{
152 if (value && !strcasecmp(value, "SE")) {
153
154 SetSplitArguments(value,d1);
155 if (maxnumberofinputfiles) {
156 SetSplitModeMaxNumOfFiles(maxnumberofinputfiles,d2);
157 }
158 if (maxinputfilesize) {
159 SetSplitModeMaxInputFileSize(maxinputfilesize,d3);
160 }
161 } else {
162 if (value)
163 SetSplitArguments(value,d1);
164 }
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Sets the SplitMaxNumOfFiles.
169
170void TAlienJDL::SetSplitModeMaxNumOfFiles(UInt_t maxnumberofinputfiles, const char *description)
171{
172 TString val;
173 val += maxnumberofinputfiles;
174 SetValue ( "SplitMaxInputFileNumber", AddQuotes ( val.Data() ) );
175
176 if (description)
177 SetDescription("SplitMaxInputFileNumber", description);
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Sets the SplitMaxInputFileSize.
182
183void TAlienJDL::SetSplitModeMaxInputFileSize(UInt_t maxinputfilesize, const char *description)
184{
185 TString val;
186 val += maxinputfilesize;
187 SetValue ( "SplitMaxInputFileSize", AddQuotes ( val.Data() ) );
188 if (description)
189 SetDescription("SplitMaxInputFileSize", description);
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Sets the split.
194
195void TAlienJDL::SetSplitArguments(const char *splitarguments, const char *description)
196{
197 if (splitarguments)
198 SetValue("Split", AddQuotes(splitarguments));
199 if (description)
200 SetDescription("Split", description);
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Sets the validation command.
205
206void TAlienJDL::SetValidationCommand(const char *value, const char *description)
207{
208 SetValue("Validationcommand", AddQuotes(value));
209 if (description)
210 SetDescription("Validationcommand", description);
211}
212
213////////////////////////////////////////////////////////////////////////////////
214/// Sets the Maxium init failed
215
216void TAlienJDL::SetMaxInitFailed(Int_t maxInitFailed, const char *description)
217{
218 TString str;
219 str += maxInitFailed;
220 SetValue("MaxInitFailed", AddQuotes(str.Data()));
221 if (description)
222 SetDescription("MaxInitFailed", description);
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Sets the Own Command
227
228void TAlienJDL::SetOwnCommand(const char *command, const char *value, const char *description)
229{
230 if ((command) && (value))
231 SetValue(command, AddQuotes(value));
232 if ((command) && (description))
233 SetDescription(command, description);
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Adds a requirement.
238
239void TAlienJDL::AddToRequirements(const char *value, const char *description)
240{
241 if (value)
242 AddToReqSet("Requirements", value);
243 if (description)
244 AddToSetDescription("Requirements", description);
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Adds a file to the input sandbox.
249
250void TAlienJDL::AddToInputSandbox(const char *value, const char *description)
251{
252 if (value)
253 AddToSet("InputFile", value);
254 if (description)
255 AddToSetDescription("InputFile", description);
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Adds a file to the output sandbox.
260
261void TAlienJDL::AddToOutputSandbox(const char *value, const char *description)
262{
263 if (value)
264 AddToSet("OutputFile", value);
265 if (description)
266 AddToSetDescription("OutputFile", description);
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// Adds a file to the input data.
271
272void TAlienJDL::AddToInputData(const char *value, const char *description)
273{
274 if (value)
275 AddToSet("InputData", value);
276 if (description)
277 AddToSetDescription("InputData", description);
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Adds a file to the input data collection.
282
283void TAlienJDL::AddToInputDataCollection(const char *value, const char *description)
284{
285 if (value)
286 AddToSet("InputDataCollection", value);
287 if (description)
288 AddToSetDescription("InputDataCollection", description);
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Adds a package name to the package section.
293
294void TAlienJDL::AddToPackages(const char *name, const char *version,
295 const char *type, const char *description)
296{
297 if (name) {
298 TString packagename = type;
299 packagename += "@";
300 packagename += name;
301 packagename += "::";
302 packagename += version;
303
304 AddToSet("Packages", packagename.Data());
305 }
306
307 if (description)
308 AddToSetDescription("Packages", description);
309}
310
311////////////////////////////////////////////////////////////////////////////////
312/// Adds a package.
313
314void TAlienJDL::AddToPackages(const char *name, const char *description)
315{
316 AddToSet("Packages", name);
317 if (description)
318 AddToSetDescription("Packages", description);
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Adds an output archive definition
323
324void TAlienJDL::AddToOutputArchive(const char* value,const char* description)
325{
326 if (value)
327 AddToSet("OutputArchive", value);
328 if (description)
329 AddToSetDescription("OutputArchive", description);
330}
331
332////////////////////////////////////////////////////////////////////////////////
333/// Adds a value to a key value which hosts a set of values.
334/// E.g. InputSandbox: {"file1","file2"}
335
336void TAlienJDL::AddToReqSet(const char *key, const char *value)
337{
338 const char *oldValue = GetValue(key);
339 TString newString;
340 if (oldValue)
341 newString = oldValue;
342 if (newString.IsNull()) {
343 newString = "(";
344 } else {
345 newString.Remove(newString.Length()-1);
346 newString += " && ";
347 }
348
349 newString += value;
350 newString += ")";
351
352 SetValue(key, newString);
353}
354
355////////////////////////////////////////////////////////////////////////////////
356/// Adds a package name to the package section.
357
358void TAlienJDL::AddToMerge(const char *filenameToMerge, const char *jdlToSubmit,
359 const char *mergedFile, const char *description )
360{
361 TString mergename ( filenameToMerge );
362 mergename += ":";
363 mergename += jdlToSubmit;
364 mergename += ":";
365 mergename += mergedFile;
366 AddToSet ( "Merge", mergename.Data() );
367 if (description)
368 AddToSetDescription("Merge", description);
369}
370
371////////////////////////////////////////////////////////////////////////////////
372/// Adds a package name the the package section.
373
374void TAlienJDL::AddToMerge(const char *merge, const char *description)
375{
376 AddToSet("Merge", merge);
377 if (description)
378 AddToSetDescription("Merge", description);
379}
380
381////////////////////////////////////////////////////////////////////////////////
382/// Tests the submission of a simple job.
383
385{
386 Info("SubmitTest", "submitting test job /bin/date");
387
388 if (!gGrid) {
389 Error("SubmitTest", "you must have a proper GRID environment initialized");
390 return kFALSE;
391 }
392
393 Clear();
394 SetExecutable("/bin/date");
395 SetArguments("-R");
396 TGridJob* job = gGrid->Submit(Generate());
397 printf("Sending:\n%s\n",Generate().Data());
398 if (job == 0) {
399 Error("SubmitTest", "submitting failed");
400 return kFALSE;
401 }
402
403 return kTRUE;
404}
405
406////////////////////////////////////////////////////////////////////////////////
407/// Set the specified value to the specified command.
408
410{
411 if ( !cmd.CompareTo ( "Executable" ) ) SetExecutable ( value.Data() );
412 else if ( !cmd.CompareTo ( "Arguments" ) ) SetArguments ( value.Data() );
413 else if ( !cmd.CompareTo ( "Email" ) ) SetEMail ( value.Data() );
414 else if ( !cmd.CompareTo ( "OutputDir" ) ) SetOutputDirectory ( value.Data() );
415 else if ( !cmd.CompareTo ( "Merge" ) ) AddToMerge ( value.Data() );
416 else if ( !cmd.CompareTo ( "MergeOutputDir" ) ) SetMergedOutputDirectory ( value.Data() );
417 else if ( !cmd.CompareTo ( "Price" ) ) SetPrice ( value.Atoi() );
418 else if ( !cmd.CompareTo ( "TTL" ) ) SetTTL ( value.Atoi() );
419 else if ( !cmd.CompareTo ( "JobTag" ) ) SetJobTag ( value.Data() );
420 else if ( !cmd.CompareTo ( "InputDataListFormat" ) ) SetInputDataListFormat ( value.Data() );
421 else if ( !cmd.CompareTo ( "InputDataList" ) ) SetInputDataList ( value.Data() );
422 else if ( !cmd.CompareTo ( "Split" ) ) SetSplitMode ( value.Data() );
423 else if ( !cmd.CompareTo ( "SplitMaxInputFileNumber" ) ) SetSplitModeMaxNumOfFiles ( value.Atoi() );
424 else if ( !cmd.CompareTo ( "SplitMaxInputFileSize" ) ) SetSplitModeMaxInputFileSize ( value.Atoi() );
425 else if ( !cmd.CompareTo ( "SplitArguments" ) ) SetSplitArguments ( value.Data() );
426 else if ( !cmd.CompareTo ( "Validationcommand" ) ) SetValidationCommand ( value.Data() );
427 else if ( !cmd.CompareTo ( "MaxInitFailed" ) ) SetMaxInitFailed ( value.Atoi() );
428 else if ( !cmd.CompareTo ( "InputSandbox" ) ) AddToInputSandbox ( value.Data() );
429 else if ( !cmd.CompareTo ( "OutputSandbox" ) ) AddToOutputSandbox ( value.Data() );
430 else if ( !cmd.CompareTo ( "InputData" ) ) AddToInputData ( value.Data() );
431 else if ( !cmd.CompareTo ( "InputDataCollection" ) ) AddToInputDataCollection ( value.Data() );
432 else if ( !cmd.CompareTo ( "Requirements" ) ) AddToRequirements ( value.Data() );
433 else if ( !cmd.CompareTo ( "InputFile" ) ) AddToInputSandbox ( value.Data() );
434 else if ( !cmd.CompareTo ( "OutputFile" ) ) AddToOutputSandbox ( value.Data() );
435 else if ( !cmd.CompareTo ( "Packages" ) ) AddToPackages ( value.Data() );
436 else if ( !cmd.CompareTo ( "OutputArchive" ) ) AddToOutputArchive ( value.Data() );
437 else
438 Error ( "SetValueByCmd()","Cmd Value not supported.." );
439}
440
441////////////////////////////////////////////////////////////////////////////////
442/// fills the TAlienJDL from inputfile (should be AliEn JDL file)
443
444void TAlienJDL::Parse(const char *filename)
445{
446 std::ifstream file;
447 file.open ( filename );
448 if ( !file.is_open() ) {
449 Error("Parse", "error opening file %s", filename);
450 return;
451 }
452
453 TString lineString;
454 Char_t line[1024];
455 while ( file.good() ) {
456 file.getline ( line,1024 );
457 lineString=line;
458 lineString.ReplaceAll ( " ","" );
459 if ( !lineString.IsNull() ) {
460 if (lineString.Index('#') == 0) continue;
461 TObjArray *strCmdOrValue = lineString.Tokenize ( "=" );
462 TObjString*strObjCmd = ( TObjString* ) strCmdOrValue->At ( 0 );
463 TObjString*strObjValue = ( TObjString* ) strCmdOrValue->At ( 1 );
464 TString cmdString ( strObjCmd->GetString() );
465 TString valueString ( strObjValue->GetString() );
466 cmdString.ReplaceAll ( " ","" );
467 valueString.ReplaceAll ( " ","" );
468 valueString.ReplaceAll ( "\",\"","`" );
469
470 TObjArray *strValues = valueString.Tokenize ( "`" );
471 for ( Int_t i=0;i<strValues->GetEntries();i++ ) {
472 TObjString *strObjValue2 = ( TObjString* ) strValues->At ( i );
473 TString valueString2 ( strObjValue2->GetString() );
474 valueString2.ReplaceAll ( "\"","" );
475 valueString2.ReplaceAll ( "{","" );
476 valueString2.ReplaceAll ( "}","" );
477 valueString2.ReplaceAll ( ";","" );
478 SetValueByCmd ( cmdString,valueString2 );
479 }
480 }
481 }
482
483 file.close();
484}
485
486////////////////////////////////////////////////////////////////////////////////
487/// Not implemented
488
490{
491}
int Int_t
Definition: RtypesCore.h:41
char Char_t
Definition: RtypesCore.h:29
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
int type
Definition: TGX11.cxx:120
R__EXTERN TGrid * gGrid
Definition: TGrid.h:128
char * Form(const char *fmt,...)
virtual void SetSplitArguments(const char *splitarguments=0, const char *description=0)
Sets the split.
Definition: TAlienJDL.cxx:195
virtual void SetMaxInitFailed(Int_t maxInitFailed, const char *description=0)
Sets the Maxium init failed.
Definition: TAlienJDL.cxx:216
virtual void SetOutputDirectory(const char *value=0, const char *description=0)
Sets OutputDirectory.
Definition: TAlienJDL.cxx:67
virtual void SetOwnCommand(const char *command=0, const char *value=0, const char *description=0)
Sets the Own Command.
Definition: TAlienJDL.cxx:228
virtual void AddToMerge(const char *filenameToMerge, const char *jdlToSubmit, const char *mergedFile, const char *description=0)
Adds a package name to the package section.
Definition: TAlienJDL.cxx:358
virtual void Parse(const char *filename)
fills the TAlienJDL from inputfile (should be AliEn JDL file)
Definition: TAlienJDL.cxx:444
virtual void SetInputDataList(const char *list="collection.xml", const char *description=0)
Sets InputDataList name.
Definition: TAlienJDL.cxx:136
void Simulate()
Not implemented.
Definition: TAlienJDL.cxx:489
virtual void AddToRequirements(const char *value=0, const char *description=0)
Adds a requirement.
Definition: TAlienJDL.cxx:239
virtual void SetTTL(UInt_t ttl=72000, const char *description=0)
To inform AliEn master about estimated Time-To-Live of included nodes.
Definition: TAlienJDL.cxx:101
virtual void AddToOutputArchive(const char *value=0, const char *description=0)
Adds an output archive definition.
Definition: TAlienJDL.cxx:324
virtual void SetSplitModeMaxInputFileSize(UInt_t maxinputfilesize=0, const char *description=0)
Sets the SplitMaxInputFileSize.
Definition: TAlienJDL.cxx:183
virtual void SetValidationCommand(const char *value, const char *description=0)
Sets the validation command.
Definition: TAlienJDL.cxx:206
virtual void SetEMail(const char *value=0, const char *description=0)
Sets eMail address.
Definition: TAlienJDL.cxx:56
virtual void SetPrice(UInt_t price=1, const char *description=0)
Sets OutputDirectory.
Definition: TAlienJDL.cxx:89
virtual void SetInputDataListFormat(const char *format="xml-single", const char *description=0)
Sets InputDataListFormat - can be "xml-single" or "xml-multi".
Definition: TAlienJDL.cxx:125
virtual void SetSplitMode(const char *value, UInt_t maxnumberofinputfiles=0, UInt_t maxinputfilesize=0, const char *d1=0, const char *d2=0, const char *d3=0)
Sets the split mode.
Definition: TAlienJDL.cxx:148
virtual void AddToOutputSandbox(const char *value=0, const char *description=0)
Adds a file to the output sandbox.
Definition: TAlienJDL.cxx:261
virtual void AddToInputSandbox(const char *value=0, const char *description=0)
Adds a file to the input sandbox.
Definition: TAlienJDL.cxx:250
virtual void AddToReqSet(const char *key, const char *value=0)
Adds a value to a key value which hosts a set of values.
Definition: TAlienJDL.cxx:336
virtual void AddToPackages(const char *name, const char *version, const char *type, const char *description=0)
Adds a package name to the package section.
Definition: TAlienJDL.cxx:294
virtual void AddToInputDataCollection(const char *value=0, const char *description=0)
Adds a file to the input data collection.
Definition: TAlienJDL.cxx:283
virtual void SetSplitModeMaxNumOfFiles(UInt_t maxnumberofinputfiles=0, const char *description=0)
Sets the SplitMaxNumOfFiles.
Definition: TAlienJDL.cxx:170
virtual void SetMergedOutputDirectory(const char *value=0, const char *description=0)
Sets merged OutputDirectory.
Definition: TAlienJDL.cxx:78
virtual void SetExecutable(const char *value=0, const char *description=0)
Sets the executable.
Definition: TAlienJDL.cxx:34
Bool_t SubmitTest()
Tests the submission of a simple job.
Definition: TAlienJDL.cxx:384
virtual void AddToInputData(const char *value=0, const char *description=0)
Adds a file to the input data.
Definition: TAlienJDL.cxx:272
virtual void SetArguments(const char *value=0, const char *description=0)
Sets the arguments.
Definition: TAlienJDL.cxx:45
virtual void SetJobTag(const char *jobtag=0, const char *description=0)
Sets Job Tag.
Definition: TAlienJDL.cxx:114
void SetValueByCmd(TString cmd, TString value)
Set the specified value to the specified command.
Definition: TAlienJDL.cxx:409
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
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
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
TString AddQuotes(const char *value)
Adds quotes to the provided string.
Definition: TGridJDL.cxx:159
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 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
virtual TGridJob * Submit(const char *)
Definition: TGrid.h:102
An array of TObjects.
Definition: TObjArray.h:37
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:522
TObject * At(Int_t idx) const
Definition: TObjArray.h:166
Collectable string class.
Definition: TObjString.h:28
const TString & GetString() const
Definition: TObjString.h:46
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:418
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1921
const char * Data() const
Definition: TString.h:364
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2197
Bool_t IsNull() const
Definition: TString.h:402
TString & Remove(Ssiz_t pos)
Definition: TString.h:668
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:634
TLine * line
Definition: file.py:1