]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/SampleLib/AliHLTDummyComponent.cxx
following suggestions by gcc 4.3
[u/mrichter/AliRoot.git] / HLT / SampleLib / AliHLTDummyComponent.cxx
CommitLineData
71d7c760 1// $Id$
2
3/**************************************************************************
9be2600f 4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
71d7c760 6 * *
9be2600f 7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
9 * for The ALICE HLT Project. *
71d7c760 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
b22e91eb 20/** @file AliHLTDummyComponent.cxx
21 @author Timm Steinbeck, Matthias Richter
22 @date
23 @brief A dummy processing component for the HLT. */
71d7c760 24
f32b83e1 25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
71d7c760 31#if __GNUC__ >= 3
32using namespace std;
33#endif
34
2d7ff710 35#include "AliHLTSystem.h"
71d7c760 36#include "AliHLTDummyComponent.h"
66043029 37#include "AliHLTDefinitions.h"
f3506ea2 38#include <cstdlib>
39#include <cerrno>
71d7c760 40
f3506ea2 41/** ROOT macro for the implementation of ROOT specific class methods */
71d7c760 42ClassImp(AliHLTDummyComponent)
43
44AliHLTDummyComponent::AliHLTDummyComponent()
2d7ff710 45 :
46 fOutputPercentage(100) // By default we copy to the output exactly what we got as input
71d7c760 47 {
c7500dae 48 // see header file for class documentation
49 // or
50 // refer to README to build package
51 // or
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
71d7c760 53 }
54
55AliHLTDummyComponent::~AliHLTDummyComponent()
56 {
c7500dae 57 // see header file for class documentation
71d7c760 58 }
59
60const char* AliHLTDummyComponent::GetComponentID()
61 {
c7500dae 62 // see header file for class documentation
71d7c760 63 return "Dummy"; // The ID of this component
64 }
65
8ede8717 66void AliHLTDummyComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
71d7c760 67 {
c7500dae 68 // see header file for class documentation
9ce4bf4a 69 /* in order to be backward compatible we have to keep the old code, at
70 * least for a while. Remember to use the new const kAliHLTVoidDataType
71 * if you are using a more recent AliRoot version (from Jan 07)
72 list.push_back(kAliHLTAnyDataType); // We do not have any requirements for our input data type(s).
73 */
8b250b0e 74
75 AliHLTComponentDataType dt =
76 { sizeof(AliHLTComponentDataType),
77 {'*','*','*','*','*','*','*','\0'},
78 {'*','*','*','\0'}};
79 list.push_back(dt);
71d7c760 80 }
81
8ede8717 82AliHLTComponentDataType AliHLTDummyComponent::GetOutputDataType()
71d7c760 83 {
c7500dae 84 // see header file for class documentation
9ce4bf4a 85 /* in order to be backward compatible we have to keep the old code, at
86 * least for a while. Remember to use the new const kAliHLTVoidDataType
87 * if you are using a more recent AliRoot version (from Jan 07)
88 return kAliHLTVoidDataType;
89 */
8b250b0e 90 AliHLTComponentDataType dt =
91 { sizeof(AliHLTComponentDataType),
92 {'\0','\0','\0','0','\0','\0','\0','\0'},
93 {'\0','\0','\0','\0'}};
94 return dt;
71d7c760 95 }
96
97void AliHLTDummyComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
98 {
c7500dae 99 // see header file for class documentation
71d7c760 100 constBase = 0;
101 inputMultiplier = ((double)fOutputPercentage)/100.0;
102 }
103
104
105
106// Spawn function, return new instance of this class
107AliHLTComponent* AliHLTDummyComponent::Spawn()
108 {
c7500dae 109 // see header file for class documentation
71d7c760 110 return new AliHLTDummyComponent;
2d7ff710 111 }
71d7c760 112
113int AliHLTDummyComponent::DoInit( int argc, const char** argv )
114 {
115 // perform initialization. We check whether our relative output size is specified in the arguments.
116 fOutputPercentage = 100;
117 int i = 0;
118 char* cpErr;
119 while ( i < argc )
120 {
833b3167 121 HLTDebug("argv[%d] == %s", i, argv[i] );
122 if ( !strcmp( argv[i], "output_percentage" ) ||
123 !strcmp( argv[i], "-output_percentage" ))
71d7c760 124 {
125 if ( i+1>=argc )
126 {
833b3167 127 HLTError("Missing output_percentage parameter");
128 return -EINVAL;
71d7c760 129 }
833b3167 130 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
71d7c760 131 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
132 if ( *cpErr )
133 {
833b3167 134 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
135 return -EINVAL;
71d7c760 136 }
833b3167 137 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
71d7c760 138 i += 2;
139 continue;
140 }
833b3167 141 HLTError("Unknown option '%s'", argv[i] );
142 return -EINVAL;
71d7c760 143 }
144 return 0;
145 }
146
147int AliHLTDummyComponent::DoDeinit()
148 {
c7500dae 149 // see header file for class documentation
71d7c760 150 return 0;
151 }
152
8ede8717 153int AliHLTDummyComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
d76bc02a 154 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
8ede8717 155 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
71d7c760 156 {
c7500dae 157 // see header file for class documentation
833b3167 158 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
71d7c760 159 // Process an event
160 unsigned long totalSize = 0;
161 // Loop over all input blocks in the event
162 for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
163 {
164 // Align the beginning of this block to the required value.
165 if ( totalSize % kAliHLTBlockAlignment )
166 totalSize += kAliHLTBlockAlignment-(totalSize % kAliHLTBlockAlignment);
167 if ( totalSize > size )
168 break;
169 // Determine the size we should use for the output for this block (the input block's size times the relative output size)
170 unsigned long mySize = (blocks[n].fSize * fOutputPercentage) / 100;
833b3167 171 HLTInfo("HLT::Dummy::DoEvent", "mySize set (1)", "mySize == %lu B - blocks[%lu].fSize == %lu - fOutputPercentage == %lu",
71d7c760 172 mySize, n, blocks[n].fSize, fOutputPercentage );
173 // Check how much space we have left and adapt this output block's size accordingly.
174 if ( totalSize + mySize > size )
175 mySize = size-totalSize;
833b3167 176 HLTInfo("HLT::Dummy::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu",
71d7c760 177 mySize, totalSize, size );
178 if ( mySize<=0 )
179 continue; // No room left to write a further block.
180 // Now copy the input block
181 unsigned long copied = 0;
182 // First copy all full multiples of the input block
183 while ( copied+blocks[n].fSize <= mySize )
184 {
833b3167 185 HLTInfo("Copying %lu B - Copied: %lu B - totalSize: %lu B",
71d7c760 186 blocks[n].fSize, copied, totalSize );
187 memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, blocks[n].fSize );
188 copied += blocks[n].fSize;
189 }
190 // And the copy the remaining fragment of the block
833b3167 191 HLTInfo("Copying %lu B - Copied: %lu B - totalSize: %lu B",
71d7c760 192 mySize-copied, copied, totalSize );
193 memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, mySize-copied );
833b3167 194 HLTInfo("Copied: %lu B - totalSize: %lu B",
71d7c760 195 copied, totalSize );
196 // Fill a block data structure for our output block.
8ede8717 197 AliHLTComponentBlockData ob;
71d7c760 198 // Let the structure be filled with the default values.
199 // This takes care of setting the shared memory and data type values to default values,
200 // so that they can be filled in by the calling code.
201 FillBlockData( ob );
202 // This block's start (offset) is after all other blocks written so far
203 ob.fOffset = totalSize;
204 // the size of this block's data.
205 ob.fSize = mySize;
ba2aabd0 206 // the data type of this block
207 ob.fDataType=blocks[n].fDataType;
71d7c760 208 // The specification of the data is copied from the input block.
209 ob.fSpecification = blocks[n].fSpecification;
210 // The data type is set automatically to the component's specified output data type.
211 // Place this block into the list of output blocks
212 outputBlocks.push_back( ob );
213 // Increase the total amount of data written so far to our output memory
214 totalSize += mySize;
215 }
216 // Finally we set the total size of output memory we consumed.
217 size = totalSize;
218 return 0;
219 }