]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/SampleLib/AliHLTSampleESDAnalysisComponent.cxx
adding option -skip-esd-object, removes specified objects form the ESD content before...
[u/mrichter/AliRoot.git] / HLT / SampleLib / AliHLTSampleESDAnalysisComponent.cxx
1 // $Id$
2
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: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /// @file   AliHLTSampleESDAnalysisComponent.cxx
20 /// @author Matthias Richter
21 /// @date   2010-04-17
22 /// @brief  A sample processing component for ESD analysis.
23 /// @ingroup alihlt_tutorial
24
25 #if __GNUC__== 3
26 using namespace std;
27 #endif
28
29 #include "AliHLTSampleESDAnalysisComponent.h"
30 #include "AliESDEvent.h"
31 #include "AliESDtrack.h"
32 #include "AliLog.h"
33 #include "TMap.h"
34 #include "TObjString.h"
35
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTSampleESDAnalysisComponent)
38
39 /** one global instance used for  registration of
40  * AliHLTSampleESDAnalysisComponent
41  * Note: there are two ways of component registration
42  * - via a global object
43  * - via the AliHLTModuleAgent::RegisterComponents function
44  * @see @ref alihlt_component_registration
45  */
46 AliHLTSampleESDAnalysisComponent gAliHLTSampleESDAnalysisComponent;
47
48 AliHLTSampleESDAnalysisComponent::AliHLTSampleESDAnalysisComponent()
49 {
50   // an example component which implements the ALICE HLT processor
51   // interface and does some analysis on the input ESD
52   //
53   // see header file for class documentation
54   // or
55   // refer to README to build package
56   // or
57   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58   //
59   // NOTE: all helper classes should be instantiated in DoInit()
60 }
61
62 AliHLTSampleESDAnalysisComponent::~AliHLTSampleESDAnalysisComponent()
63 {
64   // destructor
65   //
66   // NOTE: implement proper cleanup in DoDeinit()
67 }
68
69 const char* AliHLTSampleESDAnalysisComponent::GetComponentID()
70
71   // component property: id
72   return "SampleESDAnalysis";
73 }
74
75 void AliHLTSampleESDAnalysisComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
76 {
77   // component property: list of input data types
78   list.push_back(kAliHLTDataTypeESDObject);
79 }
80
81 AliHLTComponentDataType AliHLTSampleESDAnalysisComponent::GetOutputDataType()
82 {
83   // component property: output data type
84   return kAliHLTDataTypeTObjArray|kAliHLTDataOriginSample;
85 }
86
87 void AliHLTSampleESDAnalysisComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
88 {
89   // component property: output size estimator
90   constBase = 0;
91   inputMultiplier = 0;
92 }
93
94 void AliHLTSampleESDAnalysisComponent::GetOCDBObjectDescription( TMap* const targetMap)
95 {
96   // Get a list of OCDB object description.
97   // The list of objects is provided in a TMap
98   // - key: complete OCDB path, e.g. GRP/GRP/Data
99   // - value: short description why the object is needed
100   // Key and value objects created inside this class go into ownership of
101   // target TMap.
102   if (!targetMap) return;
103   targetMap->Add(new TObjString("HLT/ConfigSample/SampleESDAnalysis"),
104                 new TObjString("configuration object"));
105   targetMap->Add(new TObjString("GRP/GRP/Data"),
106                 new TObjString("GRP object"));
107 }
108
109 AliHLTComponent* AliHLTSampleESDAnalysisComponent::Spawn()
110 {
111   // Spawn function, return new class instance
112   return new AliHLTSampleESDAnalysisComponent;
113 }
114
115 int AliHLTSampleESDAnalysisComponent::DoInit( int argc, const char** argv )
116 {
117   // see header file for class documentation
118   int iResult=0;
119
120   // init stage 1: default values for all data members
121
122   // init stage 2: read configuration object
123   // ScanConfigurationArgument() needs to be implemented
124   TString cdbPath="HLT/ConfigSample/";
125   cdbPath+=GetComponentID();
126   iResult=ConfigureFromCDBTObjString(cdbPath);
127
128   // init stage 3: read the component arguments
129   if (iResult>=0) {
130     iResult=ConfigureFromArgumentString(argc, argv);
131   }
132
133   if (iResult>=0) {
134     // implement the component initialization
135   }
136
137   if (iResult<0) {
138     // implement cleanup
139   }
140
141   return iResult;
142 }
143
144 int AliHLTSampleESDAnalysisComponent::ScanConfigurationArgument(int argc, const char** argv)
145 {
146   // Scan configuration arguments
147   // Return the number of processed arguments
148   //        -EPROTO if argument format error (e.g. number expected but not found)
149   //
150   // The AliHLTComponent base class implements a parsing loop for argument strings and
151   // arrays of strings which is invoked by ConfigureFromArgumentString/ConfigureFromCDBTObjString
152   // The component needs to implement ScanConfigurationArgument in order to decode the arguments.
153
154   int i=0;
155   TString argument=argv[i];
156
157   if (argument.IsNull()) return 0;
158
159   // -mandatory1 arg
160   if (argument.CompareTo("-mandatory1")==0) {
161     if (++i>=argc) return -EINVAL;
162     HLTInfo("got \'-mandatory1\' argument: %s", argv[i]);
163     return 2; // keyword + 1 argument
164   }
165
166   // -optional1 arg
167   if (argument.CompareTo("-optional1")==0) {
168     if (++i>=argc) return -EINVAL;
169     HLTInfo("got \'-optional1\' argument: %s", argv[i]);
170     return 2; // keyword + 1 argument
171   }
172
173   // -optional2
174   if (argument.CompareTo("-optional2")==0) {
175     HLTInfo("got \'-optional2\' argument");
176     return 1; // only keyword
177   }
178
179   return 0;
180 }
181
182 int AliHLTSampleESDAnalysisComponent::DoDeinit()
183 {
184   // component cleanup, delete all instances of helper classes here
185
186   return 0;
187 }
188
189 int AliHLTSampleESDAnalysisComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
190                                               AliHLTComponentTriggerData& /*trigData*/)
191 {
192   // event processing function
193
194   // check if this is a data event, there are a couple of special events
195   // which should be ignored for normal processing
196   if (!IsDataEvent()) return 0;
197
198   const TObject* obj = GetFirstInputObject(kAliHLTAllDataTypes, "AliESDEvent");
199
200   // input objects are not supposed to be changed by the component, so they
201   // are defined const. However, the implementation of AliESDEvent does not
202   // support this and we need the const_cast
203   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(const_cast<TObject*>(obj));
204   TObjArray output;
205   if (esd != NULL) {
206     AliInfoClass(Form("==================== event %3d ================================", GetEventCount()));
207     esd->GetStdContent();
208     for (Int_t i = 0; i < esd->GetNumberOfTracks(); i++) {
209       AliESDtrack* track = esd->GetTrack(i);
210       AliInfoClass(Form("-------------------- track %3d --------------------------------", i));
211       track->Print("");
212       output.Add(track);
213     }
214   }
215
216   // publish the array of tracks as output
217   PushBack(&output, kAliHLTDataTypeTObjArray|kAliHLTDataOriginSample);
218
219   return 0;
220 }
221
222 int AliHLTSampleESDAnalysisComponent::Reconfigure(const char* cdbEntry, const char* chainId)
223 {
224   // reconfigure the component from the specified CDB entry, or default CDB entry
225   HLTInfo("reconfigure '%s' from entry %s", chainId, cdbEntry);
226
227   return 0;
228 }
229
230 int AliHLTSampleESDAnalysisComponent::ReadPreprocessorValues(const char* modules)
231 {
232   // read the preprocessor values for the detectors in the modules list
233   int iResult=0;
234   TString detectors(modules!=NULL?modules:"");
235   HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());
236   return iResult;
237 }