From b6280271af00545f0c46f4ab0181db18b580718a Mon Sep 17 00:00:00 2001
From: Fons Rademakers <Fons.Rademakers@cern.ch>
Date: Mon, 15 Oct 2007 14:43:39 +0000
Subject: [PATCH] From Andreas: implement suggestion coming from Savannah:
 29472. Also some minor bug fixes.

git-svn-id: http://root.cern.ch/svn/root/trunk@20351 27541ba8-7e3a-0410-8455-c3a389f83636
---
 alien/inc/TAlien.h      |  4 ++--
 alien/inc/TAlienJDL.h   |  9 +++++----
 alien/inc/TAlienJob.h   |  2 ++
 alien/src/TAlien.cxx    | 12 ++++++------
 alien/src/TAlienJDL.cxx | 30 +++++++++++++++++++++++++++---
 alien/src/TAlienJob.cxx | 27 +++++++++++++++++++++++++++
 net/inc/TGrid.h         | 16 ++++++++++++----
 net/inc/TGridJob.h      |  2 ++
 8 files changed, 83 insertions(+), 19 deletions(-)

diff --git a/alien/inc/TAlien.h b/alien/inc/TAlien.h
index 6dfc7b44e5a..f32fd3d5fc7 100644
--- a/alien/inc/TAlien.h
+++ b/alien/inc/TAlien.h
@@ -80,8 +80,8 @@ public:
    virtual TGridCollection* OpenCollection(const char* collectionfile, UInt_t maxentries = kTRUE);
    virtual TGridCollection* OpenCollectionQuery(TGridResult * queryresult, Bool_t nogrouping = kFALSE);
    virtual TGridJobStatusList* Ps(const char* options, Bool_t verbose = kTRUE);
-   virtual Bool_t Kill(UInt_t jobid);
-   virtual UInt_t Resubmit(UInt_t jobid);
+   virtual Bool_t KillById(TString jobid);
+   virtual Bool_t ResubmitById(TString jobid);
 
    //--- Catalogue Interface
    virtual TGridResult *Ls(const char *ldn="", Option_t *options="", Bool_t verbose=kFALSE);
diff --git a/alien/inc/TAlienJDL.h b/alien/inc/TAlienJDL.h
index 6f3eb50333f..10a56667674 100644
--- a/alien/inc/TAlienJDL.h
+++ b/alien/inc/TAlienJDL.h
@@ -28,7 +28,7 @@
 class TAlienJDL : public TGridJDL {
 
 public:
-   TAlienJDL() { }
+   TAlienJDL() : TGridJDL() { }
    virtual ~TAlienJDL() { };
 
    virtual void SetExecutable(const char* value=0);
@@ -52,9 +52,10 @@ public:
    virtual void AddToRequirements(const char* value=0);
    virtual void AddToPackages(const char* name="AliRoot", const char* version="newest",const char* type="VO_ALICE");
    virtual void AddToOutputArchive(const char* value=0);
-
-   Bool_t SubmitTest();
-
+   void         AddToReqSet(const char *key, const char *value=0);
+   Bool_t       SubmitTest();
+ private:
+   
    ClassDef(TAlienJDL,1)  // Creates JDL files for the AliEn middleware
 };
 
diff --git a/alien/inc/TAlienJob.h b/alien/inc/TAlienJob.h
index fb07c54ac96..d3ba9d25826 100644
--- a/alien/inc/TAlienJob.h
+++ b/alien/inc/TAlienJob.h
@@ -34,6 +34,8 @@ public:
    virtual ~TAlienJob() { }
 
    virtual TGridJobStatus *GetJobStatus() const;
+   virtual Bool_t          Resubmit();
+   virtual Bool_t          Cancel();
 
    ClassDef(TAlienJob,1)  // Alien implementation of TGridJob
 };
diff --git a/alien/src/TAlien.cxx b/alien/src/TAlien.cxx
index d151a81e38f..5b7c1c387bc 100644
--- a/alien/src/TAlien.cxx
+++ b/alien/src/TAlien.cxx
@@ -309,22 +309,22 @@ TGridJobStatusList *TAlien::Ps(const char* /*options*/, Bool_t verbose)
 }
 
 //______________________________________________________________________________
-Bool_t TAlien::Kill(UInt_t jobid)
+Bool_t TAlien::KillById(TString jobid)
 {
    // Kill a specific job.
 
-   if (gapi_kill(jobid))
+   if (gapi_kill(atoi(jobid.Data())))
       return kFALSE;
    else
       return kTRUE;
 }
 
 //______________________________________________________________________________
-UInt_t TAlien::Resubmit(UInt_t jobid)
+Bool_t TAlien::ResubmitById(TString jobid)
 {
    // Resubmit a specific job.
 
-   if (gapi_resubmit(jobid))
+  if (gapi_resubmit(atoi(jobid.Data())))
       return kFALSE;
    else
       return kTRUE;
@@ -500,10 +500,10 @@ Bool_t TAlien::Mkdir(const char* ldn, Option_t* options, Bool_t verbose)
    TString cmdline = TString("mkdir");
    if (strlen(options)) {
       cmdline +=  (TString(" ") + TString(options));
-   } else {
-      cmdline += (TString(" -s ") + TString(ldn));
    }
 
+   cmdline += (TString(" -s ") + TString(ldn));
+
    Command(cmdline, kFALSE);
 
    if (verbose) {
diff --git a/alien/src/TAlienJDL.cxx b/alien/src/TAlienJDL.cxx
index e323f7ff7fc..036219f7199 100644
--- a/alien/src/TAlienJDL.cxx
+++ b/alien/src/TAlienJDL.cxx
@@ -21,6 +21,7 @@
 #include "TGrid.h"
 #include "TGridJob.h"
 #include "Riostream.h"
+#include "TSystem.h"
 
 ClassImp(TAlienJDL)
 
@@ -57,7 +58,7 @@ void TAlienJDL::SetOutputDirectory(const char* value)
    // Sets OutputDirectory
 
    if (value)
-      SetValue("OutputDirectory", AddQuotes(value));
+      SetValue("OutputDir", AddQuotes(value));
 }
 
 //______________________________________________________________________________
@@ -65,7 +66,7 @@ void TAlienJDL:: SetPrice(UInt_t price)
 {
    // Sets OutputDirectory.
 
-   TString pricestring= (Int_t)price;
+   TString pricestring(Form("%d",price));
 
    SetValue("Price", pricestring.Data());
 }
@@ -155,7 +156,7 @@ void TAlienJDL::AddToRequirements(const char* value)
    // Adds a requirement.
 
    if (value)
-      AddToSet("Requirements", value);
+      AddToReqSet("Requirements", value);
 }
 
 //______________________________________________________________________________
