]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMultiAODInputHandler.cxx
Removed writing of jets_local.root
[u/mrichter/AliRoot.git] / STEER / AliMultiAODInputHandler.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //-------------------------------------------------------------------------
19 //     Event handler for AOD input.
20 //     This class handles multiple inputs for event mixing. 
21 //     Author: Andreas Morsch, CERN
22 //-------------------------------------------------------------------------
23
24 #include "AliMultiAODInputHandler.h"
25 #include "AliAODEvent.h"
26 #include "AliVEventPool.h"
27 #include "AliLog.h"
28 #include <TObjArray.h>
29 #include <TTree.h>
30
31
32 ClassImp(AliMultiAODInputHandler)
33
34 AliMultiAODInputHandler::AliMultiAODInputHandler() :
35     AliInputEventHandler(),
36     fBufferSize(0),
37     fNBuffered(0),
38     fIndex(0),
39     fCurrentBin(0),
40     fTree(0),
41     fEventPool(0),
42     fEventBuffer(0)
43 {
44   // Default constructor
45 }
46
47 //______________________________________________________________________________
48 AliMultiAODInputHandler::AliMultiAODInputHandler(Int_t size) :
49     AliInputEventHandler(),
50     fBufferSize(size),
51     fNBuffered(0),
52     fIndex(0),
53     fCurrentBin(0),
54     fTree(0),
55     fEventPool(0),
56     fEventBuffer(new AliAODEvent*[size])
57 {
58   // Default constructor
59     for (Int_t i = 0; i < size; i++) 
60         fEventBuffer[i] = new AliAODEvent();
61 }
62
63 //______________________________________________________________________________
64 AliMultiAODInputHandler::AliMultiAODInputHandler(const char* name, const char* title, Int_t size):
65     AliInputEventHandler(name, title),
66     fBufferSize(size),
67     fNBuffered(0),
68     fIndex(0),
69     fCurrentBin(0),
70     fTree(0),
71     fEventPool(0),
72     fEventBuffer(new AliAODEvent*[size])
73 {
74     // Constructor
75     for (Int_t i = 0; i < size; i++) 
76         fEventBuffer[i] = new AliAODEvent();
77 }
78
79 //______________________________________________________________________________
80 AliMultiAODInputHandler::~AliMultiAODInputHandler() 
81 {
82 // Destructor
83 }
84
85 Bool_t AliMultiAODInputHandler::Init(TTree* tree, Option_t* /*opt*/)
86 {
87     // Initialisation necessary for each new tree
88     fTree = tree;
89     if (!fTree) return kFALSE;
90     // Get pointer to AOD event
91     fEventBuffer[0]->ReadFromTree(fTree);
92     fIndex     = 0;
93     fNBuffered = 1;
94     return kTRUE;
95 }
96
97 Bool_t AliMultiAODInputHandler::BeginEvent(Long64_t /*entry*/)
98 {
99     // Actions before analysis of each event 
100     //
101     // Reset the number of events buffered for this bin to 0
102     if (fCurrentBin != (fEventPool->BinNumber())) {
103         fCurrentBin = fEventPool->BinNumber();
104         fNBuffered = 0;
105     }
106     return kTRUE;
107 }
108
109 Bool_t AliMultiAODInputHandler::FinishEvent()
110 {
111     // 
112     // Connect the next event in the buffer to the tree
113     fIndex++;
114     
115     fIndex %= fBufferSize;
116     AliInfo(Form("Connecting buffer entry %5d", fIndex));
117
118     fEventBuffer[fIndex]->ReadFromTree(fTree, "reconnect");
119
120     fNBuffered++;
121     if (fNBuffered > fBufferSize) fNBuffered = fBufferSize;
122
123     return (kTRUE);
124 }
125
126
127 AliAODEvent* AliMultiAODInputHandler::GetEvent(Int_t iev) const
128 {
129     // Get event number iev from buffer
130     if ((iev < 0) || (iev >= fBufferSize))
131     {
132         AliWarning(Form("Event number out of range: %10d", iev));
133         return 0;
134     }
135         
136     iev = fIndex - (fBufferSize - 1 - iev);
137     if (iev < 0) iev += fBufferSize;
138     AliInfo(Form("Event index in buffer is %5d", iev));
139     return (fEventBuffer[iev]);
140 }
141