3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
9 * for The ALICE HLT Project. *
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 **************************************************************************/
20 /** @file AliHLTDummyComponent.cxx
21 @author Timm Steinbeck, Matthias Richter
23 @brief A dummy processing component for the HLT. */
29 #include "AliHLTSystem.h"
30 #include "AliHLTDummyComponent.h"
31 #include "AliHLTDefinitions.h"
35 // this is a global object used for automatic component registration, do not use this
36 AliHLTDummyComponent gAliHLTDummyComponent;
38 ClassImp(AliHLTDummyComponent)
40 AliHLTDummyComponent::AliHLTDummyComponent()
42 fOutputPercentage(100) // By default we copy to the output exactly what we got as input
46 AliHLTDummyComponent::~AliHLTDummyComponent()
50 const char* AliHLTDummyComponent::GetComponentID()
52 return "Dummy"; // The ID of this component
55 void AliHLTDummyComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
57 /* in order to be backward compatible we have to keep the old code, at
58 * least for a while. Remember to use the new const kAliHLTVoidDataType
59 * if you are using a more recent AliRoot version (from Jan 07)
60 list.push_back(kAliHLTAnyDataType); // We do not have any requirements for our input data type(s).
63 AliHLTComponentDataType dt =
64 { sizeof(AliHLTComponentDataType),
65 {'*','*','*','*','*','*','*','\0'},
70 AliHLTComponentDataType AliHLTDummyComponent::GetOutputDataType()
72 /* in order to be backward compatible we have to keep the old code, at
73 * least for a while. Remember to use the new const kAliHLTVoidDataType
74 * if you are using a more recent AliRoot version (from Jan 07)
75 return kAliHLTVoidDataType;
77 AliHLTComponentDataType dt =
78 { sizeof(AliHLTComponentDataType),
79 {'\0','\0','\0','0','\0','\0','\0','\0'},
80 {'\0','\0','\0','\0'}};
84 void AliHLTDummyComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
87 inputMultiplier = ((double)fOutputPercentage)/100.0;
92 // Spawn function, return new instance of this class
93 AliHLTComponent* AliHLTDummyComponent::Spawn()
95 return new AliHLTDummyComponent;
98 int AliHLTDummyComponent::DoInit( int argc, const char** argv )
100 // perform initialization. We check whether our relative output size is specified in the arguments.
101 fOutputPercentage = 100;
106 Logging( kHLTLogDebug, "HLT::Dummy::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
107 if ( !strcmp( argv[i], "output_percentage" ) )
111 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Missing Argument", "Missing output_percentage parameter");
114 Logging( kHLTLogDebug, "HLT::Dummy::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
115 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
118 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
121 Logging( kHLTLogInfo, "HLT::Dummy::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
125 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
131 int AliHLTDummyComponent::DoDeinit()
136 int AliHLTDummyComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
137 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
138 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
140 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
142 unsigned long totalSize = 0;
143 // Loop over all input blocks in the event
144 for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
146 // Align the beginning of this block to the required value.
147 if ( totalSize % kAliHLTBlockAlignment )
148 totalSize += kAliHLTBlockAlignment-(totalSize % kAliHLTBlockAlignment);
149 if ( totalSize > size )
151 // Determine the size we should use for the output for this block (the input block's size times the relative output size)
152 unsigned long mySize = (blocks[n].fSize * fOutputPercentage) / 100;
153 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "mySize set (1)", "mySize == %lu B - blocks[%lu].fSize == %lu - fOutputPercentage == %lu",
154 mySize, n, blocks[n].fSize, fOutputPercentage );
155 // Check how much space we have left and adapt this output block's size accordingly.
156 if ( totalSize + mySize > size )
157 mySize = size-totalSize;
158 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu",
159 mySize, totalSize, size );
161 continue; // No room left to write a further block.
162 // Now copy the input block
163 unsigned long copied = 0;
164 // First copy all full multiples of the input block
165 while ( copied+blocks[n].fSize <= mySize )
167 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B",
168 blocks[n].fSize, copied, totalSize );
169 memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, blocks[n].fSize );
170 copied += blocks[n].fSize;
172 // And the copy the remaining fragment of the block
173 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B",
174 mySize-copied, copied, totalSize );
175 memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, mySize-copied );
176 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B",
178 // Fill a block data structure for our output block.
179 AliHLTComponentBlockData ob;
180 // Let the structure be filled with the default values.
181 // This takes care of setting the shared memory and data type values to default values,
182 // so that they can be filled in by the calling code.
184 // This block's start (offset) is after all other blocks written so far
185 ob.fOffset = totalSize;
186 // the size of this block's data.
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
196 // Finally we set the total size of output memory we consumed.