Reading friends in analysis framework inside HLT
[u/mrichter/AliRoot.git] / HLT / global / physics / AliHLTAnaManagerComponent.cxx
CommitLineData
b9f1d917 1//-*- Mode: C++ -*-
2// $Id: AliHLTAnaManagerComponent.cxx $
3/**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
6 * *
7 * Primary Authors: David Rohr, Jens Wiechula, C. Zampolli *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18/** @file AliHLTAnaManagerComponent.cxx
19 @author David Rohr, Jens Wiechula, C. Zampolli
20 @brief Component for Testing Analysis Manager inside HLT component
21*/
22
23#include "TMap.h"
24#include "TSystem.h"
25#include "TTimeStamp.h"
26#include "TObjString.h"
27#include "TH1F.h"
28#include "TList.h"
29#include "AliESDtrackCuts.h"
afdb0e0d 30#include "AliESDEvent.h"
b9f1d917 31#include "AliHLTErrorGuard.h"
32#include "AliHLTDataTypes.h"
33#include "AliHLTAnaManagerComponent.h"
34#include "AliHLTITSClusterDataFormat.h"
35#include "AliAnalysisManager.h"
36#include "AliHLTTestInputHandler.h"
37#include "AliAnalysisTaskPt.h"
38#include "AliAnalysisDataContainer.h"
39#include "TTree.h"
40
41using namespace std;
42
43/** ROOT macro for the implementation of ROOT specific class methods */
44ClassImp(AliHLTAnaManagerComponent)
45
46/*
47 * ---------------------------------------------------------------------------------
48 * Constructor / Destructor
49 * ---------------------------------------------------------------------------------
50 */
51
52// #################################################################################
53AliHLTAnaManagerComponent::AliHLTAnaManagerComponent() :
54 AliHLTProcessor(),
55 fUID(0),
56 fAnalysisManager(NULL),
afdb0e0d 57 fInputHandler(NULL){
b9f1d917 58 // an example component which implements the ALICE HLT processor
59 // interface and does some analysis on the input raw data
60 //
61 // see header file for class documentation
62 // or
63 // refer to README to build package
64 // or
65 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
66 //
67 // NOTE: all helper classes should be instantiated in DoInit()
68}
69
70// #################################################################################
71AliHLTAnaManagerComponent::~AliHLTAnaManagerComponent() {
72 // see header file for class documentation
73}
74
75/*
76 * ---------------------------------------------------------------------------------
77 * Public functions to implement AliHLTComponent's interface.
78 * These functions are required for the registration process
79 * ---------------------------------------------------------------------------------
80 */
81
82// #################################################################################
83const Char_t* AliHLTAnaManagerComponent::GetComponentID() {
84 // see header file for class documentation
85 return "AnaManagerComponent";
86}
87
88// #################################################################################
89void AliHLTAnaManagerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
90 // see header file for class documentation
91 list.push_back(kAliHLTDataTypeESDObject|kAliHLTDataOriginAny);
92 list.push_back(kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD);
93 list.push_back(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO);
949fa831 94 list.push_back(kAliHLTDataTypeESDfriendObject|kAliHLTDataOriginAny);
b9f1d917 95}
96
97// #################################################################################
98AliHLTComponentDataType AliHLTAnaManagerComponent::GetOutputDataType() {
99 // see header file for class documentation
100 return kAliHLTDataTypeTObject|kAliHLTDataOriginHLT;
101}
102
103// #################################################################################
104void AliHLTAnaManagerComponent::GetOutputDataSize( ULong_t& constBase, Double_t& inputMultiplier ) {
105 // see header file for class documentation
106 constBase = 100000;
107 inputMultiplier = 0.5;
108}
109
110// #################################################################################
111void AliHLTAnaManagerComponent::GetOCDBObjectDescription( TMap* const targetMap) {
112 // see header file for class documentation
113
114 if (!targetMap) return;
949fa831 115 /* targetMap->Add(new TObjString("HLT/ConfigGlobal/MultiplicityCorrelations"),
b9f1d917 116 new TObjString("configuration object"));
117 targetMap->Add(new TObjString("HLT/ConfigGlobal/MultiplicityCorrelationsCentrality"),
118 new TObjString("centrality configuration object"));
949fa831 119 */
b9f1d917 120 return;
121}
122
123// #################################################################################
124AliHLTComponent* AliHLTAnaManagerComponent::Spawn() {
125 // see header file for class documentation
126 return new AliHLTAnaManagerComponent;
127}
128
129/*
130 * ---------------------------------------------------------------------------------
131 * Protected functions to implement AliHLTComponent's interface.
132 * These functions provide initialization as well as the actual processing
133 * capabilities of the component.
134 * ---------------------------------------------------------------------------------
135 */
136
137// #################################################################################
afdb0e0d 138Int_t AliHLTAnaManagerComponent::DoInit( Int_t /*argc*/, const Char_t** /*argv*/ ) {
b9f1d917 139 // see header file for class documentation
140 printf("AliHLTAnaManagerComponent::DoInit\n");
141
142 Int_t iResult=0;
143
afdb0e0d 144 Printf("----> AliHLTAnaManagerComponent::DoInit");
b9f1d917 145 fAnalysisManager = new AliAnalysisManager;
146 fInputHandler = new AliHLTTestInputHandler;
147 fAnalysisManager->SetInputEventHandler(fInputHandler);
148 fAnalysisManager->SetExternalLoop(kTRUE);
149
150 AliAnalysisTaskPt *task = new AliAnalysisTaskPt("TaskPt");
151 fAnalysisManager->AddTask(task);
152 AliAnalysisDataContainer *cinput = fAnalysisManager->GetCommonInputContainer();
153 Printf("Defining output file");
949fa831 154 AliAnalysisDataContainer *coutput1 = fAnalysisManager->CreateContainer("pt", TList::Class(),
b9f1d917 155 AliAnalysisManager::kOutputContainer, "Pt.ESD.root");
156
157 // connect containers
afdb0e0d 158 Printf("---> Connecting input...");
159 fAnalysisManager->ConnectInput (task, 0, cinput );
160 Printf("---> ...connected.");
b9f1d917 161 Printf("---> Connecting output...");
162 fAnalysisManager->ConnectOutput (task, 0, coutput1);
163 Printf("---> ...connected.");
164
afdb0e0d 165 Printf("----> Calling InitAnalysis");
b9f1d917 166 fAnalysisManager->InitAnalysis();
afdb0e0d 167 Printf("----> Done.");
168 Printf("----> Calling StartAnalysis");
b9f1d917 169 fAnalysisManager->StartAnalysis("local", (TTree*)new TTree);
afdb0e0d 170 //fAnalysisManager->StartAnalysis("local", (TTree*)NULL);
171 Printf("----> Done.");
b9f1d917 172
173 return iResult;
174}
175
176
177
178// #################################################################################
179Int_t AliHLTAnaManagerComponent::DoDeinit() {
180 // see header file for class documentation
181
182 fUID = 0;
183 fAnalysisManager->SetSkipTerminate(kTRUE);
184 fAnalysisManager->Terminate();
185
186 delete fAnalysisManager;
187
188 return 0;
189}
190
191// #################################################################################
192Int_t AliHLTAnaManagerComponent::DoEvent(const AliHLTComponentEventData& evtData,
193 AliHLTComponentTriggerData& /*trigData*/) {
194 // see header file for class documentation
195
196 printf("AliHLTAnaManagerComponent::DoEvent\n");
197 Int_t iResult=0;
198
199 // -- Only use data event
200 if (!IsDataEvent())
201 return 0;
202
203 if( fUID == 0 ){
204 TTimeStamp t;
205 fUID = ( gSystem->GetPid() + t.GetNanoSec())*10 + evtData.fEventID;
206 }
207
208 // -- Get ESD object
209 // -------------------
210 AliESDEvent *esdEvent = NULL;
949fa831 211 AliESDfriend *esdFriend = NULL;
b9f1d917 212 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDObject); iter != NULL; iter = GetNextInputObject() ) {
213 esdEvent = dynamic_cast<AliESDEvent*>(const_cast<TObject*>( iter ) );
214 if( !esdEvent ){
215 HLTWarning("Wrong ESDEvent object received");
216 iResult = -1;
217 continue;
218 }
219 esdEvent->GetStdContent();
220 }
afdb0e0d 221 printf("----> ESDEvent %p has %d tracks: \n", esdEvent, esdEvent->GetNumberOfTracks());
949fa831 222 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDfriendObject); iter != NULL; iter = GetNextInputObject() ) {
223 esdFriend = dynamic_cast<AliESDfriend*>(const_cast<TObject*>( iter ) );
224 if( !esdFriend ){
225 HLTWarning("Wrong ESDFriend object received");
226 iResult = -1;
227 continue;
228 }
229 }
230 printf("----> ESDFriend %p has %d tracks: \n", esdFriend, esdFriend->GetNumberOfTracks());
b9f1d917 231
949fa831 232 fAnalysisManager->InitInputData(esdEvent, esdFriend);
afdb0e0d 233 // fInputHandler->BeginEvent(0);
b9f1d917 234 fAnalysisManager->ExecAnalysis();
235 fInputHandler->FinishEvent();
236
237
238 // -- Send histlist
239// PushBack(dynamic_cast<TObject*>(fCorrObj->GetHistList()),
240// kAliHLTDataTypeTObject|kAliHLTDataOriginHLT,fUID);
241
242 return iResult;
243}
244
245// #################################################################################
246Int_t AliHLTAnaManagerComponent::Reconfigure(const Char_t* cdbEntry, const Char_t* chainId) {
247 // see header file for class documentation
248
249 Int_t iResult=0;
250 TString cdbPath;
251 if (cdbEntry) {
252 cdbPath=cdbEntry;
253 } else {
254 cdbPath="HLT/ConfigGlobal/";
255 cdbPath+=GetComponentID();
256 }
257
258 AliInfoClass(Form("reconfigure '%s' from entry %s%s", chainId, cdbPath.Data(), cdbEntry?"":" (default)"));
259 iResult=ConfigureFromCDBTObjString(cdbPath);
260
261 return iResult;
262}
263
264// #################################################################################
265Int_t AliHLTAnaManagerComponent::ReadPreprocessorValues(const Char_t* /*modules*/) {
266 // see header file for class documentation
267 ALIHLTERRORGUARD(5, "ReadPreProcessorValues not implemented for this component");
268 return 0;
269}
270