]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/physics/AliHLTAnaManagerComponent.cxx
639bea37cb50eadcf0688eab6b30d48a770e5804
[u/mrichter/AliRoot.git] / HLT / global / physics / AliHLTAnaManagerComponent.cxx
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"
30 #include "AliESDEvent.h"
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
41 using namespace std;
42
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTAnaManagerComponent)
45
46 /*
47  * ---------------------------------------------------------------------------------
48  *                            Constructor / Destructor
49  * ---------------------------------------------------------------------------------
50  */
51
52 // #################################################################################
53 AliHLTAnaManagerComponent::AliHLTAnaManagerComponent() :
54   AliHLTProcessor(),
55   fUID(0),
56   fAnalysisManager(NULL),
57   fInputHandler(NULL){
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 // #################################################################################
71 AliHLTAnaManagerComponent::~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 // #################################################################################
83 const Char_t* AliHLTAnaManagerComponent::GetComponentID() { 
84   // see header file for class documentation
85   return "AnaManagerComponent";
86 }
87
88 // #################################################################################
89 void 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);
94   list.push_back(kAliHLTDataTypeESDfriendObject|kAliHLTDataOriginAny);
95 }
96
97 // #################################################################################
98 AliHLTComponentDataType AliHLTAnaManagerComponent::GetOutputDataType() {
99   // see header file for class documentation
100   return kAliHLTDataTypeTObject|kAliHLTDataOriginHLT;
101 }
102
103 // #################################################################################
104 void 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 // #################################################################################
111 void AliHLTAnaManagerComponent::GetOCDBObjectDescription( TMap* const targetMap) {
112   // see header file for class documentation
113
114   if (!targetMap) return;
115   /*  targetMap->Add(new TObjString("HLT/ConfigGlobal/MultiplicityCorrelations"),
116                  new TObjString("configuration object"));
117   targetMap->Add(new TObjString("HLT/ConfigGlobal/MultiplicityCorrelationsCentrality"),
118                  new TObjString("centrality configuration object"));
119   */
120   return;
121 }
122
123 // #################################################################################
124 AliHLTComponent* 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 // #################################################################################
138 Int_t AliHLTAnaManagerComponent::DoInit( Int_t /*argc*/, const Char_t** /*argv*/ ) {
139   // see header file for class documentation
140   printf("AliHLTAnaManagerComponent::DoInit\n");
141
142   Int_t iResult=0;
143
144   Printf("----> AliHLTAnaManagerComponent::DoInit"); 
145   fAnalysisManager = new AliAnalysisManager;
146   fInputHandler    = new AliHLTTestInputHandler;
147   fAnalysisManager->SetInputEventHandler(fInputHandler);
148   fAnalysisManager->SetExternalLoop(kTRUE); 
149
150   AliAnalysisTaskPt *task = new AliAnalysisTaskPt("TaskPt");
151   printf("-----> AliHLTAnaManagerComponent: here we set the usage of the friends to %d\n", (Int_t)task->GetUseFriends());
152   task->SetUseFriends(kTRUE);
153   fAnalysisManager->AddTask(task);
154   AliAnalysisDataContainer *cinput  = fAnalysisManager->GetCommonInputContainer();
155   Printf("Defining output file");
156   AliAnalysisDataContainer *coutput1 = fAnalysisManager->CreateContainer("pt", TList::Class(),
157       AliAnalysisManager::kOutputContainer, "Pt.ESD.root");
158
159   //           connect containers
160   Printf("---> Connecting input...");
161   fAnalysisManager->ConnectInput  (task,  0, cinput ); 
162   Printf("---> ...connected.");
163   Printf("---> Connecting output...");
164   fAnalysisManager->ConnectOutput (task,  0, coutput1);
165   Printf("---> ...connected.");
166
167   Printf("----> Calling InitAnalysis");
168   fAnalysisManager->InitAnalysis();
169   Printf("----> Done.");
170   Printf("----> Calling StartAnalysis");
171   fAnalysisManager->StartAnalysis("local", (TTree*)new TTree);
172   //fAnalysisManager->StartAnalysis("local", (TTree*)NULL);
173   Printf("----> Done.");
174
175   return iResult;
176 }
177
178
179
180 // #################################################################################
181 Int_t AliHLTAnaManagerComponent::DoDeinit() {
182   // see header file for class documentation
183
184   fUID = 0;
185   fAnalysisManager->SetSkipTerminate(kTRUE);
186   fAnalysisManager->Terminate();
187
188   delete fAnalysisManager;
189
190   return 0;
191 }
192
193 // #################################################################################
194 Int_t AliHLTAnaManagerComponent::DoEvent(const AliHLTComponentEventData& evtData,
195                                         AliHLTComponentTriggerData& /*trigData*/) {
196   // see header file for class documentation
197
198   printf("AliHLTAnaManagerComponent::DoEvent\n");
199   Int_t iResult=0;
200
201   // -- Only use data event
202   if (!IsDataEvent()) 
203     return 0;
204   
205   if( fUID == 0 ){
206     TTimeStamp t;
207     fUID = ( gSystem->GetPid() + t.GetNanoSec())*10 + evtData.fEventID;
208   }
209   
210   // -- Get ESD object
211   // -------------------
212   AliESDEvent *esdEvent = NULL;
213   AliESDfriend *esdFriend = NULL;
214   for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDObject); iter != NULL; iter = GetNextInputObject() ) {
215     esdEvent = dynamic_cast<AliESDEvent*>(const_cast<TObject*>( iter ) );
216     if( !esdEvent ){ 
217       HLTWarning("Wrong ESDEvent object received");
218       iResult = -1;
219       continue;
220     }
221     esdEvent->GetStdContent();
222   }
223   if (esdEvent) printf("----> ESDEvent %p has %d tracks: \n", esdEvent, esdEvent->GetNumberOfTracks());
224   else printf("----> No ESDEvent found\n");
225   for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDfriendObject); iter != NULL; iter = GetNextInputObject() ) {
226     esdFriend = dynamic_cast<AliESDfriend*>(const_cast<TObject*>( iter ) );
227     if( !esdFriend ){ 
228       HLTWarning("Wrong ESDFriend object received");
229       iResult = -1;
230       continue;
231     }
232   }
233   printf("----> ESDFriend %p has %d tracks: \n", esdFriend, esdFriend->GetNumberOfTracks());
234
235   fAnalysisManager->InitInputData(esdEvent, esdFriend);
236   //  fInputHandler->BeginEvent(0);
237   fAnalysisManager->ExecAnalysis();
238   fInputHandler->FinishEvent();
239
240
241   // -- Send histlist
242 //  PushBack(dynamic_cast<TObject*>(fCorrObj->GetHistList()),
243 //         kAliHLTDataTypeTObject|kAliHLTDataOriginHLT,fUID);
244  
245   return iResult;
246 }
247
248 // #################################################################################
249 Int_t AliHLTAnaManagerComponent::Reconfigure(const Char_t* cdbEntry, const Char_t* chainId) {
250   // see header file for class documentation
251
252   Int_t iResult=0;
253   TString cdbPath;
254   if (cdbEntry) {
255     cdbPath=cdbEntry;
256   } else {
257     cdbPath="HLT/ConfigGlobal/";
258     cdbPath+=GetComponentID();
259   }
260
261   AliInfoClass(Form("reconfigure '%s' from entry %s%s", chainId, cdbPath.Data(), cdbEntry?"":" (default)"));
262   iResult=ConfigureFromCDBTObjString(cdbPath);
263
264   return iResult;
265 }
266
267 // #################################################################################
268 Int_t AliHLTAnaManagerComponent::ReadPreprocessorValues(const Char_t* /*modules*/) {
269   // see header file for class documentation
270   ALIHLTERRORGUARD(5, "ReadPreProcessorValues not implemented for this component");
271   return 0;
272 }
273