]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/SampleLib/AliHLTDummyComponent.cxx
Make full use of newly introduced functionality:
[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"
71d7c760 32#include <stdlib.h>
33#include <errno.h>
34
35// this is a global object used for automatic component registration, do not use this
36AliHLTDummyComponent gAliHLTDummyComponent;
37
38ClassImp(AliHLTDummyComponent)
39
40AliHLTDummyComponent::AliHLTDummyComponent()
2d7ff710 41 :
42 fOutputPercentage(100) // By default we copy to the output exactly what we got as input
71d7c760 43 {
71d7c760 44 }
45
46AliHLTDummyComponent::~AliHLTDummyComponent()
47 {
48 }
49
50const char* AliHLTDummyComponent::GetComponentID()
51 {
52 return "Dummy"; // The ID of this component
53 }
54
8ede8717 55void AliHLTDummyComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
71d7c760 56 {
9ce4bf4a 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).
61 */
8b250b0e 62
63 AliHLTComponentDataType dt =
64 { sizeof(AliHLTComponentDataType),
65 {'*','*','*','*','*','*','*','\0'},
66 {'*','*','*','\0'}};
67 list.push_back(dt);
71d7c760 68 }
69
8ede8717 70AliHLTComponentDataType AliHLTDummyComponent::GetOutputDataType()
71d7c760 71 {
9ce4bf4a 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;
76 */
8b250b0e 77 AliHLTComponentDataType dt =
78 { sizeof(AliHLTComponentDataType),
79 {'\0','\0','\0','0','\0','\0','\0','\0'},
80 {'\0','\0','\0','\0'}};
81 return dt;
71d7c760 82 }
83
84void AliHLTDummyComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
85 {
86 constBase = 0;
87 inputMultiplier = ((double)fOutputPercentage)/100.0;
88 }
89
90
91
92// Spawn function, return new instance of this class
93AliHLTComponent* AliHLTDummyComponent::Spawn()
94 {
95 return new AliHLTDummyComponent;
2d7ff710 96 }
71d7c760 97
98int AliHLTDummyComponent::DoInit( int argc, const char** argv )
99 {
100 // perform initialization. We check whether our relative output size is specified in the arguments.
101 fOutputPercentage = 100;
102 int i = 0;
103 char* cpErr;
104 while ( i < argc )
105 {
106 Logging( kHLTLogDebug, "HLT::Dummy::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
107 if ( !strcmp( argv[i], "output_percentage" ) )
108 {
109 if ( i+1>=argc )
110 {
111 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Missing Argument", "Missing output_percentage parameter");
112 return ENOTSUP;
113 }
114 Logging( kHLTLogDebug, "HLT::Dummy::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
115 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
116 if ( *cpErr )
117 {
118 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
119 return EINVAL;
120 }
121 Logging( kHLTLogInfo, "HLT::Dummy::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
122 i += 2;
123 continue;
124 }
125 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
126 return EINVAL;
127 }
128 return 0;
129 }
130
131int AliHLTDummyComponent::DoDeinit()
132 {
133 return 0;
134 }
135
8ede8717 136int AliHLTDummyComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
137 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
138 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
71d7c760 139 {
140 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
141 // Process an event
142 unsigned long totalSize = 0;
143 // Loop over all input blocks in the event
144 for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
145 {
146 // Align the beginning of this block to the required value.
147 if ( totalSize % kAliHLTBlockAlignment )
148 totalSize += kAliHLTBlockAlignment-(totalSize % kAliHLTBlockAlignment);
149 if ( totalSize > size )
150 break;
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 );
160 if ( mySize<=0 )
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 )
166 {
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;
171 }
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",
177 copied, totalSize );
178 // Fill a block data structure for our output block.
8ede8717 179 AliHLTComponentBlockData ob;
71d7c760 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.
183 FillBlockData( ob );
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.
187 ob.fSize = mySize;
ba2aabd0 188 // the data type of this block
189 ob.fDataType=blocks[n].fDataType;
71d7c760 190 // The specification of the data is copied from the input block.
191 ob.fSpecification = blocks[n].fSpecification;
192 // The data type is set automatically to the component's specified output data type.
193 // Place this block into the list of output blocks
194 outputBlocks.push_back( ob );
195 // Increase the total amount of data written so far to our output memory
196 totalSize += mySize;
197 }
198 // Finally we set the total size of output memory we consumed.
199 size = totalSize;
200 return 0;
201 }