]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/SampleLib/AliHLTSampleComponent1.cxx
Adding output data type of rootifier component to the constants class.
[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
25 #if __GNUC__== 3
26 using namespace std;
27 #endif
28
29 #include "AliHLTSampleComponent1.h"
30 #include "TString.h"
31 #include "TObjString.h"
32 #include "TObjArray.h"
33 #include "AliCDBEntry.h"
34 #include "AliCDBManager.h"
35
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTSampleComponent1)
38
39 AliHLTSampleComponent1::AliHLTSampleComponent1()
40 {
41   // see header file for class documentation
42   // or
43   // refer to README to build package
44   // or
45   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
46 }
47
48 AliHLTSampleComponent1::~AliHLTSampleComponent1()
49 {
50   // see header file for class documentation
51 }
52
53 int AliHLTSampleComponent1::DoInit( int argc, const char** argv )
54 {
55   // see header file for class documentation
56   int iResult=0;
57   HLTInfo("parsing %d arguments", argc);
58
59   TString argument="";
60   TString configuration=""; 
61   int bMissingParam=0;
62   bool bHaveMandatory1=false;
63   bool bHaveMandatory2=false;
64   for (int i=0; i<argc && iResult>=0; i++) {
65     argument=argv[i];
66     if (argument.IsNull()) continue;
67
68     // -mandatory1
69     if (argument.CompareTo("-mandatory1")==0) {
70       bHaveMandatory1|=1;
71       if ((bMissingParam=(++i>=argc))) break;
72       HLTInfo("got \'-mandatory1\' argument: %s", argv[i]);
73
74       // -mandatory2
75     } else if (argument.CompareTo("-mandatory2")==0) {
76       bHaveMandatory2|=1;
77       HLTInfo("got \'-mandatory2\' argument");
78
79       // -optional1
80     } else if (argument.CompareTo("-optional1")==0) {
81       if ((bMissingParam=(++i>=argc))) break;
82       HLTInfo("got \'-optional1\' argument: %s", argv[i]);
83
84       // -optional2
85     } else if (argument.CompareTo("-optional2")==0) {
86       HLTInfo("got \'-optional2\' argument");
87
88     } else {
89       // the remaining arguments are treated as configuration
90       if (!configuration.IsNull()) configuration+=" ";
91       configuration+=argument;
92     }
93   }
94   if (bMissingParam) {
95     HLTError("missing parameter for argument %s", argument.Data());
96     iResult=-EINVAL;
97   }
98
99   if (iResult>=0 && !bHaveMandatory1) {
100     HLTError("mandatory argument \'-mandatory1\' missing");
101     iResult=-EPROTO;
102   }
103   if (iResult>=0 && !bHaveMandatory2) {
104     HLTError("mandatory argument \'-mandatory2\' missing");
105     iResult=-EPROTO;
106   }
107   if (iResult>=0 && !configuration.IsNull()) {
108     iResult=Configure(configuration.Data());
109   } else {
110     iResult=Reconfigure(NULL, NULL);
111   }
112
113   return iResult;
114 }
115
116 int AliHLTSampleComponent1::DoDeinit()
117 {
118   // see header file for class documentation
119   HLTInfo("processing cleanup");
120   return 0;
121 }
122
123 int AliHLTSampleComponent1::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
124                                       AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
125                                       AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) {
126   // see header file for class documentation
127   HLTInfo("processing data");
128   if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0 &&
129       outputPtr==0 && size==0)
130   {
131     outputBlocks.clear();
132     // this is just to get rid of the warning "unused parameter"
133   }
134   return 0;
135 }
136
137 int AliHLTSampleComponent1::Configure(const char* arguments)
138 {
139   // see header file for class documentation
140   int iResult=0;
141   if (!arguments) return iResult;
142   HLTInfo("parsing configuration string \'%s\'", arguments);
143
144   TString allArgs=arguments;
145   TString argument;
146   int bMissingParam=0;
147
148   TObjArray* pTokens=allArgs.Tokenize(" ");
149   if (pTokens) {
150     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
151       argument=((TObjString*)pTokens->At(i))->GetString();
152       if (argument.IsNull()) continue;
153
154       // -config1
155       if (argument.CompareTo("-config1")==0) {
156         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
157         HLTInfo("got \'-config1\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
158
159         // -config2
160       } else if (argument.CompareTo("-config2")==0) {
161         HLTInfo("got \'-config2\'");
162       } else {
163         HLTError("unknown argument %s", argument.Data());
164         iResult=-EINVAL;
165         break;
166       }
167     }
168     delete pTokens;
169   }
170   if (bMissingParam) {
171     HLTError("missing parameter for argument %s", argument.Data());
172     iResult=-EINVAL;
173   }
174   return iResult;
175 }
176
177 int AliHLTSampleComponent1::Reconfigure(const char* cdbEntry, const char* chainId)
178 {
179   // see header file for class documentation
180   int iResult=0;
181   const char* path="HLT/ConfigSample/SampleComponent1";
182   const char* defaultNotify="";
183   if (cdbEntry) {
184     path=cdbEntry;
185     defaultNotify=" (default)";
186   }
187   if (path) {
188     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
189     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
190     if (pEntry) {
191       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
192       if (pString) {
193         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
194         iResult=Configure(pString->GetString().Data());
195       } else {
196         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
197       }
198     } else {
199       HLTError("can not fetch object \"%s\" from CDB", path);
200     }
201   }
202   return iResult;
203 }
204
205 int AliHLTSampleComponent1::ReadPreprocessorValues(const char* modules)
206 {
207   // see header file for class documentation
208   int iResult=0;
209   TString detectors(modules!=NULL?modules:"");
210   HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());
211   return iResult;
212 }