3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
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 AliHLTDataGenerator.cxx
20 @author Matthias Richter
22 @brief HLT file publisher component implementation. */
24 // see header file for class documentation
26 // refer to README to build package
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
34 #include "AliHLTDataGenerator.h"
37 /** ROOT macro for the implementation of ROOT specific class methods */
38 ClassImp(AliHLTDataGenerator)
40 AliHLTDataGenerator::AliHLTDataGenerator()
43 fDataType(kAliHLTVoidDataType),
44 fSpecification(~(AliHLTUInt32_t)0),
52 // see header file for class documentation
54 // refer to README to build package
56 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58 // make the lists owners of their objects in order to automatically
59 // de-allocate the objects
62 AliHLTDataGenerator::~AliHLTDataGenerator()
64 // see header file for class documentation
68 const char* AliHLTDataGenerator::GetComponentID()
70 // see header file for class documentation
71 return "DataGenerator";
74 AliHLTComponentDataType AliHLTDataGenerator::GetOutputDataType()
76 // see header file for class documentation
77 return kAliHLTMultipleDataType;
80 int AliHLTDataGenerator::GetOutputDataTypes(vector<AliHLTComponentDataType>& tgtList)
82 // see header file for class documentation
85 tgtList.push_back(fDataType);
89 void AliHLTDataGenerator::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
91 // see header file for class documentation
92 constBase=fCurrSize+fRange;
96 AliHLTComponent* AliHLTDataGenerator::Spawn()
98 // see header file for class documentation
99 return new AliHLTDataGenerator;
102 int AliHLTDataGenerator::DoInit( int argc, const char** argv )
104 // see header file for class documentation
106 //HLTDebug("%d %s", argc, argv[0]);
110 for (int i=0; i<argc && iResult>=0; i++) {
112 if (argument.IsNull()) continue;
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])));
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);
132 HLTError("wrong parameter for argument %s, number expected", argument.Data());
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());
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());
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());
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());
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());
171 if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) {
172 HLTError("unknown argument %s", argument.Data());
174 } else if (iResult==-EPROTO) {
177 } else if (iResult>=0) {
185 HLTError("missing parameter for argument %s", argument.Data());
194 int AliHLTDataGenerator::ScanSizeArgument(AliHLTUInt32_t &size, const char* arg)
196 // see header file for class documentation
199 TString parameter(arg);
200 AliHLTUInt32_t base=1;
201 parameter.Remove(TString::kLeading, ' '); // remove all blanks
202 if (parameter.EndsWith("k")) {
204 parameter.Remove(TString::kTrailing, 'k');
205 } else if (parameter.EndsWith("M")) {
206 base=0x100000; // one M
207 parameter.Remove(TString::kTrailing, 'M');
209 if (parameter.IsDigit()) {
210 size=(AliHLTUInt32_t)parameter.Atoi()*base;
220 int AliHLTDataGenerator::ScanArgument(int argc, const char** argv)
222 // see header file for class documentation
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"
231 int AliHLTDataGenerator::DoDeinit()
233 // see header file for class documentation
238 int AliHLTDataGenerator::GetEvent( const AliHLTComponentEventData& /*evtData*/,
239 AliHLTComponentTriggerData& /*trigData*/,
240 AliHLTUInt8_t* outputPtr,
241 AliHLTUInt32_t& size,
242 vector<AliHLTComponentBlockData>& outputBlocks )
244 // see header file for class documentation
246 AliHLTUInt32_t generated=fCurrSize;
247 if (generated<=size ) {
248 AliHLTComponentBlockData bd;
253 bd.fDataType=fDataType;
254 bd.fSpecification=fSpecification;
255 outputBlocks.push_back(bd);
258 if (fModulo>0 && ((GetEventCount()+1)%fModulo)==0) {
259 // manipulate the size
262 if (fCurrSize==0) fCurrSize=fSize; //reset
265 if (fCurrSize<fSubtractor) {
266 fCurrSize=fSize; // reset
268 fCurrSize-=fSubtractor;
271 HLTDebug("manipulated output size: %d", fCurrSize);