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