AnalysisTask base class for multi event analysis (mixing).
authormorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 20 May 2008 14:55:41 +0000 (14:55 +0000)
committermorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 20 May 2008 14:55:41 +0000 (14:55 +0000)
ANALYSIS/ANALYSISaliceLinkDef.h
ANALYSIS/AliAnalysisTaskME.cxx [new file with mode: 0644]
ANALYSIS/AliAnalysisTaskME.h [new file with mode: 0644]
ANALYSIS/libANALYSISalice.pkg

index 608a98e..050ac5d 100644 (file)
@@ -5,6 +5,7 @@
 #pragma link off all functions;
 
 #pragma link C++ class  AliAnalysisTaskSE+;
+#pragma link C++ class  AliAnalysisTaskME+;
 #pragma link C++ class  AliAnalysisTaskESDfilter+;
 #pragma link C++ class  AliAnalysisTaskKineFilter+;
 #pragma link C++ class  AliKineTrackCuts+;
diff --git a/ANALYSIS/AliAnalysisTaskME.cxx b/ANALYSIS/AliAnalysisTaskME.cxx
new file mode 100644 (file)
index 0000000..c81d4fd
--- /dev/null
@@ -0,0 +1,170 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+#include <TROOT.h>
+#include <TSystem.h>
+#include <TInterpreter.h>
+#include <TChain.h>
+#include <TFile.h>
+#include <TList.h>
+
+#include "AliAnalysisTaskME.h"
+#include "AliAnalysisManager.h"
+#include "AliAODEvent.h"
+#include "AliAODHandler.h"
+#include "AliMultiAODInputHandler.h"
+#include "AliLog.h"
+
+
+ClassImp(AliAnalysisTaskME)
+
+////////////////////////////////////////////////////////////////////////
+
+AliAnalysisTaskME::AliAnalysisTaskME():
+    AliAnalysisTask(),
+    fDebug(0),
+    fEntry(0),
+    fFreshBufferOnly(kFALSE),
+    fInputHandler(0x0),
+    fOutputAOD(0x0),
+    fTreeA(0x0)
+{
+  // Default constructor
+}
+
+AliAnalysisTaskME::AliAnalysisTaskME(const char* name):
+    AliAnalysisTask(name, "AnalysisTaskME"),
+    fDebug(0),
+    fEntry(0),
+    fFreshBufferOnly(kFALSE),
+    fInputHandler(0x0),
+    fOutputAOD(0x0),
+    fTreeA(0x0)
+{
+  // Default constructor
+    DefineInput (0, TChain::Class());
+    DefineOutput(0,  TTree::Class());
+}
+
+AliAnalysisTaskME::AliAnalysisTaskME(const AliAnalysisTaskME& obj):
+    AliAnalysisTask(obj),
+    fDebug(0),
+    fEntry(0),
+    fFreshBufferOnly(kFALSE),
+    fInputHandler(0x0),
+    fOutputAOD(0x0),
+    fTreeA(0x0)
+{
+// Copy constructor
+    fDebug        = obj.fDebug;
+    fEntry        = obj.fEntry;
+    fInputHandler = obj.fInputHandler;
+    fOutputAOD    = obj.fOutputAOD;
+    fTreeA        = obj.fTreeA;    
+}
+
+
+AliAnalysisTaskME& AliAnalysisTaskME::operator=(const AliAnalysisTaskME& other)
+{
+// Assignment
+    AliAnalysisTask::operator=(other);
+    fDebug           = other.fDebug;
+    fEntry           = other.fEntry;
+    fFreshBufferOnly = other.fFreshBufferOnly;
+    fInputHandler    = other.fInputHandler;
+    fOutputAOD       = other.fOutputAOD;
+    fTreeA           = other.fTreeA;    
+    return *this;
+}
+
+
+void AliAnalysisTaskME::ConnectInputData(Option_t* /*option*/)
+{
+// Connect the input data
+    if (fDebug > 1) printf("AnalysisTaskME::ConnectInputData() \n");
+//
+//  Multi AOD
+//
+    fInputHandler = dynamic_cast<AliMultiAODInputHandler*> 
+       ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
+    if (fInputHandler == 0) 
+       AliFatal("Event Handler has to be MultiAODHandler !");
+}
+
+void AliAnalysisTaskME::CreateOutputObjects()
+{
+// Create the output container
+//
+//  Default AOD
+    if (fDebug > 1) printf("AnalysisTaskME::CreateOutPutData() \n");
+
+    AliAODHandler* handler = (AliAODHandler*) 
+       ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
+    
+    if (handler) {
+       fOutputAOD   = handler->GetAOD();
+       fTreeA = handler->GetTree();
+    } else {
+       AliWarning("No AOD Event Handler connected.") ; 
+    }
+    UserCreateOutputObjects();
+}
+
+void AliAnalysisTaskME::Exec(Option_t* option)
+{
+//
+// Exec analysis of one event
+    if (fDebug > 1) AliInfo("AliAnalysisTaskME::Exec() \n");
+    if( fInputHandler ) 
+       fEntry = fInputHandler->GetReadEntry();
+    if ( !((Entry()-1)%100) && fDebug > 0) 
+         AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
+         
+// Call the user analysis    
+    if (fInputHandler->IsBufferReady()) {
+       if ((fFreshBufferOnly && fInputHandler->IsFreshBuffer()) || !fFreshBufferOnly)
+       {
+           UserExec(option);
+           PostData(0, fTreeA);
+       }
+    }
+}
+
+const char* AliAnalysisTaskME::CurrentFileName()
+{
+// Returns the current file name    
+    if(fInputHandler )
+       return fInputHandler->GetTree()->GetCurrentFile()->GetName();
+    else return "";
+}
+
+void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj)
+{
+    // Add a new branch to the aod tree
+    AliAODHandler* handler = (AliAODHandler*) 
+       ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
+    if (handler) {
+       handler->AddBranch(cname, addobj);
+    }
+}
+
+AliAODEvent*  AliAnalysisTaskME::GetEvent(Int_t iev)
+{
+    // Get an event from the input handler
+    return (fInputHandler->GetEvent(iev));
+}
+
diff --git a/ANALYSIS/AliAnalysisTaskME.h b/ANALYSIS/AliAnalysisTaskME.h
new file mode 100644 (file)
index 0000000..1bcb7bd
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef ALIANALYSISTASKME_H
+#define ALIANALYSISTASKME_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+#include "AliAnalysisTask.h"
+class AliAODEvent;
+class AliInputEventHandler;
+class TTree;
+class AliMultiAODInputHandler;
+
+
+
+class AliAnalysisTaskME : public AliAnalysisTask
+{
+ public:
+    AliAnalysisTaskME();
+    AliAnalysisTaskME(const char* name);
+    AliAnalysisTaskME(const AliAnalysisTaskME& obj);
+    AliAnalysisTaskME& operator=(const AliAnalysisTaskME& other);
+    virtual ~AliAnalysisTaskME() {;}
+    // Implementation of interface methods
+    virtual void ConnectInputData(Option_t *option = "");
+    virtual void CreateOutputObjects();
+    virtual void Exec(Option_t* option);
+    virtual void SetDebugLevel(Int_t level) {fDebug = level;}
+    virtual void Init() {;}
+    virtual void RequireFreshBuffer() {fFreshBufferOnly = kTRUE;}
+    // To be implemented by user
+    virtual void UserCreateOutputObjects()  {;}
+    virtual void UserExec(Option_t* /*option*/) {;}
+    // Helpers for adding branches to the AOD
+   virtual void AddAODBranch(const char* cname, void* addobj);
+// Getters
+    virtual Int_t          DebugLevel()              {return fDebug;     }
+    virtual AliAODEvent*   GetEvent(Int_t iev);
+    virtual AliAODEvent*   AODEvent()                {return fOutputAOD; }
+    virtual TTree*         OutputTree()              {return fTreeA;     }
+    virtual Long64_t       Entry()                   {return fEntry;     }
+    virtual const char*    CurrentFileName();
+  protected:
+    Int_t                    fDebug;           //  Debug flag
+    Int_t                    fEntry;           //  Current entry in the chain
+    Bool_t                   fFreshBufferOnly; //  Flag for Exec call for fresh buffer only
+    AliMultiAODInputHandler* fInputHandler;    //! Input Handler
+    AliAODEvent*             fOutputAOD;       //! AOD out 
+    TTree*                   fTreeA;           //  AOD output Tree
+    ClassDef(AliAnalysisTaskME, 1); // Analysis task for standard jet analysis
+};
+#endif
index a8b9355..40daa28 100644 (file)
@@ -1,6 +1,7 @@
 #-*- Mode: Makefile -*-
 
-SRCS =         AliAnalysisTaskSE.cxx AliAnalysisTaskESDfilter.cxx AliAnalysisTaskKineFilter.cxx \
+SRCS =         AliAnalysisTaskSE.cxx AliAnalysisTaskME.cxx \
+       AliAnalysisTaskESDfilter.cxx AliAnalysisTaskKineFilter.cxx \
        AliKineTrackCuts.cxx AliESDtrackCuts.cxx AliESDv0Cuts.cxx
 
 CHECKALIEN = $(shell root-config --has-alien)