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. */
28 #include "AliHLTDataGenerator.h"
31 /** the global object for component registration */
32 AliHLTDataGenerator gAliHLTDataGenerator;
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTDataGenerator)
37 AliHLTDataGenerator::AliHLTDataGenerator()
40 fDataType(kAliHLTVoidDataType),
41 fSpecification(~(AliHLTUInt32_t)0),
49 // see header file for class documentation
51 // refer to README to build package
53 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 // make the lists owners of their objects in order to automatically
56 // de-allocate the objects
59 AliHLTDataGenerator::~AliHLTDataGenerator()
61 // see header file for class documentation
65 const char* AliHLTDataGenerator::GetComponentID()
67 // see header file for class documentation
68 return "DataGenerator";
71 AliHLTComponentDataType AliHLTDataGenerator::GetOutputDataType()
73 // see header file for class documentation
74 return kAliHLTMultipleDataType;
77 int AliHLTDataGenerator::GetOutputDataTypes(vector<AliHLTComponentDataType>& tgtList)
81 tgtList.push_back(fDataType);
85 void AliHLTDataGenerator::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
87 // see header file for class documentation
88 constBase=fCurrSize+fRange;
92 AliHLTComponent* AliHLTDataGenerator::Spawn()
94 // see header file for class documentation
95 return new AliHLTDataGenerator;
98 int AliHLTDataGenerator::DoInit( int argc, const char** argv )
100 // see header file for class documentation
102 //HLTDebug("%d %s", argc, argv[0]);
106 for (int i=0; i<argc && iResult>=0; i++) {
108 if (argument.IsNull()) continue;
111 if (argument.CompareTo("-datatype")==0) {
112 if ((bMissingParam=(++i>=argc))) break;
113 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
114 if ((bMissingParam=(++i>=argc))) break;
115 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
118 } else if (argument.CompareTo("-dataspec")==0) {
119 if ((bMissingParam=(++i>=argc))) break;
120 TString parameter(argv[i]);
121 parameter.Remove(TString::kLeading, ' '); // remove all blanks
122 if (parameter.IsDigit()) {
123 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
124 } else if (parameter.BeginsWith("0x") &&
125 parameter.Replace(0,2,"",0).IsHex()) {
126 sscanf(parameter.Data(),"%x", &fSpecification);
128 HLTError("wrong parameter for argument %s, number expected", argument.Data());
132 } else if (argument.CompareTo("-size")==0) {
133 if ((bMissingParam=(++i>=argc))) break;
134 if ((iResult=ScanSizeArgument(fSize, argv[i]))==-ERANGE) {
135 HLTError("wrong parameter for argument %s, number expected", argument.Data());
139 } else if (argument.CompareTo("-range")==0) {
140 if ((bMissingParam=(++i>=argc))) break;
141 if ((iResult=ScanSizeArgument(fRange, argv[i]))==-ERANGE) {
142 HLTError("wrong parameter for argument %s, number expected", argument.Data());
146 } else if (argument.CompareTo("-divisor")==0) {
147 if ((bMissingParam=(++i>=argc))) break;
148 if ((iResult=ScanSizeArgument(fDivisor, argv[i]))==-ERANGE) {
149 HLTError("wrong parameter for argument %s, number expected", argument.Data());
153 } else if (argument.CompareTo("-offset")==0) {
154 if ((bMissingParam=(++i>=argc))) break;
155 if ((iResult=ScanSizeArgument(fSubtractor, argv[i]))==-ERANGE) {
156 HLTError("wrong parameter for argument %s, number expected", argument.Data());
160 } else if (argument.CompareTo("-modulo")==0) {
161 if ((bMissingParam=(++i>=argc))) break;
162 if ((iResult=ScanSizeArgument(fModulo, argv[i]))==-ERANGE) {
163 HLTError("wrong parameter for argument %s, number expected", argument.Data());
167 if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) {
168 HLTError("unknown argument %s", argument.Data());
170 } else if (iResult==-EPROTO) {
173 } else if (iResult>=0) {
181 HLTError("missing parameter for argument %s", argument.Data());
190 int AliHLTDataGenerator::ScanSizeArgument(AliHLTUInt32_t &size, const char* arg)
194 TString parameter(arg);
195 AliHLTUInt32_t base=1;
196 parameter.Remove(TString::kLeading, ' '); // remove all blanks
197 if (parameter.EndsWith("k")) {
199 parameter.Remove(TString::kTrailing, 'k');
200 } else if (parameter.EndsWith("M")) {
201 base=0x100000; // one M
202 parameter.Remove(TString::kTrailing, 'M');
204 if (parameter.IsDigit()) {
205 size=(AliHLTUInt32_t)parameter.Atoi()*base;
215 int AliHLTDataGenerator::ScanArgument(int argc, const char** argv)
217 // see header file for class documentation
219 // there are no other arguments than the standard ones
220 if (argc==0 && argv==NULL) {
221 // this is just to get rid of the warning "unused parameter"
226 int AliHLTDataGenerator::DoDeinit()
228 // see header file for class documentation
233 int AliHLTDataGenerator::GetEvent( const AliHLTComponentEventData& /*evtData*/,
234 AliHLTComponentTriggerData& /*trigData*/,
235 AliHLTUInt8_t* outputPtr,
236 AliHLTUInt32_t& size,
237 vector<AliHLTComponentBlockData>& outputBlocks )
240 AliHLTUInt32_t generated=fCurrSize;
241 if (generated<=size ) {
242 AliHLTComponentBlockData bd;
247 bd.fDataType=fDataType;
248 bd.fSpecification=fSpecification;
249 outputBlocks.push_back(bd);
252 if (fModulo>0 && ((GetEventCount()+1)%fModulo)==0) {
253 // manipulate the size
256 if (fCurrSize==0) fCurrSize=fSize; //reset
259 if (fCurrSize<fSubtractor) {
260 fCurrSize=fSize; // reset
262 fCurrSize-=fSubtractor;
265 HLTDebug("manipulated output size: %d", fCurrSize);