]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/SampleLib/AliHLTDummyComponent.cxx
- AliHLTFileWriter added
[u/mrichter/AliRoot.git] / HLT / SampleLib / AliHLTDummyComponent.cxx
CommitLineData
71d7c760 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
b22e91eb 19/** @file AliHLTDummyComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
21 @date
22 @brief A dummy processing component for the HLT. */
71d7c760 23
24#if __GNUC__ >= 3
25using namespace std;
26#endif
27
2d7ff710 28#include "AliHLTSystem.h"
71d7c760 29#include "AliHLTDummyComponent.h"
30#include <stdlib.h>
31#include <errno.h>
32
33// this is a global object used for automatic component registration, do not use this
34AliHLTDummyComponent gAliHLTDummyComponent;
35
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 */
60 list.push_back((AliHLTComponentDataType){ sizeof(AliHLTComponentDataType), {'*','*','*','*','*','*','*','\0'},{'*','*','*','\0'}});
71d7c760 61 }
62
8ede8717 63AliHLTComponentDataType AliHLTDummyComponent::GetOutputDataType()
71d7c760 64 {
9ce4bf4a 65 /* in order to be backward compatible we have to keep the old code, at
66 * least for a while. Remember to use the new const kAliHLTVoidDataType
67 * if you are using a more recent AliRoot version (from Jan 07)
68 return kAliHLTVoidDataType;
69 */
70 return (AliHLTComponentDataType){ sizeof(AliHLTComponentDataType), {'\0','\0','\0','0','\0','\0','\0','\0'},{'\0','\0','\0','\0'}};
71d7c760 71 }
72
73void AliHLTDummyComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
74 {
75 constBase = 0;
76 inputMultiplier = ((double)fOutputPercentage)/100.0;
77 }
78
79
80
81// Spawn function, return new instance of this class
82AliHLTComponent* AliHLTDummyComponent::Spawn()
83 {
84 return new AliHLTDummyComponent;
2d7ff710 85 }
71d7c760 86
87int AliHLTDummyComponent::DoInit( int argc, const char** argv )
88 {
89 // perform initialization. We check whether our relative output size is specified in the arguments.
90 fOutputPercentage = 100;
91 int i = 0;
92 char* cpErr;
93 while ( i < argc )
94 {
95 Logging( kHLTLogDebug, "HLT::Dummy::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
96 if ( !strcmp( argv[i], "output_percentage" ) )
97 {
98 if ( i+1>=argc )
99 {
100 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Missing Argument", "Missing output_percentage parameter");
101 return ENOTSUP;
102 }
103 Logging( kHLTLogDebug, "HLT::Dummy::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
104 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
105 if ( *cpErr )
106 {
107 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
108 return EINVAL;
109 }
110 Logging( kHLTLogInfo, "HLT::Dummy::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
111 i += 2;
112 continue;
113 }
114 Logging(kHLTLogError, "HLT::Dummy::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
115 return EINVAL;
116 }
117 return 0;
118 }
119
120int AliHLTDummyComponent::DoDeinit()
121 {
122 return 0;
123 }
124
8ede8717 125int AliHLTDummyComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
126 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
127 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
71d7c760 128 {
129 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
130 // Process an event
131 unsigned long totalSize = 0;
132 // Loop over all input blocks in the event
133 for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
134 {
135 // Align the beginning of this block to the required value.
136 if ( totalSize % kAliHLTBlockAlignment )
137 totalSize += kAliHLTBlockAlignment-(totalSize % kAliHLTBlockAlignment);
138 if ( totalSize > size )
139 break;
140 // Determine the size we should use for the output for this block (the input block's size times the relative output size)
141 unsigned long mySize = (blocks[n].fSize * fOutputPercentage) / 100;
142 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "mySize set (1)", "mySize == %lu B - blocks[%lu].fSize == %lu - fOutputPercentage == %lu",
143 mySize, n, blocks[n].fSize, fOutputPercentage );
144 // Check how much space we have left and adapt this output block's size accordingly.
145 if ( totalSize + mySize > size )
146 mySize = size-totalSize;
147 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu",
148 mySize, totalSize, size );
149 if ( mySize<=0 )
150 continue; // No room left to write a further block.
151 // Now copy the input block
152 unsigned long copied = 0;
153 // First copy all full multiples of the input block
154 while ( copied+blocks[n].fSize <= mySize )
155 {
156 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B",
157 blocks[n].fSize, copied, totalSize );
158 memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, blocks[n].fSize );
159 copied += blocks[n].fSize;
160 }
161 // And the copy the remaining fragment of the block
162 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B",
163 mySize-copied, copied, totalSize );
164 memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, mySize-copied );
165 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B",
166 copied, totalSize );
167 // Fill a block data structure for our output block.
8ede8717 168 AliHLTComponentBlockData ob;
71d7c760 169 // Let the structure be filled with the default values.
170 // This takes care of setting the shared memory and data type values to default values,
171 // so that they can be filled in by the calling code.
172 FillBlockData( ob );
173 // This block's start (offset) is after all other blocks written so far
174 ob.fOffset = totalSize;
175 // the size of this block's data.
176 ob.fSize = mySize;
177 // The specification of the data is copied from the input block.
178 ob.fSpecification = blocks[n].fSpecification;
179 // The data type is set automatically to the component's specified output data type.
180 // Place this block into the list of output blocks
181 outputBlocks.push_back( ob );
182 // Increase the total amount of data written so far to our output memory
183 totalSize += mySize;
184 }
185 // Finally we set the total size of output memory we consumed.
186 size = totalSize;
187 return 0;
188 }