Fixed overwriting of an AOD extension if a task wants to add a kParamContainer in...
[u/mrichter/AliRoot.git] / STEER / AliAODHandler.h
1 #ifndef ALIAODHANDLER_H
2 #define ALIAODHANDLER_H
3 /* Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 //-------------------------------------------------------------------------
9 //     Implementation of the Event Handler Interface for AOD
10 //     Author: Andreas Morsch, CERN
11 //-------------------------------------------------------------------------
12
13 #include "AliVEventHandler.h"
14
15 class AliAODEvent;
16 class TFile;
17 class TTree;
18 class TObjArray;
19 class AliMCEventHandler;
20 class AliAODMCHeader;
21 class AliAODExtension;
22 class AliGenEventHeader;
23
24
25
26 class AliAODHandler : public AliVEventHandler {
27     
28  public:
29     AliAODHandler();
30     AliAODHandler(const char* name, const char* title);
31     virtual ~AliAODHandler();
32     virtual void         SetOutputFileName(const char* fname);
33     virtual const char*  GetOutputFileName();
34     // Extra outputs as a string separated by commas
35     virtual const char*  GetExtraOutputs() const;
36     virtual Bool_t       Init(Option_t* option);
37     virtual Bool_t       Init(TTree* /*tree*/, Option_t* /*option*/)  {return kTRUE;}
38     virtual Bool_t       BeginEvent(Long64_t /*entry*/) {fFillAOD=kFALSE; return kTRUE;}
39     virtual Bool_t       Notify() { return AliVEventHandler::Notify(); };
40     virtual Bool_t       Notify(const char * /* path */) {return kTRUE;}
41     virtual Bool_t       FinishEvent();
42     virtual Bool_t       Terminate();
43     virtual Bool_t       TerminateIO();
44     //
45     virtual void         SetCreateNonStandardAOD()               {fIsStandard = kFALSE;}
46     virtual void         SetFillAOD(Bool_t b)                    {fFillAOD = b;}
47     virtual void         SetFillAODforRun(Bool_t b)              {fFillAODRun = b;}
48     virtual void         SetNeedsHeaderReplication()             {fNeedsHeaderReplication             = kTRUE;}
49     virtual void         SetNeedsTracksBranchReplication()       {fNeedsTracksBranchReplication       = kTRUE;}
50     virtual void         SetNeedsVerticesBranchReplication()     {fNeedsVerticesBranchReplication     = kTRUE;}
51     virtual void         SetNeedsV0sBranchReplication()          {fNeedsV0sBranchReplication          = kTRUE;}
52     virtual void         SetNeedsCascadesBranchReplication()     {fNeedsCascadesBranchReplication     = kTRUE;}
53     virtual void         SetNeedsTrackletsBranchReplication()    {fNeedsTrackletsBranchReplication    = kTRUE;}
54     virtual void         SetNeedsPMDClustersBranchReplication()  {fNeedsPMDClustersBranchReplication  = kTRUE;}
55     virtual void         SetNeedsJetsBranchReplication()         {fNeedsJetsBranchReplication         = kTRUE;}
56     virtual void         SetNeedsFMDClustersBranchReplication()  {fNeedsFMDClustersBranchReplication  = kTRUE;}
57     virtual void         SetNeedsCaloClustersBranchReplication() {fNeedsCaloClustersBranchReplication = kTRUE;}
58     virtual void         SetNeedsMCParticlesBranchReplication()  {fNeedsMCParticlesBranchReplication  = kTRUE;}
59     virtual void         SetNeedsDimuonsBranchReplication()      {fNeedsDimuonsBranchReplication      = kTRUE;}
60     virtual void         SetAODIsReplicated() {fAODIsReplicated = kTRUE;}
61     //
62     AliAODEvent*         GetAOD()  {return fAODEvent;}
63     virtual TTree*       GetTree() const {return fTreeA;}
64     TObjArray*           GetExtensions() const {return fExtensions;}
65     AliAODExtension*     GetExtension(const char *filename) const;
66     TObjArray*           GetFilters() const {return fFilters;}
67     AliAODExtension*     GetFilteredAOD(const char *filename) const;
68     void                 CreateTree(Int_t flag);
69     void                 FillTree();
70     void                 AddAODtoTreeUserInfo();
71     void                 AddBranch(const char* cname, void* addobj, const char *fname="");
72     AliAODExtension*     AddExtension(const char *filename, const char *title="");                 
73     AliAODExtension*     AddFilteredAOD(const char *filename, const char *filtername);
74     Bool_t               IsStandard()                         const {return fIsStandard;}
75     Bool_t               GetFillAOD()                         const {return fFillAOD;} 
76     Bool_t               NeedsHeaderReplication()             const {return  fNeedsHeaderReplication;}
77     Bool_t               NeedsTracksBranchReplication()       const {return  fNeedsTracksBranchReplication;}
78     Bool_t               NeedsVerticesBranchReplication()     const {return  fNeedsVerticesBranchReplication;}
79     Bool_t               NeedsV0sBranchReplication()          const {return  fNeedsV0sBranchReplication;}
80     Bool_t               NeedsCascadesBranchReplication()     const {return  fNeedsCascadesBranchReplication;}
81     Bool_t               NeedsTrackletsBranchReplication()    const {return  fNeedsTrackletsBranchReplication;}
82     Bool_t               NeedsPMDClustersBranchReplication()  const {return  fNeedsPMDClustersBranchReplication;}
83     Bool_t               NeedsJetsBranchReplication()         const {return  fNeedsJetsBranchReplication;}
84     Bool_t               NeedsFMDClustersBranchReplication()  const {return  fNeedsFMDClustersBranchReplication;}
85     Bool_t               NeedsCaloClustersBranchReplication() const {return  fNeedsCaloClustersBranchReplication;}
86     Bool_t               NeedsMCParticlesBranchReplication()  const {return  fNeedsMCParticlesBranchReplication;}
87     Bool_t               NeedsDimuonsBranchReplication()      const {return  fNeedsDimuonsBranchReplication;}
88     Bool_t               AODIsReplicated()                    const {return  fAODIsReplicated;}
89     //
90     void                 SetInputTree(TTree* /*tree*/) {;}
91     void                 SetMCEventHandler(AliMCEventHandler* mcH) {fMCEventH = mcH;} // For internal use
92     void StoreMCParticles(); // Store MC particles, only to be called from AliAnalyisTaskMCParticleFilter
93
94  private:
95     void SetMCHeaderInfo(AliAODMCHeader *mcHeader,AliGenEventHeader *genHeader); // Utility function t catch different types of eventheaders
96     AliAODHandler(const AliAODHandler&);             // Not implemented
97     AliAODHandler& operator=(const AliAODHandler&);  // Not implemented
98  private:
99     Bool_t                   fIsStandard;                         // Flag for standard aod creation
100     Bool_t                   fFillAOD;                            // Flag for filling of the AOD tree at the end (all or nothing evt by evt)
101     Bool_t                   fFillAODRun;                         // Flag for filling of the AOD tree at the end (run)
102     Bool_t                   fNeedsHeaderReplication;             // Flag for header replication
103     Bool_t                   fNeedsTracksBranchReplication;       // Flag for tracks replication
104     Bool_t                   fNeedsVerticesBranchReplication;     // Flag for vertices replication
105     Bool_t                   fNeedsV0sBranchReplication;          // Flag for V0s replication
106     Bool_t                   fNeedsCascadesBranchReplication;     // Flag for Cascade replication
107     Bool_t                   fNeedsTrackletsBranchReplication;    // Flag for Tracklets replication
108     Bool_t                   fNeedsPMDClustersBranchReplication;  // Flag for PMDClusters replication
109     Bool_t                   fNeedsJetsBranchReplication;         // Flag for Jets replication
110     Bool_t                   fNeedsFMDClustersBranchReplication;  // Flag for FMDClusters replication
111     Bool_t                   fNeedsCaloClustersBranchReplication; // Flag for CaloClusters replication
112     Bool_t                   fNeedsMCParticlesBranchReplication;  // Flag for MCParticles replication
113     Bool_t                   fNeedsDimuonsBranchReplication;      // Flag for Dimuons replication
114     Bool_t                   fAODIsReplicated;                    // Flag true if replication as been executed
115     AliAODEvent             *fAODEvent;               //! Pointer to the AOD event
116     AliMCEventHandler       *fMCEventH;               //! Pointer to mc event handler needed not to depend on the manager
117     TTree                   *fTreeA;                  //! tree for AOD persistency
118     TFile                   *fFileA;                  //! Output file
119     TString                  fFileName;               //  Output file name
120     TObjArray               *fExtensions;             //  List of extensions
121     TObjArray               *fFilters;                //  List of filtered AOD's
122     ClassDef(AliAODHandler, 6)
123 };
124
125 //-------------------------------------------------------------------------
126 //     Support class for AOD extensions. This is created by the user analysis
127 //     that requires a separate file for some AOD branches. The name of the 
128 //     AliAODExtension object is the file name where the AOD branches will be
129 //     stored.
130 //     Author: Andrei Gheata, CERN
131 //-------------------------------------------------------------------------
132
133 class AliAODExtension : public TNamed {
134
135 public:
136
137 enum EAliAODExtensionFlags {
138    kFilteredAOD      = BIT(14)
139 };
140     
141     AliAODExtension() : TNamed(), fAODEvent(0), fTreeE(0), fFileE(0), fNtotal(0), fNpassed(0), fSelected(kFALSE) {}
142     AliAODExtension(const char* name, const char* title, Bool_t isfilter=kFALSE);
143     virtual ~AliAODExtension();
144     void                 AddBranch(const char* cname, void* addobj);
145     Bool_t               FinishEvent();
146     Int_t                GetNtotal() const         {return fNtotal;}
147     Int_t                GetNpassed() const        {return fNpassed;}
148     const char*          GetOutputFileName() const {return TNamed::GetName();}
149     AliAODEvent*         GetAOD() const            {return fAODEvent;}
150     TTree*               GetTree() const           {return fTreeE;}
151     Bool_t               Init(Option_t *option);
152     Bool_t               IsFilteredAOD() const     {return TObject::TestBit(kFilteredAOD);}
153     Bool_t               IsEventSelected() const   {return fSelected;}
154     void                 SelectEvent(Bool_t flag=kTRUE)  {fSelected = flag;}
155     void                 SetEvent(AliAODEvent *event);
156     void                 SetOutputFileName(const char* fname) {TNamed::SetName(fname);}
157     Bool_t               TerminateIO();
158  private:
159     AliAODExtension(const AliAODExtension&);             // Not implemented
160     AliAODExtension& operator=(const AliAODExtension&);  // Not implemented
161
162  private:
163     AliAODEvent             *fAODEvent;               //! Pointer to the AOD event
164     TTree                   *fTreeE;                  //! tree for AOD persistency
165     TFile                   *fFileE;                  //! Output file
166     Int_t                    fNtotal;                 //! Number of processed events
167     Int_t                    fNpassed;                //! Number of events that passed the filter
168     Bool_t                   fSelected;               //! Select current event for filtered AOD's. Made false at event start.
169     ClassDef(AliAODExtension, 1)                      // Support for extra AOD branches in a separate AOD file
170 };
171 #endif