@@ -219,6 +220,29 @@ void TAlienJDL::AddToOutputArchive(const char* value)
       AddToSet("OutputArchive", value);
 }
 
+//______________________________________________________________________________
+void TAlienJDL::AddToReqSet(const char *key, const char *value)
+{
+   // Adds a value to a key value which hosts a set of values.
+   // E.g. InputSandbox: {"file1","file2"}
+
+   const char *oldValue = GetValue(key);
+   TString newString;
+   if (oldValue)
+      newString = oldValue;
+   if (newString.IsNull()) {
+      newString = "(";
+   } else {
+      newString.Remove(newString.Length()-1);
+      newString += " && ";
+   }
+
+   newString += value;
+   newString += ")";
+
+   SetValue(key, newString);
+}
+
 //______________________________________________________________________________
 Bool_t TAlienJDL::SubmitTest()
 {
diff --git a/alien/src/TAlienJob.cxx b/alien/src/TAlienJob.cxx
index e6e35077a84..78d180474cd 100644
--- a/alien/src/TAlienJob.cxx
+++ b/alien/src/TAlienJob.cxx
@@ -19,6 +19,7 @@
 //                                                                      //
 //////////////////////////////////////////////////////////////////////////
 
+#include "TGrid.h"
 #include "TAlienJob.h"
 #include "TAlienJobStatus.h"
 #include "TObjString.h"
@@ -59,3 +60,29 @@ TGridJobStatus *TAlienJob::GetJobStatus() const
 
    return status;
 }
+
+//______________________________________________________________________________
+Bool_t TAlienJob::Cancel()
+{
+   // Cancels a job e.g. sends a kill command.
+   // Returns kFALSE in case of failure, otherwise kTRUE.
+
+   if (gGrid) {
+      return gGrid->Kill((TGridJob*)this);
+   }
+   Error("Cancel","No GRID connection (gGrid=0)");
+   return kFALSE;
+}
+
+//______________________________________________________________________________
+Bool_t TAlienJob::Resubmit()
+{
+   // Resubmits a job.
+   // Returns kFALSE in case of failure, otherwise kTRUE.
+
+   if (gGrid) {
+      return gGrid->Resubmit((TGridJob*)this);
+   }
+   Error("Cancel","No GRID connection (gGrid=0)");
+   return kFALSE;
+}
diff --git a/net/inc/TGrid.h b/net/inc/TGrid.h
index d0a19b6ec97..3612c0ab5fe 100644
--- a/net/inc/TGrid.h
+++ b/net/inc/TGrid.h
@@ -37,6 +37,10 @@
 #include "TString.h"
 #endif
 
+#ifndef ROOT_TGridJob
+#include "TGridJob.h"
+#endif
+
 class TGridResult;
 class TGridJDL;
 class TGridJob;
@@ -112,10 +116,14 @@ public:
       { MayNotUse("OpenCollection"); return 0; }
    virtual TGridJobStatusList* Ps(const char* /*options*/, Bool_t /*verbose*/ = kTRUE)
       { MayNotUse("Ps"); return 0; }
-   virtual Bool_t Kill(UInt_t /*jobid*/)
-      { MayNotUse("Kill"); return kFALSE; }
-   virtual UInt_t Resubmit(UInt_t /*jobid*/)
-      { MayNotUse("Resubmit"); return 0; }
+   virtual Bool_t KillById(TString /*jobid*/)
+      { MayNotUse("KillById"); return kFALSE; }
+   virtual Bool_t ResubmitById(TString /*jobid*/)
+      { MayNotUse("ResubmitById"); return 0; }
+   virtual Bool_t Kill(TGridJob *gridjob)
+      { return ((gridjob)?KillById(gridjob->GetJobID()):kFALSE); }
+   virtual Bool_t Resubmit(TGridJob* gridjob)
+      { return ((gridjob)?ResubmitById(gridjob->GetJobID()):kFALSE); }
 
    //--- Load desired plugin and setup conection to GRID
    static TGrid *Connect(const char *grid, const char *uid = 0,
diff --git a/net/inc/TGridJob.h b/net/inc/TGridJob.h
index 39d251f8c76..11f0512022e 100644
--- a/net/inc/TGridJob.h
+++ b/net/inc/TGridJob.h
@@ -46,6 +46,8 @@ public:
    virtual TGridJobStatus *GetJobStatus() const = 0;
    virtual Int_t           GetOutputSandbox(const char *localpath, Option_t *opt = 0);
 
+   virtual Bool_t          Resubmit() = 0;
+   virtual Bool_t          Cancel () = 0;
    ClassDef(TGridJob,1)  // ABC defining interface to a GRID job
 };
 
-- 
GitLab