]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/SampleLib/AliHLTSampleComponent1.cxx
5f00ffadad0e94e46111945b5081862a83204ed6
[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   TString argument="";
152   TString configuration=""; 
153   int i=0;
154     argument=argv[i];
155     if (argument.IsNull()) return 0;
156
157     // -mandatory1
158     if (argument.CompareTo("-mandatory1")==0) {
159       if (++i>=argc) return -EPROTO;
160       HLTInfo("got \'-mandatory1\' argument: %s", argv[i]);
161       fArgument1=1;
162
163       // -mandatory2
164     } else if (argument.CompareTo("-mandatory2")==0) {
165       fArgument2=1;
166       HLTInfo("got \'-mandatory2\' argument");
167
168       // -config1
169     } else if (argument.CompareTo("-config1")==0) {
170       if (++i>=argc) return -EPROTO;
171       HLTInfo("got \'%s\' argument: %s", argument.Data(), argv[i]);
172
173       // -config2
174     } else if (argument.CompareTo("-config2")==0) {
175       HLTInfo("got \'%s\' argument", argument.Data());
176
177     } else {
178       // no recognized argument
179       i--;
180     }
181
182   return i+1;
183 }
184
185 int AliHLTSampleComponent1::DoDeinit()
186 {
187   // see header file for class documentation
188   HLTInfo("processing cleanup");
189   return 0;
190 }
191
192 int AliHLTSampleComponent1::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
193                                       AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
194                                       AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) {
195   // see header file for class documentation
196   HLTInfo("processing data");
197   if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0 &&
198       outputPtr==0 && size==0)
199   {
200     outputBlocks.clear();
201     // this is just to get rid of the warning "unused parameter"
202   }
203   return 0;
204 }
205 int AliHLTSampleComponent1::Reconfigure(const char* cdbEntry, const char* chainId)
206 {
207   // see header file for class documentation
208   int iResult=0;
209   const char* path="HLT/ConfigSample/SampleComponent1";
210   const char* defaultNotify="";
211   if (cdbEntry) {
212     path=cdbEntry;
213     defaultNotify=" (default)";
214   }
215
216   HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
217   iResult=ConfigureFromCDBTObjString(path);
218
219   return iResult;
220 }
221
222 int AliHLTSampleComponent1::ReadPreprocessorValues(const char* modules)
223 {
224   // see header file for class documentation
225   int iResult=0;
226   TString detectors(modules!=NULL?modules:"");
227   HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());
228   return iResult;
229 }