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