3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /// @file AliHLTSampleESDAnalysisComponent.cxx
20 /// @author Matthias Richter
22 /// @brief A sample processing component for ESD analysis.
23 /// @ingroup alihlt_tutorial
29 #include "AliHLTSampleESDAnalysisComponent.h"
30 #include "AliESDEvent.h"
31 #include "AliESDtrack.h"
34 #include "TObjString.h"
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTSampleESDAnalysisComponent)
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
46 AliHLTSampleESDAnalysisComponent gAliHLTSampleESDAnalysisComponent;
48 AliHLTSampleESDAnalysisComponent::AliHLTSampleESDAnalysisComponent()
50 // an example component which implements the ALICE HLT processor
51 // interface and does some analysis on the input ESD
53 // see header file for class documentation
55 // refer to README to build package
57 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
59 // NOTE: all helper classes should be instantiated in DoInit()
62 AliHLTSampleESDAnalysisComponent::~AliHLTSampleESDAnalysisComponent()
66 // NOTE: implement proper cleanup in DoDeinit()
69 const char* AliHLTSampleESDAnalysisComponent::GetComponentID()
71 // component property: id
72 return "SampleESDAnalysis";
75 void AliHLTSampleESDAnalysisComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
77 // component property: list of input data types
78 list.push_back(kAliHLTDataTypeESDObject);
81 AliHLTComponentDataType AliHLTSampleESDAnalysisComponent::GetOutputDataType()
83 // component property: output data type
84 return kAliHLTDataTypeTObjArray|kAliHLTDataOriginSample;
87 void AliHLTSampleESDAnalysisComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
89 // component property: output size estimator
94 void AliHLTSampleESDAnalysisComponent::GetOCDBObjectDescription( TMap* const targetMap)
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
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"));
109 AliHLTComponent* AliHLTSampleESDAnalysisComponent::Spawn()
111 // Spawn function, return new class instance
112 return new AliHLTSampleESDAnalysisComponent;
115 int AliHLTSampleESDAnalysisComponent::DoInit( int argc, const char** argv )
117 // see header file for class documentation
120 // init stage 1: default values for all data members
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);
128 // init stage 3: read the component arguments
130 iResult=ConfigureFromArgumentString(argc, argv);
134 // implement the component initialization
144 int AliHLTSampleESDAnalysisComponent::ScanConfigurationArgument(int argc, const char** argv)
146 // Scan configuration arguments
147 // Return the number of processed arguments
148 // -EPROTO if argument format error (e.g. number expected but not found)
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.
155 TString argument=argv[i];
157 if (argument.IsNull()) return 0;
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
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
174 if (argument.CompareTo("-optional2")==0) {
175 HLTInfo("got \'-optional2\' argument");
176 return 1; // only keyword
182 int AliHLTSampleESDAnalysisComponent::DoDeinit()
184 // component cleanup, delete all instances of helper classes here
189 int AliHLTSampleESDAnalysisComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
190 AliHLTComponentTriggerData& /*trigData*/)
192 // event processing function
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;
198 const TObject* obj = GetFirstInputObject(kAliHLTAllDataTypes, "AliESDEvent");
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));
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));
216 // publish the array of tracks as output
217 PushBack(&output, kAliHLTDataTypeTObjArray|kAliHLTDataOriginSample);
222 int AliHLTSampleESDAnalysisComponent::Reconfigure(const char* cdbEntry, const char* chainId)
224 // reconfigure the component from the specified CDB entry, or default CDB entry
225 HLTInfo("reconfigure '%s' from entry %s", chainId, cdbEntry);
230 int AliHLTSampleESDAnalysisComponent::ReadPreprocessorValues(const char* modules)
232 // read the preprocessor values for the detectors in the modules list
234 TString detectors(modules!=NULL?modules:"");
235 HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());