]>
Commit | Line | Data |
---|---|---|
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 | |
25 | using namespace std; | |
26 | #endif | |
27 | ||
28 | #include "AliHLTDummyComponent.h" | |
29 | #include <stdlib.h> | |
30 | #include <errno.h> | |
31 | ||
32 | // this is a global object used for automatic component registration, do not use this | |
33 | AliHLTDummyComponent gAliHLTDummyComponent; | |
34 | ||
35 | ClassImp(AliHLTDummyComponent) | |
36 | ||
37 | AliHLTDummyComponent::AliHLTDummyComponent() | |
38 | { | |
39 | fOutputPercentage = 100; // By default we copy to the output exactly what we got as input | |
40 | } | |
41 | ||
42 | AliHLTDummyComponent::~AliHLTDummyComponent() | |
43 | { | |
44 | } | |
45 | ||
46 | const char* AliHLTDummyComponent::GetComponentID() | |
47 | { | |
48 | return "Dummy"; // The ID of this component | |
49 | } | |
50 | ||
51 | void AliHLTDummyComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list) | |
52 | { | |
53 | list.clear(); // We do not have any requirements for our input data type(s). | |
54 | } | |
55 | ||
56 | AliHLTComponent_DataType AliHLTDummyComponent::GetOutputDataType() | |
57 | { | |
58 | return (AliHLTComponent_DataType){ sizeof(AliHLTComponent_DataType), {'D','U','M','M','Y',' ',' ',' '},{'D','U','M','Y'}}; | |
59 | } | |
60 | ||
61 | void AliHLTDummyComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
62 | { | |
63 | constBase = 0; | |
64 | inputMultiplier = ((double)fOutputPercentage)/100.0; | |
65 | } | |
66 | ||
67 | ||
68 | ||
69 | // Spawn function, return new instance of this class | |
70 | AliHLTComponent* AliHLTDummyComponent::Spawn() | |
71 | { | |
72 | return new AliHLTDummyComponent; | |
73 | }; | |
74 | ||
75 | int AliHLTDummyComponent::DoInit( int argc, const char** argv ) | |
76 | { | |
77 | // perform initialization. We check whether our relative output size is specified in the arguments. | |
78 | fOutputPercentage = 100; | |
79 | int i = 0; | |
80 | char* cpErr; | |
81 | while ( i < argc ) | |
82 | { | |
83 | Logging( kHLTLogDebug, "HLT::Dummy::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] ); | |
84 | if ( !strcmp( argv[i], "output_percentage" ) ) | |
85 | { | |
86 | if ( i+1>=argc ) | |
87 | { | |
88 | Logging(kHLTLogError, "HLT::Dummy::DoInit", "Missing Argument", "Missing output_percentage parameter"); | |
89 | return ENOTSUP; | |
90 | } | |
91 | Logging( kHLTLogDebug, "HLT::Dummy::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] ); | |
92 | fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 ); | |
93 | if ( *cpErr ) | |
94 | { | |
95 | Logging(kHLTLogError, "HLT::Dummy::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] ); | |
96 | return EINVAL; | |
97 | } | |
98 | Logging( kHLTLogInfo, "HLT::Dummy::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage ); | |
99 | i += 2; | |
100 | continue; | |
101 | } | |
102 | Logging(kHLTLogError, "HLT::Dummy::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] ); | |
103 | return EINVAL; | |
104 | } | |
105 | return 0; | |
106 | } | |
107 | ||
108 | int AliHLTDummyComponent::DoDeinit() | |
109 | { | |
110 | return 0; | |
111 | } | |
112 | ||
113 | int AliHLTDummyComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, | |
114 | AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr, | |
115 | AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks ) | |
116 | { | |
117 | Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage ); | |
118 | // Process an event | |
119 | unsigned long totalSize = 0; | |
120 | // Loop over all input blocks in the event | |
121 | for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ ) | |
122 | { | |
123 | // Align the beginning of this block to the required value. | |
124 | if ( totalSize % kAliHLTBlockAlignment ) | |
125 | totalSize += kAliHLTBlockAlignment-(totalSize % kAliHLTBlockAlignment); | |
126 | if ( totalSize > size ) | |
127 | break; | |
128 | // Determine the size we should use for the output for this block (the input block's size times the relative output size) | |
129 | unsigned long mySize = (blocks[n].fSize * fOutputPercentage) / 100; | |
130 | Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "mySize set (1)", "mySize == %lu B - blocks[%lu].fSize == %lu - fOutputPercentage == %lu", | |
131 | mySize, n, blocks[n].fSize, fOutputPercentage ); | |
132 | // Check how much space we have left and adapt this output block's size accordingly. | |
133 | if ( totalSize + mySize > size ) | |
134 | mySize = size-totalSize; | |
135 | Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu", | |
136 | mySize, totalSize, size ); | |
137 | if ( mySize<=0 ) | |
138 | continue; // No room left to write a further block. | |
139 | // Now copy the input block | |
140 | unsigned long copied = 0; | |
141 | // First copy all full multiples of the input block | |
142 | while ( copied+blocks[n].fSize <= mySize ) | |
143 | { | |
144 | Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B", | |
145 | blocks[n].fSize, copied, totalSize ); | |
146 | memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, blocks[n].fSize ); | |
147 | copied += blocks[n].fSize; | |
148 | } | |
149 | // And the copy the remaining fragment of the block | |
150 | Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B", | |
151 | mySize-copied, copied, totalSize ); | |
152 | memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, mySize-copied ); | |
153 | Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B", | |
154 | copied, totalSize ); | |
155 | // Fill a block data structure for our output block. | |
156 | AliHLTComponent_BlockData ob; | |
157 | // Let the structure be filled with the default values. | |
158 | // This takes care of setting the shared memory and data type values to default values, | |
159 | // so that they can be filled in by the calling code. | |
160 | FillBlockData( ob ); | |
161 | // This block's start (offset) is after all other blocks written so far | |
162 | ob.fOffset = totalSize; | |
163 | // the size of this block's data. | |
164 | ob.fSize = mySize; | |
165 | // The specification of the data is copied from the input block. | |
166 | ob.fSpecification = blocks[n].fSpecification; | |
167 | // The data type is set automatically to the component's specified output data type. | |
168 | // Place this block into the list of output blocks | |
169 | outputBlocks.push_back( ob ); | |
170 | // Increase the total amount of data written so far to our output memory | |
171 | totalSize += mySize; | |
172 | } | |
173 | // Finally we set the total size of output memory we consumed. | |
174 | size = totalSize; | |
175 | return 0; | |
176 | } |