]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/util/AliHLTDataGenerator.cxx
added collector component and HLTOUT handler for component statistics blocks and
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTDataGenerator.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  *                  for The ALICE HLT Project.                            *
9  *                                                                        *
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  **************************************************************************/
18
19 /** @file   AliHLTDataGenerator.cxx
20     @author Matthias Richter
21     @date   
22     @brief  HLT file publisher component implementation. */
23
24 // see header file for class documentation
25 // or
26 // refer to README to build package
27 // or
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29
30 #if __GNUC__>= 3
31 using namespace std;
32 #endif
33
34 #include "AliHLTDataGenerator.h"
35 #include "TString.h"
36
37 /** ROOT macro for the implementation of ROOT specific class methods */
38 ClassImp(AliHLTDataGenerator)
39
40 AliHLTDataGenerator::AliHLTDataGenerator()
41   :
42   AliHLTDataSource(),
43   fDataType(kAliHLTVoidDataType),
44   fSpecification(~(AliHLTUInt32_t)0),
45   fSize(0),
46   fCurrSize(0),
47   fRange(0),
48   fDivisor(0),
49   fSubtractor(0),
50   fModulo(0)
51 {
52   // see header file for class documentation
53   // or
54   // refer to README to build package
55   // or
56   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57
58   // make the lists owners of their objects in order to automatically
59   // de-allocate the objects
60 }
61
62 AliHLTDataGenerator::~AliHLTDataGenerator()
63 {
64   // see header file for class documentation
65
66 }
67
68 const char* AliHLTDataGenerator::GetComponentID()
69 {
70   // see header file for class documentation
71   return "DataGenerator";
72 }
73
74 AliHLTComponentDataType AliHLTDataGenerator::GetOutputDataType()
75 {
76   // see header file for class documentation
77   return kAliHLTMultipleDataType;
78 }
79
80 int AliHLTDataGenerator::GetOutputDataTypes(vector<AliHLTComponentDataType>& tgtList)
81 {
82   // see header file for class documentation
83   int count=0;
84   tgtList.clear();
85   tgtList.push_back(fDataType);
86   return count;
87 }
88
89 void AliHLTDataGenerator::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
90 {
91   // see header file for class documentation
92   constBase=fCurrSize+fRange;
93   inputMultiplier=1.0;
94 }
95
96 AliHLTComponent* AliHLTDataGenerator::Spawn()
97 {
98   // see header file for class documentation
99   return new AliHLTDataGenerator;
100 }
101
102 int AliHLTDataGenerator::DoInit( int argc, const char** argv )
103 {
104   // see header file for class documentation
105
106   //HLTDebug("%d %s", argc, argv[0]);
107   int iResult=0;
108   TString argument="";
109   int bMissingParam=0;
110   for (int i=0; i<argc && iResult>=0; i++) {
111     argument=argv[i];
112     if (argument.IsNull()) continue;
113
114     // -datatype
115     if (argument.CompareTo("-datatype")==0) {
116       if ((bMissingParam=(++i>=argc))) break;
117       memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
118       if ((bMissingParam=(++i>=argc))) break;
119       memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
120
121       // -dataspec
122     } else if (argument.CompareTo("-dataspec")==0) {
123       if ((bMissingParam=(++i>=argc))) break;
124       TString parameter(argv[i]);
125       parameter.Remove(TString::kLeading, ' '); // remove all blanks
126       if (parameter.IsDigit()) {
127         fSpecification=(AliHLTUInt32_t)parameter.Atoi();
128       } else if (parameter.BeginsWith("0x") &&
129                  parameter.Replace(0,2,"",0).IsHex()) {
130         sscanf(parameter.Data(),"%x", &fSpecification);
131       } else {
132         HLTError("wrong parameter for argument %s, number expected", argument.Data());
133         iResult=-EINVAL;
134       }
135       // -size
136     } else if (argument.CompareTo("-size")==0) {
137       if ((bMissingParam=(++i>=argc))) break;
138       if ((iResult=ScanSizeArgument(fSize, argv[i]))==-ERANGE) {
139         HLTError("wrong parameter for argument %s, number expected", argument.Data());
140         iResult=-EINVAL;
141       }
142       // -range
143     } else if (argument.CompareTo("-range")==0) {
144       if ((bMissingParam=(++i>=argc))) break;
145       if ((iResult=ScanSizeArgument(fRange, argv[i]))==-ERANGE) {
146         HLTError("wrong parameter for argument %s, number expected", argument.Data());
147         iResult=-EINVAL;
148       }
149       // -divisor
150     } else if (argument.CompareTo("-divisor")==0) {
151       if ((bMissingParam=(++i>=argc))) break;
152       if ((iResult=ScanSizeArgument(fDivisor, argv[i]))==-ERANGE) {
153         HLTError("wrong parameter for argument %s, number expected", argument.Data());
154         iResult=-EINVAL;
155       }
156       // -offset
157     } else if (argument.CompareTo("-offset")==0) {
158       if ((bMissingParam=(++i>=argc))) break;
159       if ((iResult=ScanSizeArgument(fSubtractor, argv[i]))==-ERANGE) {
160         HLTError("wrong parameter for argument %s, number expected", argument.Data());
161         iResult=-EINVAL;
162       }
163       // -modulo
164     } else if (argument.CompareTo("-modulo")==0) {
165       if ((bMissingParam=(++i>=argc))) break;
166       if ((iResult=ScanSizeArgument(fModulo, argv[i]))==-ERANGE) {
167         HLTError("wrong parameter for argument %s, number expected", argument.Data());
168         iResult=-EINVAL;
169       }
170     } else {
171       if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) {
172         HLTError("unknown argument %s", argument.Data());
173         break;
174       } else if (iResult==-EPROTO) {
175         bMissingParam=1;
176         break;
177       } else if (iResult>=0) {
178         i+=iResult;
179         iResult=0;
180       }
181     }
182   }
183
184   if (bMissingParam) {
185     HLTError("missing parameter for argument %s", argument.Data());
186     iResult=-EINVAL;
187   }
188
189   fCurrSize=fSize;
190
191   return iResult;
192 }
193
194 int AliHLTDataGenerator::ScanSizeArgument(AliHLTUInt32_t &size, const char* arg)
195 {
196   // see header file for class documentation
197   int iResult=0;
198   if (arg) {
199     TString parameter(arg);
200     AliHLTUInt32_t base=1;
201     parameter.Remove(TString::kLeading, ' '); // remove all blanks
202     if (parameter.EndsWith("k")) {
203       base=0x400; // one k
204       parameter.Remove(TString::kTrailing, 'k');
205     } else if (parameter.EndsWith("M")) {
206       base=0x100000; // one M
207       parameter.Remove(TString::kTrailing, 'M');
208     }
209     if (parameter.IsDigit()) {
210       size=(AliHLTUInt32_t)parameter.Atoi()*base;
211     } else {
212       iResult=-ERANGE;
213     }
214   } else {
215     iResult=-EINVAL;
216   }
217   return iResult;
218 }
219
220 int AliHLTDataGenerator::ScanArgument(int argc, const char** argv)
221 {
222   // see header file for class documentation
223
224   // there are no other arguments than the standard ones
225   if (argc==0 && argv==NULL) {
226     // this is just to get rid of the warning "unused parameter"
227   }
228   return -EPROTO;
229 }
230
231 int AliHLTDataGenerator::DoDeinit()
232 {
233   // see header file for class documentation
234   int iResult=0;
235   return iResult;
236 }
237
238 int AliHLTDataGenerator::GetEvent( const AliHLTComponentEventData& /*evtData*/,
239                                    AliHLTComponentTriggerData& /*trigData*/,
240                                    AliHLTUInt8_t* outputPtr, 
241                                    AliHLTUInt32_t& size,
242                                    vector<AliHLTComponentBlockData>& outputBlocks )
243 {
244   // see header file for class documentation
245   int iResult=0;
246   AliHLTUInt32_t generated=fCurrSize;
247   if (generated<=size ) {
248     AliHLTComponentBlockData bd;
249     FillBlockData(bd);
250     bd.fPtr=outputPtr;
251     bd.fOffset=0;
252     bd.fSize=generated;
253     bd.fDataType=fDataType;
254     bd.fSpecification=fSpecification;
255     outputBlocks.push_back(bd);
256     size=generated;
257
258     if (fModulo>0 && ((GetEventCount()+1)%fModulo)==0) {
259       // manipulate the size
260       if (fDivisor>0) {
261         fCurrSize/=fDivisor;
262         if (fCurrSize==0) fCurrSize=fSize; //reset
263       }
264       if (fSubtractor>0) {
265         if (fCurrSize<fSubtractor) {
266           fCurrSize=fSize; // reset
267         } else {
268           fCurrSize-=fSubtractor;
269         }
270       }
271       HLTDebug("manipulated output size: %d", fCurrSize);
272     }
273
274   } else {
275     iResult=-ENOSPC;
276   }
277
278   return iResult;
279 }