]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/SampleLib/AliHLTSampleComponent1.cxx
updated SampleComponent to the latest interface version, code cleanup, update of...
[u/mrichter/AliRoot.git] / HLT / SampleLib / AliHLTSampleComponent1.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 //*                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
9 //*                  for The ALICE HLT Project.                            *
10 //*                                                                        *
11 //* Permission to use, copy, modify and distribute this software and its   *
12 //* documentation strictly for non-commercial purposes is hereby granted   *
13 //* without fee, provided that the above copyright notice appears in all   *
14 //* copies and that both the copyright notice and this permission notice   *
15 //* appear in the supporting documentation. The authors make no claims     *
16 //* about the suitability of this software for any purpose. It is          *
17 //* provided "as is" without express or implied warranty.                  *
18 //**************************************************************************
19
20 //  @file   AliHLTSampleComponent1.cxx
21 //  @author Matthias Richter, Timm M. Steinbeck
22 //  @date   
23 //  @brief  A sample processing component for the HLT.
24 //          Component illustrates the basic functionality and component
25 //          initialization. 
26
27 #if __GNUC__== 3
28 using namespace std;
29 #endif
30
31 #include "AliHLTSampleComponent1.h"
32 #include "TString.h"
33 #include "TObjString.h"
34 #include "TMap.h"
35
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTSampleComponent1)
38
39 /** one global instance used for registration */
40 AliHLTSampleComponent1 gAliHLTSampleComponent1;
41
42 AliHLTSampleComponent1::AliHLTSampleComponent1()
43   : AliHLTProcessor()
44   , fArgument1(0)
45   , fArgument2(0)
46 {
47   // an example component which implements the ALICE HLT processor
48   // interface and illustrates the basic interface methods
49   //
50   // see header file for class documentation
51   // or
52   // refer to README to build package
53   // or
54   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55   //
56   // NOTE: all helper classes should be instantiated in DoInit()
57 }
58
59 AliHLTSampleComponent1::~AliHLTSampleComponent1()
60 {
61   // destructor
62   //
63   // NOTE: implement proper cleanup in DoDeinit()
64 }
65
66 const char* AliHLTSampleComponent1::GetComponentID()
67
68   // component property: id
69   return "Sample-component1";
70 }
71
72 void AliHLTSampleComponent1::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
73 {
74   // component property: list of input data types
75     list.push_back(kAliHLTAnyDataType);
76 }
77
78 AliHLTComponentDataType AliHLTSampleComponent1::GetOutputDataType()
79 {
80   // component property: output data type
81   return kAliHLTVoidDataType;
82 }
83
84 void AliHLTSampleComponent1::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
85 {
86   // component property: output size estimator
87   constBase = 0;
88   inputMultiplier = 0;
89 }
90
91 void AliHLTSampleComponent1::GetOCDBObjectDescription( TMap* const targetMap)
92 {
93   // Get a list of OCDB object description.
94   // The list of objects is provided in a TMap
95   // - key: complete OCDB path, e.g. GRP/GRP/Data
96   // - value: short description why the object is needed
97   // Key and value objects created inside this class go into ownership of
98   // target TMap.
99   if (!targetMap) return;
100   targetMap->Add(new TObjString("HLT/ConfigSample/SampleComponent1"),
101                  new TObjString("configuration object"));
102 }
103
104 AliHLTComponent* AliHLTSampleComponent1::Spawn()
105 {
106   // Spawn function, return new class instance
107   return new AliHLTSampleComponent1;
108 }
109
110 int AliHLTSampleComponent1::DoInit( int argc, const char** argv )
111 {
112   // see header file for class documentation
113   int iResult=0;
114
115   // init stage 1: default values for all data members
116   fArgument1=0;
117   fArgument2=0;
118
119   // init stage 2: read configuration object
120   // ScanConfigurationArgument() needs to be implemented
121   TString cdbPath="HLT/ConfigSample/SampleComponent1";
122   iResult=ConfigureFromCDBTObjString(cdbPath);
123
124   // init stage 3: read the component arguments
125   if (iResult>=0) {
126     iResult=ConfigureFromArgumentString(argc, argv);
127   }
128
129   if (iResult>=0) {
130     // implement the component initialization
131     if (!fArgument1) {
132       HLTError("mandatory argument \'-mandatory1\' missing");
133       iResult=-EPROTO;
134     }
135     if (!fArgument2) {
136       HLTError("mandatory argument \'-mandatory2\' missing");
137       iResult=-EPROTO;
138     }
139   }
140
141   if (iResult<0) {
142     // implement cleanup
143   }
144
145   return iResult;
146 }
147
148 int AliHLTSampleComponent1::ScanConfigurationArgument( int argc, const char** argv )
149 {
150   // see header file for class documentation
151   int iResult=0;
152
153   TString argument="";
154   TString configuration=""; 
155   int bMissingParam=0;
156   int i=0;
157     argument=argv[i];
158     if (argument.IsNull()) return 0;
159
160     // -mandatory1
161     if (argument.CompareTo("-mandatory1")==0) {
162       if (++i>=argc) return -EPROTO;
163       HLTInfo("got \'-mandatory1\' argument: %s", argv[i]);
164       fArgument1=1;
165
166       // -mandatory2
167     } else if (argument.CompareTo("-mandatory2")==0) {
168       fArgument2=1;
169       HLTInfo("got \'-mandatory2\' argument");
170
171       // -config1
172     } else if (argument.CompareTo("-config1")==0) {
173       if (++i>=argc) return -EPROTO;
174       HLTInfo("got \'%s\' argument: %s", argument.Data(), argv[i]);
175
176       // -config2
177     } else if (argument.CompareTo("-config2")==0) {
178       HLTInfo("got \'%s\' argument", argument.Data());
179
180     } else {
181       // no recognized argument
182       i--;
183     }
184
185   return i+1;
186 }
187
188 int AliHLTSampleComponent1::DoDeinit()
189 {
190   // see header file for class documentation
191   HLTInfo("processing cleanup");
192   return 0;
193 }
194
195 int AliHLTSampleComponent1::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
196                                       AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
197                                       AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) {
198   // see header file for class documentation
199   HLTInfo("processing data");
200   if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0 &&
201       outputPtr==0 && size==0)
202   {
203     outputBlocks.clear();
204     // this is just to get rid of the warning "unused parameter"
205   }
206   return 0;
207 }
208 int AliHLTSampleComponent1::Reconfigure(const char* cdbEntry, const char* chainId)
209 {
210   // see header file for class documentation
211   int iResult=0;
212   const char* path="HLT/ConfigSample/SampleComponent1";
213   const char* defaultNotify="";
214   if (cdbEntry) {
215     path=cdbEntry;
216     defaultNotify=" (default)";
217   }
218
219   HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
220   iResult=ConfigureFromCDBTObjString(path);
221
222   return iResult;
223 }
224
225 int AliHLTSampleComponent1::ReadPreprocessorValues(const char* modules)
226 {
227   // see header file for class documentation
228   int iResult=0;
229   TString detectors(modules!=NULL?modules:"");
230   HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());
231   return iResult;
232 }