]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDInputHandler.cxx
Fix memory leak when reading AliESDfriends, now deleted for every event
[u/mrichter/AliRoot.git] / STEER / AliESDInputHandler.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 ESD input 
20 //     Author: Andreas Morsch, CERN
21 //-------------------------------------------------------------------------
22
23 #include <TTree.h>
24 #include <TString.h>
25 #include <TObjString.h>
26
27 #include "AliESDInputHandler.h"
28 #include "AliESDEvent.h"
29 #include "AliESD.h"
30 #include "AliLog.h"
31
32 ClassImp(AliESDInputHandler)
33
34 //______________________________________________________________________________
35 AliESDInputHandler::AliESDInputHandler() :
36   AliInputEventHandler(),
37   fEvent(0x0)
38 {
39   // default constructor
40 }
41
42 //______________________________________________________________________________
43 AliESDInputHandler::~AliESDInputHandler() 
44 {
45   // destructor
46   //  delete fEvent;
47 }
48
49 //______________________________________________________________________________
50 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
51     AliInputEventHandler(name, title), fEvent(0x0), fBranches("")
52 {
53 }
54
55 Bool_t AliESDInputHandler::Init(TTree* tree,  Option_t* /*opt*/)
56 {
57     // Initialisation necessary for each new tree 
58     fTree = tree;
59     
60     if (!fTree) return kFALSE;
61     // Get pointer to ESD event
62     SwitchOffBranches();
63     
64     if (fEvent) {
65       delete fEvent;
66       fEvent = 0;
67     }
68     fEvent = new AliESDEvent();
69
70     fEvent->ReadFromTree(fTree);
71     return kTRUE;
72 }
73
74 Bool_t AliESDInputHandler::BeginEvent(Long64_t /*entry*/)
75 {
76     // Copy from old to new format if necessary
77   AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
78   if (old) {
79         ((AliESDEvent*)fEvent)->CopyFromOldESD();
80         old->Reset();
81   }
82   return kTRUE;
83 }
84
85 Bool_t  AliESDInputHandler::FinishEvent(){
86   if(fEvent)fEvent->Reset();
87   return kTRUE;
88
89
90 void AliESDInputHandler::SwitchOffBranches() const {
91   //
92   // Switch of branches on user request
93   TObjArray * tokens = fBranches.Tokenize(" ");
94   Int_t ntok = tokens->GetEntries();
95   for (Int_t i = 0; i < ntok; i++)  {
96     TString str = ((TObjString*) tokens->At(i))->GetString();
97     fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
98     AliInfo(Form("Branch %s switched off \n", str.Data()));
99   }
100 }