]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
- AliAnalysisTask::OpenFile(i) opens and returns the file for the container
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 4 Dec 2007 16:10:50 +0000 (16:10 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 4 Dec 2007 16:10:50 +0000 (16:10 +0000)
connected at task output slot <i>. Works also in PROOF mode now.
- Added kSpecialOutput user-settable flag to AliAnalysisDataContainer. Output
containers that are to be dumped to a special file will be copied in PROOF mode from each
slave to a default remote location specified via AliAnalysisManager::SetSpecialOutputLocation()
File names will be prepended with the host name of the slave they were produced on.
One needs to open the special file in MyTask::CreateOutputObjects():
   OpenFile(iout_slot)
The files on the slaves will be closed by the system in SlaveTerminate phase.

Ex:
MyAnalysis.C
{
   mgr = new AliAnalysisManager("demo","");
   mgr->SetSpecialOutputLocation("root://lxb0000.cern.ch//alien/alice/"); // xrootd location
   MyTask *task = new MyTask();
   mgr->AddTask(task);
   // Create output container to be written in file sptree.root
   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("csp_tree", TTree::Class(), AliAnalysisManager::kOutputContainer, "sptree.root");
   coutput1->SetSpecialOutput();
   mgr->ConnectOutput(task,3,coutput1); // connect container to output #3 of MyTask
   ...
   mgr->StartAnalysis("proof", chain,...);
}

void MyTask::MyTask()
{
  ...
  DefineInput(3, TTree::Class());
  ...
}

void MyTask::CreateOutputObjects()
{
   ...
   TFile *f = OpenFile(3);
   ...
   fTreeOnOutput3 = new TTree(...)
}

void MyTask::Exec()
{
   ...   processing ...
   tree->Fill();
   PostData(3,tree);
}

ANALYSIS/AliAnalysisDataContainer.h
ANALYSIS/AliAnalysisManager.cxx
ANALYSIS/AliAnalysisManager.h
ANALYSIS/AliAnalysisTask.cxx
ANALYSIS/AliAnalysisTask.h

index 3d3f235a4dbc74859ea0cd3cd3439200734fb5c3..84d7d163d20c642682a3f7f95aec05c518c68726 100644 (file)
@@ -39,7 +39,8 @@ enum ENotifyMessage {
    kFileChange
 };   
 enum EAnalysisContainerFlags {
-   kPostEventLoop = BIT(14)
+   kPostEventLoop = BIT(14),
+   kSpecialOutput = BIT(15)
 };     
    AliAnalysisDataContainer();
    AliAnalysisDataContainer(const AliAnalysisDataContainer &cont);
@@ -60,6 +61,7 @@ enum EAnalysisContainerFlags {
    virtual Bool_t            SetData(TObject *data, Option_t *option="");
    void                      SetDataOwned(Bool_t flag) {fOwnedData = flag;}
    void                      SetPostEventLoop(Bool_t flag=kTRUE) {TObject::SetBit(kPostEventLoop,flag);}
+   void                      SetSpecialOutput(Bool_t flag=kTRUE) {TObject::SetBit(kSpecialOutput,flag);}
    void                      SetFileName(const char *filename) {fFileName = filename;}
    void                      SetProducer(AliAnalysisTask *prod, Int_t islot);
    void                      AddConsumer(AliAnalysisTask *cons, Int_t islot);
@@ -70,6 +72,7 @@ enum EAnalysisContainerFlags {
    // Container status checking
    Bool_t                    IsDataReady() const  {return fDataReady;}
    Bool_t                    IsPostEventLoop() const {return TObject::TestBit(kPostEventLoop);}
+   Bool_t                    IsSpecialOutput() const {return TObject::TestBit(kSpecialOutput);}
    Bool_t                    IsOwnedData() const  {return fOwnedData;}
    Bool_t                    ClientsExecuted() const;
    Bool_t                    HasConsumers() const {return (fConsumers != 0);}
index 975bc28a0026eb32abec6587cb07012f48274c8f..a7305e055d94019d537e2a290d1a53810a9298d2 100644 (file)
@@ -359,6 +359,19 @@ void AliAnalysisManager::PackOutput(TList *target)
             if (fDebug > 1) printf("   Packing container %s...\n", output->GetName());
             target->Add(wrap);
          }   
+         // Special outputs files are closed and copied on the remote location
+         if (output->IsSpecialOutput() && strlen(output->GetFileName())) {
+            TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(output->GetFileName());
+            if (!file) continue;
+            file->Close();
+            if (strlen(fSpecialOutputLocation.Data())) {
+               TString remote = fSpecialOutputLocation;
+               remote += "/";
+               remote += gSystem->HostName();
+               remote += output->GetFileName();
+               TFile::Cp(output->GetFileName(), remote.Data());
+            }
+         }      
       }
    } 
    if (fDebug > 1) {
index 0487656f0179bafd8686307f541c44e612f0d94f..46465787198266c406f076127627324ba5c57da5 100644 (file)
@@ -81,6 +81,7 @@ enum EAliAnalysisFlags {
    void                SetAnalysisType(EAliAnalysisExecMode mode) {fMode = mode;}
    void                SetCurrentEntry(Long64_t entry) {fCurrentEntry = entry;}
    void                SetDebugLevel(UInt_t level) {fDebug = level;}
+   void                SetSpecialOutputLocation(const char *location) {fSpecialOutputLocation = location;}
    void                SetDisableBranches(Bool_t disable=kTRUE) {TObject::SetBit(kDisableBranches,disable);}
    void                SetCollectSysInfoEach(Int_t nevents=0) {fNSysInfo = nevents;}
    void                SetInputEventHandler(AliVEventHandler*  handler)  {fInputEventHandler   = handler;}
@@ -131,6 +132,7 @@ private:
    EAliAnalysisExecMode    fMode;                // Execution mode
    Bool_t                  fInitOK;              // Initialisation done
    UInt_t                  fDebug;               // Debug level
+   TString                 fSpecialOutputLocation; // URL/path where the special outputs will be copied
    TObjArray              *fTasks;               // List of analysis tasks
    TObjArray              *fTopTasks;            // List of top tasks
    TObjArray              *fZombies;             // List of zombie tasks
@@ -139,6 +141,6 @@ private:
    TObjArray              *fOutputs;             // List of containers with results
 
    static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
-   ClassDef(AliAnalysisManager,2)  // Analysis manager class
+   ClassDef(AliAnalysisManager,3)  // Analysis manager class
 };   
 #endif
index 86f9ae3f929350170b9ef712d2206b983bd18eec..2ea368db23ade12bed603478af38bd1048e711d2 100644 (file)
@@ -426,7 +426,7 @@ void AliAnalysisTask::CreateOutputObjects()
 }
 
 //______________________________________________________________________________
