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. */
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
35 #include "AliHLTSystem.h"
36 #include "AliHLTDummyComponent.h"
37 #include "AliHLTDefinitions.h"
41 /** ROOT macro for the implementation of ROOT specific class methods */
42 ClassImp(AliHLTDummyComponent)
44 AliHLTDummyComponent::AliHLTDummyComponent()
46 fOutputPercentage(100) // By default we copy to the output exactly what we got as input
48 // see header file for class documentation
50 // refer to README to build package
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 AliHLTDummyComponent::~AliHLTDummyComponent()
57 // see header file for class documentation
60 const char* AliHLTDummyComponent::GetComponentID()
62 // see header file for class documentation
63 return "Dummy"; // The ID of this component
66 void AliHLTDummyComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
68 // see header file for class documentation
69 /* in order to be backward compatible we have to keep the old code, at
70 * least for a while. Remember to use the new const kAliHLTVoidDataType
71 * if you are using a more recent AliRoot version (from Jan 07)
72 list.push_back(kAliHLTAnyDataType); // We do not have any requirements for our input data type(s).
75 AliHLTComponentDataType dt =
76 { sizeof(AliHLTComponentDataType),
77 {'*','*','*','*','*','*','*','\0'},
82 AliHLTComponentDataType AliHLTDummyComponent::GetOutputDataType()
84 // see header file for class documentation
85 /* in order to be backward compatible we have to keep the old code, at
86 * least for a while. Remember to use the new const kAliHLTVoidDataType
87 * if you are using a more recent AliRoot version (from Jan 07)
88 return kAliHLTVoidDataType;
90 AliHLTComponentDataType dt =
91 { sizeof(AliHLTComponentDataType),
92 {'\0','\0','\0','0','\0','\0','\0','\0'},
93 {'\0','\0','\0','\0'}};
97 void AliHLTDummyComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
99 // see header file for class documentation
101 inputMultiplier = ((double)fOutputPercentage)/100.0;
106 // Spawn function, return new instance of this class
107 AliHLTComponent* AliHLTDummyComponent::Spawn()
109 // see header file for class documentation
110 return new AliHLTDummyComponent;
113 int AliHLTDummyComponent::DoInit( int argc, const char** argv )
115 // perform initialization. We check whether our relative output size is specified in the arguments.
116 fOutputPercentage = 100;
121 Logging( kHLTLogDebug, "HLT::Dummy::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
122 if ( !strcmp( argv[i], "output_percentage" ) )
126 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Missing Argument", "Missing output_percentage parameter");
129 Logging( kHLTLogDebug, "HLT::Dummy::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
130 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
133 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
136 Logging( kHLTLogInfo, "HLT::Dummy::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
140 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
146 int AliHLTDummyComponent::DoDeinit()
148 // see header file for class documentation
152 int AliHLTDummyComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
153 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
154 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
156 // see header file for class documentation
157 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
159 unsigned long totalSize = 0;
160 // Loop over all input blocks in the event
161 for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
163 // Align the beginning of this block to the required value.
164 if ( totalSize % kAliHLTBlockAlignment )
165 totalSize += kAliHLTBlockAlignment-(totalSize % kAliHLTBlockAlignment);
166 if ( totalSize > size )
168 // Determine the size we should use for the output for this block (the input block's size times the relative output size)
169 unsigned long mySize = (blocks[n].fSize * fOutputPercentage) / 100;
170 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "mySize set (1)", "mySize == %lu B - blocks[%lu].fSize == %lu - fOutputPercentage == %lu",
171 mySize, n, blocks[n].fSize, fOutputPercentage );
172 // Check how much space we have left and adapt this output block's size accordingly.
173 if ( totalSize + mySize > size )
174 mySize = size-totalSize;
175 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu",
176 mySize, totalSize, size );
178 continue; // No room left to write a further block.
179 // Now copy the input block
180 unsigned long copied = 0;
181 // First copy all full multiples of the input block
182 while ( copied+blocks[n].fSize <= mySize )
184 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B",
185 blocks[n].fSize, copied, totalSize );
186 memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, blocks[n].fSize );
187 copied += blocks[n].fSize;
189 // And the copy the remaining fragment of the block
190 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B",
191 mySize-copied, copied, totalSize );
192 memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, mySize-copied );
193 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B",
195 // Fill a block data structure for our output block.
196 AliHLTComponentBlockData ob;
197 // Let the structure be filled with the default values.
198 // This takes care of setting the shared memory and data type values to default values,
199 // so that they can be filled in by the calling code.
201 // This block's start (offset) is after all other blocks written so far
202 ob.fOffset = totalSize;
203 // the size of this block's data.
205 // the data type of this block
206 ob.fDataType=blocks[n].fDataType;
207 // The specification of the data is copied from the input block.
208 ob.fSpecification = blocks[n].fSpecification;
209 // The data type is set automatically to the component's specified output data type.
210 // Place this block into the list of output blocks
211 outputBlocks.push_back( ob );
212 // Increase the total amount of data written so far to our output memory
215 // Finally we set the total size of output memory we consumed.