f23a6e1a |
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> * |
f23a6e1a |
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 | |
bfccbf68 |
19 | /** @file AliHLTComponent.cxx |
20 | @author Matthias Richter, Timm Steinbeck |
21 | @date |
22 | @brief Base class implementation for HLT components. */ |
f23a6e1a |
23 | |
0c0c9d99 |
24 | #if __GNUC__>= 3 |
f23a6e1a |
25 | using namespace std; |
26 | #endif |
27 | |
85869391 |
28 | #include "AliHLTStdIncludes.h" |
f23a6e1a |
29 | #include "AliHLTComponent.h" |
30 | #include "AliHLTComponentHandler.h" |
f23a6e1a |
31 | #include "AliHLTSystem.h" |
32 | |
b22e91eb |
33 | /** ROOT macro for the implementation of ROOT specific class methods */ |
f23a6e1a |
34 | ClassImp(AliHLTComponent) |
35 | |
f23a6e1a |
36 | AliHLTComponent::AliHLTComponent() |
85869391 |
37 | : |
53feaef5 |
38 | fEnvironment(), |
39 | fCurrentEvent(0) |
f23a6e1a |
40 | { |
41 | memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); |
42 | if (fpComponentHandler) |
43 | fpComponentHandler->ScheduleRegister(this); |
44 | } |
45 | |
46 | AliHLTComponent::~AliHLTComponent() |
47 | { |
48 | } |
49 | |
b22e91eb |
50 | AliHLTComponentHandler* AliHLTComponent::fpComponentHandler=NULL; |
51 | |
85869391 |
52 | int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite) |
53 | { |
54 | int iResult=0; |
55 | if (fpComponentHandler==NULL || bOverwrite!=0) |
56 | fpComponentHandler=pCH; |
57 | else |
58 | iResult=-EPERM; |
59 | return iResult; |
60 | } |
61 | |
62 | int AliHLTComponent::UnsetGlobalComponentHandler() { |
63 | return SetGlobalComponentHandler(NULL,1); |
64 | } |
65 | |
f23a6e1a |
66 | int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv ) |
67 | { |
68 | int iResult=0; |
69 | if (environ) { |
70 | memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment)); |
71 | fEnvironment.fParam=environ_param; |
72 | } |
73 | iResult=DoInit(argc, argv); |
74 | return iResult; |
75 | } |
76 | |
77 | int AliHLTComponent::Deinit() |
78 | { |
79 | int iResult=0; |
80 | iResult=DoDeinit(); |
81 | return iResult; |
82 | } |
fa2e9b7c |
83 | |
53feaef5 |
84 | int AliHLTComponent::DoInit( int argc, const char** argv ) |
85 | { |
86 | if (argc==0 && argv==NULL) { |
87 | // this is currently just to get rid of the warning "unused parameter" |
88 | } |
89 | return 0; |
90 | } |
91 | |
92 | int AliHLTComponent::DoDeinit() |
93 | { |
94 | return 0; |
95 | } |
96 | |
9ce4bf4a |
97 | void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) { |
98 | memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 ); |
99 | strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize ); |
100 | strcat( output, ":" ); |
101 | strncat( output, type.fID, kAliHLTComponentDataTypefIDsize ); |
fa2e9b7c |
102 | } |
103 | |
9ce4bf4a |
104 | string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type ) |
105 | { |
106 | string out(""); |
107 | if (type==kAliHLTVoidDataType) { |
108 | out="VOID:VOID"; |
109 | } else { |
110 | out.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize); |
111 | out.append(":"); |
112 | out.append(type.fID, kAliHLTComponentDataTypefIDsize); |
113 | } |
114 | return out; |
115 | } |
116 | |
117 | |
85869391 |
118 | void* AliHLTComponent::AllocMemory( unsigned long size ) { |
119 | if (fEnvironment.fAllocMemoryFunc) |
120 | return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size ); |
9ce4bf4a |
121 | HLTFatal("no memory allocation handler registered"); |
85869391 |
122 | return NULL; |
123 | } |
124 | |
8ede8717 |
125 | int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount, |
126 | AliHLTComponentBlockData** outputBlocks ) { |
9ce4bf4a |
127 | if ( blockCount==NULL || outputBlocks==NULL ) |
2d7ff710 |
128 | return -EFAULT; |
fa2e9b7c |
129 | AliHLTUInt32_t count = blocks.size(); |
130 | if ( !count ) |
131 | { |
132 | *blockCount = 0; |
133 | *outputBlocks = NULL; |
134 | return 0; |
135 | } |
8ede8717 |
136 | *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) ); |
fa2e9b7c |
137 | if ( !*outputBlocks ) |
2d7ff710 |
138 | return -ENOMEM; |
fa2e9b7c |
139 | for ( unsigned long i = 0; i < count; i++ ) |
140 | (*outputBlocks)[i] = blocks[i]; |
141 | *blockCount = count; |
142 | return 0; |
143 | |
144 | } |
0c0c9d99 |
145 | |
8ede8717 |
146 | int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) { |
85869391 |
147 | if (fEnvironment.fGetEventDoneDataFunc) |
148 | return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd ); |
149 | return -ENOSYS; |
150 | } |
151 | |
8ede8717 |
152 | int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList) |
0c0c9d99 |
153 | { |
154 | int iResult=0; |
155 | if (pConsumer) { |
8ede8717 |
156 | vector<AliHLTComponentDataType> ctlist; |
0c0c9d99 |
157 | ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist); |
8ede8717 |
158 | vector<AliHLTComponentDataType>::iterator type=ctlist.begin(); |
0c0c9d99 |
159 | while (type!=ctlist.end() && iResult==0) { |
9ce4bf4a |
160 | if ((*type)==GetOutputDataType() || |
161 | (*type)==kAliHLTAnyDataType) { |
0c0c9d99 |
162 | if (tgtList) tgtList->push_back(*type); |
163 | iResult++; |
9ce4bf4a |
164 | // this loop has to be changed in case of multiple output types |
0c0c9d99 |
165 | break; |
166 | } |
167 | type++; |
168 | } |
169 | } else { |
170 | iResult=-EINVAL; |
171 | } |
172 | return iResult; |
173 | } |
2d7ff710 |
174 | |
175 | void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) { |
176 | blockData.fStructSize = sizeof(blockData); |
177 | FillShmData( blockData.fShmKey ); |
178 | blockData.fOffset = ~(AliHLTUInt32_t)0; |
179 | blockData.fPtr = NULL; |
180 | blockData.fSize = 0; |
181 | FillDataType( blockData.fDataType ); |
182 | blockData.fSpecification = ~(AliHLTUInt32_t)0; |
183 | } |
184 | |
185 | void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) { |
186 | shmData.fStructSize = sizeof(shmData); |
187 | shmData.fShmType = gkAliHLTComponentInvalidShmType; |
188 | shmData.fShmID = gkAliHLTComponentInvalidShmID; |
189 | } |
190 | |
191 | void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) { |
9ce4bf4a |
192 | dataType=kAliHLTVoidDataType; |
2d7ff710 |
193 | } |
194 | |
195 | void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) { |
196 | memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize); |
197 | memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize); |
198 | } |
199 | |
200 | void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) { |
201 | tgtdt.fStructSize = sizeof(AliHLTComponentDataType); |
202 | memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize); |
203 | memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize); |
204 | |
9ce4bf4a |
205 | if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) { |
2d7ff710 |
206 | HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize); |
207 | } |
208 | strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize); |
209 | |
9ce4bf4a |
210 | if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) { |
2d7ff710 |
211 | HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize); |
212 | } |
213 | strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize); |
214 | } |
9ce4bf4a |
215 | |
216 | void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData) |
217 | { |
218 | memset(&evtData, 0, sizeof(AliHLTComponentEventData)); |
219 | evtData.fStructSize=sizeof(AliHLTComponentEventData); |
220 | } |
221 | |
222 | void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) { |
223 | TString msg; |
224 | msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize); |
225 | for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) { |
226 | if (dt.fID[i]!=0) msg+=dt.fID[i]; |
227 | else msg+="\\0"; |
228 | } |
229 | msg+="\" Origin=\""; |
230 | for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) { |
231 | if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i]; |
232 | else msg+="\\0"; |
233 | } |
234 | msg+="\""; |
235 | HLTMessage(msg.Data()); |
236 | } |
237 | |