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