]>
Commit | Line | Data |
---|---|---|
9d9ffd37 | 1 | /************************************************************************** |
2 | * This file is property of and copyright by the ALICE HLT Project * | |
3 | * ALICE Experiment at CERN, All rights reserved. * | |
4 | * * | |
5 | * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> * | |
6 | * Sebastian Bablok * | |
7 | * for The ALICE HLT Project. * | |
8 | * * | |
9 | * Permission to use, copy, modify and distribute this software and its * | |
10 | * documentation strictly for non-commercial purposes is hereby granted * | |
11 | * without fee, provided that the above copyright notice appears in all * | |
12 | * copies and that both the copyright notice and this permission notice * | |
13 | * appear in the supporting documentation. The authors make no claims * | |
14 | * about the suitability of this software for any purpose. It is * | |
15 | * provided "as is" without express or implied warranty. * | |
16 | **************************************************************************/ | |
17 | ||
18 | /** | |
19 | * @file AliHLTCalibrationProcessor.cxx | |
20 | * @author Jochen Thaeder, Sebastian Bablok | |
21 | * @date | |
22 | * @brief Base class of HLT calibration components. */ | |
23 | ||
24 | #if __GNUC__ >= 3 | |
25 | using namespace std; | |
26 | #endif | |
27 | ||
28 | #include "AliHLTCalibrationProcessor.h" | |
29 | #include "AliHLTMemoryFile.h" | |
30 | ||
31 | #include <cstdlib> | |
32 | #include <cerrno> | |
33 | #include <string.h> | |
34 | #include <TObjString.h> | |
35 | #include <TFile.h> | |
36 | ||
773aff84 | 37 | ClassImp(AliHLTCalibrationProcessor); |
9d9ffd37 | 38 | |
39 | ||
40 | const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize = 204; | |
41 | const AliHLTUInt32_t AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion = 1; | |
42 | ||
43 | /* | |
44 | * ################ Constructor / Destructor #################### | |
45 | */ | |
46 | ||
47 | AliHLTCalibrationProcessor::AliHLTCalibrationProcessor() : | |
48 | fEventModulo(0), | |
49 | fUseCorruptEvents(kFALSE), | |
50 | fEventCounter(0), | |
51 | fDDLNumber(), | |
52 | fDummy(0) { | |
53 | ||
54 | // see header file for class documentation | |
55 | // or | |
56 | // refer to README to build package | |
57 | // or | |
58 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
59 | } | |
60 | ||
61 | AliHLTCalibrationProcessor::~AliHLTCalibrationProcessor() { | |
62 | // see header file for class documentation | |
63 | } | |
64 | ||
65 | /* | |
66 | * ######################## InitCalibration ##################### | |
67 | */ | |
68 | ||
7c4091c1 | 69 | Int_t AliHLTCalibrationProcessor::DoInit( int argc, const char** argv ) { |
9d9ffd37 | 70 | // see header file for class documentation |
71 | ||
72 | Int_t iResult = 0; | |
73 | TString argument = ""; | |
74 | TString parameter = ""; | |
75 | Int_t bMissingParam=0; | |
76 | ||
77 | for ( Int_t ii=0; ii<argc && iResult>=0; ii++ ) { | |
78 | argument = argv[ii]; | |
79 | ||
80 | if ( argument.IsNull() ) continue; | |
81 | ||
82 | // -eventmodulo | |
83 | if ( argument.CompareTo("-eventmodulo") == 0 ) { | |
84 | if ( ( bMissingParam=( ++ii >= argc ) ) ) break; | |
85 | parameter = argv[ii]; | |
86 | parameter.Remove(TString::kLeading, ' '); // remove all blanks | |
87 | if (parameter.IsDigit()) { | |
88 | fEventModulo = parameter.Atoi(); | |
89 | HLTInfo("EventModulo is set to %d.", fEventModulo); | |
90 | } | |
91 | else { | |
92 | HLTError("Cannot convert EventModulo specifier '%s'.", argv[ii]); | |
93 | iResult = -EINVAL; | |
94 | break; | |
95 | } | |
96 | } | |
97 | // -usecorruptevents | |
98 | else if ( argument.CompareTo( "-usecorruptevents" ) == 0 ) { | |
99 | HLTInfo( "Passing through of corrupted events enabled." ); | |
100 | fUseCorruptEvents = kTRUE; | |
101 | } | |
102 | // not known by calibration processor | |
103 | else { | |
104 | if ( ( iResult = ScanArgument( argc-ii, &argv[ii] ) ) == -EINVAL ) { | |
105 | HLTError( "unknown argument %s", argument.Data() ); | |
106 | break; | |
107 | } | |
108 | else if ( iResult == -EPROTO ) { | |
109 | bMissingParam = 1; | |
110 | break; | |
111 | } | |
112 | else if ( iResult >= 0 ) { | |
113 | ii += iResult; | |
114 | iResult = 0; | |
115 | } | |
116 | } | |
117 | } | |
118 | ||
119 | if ( bMissingParam ) { | |
120 | HLTError( "missing parameter for argument %s", argument.Data() ); | |
121 | iResult = -EPROTO; | |
122 | } | |
123 | ||
124 | if ( iResult >= 0 ) { | |
125 | iResult = InitCalibration(); | |
126 | } | |
127 | ||
128 | return iResult; | |
129 | } | |
130 | ||
131 | Int_t AliHLTCalibrationProcessor::InitCalibration() { | |
132 | // see header file for class documentation | |
133 | ||
134 | // fDummy is just touched here to avoid coding convention violation RC11. | |
135 | // The function can not be declared const since it is just the default implementation, | |
136 | // overloaded virtual function might not be const. | |
137 | fDummy = 0; | |
138 | ||
139 | return 0; | |
140 | } | |
141 | ||
142 | ||
7c4091c1 | 143 | Int_t AliHLTCalibrationProcessor::ScanArgument(int argc, const char** argv) { |
9d9ffd37 | 144 | // see header file for class documentation |
145 | ||
146 | // there are no other arguments than the standard ones | |
147 | if ( argc == 0 && argv == NULL) { | |
148 | // this is just to get rid of the warning "unused parameter" | |
149 | } | |
150 | ||
151 | // fDummy is just touched here to avoid coding convention violation RC11. | |
152 | // The function can not be declared const since it is just the default implementation, | |
153 | // overloaded virtual function might not be const. | |
154 | fDummy = 0; | |
155 | ||
156 | return -EINVAL; | |
157 | } | |
158 | ||
159 | /* | |
160 | * ######################## DeinitCalibration ##################### | |
161 | */ | |
162 | ||
163 | Int_t AliHLTCalibrationProcessor::DoDeinit() { | |
164 | // see header file for class documentation | |
165 | ||
166 | int iResult = DeinitCalibration(); | |
167 | ||
168 | return iResult; | |
169 | } | |
170 | ||
171 | Int_t AliHLTCalibrationProcessor::DeinitCalibration() { | |
172 | // see header file for class documentation | |
173 | ||
174 | // fDummy is just touched here to avoid coding convention violation RC11. | |
175 | // The function can not be declared const since it is just the default implementation, | |
176 | // overloaded virtual function might not be const. | |
177 | fDummy = 0; | |
178 | ||
179 | return 0; | |
180 | } | |
181 | ||
182 | /* | |
183 | * ######################## DoEvent ##################### | |
184 | */ | |
185 | ||
186 | Int_t AliHLTCalibrationProcessor::DoEvent( const AliHLTComponentEventData& evtData, | |
187 | const AliHLTComponentBlockData* blocks, | |
188 | AliHLTComponentTriggerData& trigData, | |
189 | AliHLTUInt8_t* outputPtr, | |
190 | AliHLTUInt32_t& size, | |
191 | vector<AliHLTComponentBlockData>& outputBlocks ) | |
192 | { | |
193 | // see header file for class documentation | |
194 | ||
195 | Int_t iResult = 0; | |
196 | const AliHLTComponentBlockData* iter = NULL; | |
197 | ||
198 | const AliHLTComponentBlockData* blkSOR = NULL; | |
199 | const AliHLTComponentBlockData* blkEOR = NULL; | |
200 | const AliHLTComponentBlockData* blkDDL = NULL; | |
201 | ||
202 | HLTInfo( "Event ID: %lu", evtData.fEventID ); | |
203 | ||
204 | // --------------- START OF RUN ----------------- | |
205 | blkSOR = GetFirstInputBlock( kAliHLTDataTypeSOR ); | |
206 | ||
207 | // ---------------- END OF RUN ------------------ | |
208 | blkEOR = GetFirstInputBlock( kAliHLTDataTypeEOR ); | |
209 | ||
210 | // -------------- GET DDLNumber ----------------- | |
211 | blkDDL = GetFirstInputBlock( kAliHLTDataTypeDDL ); | |
212 | ||
213 | if ( blkDDL ) { | |
214 | HLTInfo("DDLLIST block received, size: %u", iter->fSize ); | |
215 | //AliHLTEventDDL ddlList = ( AliHLTEventDDL* ) iter->fPtr; | |
216 | } | |
217 | ||
218 | // ------------ decide which event type ---------- | |
219 | ||
220 | // - if event Type is not SOR or EOR -> process data | |
221 | if ( ! blkEOR && !blkSOR ) { | |
222 | iResult = ProcessCalibration( evtData, blocks, trigData, outputPtr, size, outputBlocks ); | |
223 | fEventCounter++; | |
224 | } | |
225 | ||
226 | // - if event Type is EOR or event modulo is set -> ship data to FXS | |
227 | // - use event modulo ship data also during the run | |
228 | if ( ( fEventModulo > 0 && fEventCounter == fEventModulo ) || blkEOR ){ | |
229 | HLTDebug ( "Ship Data to FXS!" ); | |
230 | iResult = ShipDataToFXS( evtData, blocks, trigData, outputPtr, size, outputBlocks ); | |
231 | fEventCounter = 0; | |
232 | } | |
233 | ||
234 | return iResult; | |
235 | } | |
236 | ||
237 | /* | |
238 | * ######################## ProcessCalibration ##################### | |
239 | */ | |
240 | ||
241 | Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& evtData, | |
242 | const AliHLTComponentBlockData* blocks, | |
243 | AliHLTComponentTriggerData& trigData, | |
244 | AliHLTUInt8_t* outputPtr, | |
245 | AliHLTUInt32_t& size, | |
246 | vector<AliHLTComponentBlockData>& outputBlocks ) { | |
247 | // see header file for class documentation | |
248 | ||
249 | // we just forward to the high level method, all other parameters already | |
250 | // have been stored internally | |
251 | return ProcessCalibration( evtData, trigData ); | |
252 | } | |
253 | ||
254 | Int_t AliHLTCalibrationProcessor::ProcessCalibration( const AliHLTComponentEventData& evtData, | |
255 | AliHLTComponentTriggerData& trigData) { | |
256 | // see header file for class documentation | |
257 | ||
258 | HLTFatal( "no processing method implemented" ); | |
259 | return -ENOSYS; | |
260 | } | |
261 | ||
262 | /* | |
263 | * ######################## ShipDataToFXS ##################### | |
264 | */ | |
265 | ||
266 | Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& evtData, | |
267 | const AliHLTComponentBlockData* blocks, | |
268 | AliHLTComponentTriggerData& trigData, | |
269 | AliHLTUInt8_t* outputPtr, | |
270 | AliHLTUInt32_t& size, | |
271 | vector<AliHLTComponentBlockData>& outputBlocks ) { | |
272 | // see header file for class documentation | |
273 | ||
274 | // we just forward to the high level method, all other parameters already | |
275 | // have been stored internally | |
276 | return ShipDataToFXS( evtData, trigData ); | |
277 | } | |
278 | ||
279 | ||
280 | Int_t AliHLTCalibrationProcessor::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData) { | |
281 | // see header file for class documentation | |
282 | ||
283 | HLTFatal( "no processing method implemented" ); | |
284 | return -ENOSYS; | |
285 | } | |
286 | ||
287 | /* | |
288 | * ######################## CreateFXSHeader ##################### | |
289 | */ | |
290 | ||
291 | Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTFXSHeader &pHeader, const char* pDetector, const char* pFileID, const char* pDDLNumber ) { | |
292 | // see header file for class documentation | |
293 | ||
294 | Int_t iResult = 0; | |
295 | ||
296 | AliHLTUInt32_t runNumber = GetRunNo(); // debug : 2176; | |
297 | ||
298 | HLTDebug( "RunNumber = %d", runNumber ); | |
299 | ||
300 | /* STILL TO BE DONE .. but interface fixed */ | |
301 | ||
302 | // if ( pDDLNumber != "" ) { | |
303 | char ddltmp[5] = "4444"; | |
304 | strncpy ( fDDLNumber, ddltmp, gkAliHLTFXSHeaderfDDLNumberSize ); | |
305 | //} | |
306 | //else { | |
307 | //strncpy ( fDDLNumber, pDDLNumber, gkAliHLTFXSHeaderfDDLNumberSize ); | |
308 | //} | |
309 | ||
310 | fDDLNumber[gkAliHLTFXSHeaderfDDLNumberSize] = 0; | |
311 | ||
312 | // -- Fill Header | |
313 | ||
314 | // Fill header version | |
315 | pHeader.fHeaderVersion = AliHLTCalibrationProcessor::fgkFXSProtocolHeaderVersion; | |
316 | ||
317 | // Fill run number | |
318 | pHeader.fRunNumber = runNumber; | |
319 | ||
320 | // Fill origin | |
321 | HLTDebug( "FXS Header Detector size max %i - actual %i .",gkAliHLTFXSHeaderfOriginSize, strlen( pDetector ) ); | |
322 | strncpy ( pHeader.fOrigin, pDetector, gkAliHLTFXSHeaderfOriginSize ) ; | |
323 | ||
324 | // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfOriginSize, write one 0 is cheaper than an if. | |
325 | pHeader.fOrigin[gkAliHLTFXSHeaderfOriginSize] = 0; | |
326 | ||
327 | // Fill file ID | |
328 | HLTInfo( "FXS Header FileID size max %i - actual %i .",gkAliHLTFXSHeaderfFileIDSize, strlen( pFileID ) ); | |
329 | strncpy ( pHeader.fFileID, pFileID, gkAliHLTFXSHeaderfFileIDSize ) ; | |
330 | ||
331 | // To take care if fileIDs which are longer than gkAliHLTFXSHeaderfFileIDSize, write one 0 is cheaper than an if. | |
332 | pHeader.fFileID[gkAliHLTFXSHeaderfFileIDSize] = 0; | |
333 | ||
334 | // Fill DDL number | |
335 | HLTInfo( "FXS Header DDLNumber size max %i - actual %i .", gkAliHLTFXSHeaderfDDLNumberSize, strlen( pDDLNumber ) ); | |
336 | strncpy ( pHeader.fDDLNumber, fDDLNumber, gkAliHLTFXSHeaderfDDLNumberSize) ; | |
337 | ||
338 | // To take care if DDLNumber which are longer than gkAliHLTFXSHeaderfDDLNumberSize, write one 0 is cheaper than an if. | |
339 | pHeader.fDDLNumber[gkAliHLTFXSHeaderfDDLNumberSize] = 0; | |
340 | ||
e83e889b | 341 | return iResult; |
9d9ffd37 | 342 | } // Int_t AliHLTCalibrationProcessor::CreateFXSHeader( AliHLTXSHeader &pHeader, const char* pDetector, const char* pFileID, const char* pDDLNumber ) { |
343 | ||
344 | /* | |
345 | * ######################## PushToFXS ##################### | |
346 | */ | |
347 | ||
348 | Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, const char* pDDLNumber ) { | |
349 | // see header file for class documentation | |
350 | ||
351 | Int_t iResult = 0; | |
352 | ||
353 | AliHLTFXSHeader pHeader; | |
354 | ||
355 | CreateFXSHeader( pHeader, pDetector, pFileID, pDDLNumber ); | |
356 | ||
357 | if ( pObject ) { | |
358 | ||
359 | AliHLTMemoryFile* pMemFile = CreateMemoryFile( kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec ); | |
360 | if ( pMemFile ) { | |
361 | ||
362 | iResult = pMemFile->WriteHeader( (const char*) &pHeader, AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize ); | |
363 | ||
364 | if ( iResult ) { | |
365 | HLTError( "Buffer size to small - for header!" ); | |
366 | } | |
367 | else { | |
368 | iResult = Write( pMemFile, pObject ); | |
369 | if ( !iResult ) { | |
370 | HLTError( "Buffer size to small - for data!" ); | |
371 | } | |
372 | else { | |
373 | iResult = CloseMemoryFile( pMemFile ); | |
374 | } | |
375 | } | |
376 | } | |
377 | else { | |
378 | iResult = -ENOMEM; | |
379 | } | |
380 | } | |
381 | else { | |
382 | iResult=-EINVAL; | |
383 | } | |
384 | ||
385 | return iResult; | |
386 | ||
387 | } // Int_t AliHLTCalibrationProcessor::PushToFXS(TObject* pObject, const char* detector, const char* pFileID, const char* pDDLNumber ) { | |
388 | ||
389 | Int_t AliHLTCalibrationProcessor::PushToFXS( void* pBuffer, int iSize, const char* pDetector, const char* pFileID, const char* pDDLNumber ) { | |
390 | ||
391 | Int_t iResult = 0; | |
392 | ||
393 | AliHLTFXSHeader pHeader; | |
394 | ||
395 | CreateFXSHeader( pHeader, pDetector, pFileID, pDDLNumber ); | |
396 | ||
397 | iResult = PushBack( pBuffer, iSize, kAliHLTDataTypeFXSCalib, kAliHLTVoidDataSpec, (void*) (&pHeader), AliHLTCalibrationProcessor::fgkFXSProtocolHeaderSize ); | |
398 | ||
399 | return iResult; | |
400 | ||
401 | } // Int_t AliHLTCalibrationProcessor::PushToFXS(void* pBuffer, int iSize, const char* pDdetector, const char* pFileID, const char* pDDLNumber = "") { | |
402 |