]>
Commit | Line | Data |
---|---|---|
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 |
32 | using 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 | 42 | ClassImp(AliHLTDummyComponent) |
43 | ||
44 | AliHLTDummyComponent::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 | ||
55 | AliHLTDummyComponent::~AliHLTDummyComponent() | |
56 | { | |
c7500dae | 57 | // see header file for class documentation |
71d7c760 | 58 | } |
59 | ||
60 | const char* AliHLTDummyComponent::GetComponentID() | |
61 | { | |
c7500dae | 62 | // see header file for class documentation |
71d7c760 | 63 | return "Dummy"; // The ID of this component |
64 | } | |
65 | ||
8ede8717 | 66 | void AliHLTDummyComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) |
71d7c760 | 67 | { |
c7500dae | 68 | // see header file for class documentation |
289c6c1a | 69 | list.push_back(kAliHLTAnyDataType); // We do not have any requirements for our input data type(s). |
8b250b0e | 70 | |
71d7c760 | 71 | } |
72 | ||
8ede8717 | 73 | AliHLTComponentDataType AliHLTDummyComponent::GetOutputDataType() |
71d7c760 | 74 | { |
c7500dae | 75 | // see header file for class documentation |
9ce4bf4a | 76 | /* in order to be backward compatible we have to keep the old code, at |
77 | * least for a while. Remember to use the new const kAliHLTVoidDataType | |
78 | * if you are using a more recent AliRoot version (from Jan 07) | |
79 | return kAliHLTVoidDataType; | |
80 | */ | |
8b250b0e | 81 | AliHLTComponentDataType dt = |
82 | { sizeof(AliHLTComponentDataType), | |
83 | {'\0','\0','\0','0','\0','\0','\0','\0'}, | |
84 | {'\0','\0','\0','\0'}}; | |
85 | return dt; | |
71d7c760 | 86 | } |
87 | ||
88 | void AliHLTDummyComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
89 | { | |
c7500dae | 90 | // see header file for class documentation |
71d7c760 | 91 | constBase = 0; |
92 | inputMultiplier = ((double)fOutputPercentage)/100.0; | |
93 | } | |
94 | ||
95 | ||
96 | ||
97 | // Spawn function, return new instance of this class | |
98 | AliHLTComponent* AliHLTDummyComponent::Spawn() | |
99 | { | |
c7500dae | 100 | // see header file for class documentation |
71d7c760 | 101 | return new AliHLTDummyComponent; |
2d7ff710 | 102 | } |
71d7c760 | 103 | |
104 | int AliHLTDummyComponent::DoInit( int argc, const char** argv ) | |
105 | { | |
106 | // perform initialization. We check whether our relative output size is specified in the arguments. | |
107 | fOutputPercentage = 100; | |
108 | int i = 0; | |
109 | char* cpErr; | |
110 | while ( i < argc ) | |
111 | { | |
833b3167 | 112 | HLTDebug("argv[%d] == %s", i, argv[i] ); |
113 | if ( !strcmp( argv[i], "output_percentage" ) || | |
114 | !strcmp( argv[i], "-output_percentage" )) | |
71d7c760 | 115 | { |
116 | if ( i+1>=argc ) | |
117 | { | |
833b3167 | 118 | HLTError("Missing output_percentage parameter"); |
119 | return -EINVAL; | |
71d7c760 | 120 | } |
833b3167 | 121 | HLTDebug("argv[%d+1] == %s", i, argv[i+1] ); |
71d7c760 | 122 | fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 ); |
123 | if ( *cpErr ) | |
124 | { | |
833b3167 | 125 | HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] ); |
126 | return -EINVAL; | |
71d7c760 | 127 | } |
833b3167 | 128 | HLTInfo("Output percentage set to %lu %%", fOutputPercentage ); |
71d7c760 | 129 | i += 2; |
130 | continue; | |
131 | } | |
833b3167 | 132 | HLTError("Unknown option '%s'", argv[i] ); |
133 | return -EINVAL; | |
71d7c760 | 134 | } |
135 | return 0; | |
136 | } | |
137 | ||
138 | int AliHLTDummyComponent::DoDeinit() | |
139 | { | |
c7500dae | 140 | // see header file for class documentation |
71d7c760 | 141 | return 0; |
142 | } | |
143 | ||
8ede8717 | 144 | int AliHLTDummyComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, |
d76bc02a | 145 | AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, |
8ede8717 | 146 | AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) |
71d7c760 | 147 | { |
c7500dae | 148 | // see header file for class documentation |
833b3167 | 149 | HLTInfo("Output percentage set to %lu %%", fOutputPercentage ); |
71d7c760 | 150 | // Process an event |
151 | unsigned long totalSize = 0; | |
152 | // Loop over all input blocks in the event | |
153 | for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ ) | |
154 | { | |
155 | // Align the beginning of this block to the required value. | |
156 | if ( totalSize % kAliHLTBlockAlignment ) | |
157 | totalSize += kAliHLTBlockAlignment-(totalSize % kAliHLTBlockAlignment); | |
158 | if ( totalSize > size ) | |
159 | break; | |
160 | // Determine the size we should use for the output for this block (the input block's size times the relative output size) | |
161 | unsigned long mySize = (blocks[n].fSize * fOutputPercentage) / 100; | |
833b3167 | 162 | HLTInfo("HLT::Dummy::DoEvent", "mySize set (1)", "mySize == %lu B - blocks[%lu].fSize == %lu - fOutputPercentage == %lu", |
71d7c760 | 163 | mySize, n, blocks[n].fSize, fOutputPercentage ); |
164 | // Check how much space we have left and adapt this output block's size accordingly. | |
165 | if ( totalSize + mySize > size ) | |
166 | mySize = size-totalSize; | |
833b3167 | 167 | HLTInfo("HLT::Dummy::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu", |
71d7c760 | 168 | mySize, totalSize, size ); |
169 | if ( mySize<=0 ) | |
170 | continue; // No room left to write a further block. | |
171 | // Now copy the input block | |
172 | unsigned long copied = 0; | |
173 | // First copy all full multiples of the input block | |
174 | while ( copied+blocks[n].fSize <= mySize ) | |
175 | { | |
833b3167 | 176 | HLTInfo("Copying %lu B - Copied: %lu B - totalSize: %lu B", |
71d7c760 | 177 | blocks[n].fSize, copied, totalSize ); |
178 | memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, blocks[n].fSize ); | |
179 | copied += blocks[n].fSize; | |
180 | } | |
181 | // And the copy the remaining fragment of the block | |
833b3167 | 182 | HLTInfo("Copying %lu B - Copied: %lu B - totalSize: %lu B", |
71d7c760 | 183 | mySize-copied, copied, totalSize ); |
184 | memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, mySize-copied ); | |
833b3167 | 185 | HLTInfo("Copied: %lu B - totalSize: %lu B", |
71d7c760 | 186 | copied, totalSize ); |
187 | // Fill a block data structure for our output block. | |
8ede8717 | 188 | AliHLTComponentBlockData ob; |
71d7c760 | 189 | // Let the structure be filled with the default values. |
190 | // This takes care of setting the shared memory and data type values to default values, | |
191 | // so that they can be filled in by the calling code. | |
192 | FillBlockData( ob ); | |
193 | // This block's start (offset) is after all other blocks written so far | |
194 | ob.fOffset = totalSize; | |
195 | // the size of this block's data. | |
196 | ob.fSize = mySize; | |
ba2aabd0 | 197 | // the data type of this block |
198 | ob.fDataType=blocks[n].fDataType; | |
71d7c760 | 199 | // The specification of the data is copied from the input block. |
200 | ob.fSpecification = blocks[n].fSpecification; | |
201 | // The data type is set automatically to the component's specified output data type. | |
202 | // Place this block into the list of output blocks | |
203 | outputBlocks.push_back( ob ); | |
204 | // Increase the total amount of data written so far to our output memory | |
205 | totalSize += mySize; | |
206 | } | |
207 | // Finally we set the total size of output memory we consumed. | |
208 | size = totalSize; | |
209 | return 0; | |
210 | } |