]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/SampleLib/AliHLTSampleESDAnalysisComponent.cxx
Bugfix, make sure m2 of invariant mass pair is positive
[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 */
40 AliHLTSampleESDAnalysisComponent gAliHLTSampleESDAnalysisComponent;
41
42 AliHLTSampleESDAnalysisComponent::AliHLTSampleESDAnalysisComponent()
43 {
44   // an example component which implements the ALICE HLT processor
45   // interface and does some analysis on the input ESD
46   //
47   // see header file for class documentation
48   // or
49   // refer to README to build package
50   // or
51   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
52   //
53   // NOTE: all helper classes should be instantiated in DoInit()
54 }
55
56 AliHLTSampleESDAnalysisComponent::~AliHLTSampleESDAnalysisComponent()
57 {
58   // destructor
59   //
60   // NOTE: implement proper cleanup in DoDeinit()
61 }
62
63 const char* AliHLTSampleESDAnalysisComponent::GetComponentID()
64
65   // component property: id
66   return "SampleESDAnalysis";
67 }
68
69 void AliHLTSampleESDAnalysisComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
70 {
71   // component property: list of input data types
72     list.push_back(kAliHLTDataTypeESDObject);
73 }
74
75 AliHLTComponentDataType AliHLTSampleESDAnalysisComponent::GetOutputDataType()
76 {
77   // component property: output data type
78   return kAliHLTDataTypeTObjArray|kAliHLTDataOriginSample;
79 }
80
81 void AliHLTSampleESDAnalysisComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
82 {
83   // component property: output size estimator
84   constBase = 0;
85   inputMultiplier = 0;
86 }
87
88 void AliHLTSampleESDAnalysisComponent::GetOCDBObjectDescription( TMap* const targetMap)
89 {
90   // Get a list of OCDB object description.
91   // The list of objects is provided in a TMap
92   // - key: complete OCDB path, e.g. GRP/GRP/Data
93   // - value: short description why the object is needed
94   // Key and value objects created inside this class go into ownership of
95   // target TMap.
96   if (!targetMap) return;
97   targetMap->Add(new TObjString("HLT/ConfigSample/SampleESDAnalysis"),
98                 new TObjString("configuration object"));
99   targetMap->Add(new TObjString("GRP/GRP/Data"),
100                 new TObjString("GRP object"));
101 }
102
103 AliHLTComponent* AliHLTSampleESDAnalysisComponent::Spawn()
104 {
105   // Spawn function, return new class instance
106   return new AliHLTSampleESDAnalysisComponent;
107 }
108
109 int AliHLTSampleESDAnalysisComponent::DoInit( int argc, const char** argv )
110 {
111   // see header file for class documentation
112   int iResult=0;
113
114   // init stage 1: default values for all data members
115
116   // init stage 2: read configuration object
117   // ScanConfigurationArgument() needs to be implemented
118   TString cdbPath="HLT/ConfigSample/";
119   cdbPath+=GetComponentID();
120   iResult=ConfigureFromCDBTObjString(cdbPath);
121
122   // init stage 3: read the component arguments
123   if (iResult>=0) {
124     iResult=ConfigureFromArgumentString(argc, argv);
125   }
126
127   if (iResult>=0) {
128     // implement the component initialization
129   }
130
131   if (iResult<0) {
132     // implement cleanup
133   }
134
135   return iResult;
136 }
137
138 int AliHLTSampleESDAnalysisComponent::ScanConfigurationArgument(int argc, const char** argv)
139 {
140   // Scan configuration arguments
141   // Return the number of processed arguments
142   //        -EPROTO if argument format error (e.g. number expected but not found)
143   //
144   // The AliHLTComponent base class implements a parsing loop for argument strings and
145   // arrays of strings which is invoked by ConfigureFromArgumentString/ConfigureFromCDBTObjString
146   // The component needs to implement ScanConfigurationArgument in order to decode the arguments.
147
148   int i=0;
149   TString argument=argv[i];
150
151   if (argument.IsNull()) return 0;
152
153   // -mandatory1 arg
154   if (argument.CompareTo("-mandatory1")==0) {
155     if (++i>=argc) return -EINVAL;
156     HLTInfo("got \'-mandatory1\' argument: %s", argv[i]);
157     return 2; // keyword + 1 argument
158   }
159
160   // -optional1 arg
161   if (argument.CompareTo("-optional1")==0) {
162     if (++i>=argc) return -EINVAL;
163     HLTInfo("got \'-optional1\' argument: %s", argv[i]);
164     return 2; // keyword + 1 argument
165   }
166
167   // -optional2
168   if (argument.CompareTo("-optional2")==0) {
169     HLTInfo("got \'-optional2\' argument");
170     return 1; // only keyword
171   }
172
173   return 0;
174 }
175
176 int AliHLTSampleESDAnalysisComponent::DoDeinit()
177 {
178   // component cleanup, delete all instances of helper classes here
179
180   return 0;
181 }
182
183 int AliHLTSampleESDAnalysisComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
184                                               AliHLTComponentTriggerData& /*trigData*/)
185 {
186   // event processing function
187
188   // check if this is a data event, there are a couple of special events
189   // which should be ignored for normal processing
190   if (!IsDataEvent()) return 0;
191
192   const TObject* obj = GetFirstInputObject(kAliHLTAllDataTypes, "AliESDEvent");
193
194   // input objects are not supposed to be changed by the component, so they
195   // are defined const. However, the implementation of AliESDEvent does not
196   // support this and we need the const_cast
197   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(const_cast<TObject*>(obj));
198   TObjArray output;
199   if (esd != NULL) {
200     AliInfoClass(Form("==================== event %3d ================================", GetEventCount()));
201     esd->GetStdContent();
202     for (Int_t i = 0; i < esd->GetNumberOfTracks(); i++) {
203       AliESDtrack* track = esd->GetTrack(i);
204       AliInfoClass(Form("-------------------- track %3d --------------------------------", i));
205       track->Print("");
206       output.Add(track);
207     }
208   }
209
210   // publish the array of tracks as output
211   PushBack(&output, kAliHLTDataTypeTObjArray|kAliHLTDataOriginSample);
212
213   return 0;
214 }
215
216 int AliHLTSampleESDAnalysisComponent::Reconfigure(const char* cdbEntry, const char* chainId)
217 {
218   // reconfigure the component from the specified CDB entry, or default CDB entry
219   HLTInfo("reconfigure '%s' from entry %s", chainId, cdbEntry);
220
221   return 0;
222 }
223
224 int AliHLTSampleESDAnalysisComponent::ReadPreprocessorValues(const char* modules)
225 {
226   // read the preprocessor values for the detectors in the modules list
227   int iResult=0;
228   TString detectors(modules!=NULL?modules:"");
229   HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());
230   return iResult;
231 }