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