00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "TAlienJDL.h"
00022 #include "TGrid.h"
00023 #include "TGridJob.h"
00024 #include "Riostream.h"
00025 #include "TSystem.h"
00026 #include "TObjString.h"
00027 #include "TObjArray.h"
00028
00029 ClassImp(TAlienJDL)
00030
00031
00032 void TAlienJDL::SetExecutable(const char *value, const char *description)
00033 {
00034
00035
00036 if (value)
00037 SetValue("Executable", AddQuotes(value));
00038 if (description)
00039 SetDescription("Executable", description);
00040 }
00041
00042
00043 void TAlienJDL::SetArguments(const char *value, const char *description)
00044 {
00045
00046
00047 if (value)
00048 SetValue("Arguments", AddQuotes(value));
00049 if (description)
00050 SetDescription("Arguments", description);
00051 }
00052
00053
00054 void TAlienJDL::SetEMail(const char *value, const char *description)
00055 {
00056
00057
00058 if (value)
00059 SetValue("Email", AddQuotes(value));
00060 if (description)
00061 SetDescription("Email", description);
00062 }
00063
00064
00065 void TAlienJDL::SetOutputDirectory(const char *value, const char *description)
00066 {
00067
00068
00069 if (value)
00070 SetValue ("OutputDir", AddQuotes(value));
00071 if (description)
00072 SetDescription("OutputDir", description);
00073 }
00074
00075
00076 void TAlienJDL::SetMergedOutputDirectory ( const char * value,const char* description)
00077 {
00078
00079
00080 if (value)
00081 SetValue ("MergeOutputDir", AddQuotes(value));
00082 if (description)
00083 SetDescription("MergeOutputDir", description);
00084 }
00085
00086
00087 void TAlienJDL:: SetPrice(UInt_t price,const char* description)
00088 {
00089
00090
00091 TString pricestring(Form("%d",price));
00092 SetValue("Price", AddQuotes(pricestring.Data()));
00093
00094 if (description)
00095 SetDescription("Price", description);
00096 }
00097
00098
00099 void TAlienJDL:: SetTTL(UInt_t ttl, const char *description)
00100 {
00101
00102
00103 TString ttlstring;
00104 ttlstring+= ttl;
00105 SetValue("TTL", ttlstring.Data());
00106
00107 if (description)
00108 SetDescription("TTL", description);
00109 }
00110
00111
00112 void TAlienJDL::SetJobTag(const char* value,const char* description)
00113 {
00114
00115
00116 if (value)
00117 SetValue("JobTag", AddQuotes(value));
00118 if (description)
00119 SetDescription("JobTag", description);
00120 }
00121
00122
00123 void TAlienJDL::SetInputDataListFormat(const char* value,const char* description)
00124 {
00125
00126
00127 if (value)
00128 SetValue("InputDataListFormat", AddQuotes(value));
00129 if (description)
00130 SetDescription("InputDataListFormat", description);
00131 }
00132
00133
00134 void TAlienJDL::SetInputDataList(const char* value,const char* description)
00135 {
00136
00137
00138 if (value)
00139 SetValue("InputDataList", AddQuotes(value));
00140 if (description)
00141 SetDescription("InputDataList", description);
00142 }
00143
00144
00145
00146 void TAlienJDL::SetSplitMode(const char *value, UInt_t maxnumberofinputfiles,
00147 UInt_t maxinputfilesize, const char *d1, const char *d2,
00148 const char *d3)
00149 {
00150
00151
00152 if (value && !strcasecmp(value, "SE")) {
00153
00154 SetSplitArguments(value,d1);
00155 if (maxnumberofinputfiles) {
00156 SetSplitModeMaxNumOfFiles(maxnumberofinputfiles,d2);
00157 }
00158 if (maxinputfilesize) {
00159 SetSplitModeMaxInputFileSize(maxinputfilesize,d3);
00160 }
00161 } else {
00162 if (value)
00163 SetSplitArguments(value,d1);
00164 }
00165 }
00166
00167
00168 void TAlienJDL::SetSplitModeMaxNumOfFiles(UInt_t maxnumberofinputfiles, const char *description)
00169 {
00170
00171
00172 TString val;
00173 val += maxnumberofinputfiles;
00174 SetValue ( "SplitMaxInputFileNumber", AddQuotes ( val.Data() ) );
00175
00176 if (description)
00177 SetDescription("SplitMaxInputFileNumber", description);
00178 }
00179
00180
00181 void TAlienJDL::SetSplitModeMaxInputFileSize(UInt_t maxinputfilesize, const char *description)
00182 {
00183
00184
00185 TString val;
00186 val += maxinputfilesize;
00187 SetValue ( "SplitMaxInputFileSize", AddQuotes ( val.Data() ) );
00188 if (description)
00189 SetDescription("SplitMaxInputFileSize", description);
00190 }
00191
00192
00193 void TAlienJDL::SetSplitArguments(const char *splitarguments, const char *description)
00194 {
00195
00196
00197 if (splitarguments)
00198 SetValue("Split", AddQuotes(splitarguments));
00199 if (description)
00200 SetDescription("Split", description);
00201 }
00202
00203
00204 void TAlienJDL::SetValidationCommand(const char *value, const char *description)
00205 {
00206
00207
00208 SetValue("Validationcommand", AddQuotes(value));
00209 if (description)
00210 SetDescription("Validationcommand", description);
00211 }
00212
00213
00214 void TAlienJDL::SetMaxInitFailed(Int_t maxInitFailed, const char *description)
00215 {
00216
00217 TString str;
00218 str += maxInitFailed;
00219 SetValue("MaxInitFailed", AddQuotes(str.Data()));
00220 if (description)
00221 SetDescription("MaxInitFailed", description);
00222 }
00223
00224
00225 void TAlienJDL::SetOwnCommand(const char *command, const char *value, const char *description)
00226 {
00227
00228 if ((command) && (value))
00229 SetValue(command, AddQuotes(value));
00230 if ((command) && (description))
00231 SetDescription(command, description);
00232 }
00233
00234
00235 void TAlienJDL::AddToRequirements(const char *value, const char *description)
00236 {
00237
00238
00239 if (value)
00240 AddToReqSet("Requirements", value);
00241 if (description)
00242 AddToSetDescription("Requirements", description);
00243 }
00244
00245
00246 void TAlienJDL::AddToInputSandbox(const char *value, const char *description)
00247 {
00248
00249
00250 if (value)
00251 AddToSet("InputFile", value);
00252 if (description)
00253 AddToSetDescription("InputFile", description);
00254 }
00255
00256
00257 void TAlienJDL::AddToOutputSandbox(const char *value, const char *description)
00258 {
00259
00260
00261 if (value)
00262 AddToSet("OutputFile", value);
00263 if (description)
00264 AddToSetDescription("OutputFile", description);
00265 }
00266
00267
00268 void TAlienJDL::AddToInputData(const char *value, const char *description)
00269 {
00270
00271
00272 if (value)
00273 AddToSet("InputData", value);
00274 if (description)
00275 AddToSetDescription("InputData", description);
00276 }
00277
00278
00279 void TAlienJDL::AddToInputDataCollection(const char *value, const char *description)
00280 {
00281
00282
00283 if (value)
00284 AddToSet("InputDataCollection", value);
00285 if (description)
00286 AddToSetDescription("InputDataCollection", description);
00287 }
00288
00289
00290 void TAlienJDL::AddToPackages(const char *name, const char *version,
00291 const char *type, const char *description)
00292 {
00293
00294
00295 if (name) {
00296 TString packagename = type;
00297 packagename += "@";
00298 packagename += name;
00299 packagename += "::";
00300 packagename += version;
00301
00302 AddToSet("Packages", packagename.Data());
00303 }
00304
00305 if (description)
00306 AddToSetDescription("Packages", description);
00307 }
00308
00309
00310 void TAlienJDL::AddToPackages(const char *name, const char *description)
00311 {
00312
00313
00314 AddToSet("Packages", name);
00315 if (description)
00316 AddToSetDescription("Packages", description);
00317 }
00318
00319
00320 void TAlienJDL::AddToOutputArchive(const char* value,const char* description)
00321 {
00322
00323
00324 if (value)
00325 AddToSet("OutputArchive", value);
00326 if (description)
00327 AddToSetDescription("OutputArchive", description);
00328 }
00329
00330
00331 void TAlienJDL::AddToReqSet(const char *key, const char *value)
00332 {
00333
00334
00335
00336 const char *oldValue = GetValue(key);
00337 TString newString;
00338 if (oldValue)
00339 newString = oldValue;
00340 if (newString.IsNull()) {
00341 newString = "(";
00342 } else {
00343 newString.Remove(newString.Length()-1);
00344 newString += " && ";
00345 }
00346
00347 newString += value;
00348 newString += ")";
00349
00350 SetValue(key, newString);
00351 }
00352
00353
00354 void TAlienJDL::AddToMerge(const char *filenameToMerge, const char *jdlToSubmit,
00355 const char *mergedFile, const char *description )
00356 {
00357
00358
00359 TString mergename ( filenameToMerge );
00360 mergename += ":";
00361 mergename += jdlToSubmit;
00362 mergename += ":";
00363 mergename += mergedFile;
00364 AddToSet ( "Merge", mergename.Data() );
00365 if (description)
00366 AddToSetDescription("Merge", description);
00367 }
00368
00369
00370 void TAlienJDL::AddToMerge(const char *merge, const char *description)
00371 {
00372
00373
00374 AddToSet("Merge", merge);
00375 if (description)
00376 AddToSetDescription("Merge", description);
00377 }
00378
00379
00380 Bool_t TAlienJDL::SubmitTest()
00381 {
00382
00383
00384 Info("SubmitTest", "submitting test job /bin/date");
00385
00386 if (!gGrid) {
00387 Error("SubmitTest", "you must have a proper GRID environment initialized");
00388 return kFALSE;
00389 }
00390
00391 Clear();
00392 SetExecutable("/bin/date");
00393 SetArguments("-R");
00394 TGridJob* job = gGrid->Submit(Generate());
00395 printf("Sending:\n%s\n",Generate().Data());
00396 if (job == 0) {
00397 Error("SubmitTest", "submitting failed");
00398 return kFALSE;
00399 }
00400
00401 return kTRUE;
00402 }
00403
00404
00405 void TAlienJDL::SetValueByCmd(TString cmd, TString value)
00406 {
00407
00408
00409 if ( !cmd.CompareTo ( "Executable" ) ) SetExecutable ( value.Data() );
00410 else if ( !cmd.CompareTo ( "Arguments" ) ) SetArguments ( value.Data() );
00411 else if ( !cmd.CompareTo ( "Email" ) ) SetEMail ( value.Data() );
00412 else if ( !cmd.CompareTo ( "OutputDir" ) ) SetOutputDirectory ( value.Data() );
00413 else if ( !cmd.CompareTo ( "Merge" ) ) AddToMerge ( value.Data() );
00414 else if ( !cmd.CompareTo ( "MergeOutputDir" ) ) SetMergedOutputDirectory ( value.Data() );
00415 else if ( !cmd.CompareTo ( "Price" ) ) SetPrice ( value.Atoi() );
00416 else if ( !cmd.CompareTo ( "TTL" ) ) SetTTL ( value.Atoi() );
00417 else if ( !cmd.CompareTo ( "JobTag" ) ) SetJobTag ( value.Data() );
00418 else if ( !cmd.CompareTo ( "InputDataListFormat" ) ) SetInputDataListFormat ( value.Data() );
00419 else if ( !cmd.CompareTo ( "InputDataList" ) ) SetInputDataList ( value.Data() );
00420 else if ( !cmd.CompareTo ( "Split" ) ) SetSplitMode ( value.Data() );
00421 else if ( !cmd.CompareTo ( "SplitMaxInputFileNumber" ) ) SetSplitModeMaxNumOfFiles ( value.Atoi() );
00422 else if ( !cmd.CompareTo ( "SplitMaxInputFileSize" ) ) SetSplitModeMaxInputFileSize ( value.Atoi() );
00423 else if ( !cmd.CompareTo ( "SplitArguments" ) ) SetSplitArguments ( value.Data() );
00424 else if ( !cmd.CompareTo ( "Validationcommand" ) ) SetValidationCommand ( value.Data() );
00425 else if ( !cmd.CompareTo ( "MaxInitFailed" ) ) SetMaxInitFailed ( value.Atoi() );
00426 else if ( !cmd.CompareTo ( "InputSandbox" ) ) AddToInputSandbox ( value.Data() );
00427 else if ( !cmd.CompareTo ( "OutputSandbox" ) ) AddToOutputSandbox ( value.Data() );
00428 else if ( !cmd.CompareTo ( "InputData" ) ) AddToInputData ( value.Data() );
00429 else if ( !cmd.CompareTo ( "InputDataCollection" ) ) AddToInputDataCollection ( value.Data() );
00430 else if ( !cmd.CompareTo ( "Requirements" ) ) AddToRequirements ( value.Data() );
00431 else if ( !cmd.CompareTo ( "InputFile" ) ) AddToInputSandbox ( value.Data() );
00432 else if ( !cmd.CompareTo ( "OutputFile" ) ) AddToOutputSandbox ( value.Data() );
00433 else if ( !cmd.CompareTo ( "Packages" ) ) AddToPackages ( value.Data() );
00434 else if ( !cmd.CompareTo ( "OutputArchive" ) ) AddToOutputArchive ( value.Data() );
00435 else
00436 Error ( "SetValueByCmd()","Cmd Value not supported.." );
00437 }
00438
00439
00440 void TAlienJDL::Parse(const char *filename)
00441 {
00442
00443
00444 ifstream file;
00445 file.open ( filename );
00446 if ( !file.is_open() ) {
00447 Error("Parse", "error opening file %s", filename);
00448 return;
00449 }
00450
00451 TString lineString;
00452 Char_t line[1024];
00453 while ( file.good() ) {
00454 file.getline ( line,1024 );
00455 lineString=line;
00456 lineString.ReplaceAll ( " ","" );
00457 if ( !lineString.IsNull() ) {
00458 if (lineString.Index('#') == 0) continue;
00459 TObjArray *strCmdOrValue = lineString.Tokenize ( "=" );
00460 TObjString*strObjCmd = ( TObjString* ) strCmdOrValue->At ( 0 );
00461 TObjString*strObjValue = ( TObjString* ) strCmdOrValue->At ( 1 );
00462 TString cmdString ( strObjCmd->GetString() );
00463 TString valueString ( strObjValue->GetString() );
00464 cmdString.ReplaceAll ( " ","" );
00465 valueString.ReplaceAll ( " ","" );
00466 valueString.ReplaceAll ( "\",\"","`" );
00467
00468 TObjArray *strValues = valueString.Tokenize ( "`" );
00469 for ( Int_t i=0;i<strValues->GetEntries();i++ ) {
00470 TObjString *strObjValue2 = ( TObjString* ) strValues->At ( i );
00471 TString valueString2 ( strObjValue2->GetString() );
00472 valueString2.ReplaceAll ( "\"","" );
00473 valueString2.ReplaceAll ( "{","" );
00474 valueString2.ReplaceAll ( "}","" );
00475 valueString2.ReplaceAll ( ";","" );
00476 SetValueByCmd ( cmdString,valueString2 );
00477 }
00478 }
00479 }
00480
00481 file.close();
00482 }
00483
00484
00485 void TAlienJDL::Simulate()
00486 {
00487
00488 }