-void AliAnalysisTask::OpenFile(Int_t iout, Option_t *option) const
+TFile *AliAnalysisTask::OpenFile(Int_t iout, Option_t *option) const
 {
 // This method has to be called INSIDE the user redefined CreateOutputObjects
 // method, before creating each object corresponding to the output containers
@@ -448,11 +448,18 @@ void AliAnalysisTask::OpenFile(Int_t iout, Option_t *option) const
 //    fHist2 = new TH2F("my quality check hist2",...);
 // }
    
-   if (iout<0 || iout>=fNoutputs) return;
-   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
-   if (!mgr || mgr->GetAnalysisType()==AliAnalysisManager::kProofAnalysis) return;
+   if (iout<0 || iout>=fNoutputs) {
+      Error("OpenFile", "No output slot for task %s with index %d", GetName(), iout);
+      return NULL;
+   }   
+   // We allow file opening also on the slaves (AG)
+//   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+//   if (!mgr || mgr->GetAnalysisType()==AliAnalysisManager::kProofAnalysis) return;
    AliAnalysisDataContainer *cont = GetOutputSlot(iout)->GetContainer();
-   if (strlen(cont->GetFileName())) new TFile(cont->GetFileName(), option);
+   TFile *f = NULL;
+   if (strlen(cont->GetFileName())) f = new TFile(cont->GetFileName(), option);
+   if (f && !f->IsZombie()) return f;
+   return NULL;
 }
 
 //______________________________________________________________________________
index 37f93c65bf0571100cb6a06b1e176525f0d9c12b..7929f485e1a34d7acba9a1cbe0129801e4bf19fd 100644 (file)
@@ -21,6 +21,7 @@
 #endif
 
 class TClass;
+class TFile;
 class AliAnalysisDataSlot;
 class AliAnalysisDataContainer;
 
@@ -71,7 +72,7 @@ class AliAnalysisTask : public TTask {
   //=====================================================================
   // === CALL THIS IN CreateOutputObjects BEFORE CREATING THE OBJECT FOR EACH 
   // OUTPUT IOUT THAT HAS TO BE WRITTEN TO A FILE
-  void                      OpenFile(Int_t iout, Option_t *option="RECREATE") const;
+  TFile                    *OpenFile(Int_t iout, Option_t *option="RECREATE") const;
   
 public:  
   AliAnalysisTask();