memory leak https://savannah.cern.ch/bugs/index.php?87435 finally fixed
[u/mrichter/AliRoot.git] / ANALYSIS / AliPhysicsSelectionTask.cxx
CommitLineData
78167ba7 1/* $Id$ */
2
3#include "AliPhysicsSelectionTask.h"
4
5#include <TFile.h>
6#include <TH1F.h>
7#include <TH2F.h>
8
9#include <AliLog.h>
10#include <AliESDEvent.h>
11#include <AliHeader.h>
12
13#include "AliPhysicsSelection.h"
14#include "AliAnalysisManager.h"
15#include "AliInputEventHandler.h"
16
17//#include "AliBackgroundSelection.h"
18
19ClassImp(AliPhysicsSelectionTask)
20
21AliPhysicsSelectionTask::AliPhysicsSelectionTask() :
22 AliAnalysisTaskSE("AliPhysicsSelectionTask"),
23 fOutput(0),
24 fOption(""),
25 fPhysicsSelection(0)
26{
27 //
28 // Default event handler
29 //
30}
31
32AliPhysicsSelectionTask::AliPhysicsSelectionTask(const char* opt) :
33 AliAnalysisTaskSE("AliPhysicsSelectionTask"),
34 fOutput(0),
35 fOption(opt),
36 fPhysicsSelection(new AliPhysicsSelection())
37{
38 //
39 // Constructor. Initialization of pointers
40 //
41 AliInputEventHandler* handler = dynamic_cast<AliInputEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
42 if (handler) {
43 handler->SetEventSelection(fPhysicsSelection);
44 AliInfo("Physics Event Selection enabled.");
45 } else {
46 AliError("No input event handler connected to analysis manager. No Physics Event Selection.");
47 }
48 // Define input and output slots here
49 DefineOutput(1, TList::Class());
e1d47d6a 50 fBranchNames = "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,AliESDFMD.,AliESDVZERO.,AliESDZDC.,SPDVertex.,PrimaryVertex.";
78167ba7 51
52 AliLog::SetClassDebugLevel("AliPhysicsSelectionTask", AliLog::kWarning);
53}
54
55AliPhysicsSelectionTask::~AliPhysicsSelectionTask()
56{
57 //
58 // Destructor
59 //
60
61 // histograms are in the output list and deleted when the output
62 // list is deleted by the TSelector dtor
63
3be0b665 64 if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
78167ba7 65 delete fOutput;
66 fOutput = 0;
67 }
68}
69
70void AliPhysicsSelectionTask::UserCreateOutputObjects()
71{
72 // create result objects and add to output list
73
74 Printf("AliPhysicsSelectionTask::CreateOutputObjects");
75
76 fOutput = new TList;
77 fOutput->SetOwner();
78
79 if (!fPhysicsSelection)
80 fPhysicsSelection = new AliPhysicsSelection;
81
82 fOutput->Add(fPhysicsSelection);
222dc7b5 83 // All tasks must post data once for all outputs (AG)
84 PostData(1, fOutput);
78167ba7 85}
86
87void AliPhysicsSelectionTask::UserExec(Option_t*)
88{
89 // process the event
90
38c52e61 91 // AliPhysicsSelection::IsCollisionCandidate is called from the event handler
92 // post the data here anyway!
78167ba7 93 PostData(1, fOutput);
78167ba7 94}
95
e9247450 96void AliPhysicsSelectionTask::FinishTaskOutput()
97{
98// This gets called at the end of the processing on the worker. It allows dumping
99// statistics printed by the physics selection object to the statistics message
100// handled by the analysis manager.
101 if (fPhysicsSelection) fPhysicsSelection->Print("STAT");
102}
103
78167ba7 104void AliPhysicsSelectionTask::Terminate(Option_t *)
105{
106 // The Terminate() function is the last function to be called during
107 // a query. It always runs on the client, it can be used to present
108 // the results graphically or save the results to file.
109
110 fOutput = dynamic_cast<TList*> (GetOutputData(1));
111 if (!fOutput)
112 Printf("ERROR: fOutput not available");
113
114 if (fOutput)
115 {
116 fPhysicsSelection = dynamic_cast<AliPhysicsSelection*> (fOutput->FindObject("AliPhysicsSelection"));
117 }
118
119 TFile* fout = new TFile("event_stat.root", "RECREATE");
120
121 if (fPhysicsSelection)
122 {
123 fPhysicsSelection->Print();
decf6fd4 124 fPhysicsSelection->SaveHistograms();
78167ba7 125 }
126
127 fout->Write();
128 fout->Close();
129
130 Printf("Writting result to event_stat.root");
131}