]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/SampleLib/AliHLTDummyComponent.cxx
documentation
[u/mrichter/AliRoot.git] / HLT / SampleLib / AliHLTDummyComponent.cxx
1 // $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * ALICE Experiment at CERN, All rights reserved.                         *
6  *                                                                        *
7  * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8  *                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
9  *                  for The ALICE HLT Project.                            *
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
20 /** @file   AliHLTDummyComponent.cxx
21     @author Timm Steinbeck, Matthias Richter
22     @date   
23     @brief  A dummy processing component for the HLT. */
24
25 #if __GNUC__ >= 3
26 using namespace std;
27 #endif
28
29 #include "AliHLTSystem.h"
30 #include "AliHLTDummyComponent.h"
31 #include "AliHLTDefinitions.h"
32 #include <stdlib.h>
33 #include <errno.h>
34
35 // this is a global object used for automatic component registration, do not use this
36 AliHLTDummyComponent gAliHLTDummyComponent;
37
38 ClassImp(AliHLTDummyComponent)
39     
40 AliHLTDummyComponent::AliHLTDummyComponent()
41   :
42     fOutputPercentage(100) // By default we copy to the output exactly what we got as input
43     {
44     }
45
46 AliHLTDummyComponent::~AliHLTDummyComponent()
47     {
48     }
49
50 const char* AliHLTDummyComponent::GetComponentID()
51     {
52     return "Dummy"; // The ID of this component
53     }
54
55 void AliHLTDummyComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
56     {
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       */
62
63       AliHLTComponentDataType dt = 
64         { sizeof(AliHLTComponentDataType),
65           {'*','*','*','*','*','*','*','\0'},
66           {'*','*','*','\0'}};
67        list.push_back(dt);
68     }
69
70 AliHLTComponentDataType AliHLTDummyComponent::GetOutputDataType()
71     {
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       */
77       AliHLTComponentDataType dt = 
78         { sizeof(AliHLTComponentDataType),
79           {'\0','\0','\0','0','\0','\0','\0','\0'},
80           {'\0','\0','\0','\0'}};
81       return dt;
82     }
83
84 void 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
93 AliHLTComponent* AliHLTDummyComponent::Spawn()
94     {
95     return new AliHLTDummyComponent;
96     }
97
98 int 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
131 int AliHLTDummyComponent::DoDeinit()
132     {
133     return 0;
134     }
135
136 int AliHLTDummyComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
137                                       AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
138                                       AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
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.
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.
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;
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
194         totalSize += mySize;
195         }
196     // Finally we set the total size of output memory we consumed.
197     size = totalSize;
198     return 0;
199     }