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