MultiAODInputHandler: an input handler for aod event muxing.
authormorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 20 May 2008 10:51:03 +0000 (10:51 +0000)
committermorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 20 May 2008 10:51:03 +0000 (10:51 +0000)
STEER/AODLinkDef.h
STEER/AliMultiAODInputHandler.cxx [new file with mode: 0644]
STEER/AliMultiAODInputHandler.h [new file with mode: 0644]
STEER/libAOD.pkg

index cf23118..f1a5be6 100644 (file)
@@ -32,6 +32,7 @@
 #pragma link C++ class AliAODv0+;
 #pragma link C++ class AliAODHandler+;
 #pragma link C++ class AliAODInputHandler+;
+#pragma link C++ class AliMultiAODInputHandler+;
 #pragma link C++ class AliAODTracklets+;
 #pragma link C++ class AliAODTagCreator+;
 #pragma link C++ class AliAODCaloCells+;
diff --git a/STEER/AliMultiAODInputHandler.cxx b/STEER/AliMultiAODInputHandler.cxx
new file mode 100644 (file)
index 0000000..7eae0e5
--- /dev/null
@@ -0,0 +1,112 @@
+/**************************************************************************
+ * Copyright(c) 1998-2007, 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$ */
+
+//-------------------------------------------------------------------------
+//     Event handler for AOD input.
+//     This class handles multiple inputs for event mixing. 
+//     Author: Andreas Morsch, CERN
+//-------------------------------------------------------------------------
+
+#include "AliMultiAODInputHandler.h"
+//#include "AliEventPool.h"
+#include "AliAODEvent.h"
+#include "AliLog.h"
+#include <TObjArray.h>
+#include <TTree.h>
+
+
+ClassImp(AliMultiAODInputHandler)
+
+//______________________________________________________________________________
+AliMultiAODInputHandler::AliMultiAODInputHandler(Int_t size) :
+    AliInputEventHandler(),
+    fBufferSize(size),
+    fNBuffered(0),
+    fIndex(0),
+    fTree(0),
+    fEventPool(0),
+    fEventBuffer(new AliAODEvent*[size])
+{
+  // Default constructor
+    for (Int_t i = 0; i < size; i++) 
+       fEventBuffer[i] = new AliAODEvent();
+}
+
+//______________________________________________________________________________
+AliMultiAODInputHandler::AliMultiAODInputHandler(const char* name, const char* title, Int_t size):
+    AliInputEventHandler(name, title),
+    fBufferSize(size),
+    fNBuffered(0),
+    fIndex(0),
+    fTree(0),
+    fEventPool(0),
+    fEventBuffer(new AliAODEvent*[size])
+{
+    // Constructor
+    for (Int_t i = 0; i < size; i++) 
+       fEventBuffer[i] = new AliAODEvent();
+}
+
+//______________________________________________________________________________
+AliMultiAODInputHandler::~AliMultiAODInputHandler() 
+{
+// Destructor
+}
+
+Bool_t AliMultiAODInputHandler::Init(TTree* tree, Option_t* /*opt*/)
+{
+    // Initialisation necessary for each new tree
+    fTree = tree;
+    if (!fTree) return kFALSE;
+    // Get pointer to AOD event
+    fEventBuffer[0]->ReadFromTree(fTree);
+    fIndex = 0;
+    fNBuffered = 1;
+    return kTRUE;
+}
+
+Bool_t AliMultiAODInputHandler::FinishEvent()
+{
+    // 
+    // Connect the next event in the buffer to the tree
+    fIndex++;
+    fNBuffered++;
+    if (fNBuffered > fBufferSize) fNBuffered = fBufferSize;
+    
+    fIndex %= fBufferSize;
+    AliInfo(Form("Connecting buffer entry %5d", fIndex));
+    fEventBuffer[fIndex]->Clear();
+    fEventBuffer[fIndex]->ReadFromTree(fTree, "reconnect");
+    return (kTRUE);
+}
+
+
+AliAODEvent* AliMultiAODInputHandler::GetEvent(Int_t iev)
+{
+    // Get event number iev from buffer
+    if ((iev < 0) || (iev >= fBufferSize))
+    {
+       AliWarning(Form("Event number out of range: %10d", iev));
+       return 0;
+    }
+       
+    iev = fIndex - (fBufferSize - 1 - iev);
+    if (iev < 0) iev += fBufferSize;
+    AliInfo(Form("Event index in buffer is %5d", iev));
+    return (fEventBuffer[iev]);
+}
+
diff --git a/STEER/AliMultiAODInputHandler.h b/STEER/AliMultiAODInputHandler.h
new file mode 100644 (file)
index 0000000..b6f9e7e
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef ALIMULTIAODINPUTHANDLER_H
+#define ALIMULTIAODINPUTHANDLER_H
+/* Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//-------------------------------------------------------------------------
+//     AOD Input Handler realisation of the AliVEventHandler interface.
+//     This class handles multiple events for mixing.
+//     Author: Andreas Morsch, CERN
+//-------------------------------------------------------------------------
+
+#include "AliInputEventHandler.h"
+class TObject;
+class AliAODEvent;
+
+class AliMultiAODInputHandler : public AliInputEventHandler {
+
+ public:
+    AliMultiAODInputHandler(Int_t size);
+    AliMultiAODInputHandler(const char* name, const char* title, Int_t size);
+    virtual ~AliMultiAODInputHandler();
+    void   SetBufferSize(Int_t size) {fBufferSize = size;}
+    void   SetEventPool(TObject* pool) {fEventPool = pool;}
+    Int_t  GetBufferSize()           const {return fBufferSize;}
+    Int_t  GetNBuffered()            const {return fNBuffered;}
+    Bool_t IsBufferReady()           const {return (fNBuffered >= fBufferSize);}
+    Bool_t IsFreshBuffer()           const {return (fIndex == (fBufferSize - 1));}
+           
+    TObject*       GetEventPool()    const {return fEventPool;}
+    AliAODEvent*   GetEvent(Int_t iev);
+    // From the interface
+    virtual Bool_t Init(TTree* tree, Option_t* /*opt*/);
+    virtual Bool_t FinishEvent();
+ private:
+    AliMultiAODInputHandler(const AliMultiAODInputHandler& handler);             
+    AliMultiAODInputHandler& operator=(const AliMultiAODInputHandler& handler);  
+ private:
+    Int_t          fBufferSize;   // Size of the buffer
+    Int_t          fNBuffered;    // Number of events actually buffered
+    Int_t          fIndex;        // Pointer to most recent event
+    TTree*         fTree;         // Pointer to the tree
+    TObject*       fEventPool;    // Pointer to the pool
+    AliAODEvent**  fEventBuffer;  // The event buffer
+    ClassDef(AliMultiAODInputHandler, 1);
+};
+
+#endif
index 0273029..a9cbf7b 100644 (file)
@@ -5,7 +5,7 @@ SRCS = AliAODEvent.cxx AliAODHeader.cxx \
        AliAODCluster.cxx AliAODCaloCluster.cxx AliAODPmdCluster.cxx AliAODFmdCluster.cxx \
        AliAODJet.cxx AliAODPhoton.cxx AliAODRedCov.cxx AliAODRecoDecay.cxx \
        AliAODHandler.cxx AliAODTracklets.cxx AliAODTagCreator.cxx \
-       AliAODv0.cxx AliAODCaloCells.cxx AliAODInputHandler.cxx AliAODDiJet.cxx
+       AliAODv0.cxx AliAODCaloCells.cxx AliAODInputHandler.cxx AliMultiAODInputHandler.cxx AliAODDiJet.cxx
 
 HDRS:= $(SRCS:.cxx=.h)