3 //**************************************************************************
4 //* This file is property of and copyright by the *
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
25 #include "AliHLTSampleESDAnalysisComponent.h"
26 #include "AliESDEvent.h"
27 #include "AliESDtrack.h"
30 #include "TObjString.h"
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTSampleESDAnalysisComponent)
37 /** one global instance used for registration of
38 * AliHLTSampleESDAnalysisComponent
39 * Note: there are two ways of component registration
40 * - via a global object
41 * - via the AliHLTModuleAgent::RegisterComponents function
42 * @see @ref alihlt_component_registration
44 AliHLTSampleESDAnalysisComponent gAliHLTSampleESDAnalysisComponent;
46 AliHLTSampleESDAnalysisComponent::AliHLTSampleESDAnalysisComponent()
48 // an example component which implements the ALICE HLT processor
49 // interface and does some analysis on the input ESD
51 // see header file for class documentation
53 // refer to README to build package
55 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57 // NOTE: all helper classes should be instantiated in DoInit()
60 AliHLTSampleESDAnalysisComponent::~AliHLTSampleESDAnalysisComponent()
64 // NOTE: implement proper cleanup in DoDeinit()
67 const char* AliHLTSampleESDAnalysisComponent::GetComponentID()
69 // component property: id
70 return "SampleESDAnalysis";
73 void AliHLTSampleESDAnalysisComponent::GetInputDataTypes( AliHLTComponentDataTypeList& list)
75 // component property: list of input data types
76 list.push_back(kAliHLTDataTypeESDObject);
79 AliHLTComponentDataType AliHLTSampleESDAnalysisComponent::GetOutputDataType()
81 // component property: output data type
82 return kAliHLTDataTypeTObjArray|kAliHLTDataOriginSample;
85 void AliHLTSampleESDAnalysisComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
87 // component property: output size estimator
92 void AliHLTSampleESDAnalysisComponent::GetOCDBObjectDescription( TMap* const targetMap)
94 // Get a list of OCDB object description.
95 // The list of objects is provided in a TMap
96 // - key: complete OCDB path, e.g. GRP/GRP/Data
97 // - value: short description why the object is needed
98 // Key and value objects created inside this class go into ownership of
100 if (!targetMap) return;
101 targetMap->Add(new TObjString("HLT/ConfigSample/SampleESDAnalysis"),
102 new TObjString("configuration object"));
103 targetMap->Add(new TObjString("GRP/GRP/Data"),
104 new TObjString("GRP object"));
107 AliHLTComponent* AliHLTSampleESDAnalysisComponent::Spawn()
109 // Spawn function, return new class instance
110 return new AliHLTSampleESDAnalysisComponent;
113 int AliHLTSampleESDAnalysisComponent::DoInit( int argc, const char** argv )
115 // see header file for class documentation
118 // init stage 1: default values for all data members
120 // init stage 2: read configuration object
121 // ScanConfigurationArgument() needs to be implemented
122 TString cdbPath="HLT/ConfigSample/";
123 cdbPath+=GetComponentID();
124 iResult=ConfigureFromCDBTObjString(cdbPath);
126 // init stage 3: read the component arguments
128 iResult=ConfigureFromArgumentString(argc, argv);
132 // implement the component initialization
142 int AliHLTSampleESDAnalysisComponent::ScanConfigurationArgument(int argc, const char** argv)
144 // Scan configuration arguments
145 // Return the number of processed arguments
146 // -EPROTO if argument format error (e.g. number expected but not found)
148 // The AliHLTComponent base class implements a parsing loop for argument strings and
149 // arrays of strings which is invoked by ConfigureFromArgumentString/ConfigureFromCDBTObjString
150 // The component needs to implement ScanConfigurationArgument in order to decode the arguments.
153 TString argument=argv[i];
155 if (argument.IsNull()) return 0;
158 if (argument.CompareTo("-mandatory1")==0) {
159 if (++i>=argc) return -EINVAL;
160 HLTInfo("got \'-mandatory1\' argument: %s", argv[i]);
161 return 2; // keyword + 1 argument
165 if (argument.CompareTo("-optional1")==0) {
166 if (++i>=argc) return -EINVAL;
167 HLTInfo("got \'-optional1\' argument: %s", argv[i]);
168 return 2; // keyword + 1 argument
172 if (argument.CompareTo("-optional2")==0) {
173 HLTInfo("got \'-optional2\' argument");
174 return 1; // only keyword
180 int AliHLTSampleESDAnalysisComponent::DoDeinit()
182 // component cleanup, delete all instances of helper classes here
187 int AliHLTSampleESDAnalysisComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
188 AliHLTComponentTriggerData& /*trigData*/)
190 // event processing function
192 // check if this is a data event, there are a couple of special events
193 // which should be ignored for normal processing
194 if (!IsDataEvent()) return 0;
196 TObjArray output; // an array for publishing the tracks as separate output
198 AliInfoClass(Form("==================== event %3d ================================", GetEventCount()));
199 for (const TObject* obj = GetFirstInputObject();
201 obj = GetNextInputObject()) {
202 AliInfoClass(Form("object: %s", obj->GetName()));
203 if (obj->IsA()==AliESDEvent::Class()) {
204 // input objects are not supposed to be changed by the component, so they
205 // are defined const. However, the implementation of AliESDEvent does not
206 // support this and we need the const_cast
207 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(const_cast<TObject*>(obj));
209 esd->GetStdContent();
210 for (Int_t i = 0; i < esd->GetNumberOfTracks(); i++) {
211 AliESDtrack* track = esd->GetTrack(i);
212 AliInfoClass(Form("-------------------- track %3d --------------------------------", i));
220 // publish the array of tracks as output
221 PushBack(&output, kAliHLTDataTypeTObjArray|kAliHLTDataOriginSample);
226 int AliHLTSampleESDAnalysisComponent::Reconfigure(const char* cdbEntry, const char* chainId)
228 // reconfigure the component from the specified CDB entry, or default CDB entry
229 HLTInfo("reconfigure '%s' from entry %s", chainId, cdbEntry);
234 int AliHLTSampleESDAnalysisComponent::ReadPreprocessorValues(const char* modules)
236 // read the preprocessor values for the detectors in the modules list
238 TString detectors(modules!=NULL?modules:"");
239 HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());