]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODInputHandler.cxx
Cast to AliMCParticle*
[u/mrichter/AliRoot.git] / STEER / AliAODInputHandler.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 //     Author: Andreas Morsch, CERN
21 //-------------------------------------------------------------------------
22
23 #include <TTree.h>
24 #include <TList.h>
25 #include <TNamed.h>
26 #include <TFile.h>
27
28 #include "AliAODInputHandler.h"
29 #include "AliAODEvent.h"
30
31 ClassImp(AliAODInputHandler)
32
33 static Option_t *gAODDataType = "AOD";
34
35 //______________________________________________________________________________
36 AliAODInputHandler::AliAODInputHandler() :
37     AliInputEventHandler(),
38     fEvent(0),
39     fFriends(new TList())
40 {
41   // Default constructor
42 }
43
44 //______________________________________________________________________________
45 AliAODInputHandler::AliAODInputHandler(const char* name, const char* title):
46   AliInputEventHandler(name, title),
47   fEvent(0),
48   fFriends(new TList())
49 {
50     // Constructor
51 }
52
53 //______________________________________________________________________________
54 AliAODInputHandler::~AliAODInputHandler() 
55 {
56 // Destructor
57     fFriends->Delete();
58 }
59
60
61 Bool_t AliAODInputHandler::Init(TTree* tree, Option_t* /*opt*/)
62 {
63     // Initialisation necessary for each new tree
64     fTree = tree;
65     TIter next(fFriends);
66     TNamed* obj;
67  
68     if (!fTree) return kFALSE;
69     fTree->GetEntry(0);
70     TString aodTreeFName,aodFriendTreeFName;
71
72     while((obj = (TNamed*)next())) {
73         if (fTree->GetTree()) {
74           aodTreeFName = (fTree->GetTree()->GetCurrentFile())->GetName();
75           aodFriendTreeFName = aodTreeFName;
76           aodFriendTreeFName.ReplaceAll("AliAOD.root",obj->GetName());
77           aodFriendTreeFName.ReplaceAll("AliAODs.root",obj->GetName());
78           (fTree->GetTree())->AddFriend("aodTree", aodFriendTreeFName.Data());
79         } else {
80             aodTreeFName = (fTree->GetCurrentFile())->GetName();
81             aodFriendTreeFName = aodTreeFName;
82             aodFriendTreeFName.ReplaceAll("AliAOD.root",obj->GetName());
83             aodFriendTreeFName.ReplaceAll("AliAODs.root",obj->GetName());
84             fTree->AddFriend("aodTree", aodFriendTreeFName.Data());
85         }
86     }
87  
88
89     SwitchOffBranches();
90     SwitchOnBranches();
91     
92     // Get pointer to AOD event
93     if (!fEvent) fEvent = new AliAODEvent();
94
95     fEvent->ReadFromTree(fTree);
96     return kTRUE;
97 }
98
99 Bool_t AliAODInputHandler::BeginEvent(Long64_t /*entry*/)
100 {
101     //
102     //if (fTree) fTree->BranchRef();
103     return kTRUE;
104 }
105
106 void AliAODInputHandler::AddFriend(char* filename)
107 {
108     // Add a friend tree 
109     TNamed* obj = new TNamed(filename, filename);
110     fFriends->Add(obj);
111 }
112
113 Option_t *AliAODInputHandler::GetDataType() const
114 {
115 // Returns handled data type.
116    return gAODDataType;
117 }