]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliMultiEventInputHandler.cxx
Creation of buffer delayed until Init()
[u/mrichter/AliRoot.git] / ANALYSIS / AliMultiEventInputHandler.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 multiple VEvent input.
20 //     This class handles multiple inputs for event mixing. 
21 //     Author: Andreas Morsch, CERN
22 //-------------------------------------------------------------------------
23
24 #include "AliMultiEventInputHandler.h"
25 #include "AliVEvent.h"
26 #include "AliAODEvent.h"
27 #include "AliESDEvent.h"
28 #include "AliVEventPool.h"
29 #include "AliLog.h"
30 #include <TObjArray.h>
31 #include <TTree.h>
32
33
34 ClassImp(AliMultiEventInputHandler)
35
36 AliMultiEventInputHandler::AliMultiEventInputHandler() :
37     AliInputEventHandler(),
38     fBufferSize(0),
39     fFormat(1),
40     fNBuffered(0),
41     fIndex(0),
42     fCurrentBin(0),
43     fEventPool(0),
44     fEventBuffer(0)
45 {
46   // Default constructor
47 }
48
49 //______________________________________________________________________________
50 AliMultiEventInputHandler::AliMultiEventInputHandler(Int_t size, Int_t format) :
51     AliInputEventHandler(),
52     fBufferSize(size),
53     fFormat(format),
54     fNBuffered(0),
55     fIndex(0),
56     fCurrentBin(0),
57     fEventPool(0),
58     fEventBuffer(0)
59 {
60   // constructor
61 }
62
63 //______________________________________________________________________________
64 AliMultiEventInputHandler::AliMultiEventInputHandler(const char* name, const char* title, Int_t size, Int_t format):
65     AliInputEventHandler(name, title),
66     fBufferSize(size),
67     fFormat(format),
68     fNBuffered(0),
69     fIndex(0),
70     fCurrentBin(0),
71     fEventPool(0),
72     fEventBuffer(0)
73 {
74     // Constructor
75
76 }
77
78 //______________________________________________________________________________
79 AliMultiEventInputHandler::~AliMultiEventInputHandler() 
80 {
81 // Destructor
82 }
83
84 Bool_t AliMultiEventInputHandler::Init(TTree* tree, Option_t* /*opt*/)
85 {
86     // Initialisation necessary for each new tree
87     if (!fEventBuffer) {
88         fEventBuffer = new AliVEvent*[fBufferSize];
89         
90         for (Int_t i = 0; i < fBufferSize; i++) 
91             if (fFormat == 1) {
92                 fEventBuffer[i] = new AliAODEvent();
93             } else if (fFormat == 0) {
94                 fEventBuffer[i] = new AliESDEvent();
95             } else{
96                 AliWarning(Form("Unknown Format %5d", fFormat));
97             }
98     }
99     
100
101     fTree = tree;
102     if (!fTree) return kFALSE;
103     for (Int_t i = 0; i < fBufferSize; i++) 
104         fEventBuffer[i]->Clear();
105     fIndex     = 0;
106     fNBuffered = 1;
107     return kTRUE;
108 }
109
110
111 Bool_t AliMultiEventInputHandler::Notify(const char */*path*/)
112 {
113     // Connect to new tree
114
115         
116     static Bool_t first = kTRUE;
117     
118     
119     if (first) {
120         fEventBuffer[0]->ReadFromTree(fTree, "");
121         first = kFALSE;
122     } else {
123         fEventBuffer[0]->ReadFromTree(fTree, "reconnect");
124     }
125     
126     
127     return (kTRUE);
128 }
129
130 Bool_t AliMultiEventInputHandler::BeginEvent(Long64_t /*entry*/)
131 {
132     // Actions before analysis of each event 
133     //
134     // Reset the number of events buffered for this bin to 0
135     if (fCurrentBin != (fEventPool->BinNumber())) {
136         fCurrentBin = fEventPool->BinNumber();
137         fNBuffered = 0;
138     }
139     return kTRUE;
140 }
141
142 Bool_t AliMultiEventInputHandler::FinishEvent()
143 {
144     // 
145     // Connect the next event in the buffer to the tree
146     fIndex++;
147     
148     fIndex %= fBufferSize;
149     AliInfo(Form("Connecting buffer entry %5d", fIndex));
150     fEventBuffer[fIndex]->Clear();
151     fEventBuffer[fIndex]->ReadFromTree(fTree, "reconnect");
152
153     fNBuffered++;
154     if (fNBuffered > fBufferSize) fNBuffered = fBufferSize;
155
156     return (kTRUE);
157 }
158
159 AliVEvent* AliMultiEventInputHandler::GetEvent(Int_t iev) const
160 {
161     // Get event number iev from buffer
162     if ((iev < 0) || (iev >= fBufferSize))
163     {
164         AliWarning(Form("Event number out of range: %10d", iev));
165         return 0;
166     }
167         
168     iev = fIndex - (fBufferSize - 1 - iev);
169     if (iev < 0) iev += fBufferSize;
170     AliInfo(Form("Event index in buffer is %5d", iev));
171     return (fEventBuffer[iev]);
172 }
173