Cleanup of documentation and code.
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONTriggerReconstructorComponent.cxx
CommitLineData
6efe69e7 1/**************************************************************************
b39b98c8 2 * This file is property of and copyright by the ALICE HLT Project *
6efe69e7 3 * All rights reserved. *
4 * *
5 * Primary Authors: *
6 * Indranil Das <indra.das@saha.ac.in> *
b39b98c8 7 * Artur Szostak <artursz@iafrica.com> *
6efe69e7 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 *
b39b98c8 14 * about the suitability of this software for any purpose. It is *
6efe69e7 15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18/* $Id$ */
19
6253e09b 20///
21/// @file AliHLTMUONTriggerReconstructorComponent.cxx
22/// @author Indranil Das <indra.das@saha.ac.in>, Artur Szostak <artursz@iafrica.com>
23/// @date
24/// @brief Implementation of the trigger DDL reconstructor component.
25///
6efe69e7 26
6efe69e7 27#include "AliHLTMUONTriggerReconstructorComponent.h"
960d54ad 28#include "AliHLTMUONTriggerReconstructor.h"
29#include "AliHLTMUONHitReconstructor.h"
30#include "AliHLTMUONConstants.h"
b39b98c8 31#include "AliHLTMUONUtils.h"
227e7192 32#include "AliHLTMUONDataBlockWriter.h"
c95cf30c 33#include "AliCDBManager.h"
34#include "AliCDBStorage.h"
35#include "AliGeomManager.h"
36#include "AliMUONGeometryTransformer.h"
37#include "AliMUONGeometryDetElement.h"
38#include "AliMpCDB.h"
39#include "AliMpDDLStore.h"
40#include "AliMpPad.h"
41#include "AliMpSegmentation.h"
42#include "AliMpDEIterator.h"
43#include "AliMpVSegmentation.h"
44#include "AliMpDEManager.h"
45#include "AliMpLocalBoard.h"
46#include "AliMpTriggerCrate.h"
227e7192 47#include <cstdlib>
48#include <cerrno>
5d1682b9 49#include <cassert>
b39b98c8 50#include <fstream>
6efe69e7 51
c95cf30c 52
6efe69e7 53ClassImp(AliHLTMUONTriggerReconstructorComponent)
b39b98c8 54
55
227e7192 56AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent() :
6253e09b 57 AliHLTProcessor(),
227e7192 58 fTrigRec(NULL),
b39b98c8 59 fDDL(-1),
80590aa1 60 fWarnForUnexpecedBlock(false),
61 fSuppressPartialTrigs(false)
960d54ad 62{
6253e09b 63 ///
64 /// Default constructor.
65 ///
960d54ad 66}
67
6efe69e7 68
69AliHLTMUONTriggerReconstructorComponent::~AliHLTMUONTriggerReconstructorComponent()
960d54ad 70{
6253e09b 71 ///
72 /// Default destructor.
73 ///
a6b16447 74
75 if (fTrigRec != NULL) delete fTrigRec;
960d54ad 76}
77
6efe69e7 78
79const char* AliHLTMUONTriggerReconstructorComponent::GetComponentID()
960d54ad 80{
6253e09b 81 ///
82 /// Inherited from AliHLTComponent. Returns the component ID.
83 ///
84
227e7192 85 return AliHLTMUONConstants::TriggerReconstructorId();
960d54ad 86}
87
88
89void AliHLTMUONTriggerReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list)
90{
6253e09b 91 ///
92 /// Inherited from AliHLTProcessor. Returns the list of expected input data types.
93 ///
94
227e7192 95 list.clear();
668eee9f 96 list.push_back( AliHLTMUONConstants::DDLRawDataType() );
960d54ad 97}
6efe69e7 98
6efe69e7 99
100AliHLTComponentDataType AliHLTMUONTriggerReconstructorComponent::GetOutputDataType()
960d54ad 101{
6253e09b 102 ///
103 /// Inherited from AliHLTComponent. Returns the output data type.
104 ///
105
227e7192 106 return AliHLTMUONConstants::TriggerRecordsBlockDataType();
960d54ad 107}
6efe69e7 108
6efe69e7 109
227e7192 110void AliHLTMUONTriggerReconstructorComponent::GetOutputDataSize(
111 unsigned long& constBase, double& inputMultiplier
112 )
960d54ad 113{
6253e09b 114 ///
115 /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
116 ///
117
227e7192 118 constBase = sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType);
c2e03d6e 119 inputMultiplier = 4;
960d54ad 120}
6efe69e7 121
122
6efe69e7 123AliHLTComponent* AliHLTMUONTriggerReconstructorComponent::Spawn()
960d54ad 124{
6253e09b 125 ///
126 /// Inherited from AliHLTComponent. Creates a new object instance.
127 ///
128
227e7192 129 return new AliHLTMUONTriggerReconstructorComponent;
960d54ad 130}
131
6efe69e7 132
960d54ad 133int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
6efe69e7 134{
6253e09b 135 ///
136 /// Inherited from AliHLTComponent.
137 /// Parses the command line parameters and initialises the component.
138 ///
139
b39b98c8 140 // perform initialization.
141
142 HLTInfo("Initialising dHLT trigger reconstructor component.");
6efe69e7 143
a6b16447 144 // Make sure to cleanup fTrigRec if it is still there for some reason.
145 if (fTrigRec != NULL)
146 {
147 delete fTrigRec;
148 fTrigRec = NULL;
149 }
150
151 try
152 {
153 fTrigRec = new AliHLTMUONTriggerReconstructor();
154 }
155 catch (const std::bad_alloc&)
156 {
157 HLTError("Could not allocate more memory for the trigger reconstructor component.");
158 return -ENOMEM;
159 }
160
161 fDDL = -1;
b39b98c8 162 fWarnForUnexpecedBlock = false;
163 fSuppressPartialTrigs = false;
960d54ad 164
b39b98c8 165 const char* lutFileName = NULL;
c95cf30c 166 const char* cdbPath = NULL;
167 Int_t run = -1;
168 bool useCDB = false;
b39b98c8 169
170 for (int i = 0; i < argc; i++)
171 {
6ec6a7c1 172 if (strcmp( argv[i], "-lut" ) == 0)
b39b98c8 173 {
174 if ( argc <= i+1 )
175 {
176 HLTError("LookupTable filename not specified." );
a6b16447 177 // Make sure to delete fTrigRec to avoid partial initialisation.
178 delete fTrigRec;
179 fTrigRec = NULL;
180 return -EINVAL;
b39b98c8 181 }
182
183 lutFileName = argv[i+1];
184
185 i++;
186 continue;
187 }
188
6ec6a7c1 189 if (strcmp( argv[i], "-ddl" ) == 0)
b39b98c8 190 {
191 if ( argc <= i+1 )
192 {
c95cf30c 193 HLTError("DDL number not specified. It must be in the range [21..22]" );
a6b16447 194 // Make sure to delete fTrigRec to avoid partial initialisation.
195 delete fTrigRec;
196 fTrigRec = NULL;
197 return -EINVAL;
b39b98c8 198 }
199
200 char* cpErr = NULL;
201 unsigned long num = strtoul(argv[i+1], &cpErr, 0);
202 if (cpErr == NULL or *cpErr != '\0')
203 {
a6b16447 204 HLTError("Cannot convert '%s' to a DDL Number.", argv[i+1] );\
205 // Make sure to delete fTrigRec to avoid partial initialisation.
206 delete fTrigRec;
207 fTrigRec = NULL;
208 return -EINVAL;
b39b98c8 209 }
210 if (num < 21 or 22 < num)
211 {
c95cf30c 212 HLTError("The DDL ID number must be in the range [21..22].");
a6b16447 213 // Make sure to delete fTrigRec to avoid partial initialisation.
214 delete fTrigRec;
215 fTrigRec = NULL;
216 return -EINVAL;
b39b98c8 217 }
218 fDDL = num - 1; // Convert to DDL number in the range 0..21
219
220 i++;
221 continue;
222 }
c95cf30c 223
224 if (strcmp( argv[i], "-cdb" ) == 0)
225 {
226 useCDB = true;
227 continue;
228 }
229
230 if (strcmp( argv[i], "-cdbpath" ) == 0)
231 {
232 if ( argc <= i+1 )
233 {
234 HLTError("The CDB path was not specified." );
235 // Make sure to delete fTrigRec to avoid partial initialisation.
236 delete fTrigRec;
237 fTrigRec = NULL;
238 return -EINVAL;
239 }
240 cdbPath = argv[i+1];
241 useCDB = true;
242 i++;
243 continue;
244 }
245
246 if (strcmp( argv[i], "-run" ) == 0)
247 {
248 if ( argc <= i+1 )
249 {
250 HLTError("The RUN number was not specified." );
251 // Make sure to delete fTrigRec to avoid partial initialisation.
252 delete fTrigRec;
253 fTrigRec = NULL;
254 return -EINVAL;
255 }
256
257 char* cpErr = NULL;
258 run = Int_t( strtoul(argv[i+1], &cpErr, 0) );
259 if (cpErr == NULL or *cpErr != '\0')
260 {
261 HLTError("Cannot convert '%s' to a valid run number."
262 " Expected an integer value.", argv[i+1]
263 );
264 // Make sure to delete fTrigRec to avoid partial initialisation.
265 delete fTrigRec;
266 fTrigRec = NULL;
267 return -EINVAL;
268 }
b39b98c8 269
c95cf30c 270 i++;
271 continue;
272 }
273
6ec6a7c1 274 if (strcmp( argv[i], "-warn_on_unexpected_block" ) == 0)
b39b98c8 275 {
276 fWarnForUnexpecedBlock = true;
277 continue;
278 }
c95cf30c 279
6ec6a7c1 280 if (strcmp( argv[i], "-suppress_partial_triggers" ) == 0)
b39b98c8 281 {
282 fSuppressPartialTrigs = true;
283 continue;
284 }
285
286 HLTError("Unknown option '%s'.", argv[i] );
a6b16447 287 // Make sure to delete fTrigRec to avoid partial initialisation.
288 delete fTrigRec;
289 fTrigRec = NULL;
290 return -EINVAL;
c95cf30c 291
a6b16447 292 } // for loop
b39b98c8 293
c95cf30c 294 if (lutFileName == NULL) useCDB = true;
295
b39b98c8 296 if (fDDL == -1)
297 {
298 HLTWarning("DDL number not specified. Cannot check if incomming data is valid.");
960d54ad 299 }
960d54ad 300
c95cf30c 301 int result = 0;
302 if (useCDB)
b39b98c8 303 {
c95cf30c 304 HLTInfo("Loading lookup table information from CDB for DDL %d.", fDDL+1);
305 if (fDDL == -1)
306 HLTWarning("DDL number not specified. The lookup table loaded from CDB will be empty!");
307 result = ReadCDB(cdbPath, run);
960d54ad 308 }
b39b98c8 309 else
310 {
c95cf30c 311 HLTInfo("Loading lookup table information from file %s.", lutFileName);
312 result = ReadLookUpTable(lutFileName);
313 }
314 if (result != 0)
315 {
316 // Error messages already generated in ReadCDB or ReadLookUpTable.
317
318 // Make sure to delete fTrigRec to avoid partial initialisation.
319 delete fTrigRec;
320 fTrigRec = NULL;
321 return result;
960d54ad 322 }
b39b98c8 323
324 return 0;
6efe69e7 325}
326
960d54ad 327
6efe69e7 328int AliHLTMUONTriggerReconstructorComponent::DoDeinit()
960d54ad 329{
6253e09b 330 ///
331 /// Inherited from AliHLTComponent. Performs a cleanup of the component.
332 ///
333
b39b98c8 334 HLTInfo("Deinitialising dHLT trigger reconstructor component.");
227e7192 335
b39b98c8 336 if (fTrigRec != NULL)
227e7192 337 {
338 delete fTrigRec;
339 fTrigRec = NULL;
340 }
341 return 0;
960d54ad 342}
6efe69e7 343
227e7192 344
960d54ad 345int AliHLTMUONTriggerReconstructorComponent::DoEvent(
346 const AliHLTComponentEventData& evtData,
b39b98c8 347 const AliHLTComponentBlockData* blocks,
348 AliHLTComponentTriggerData& /*trigData*/,
349 AliHLTUInt8_t* outputPtr,
960d54ad 350 AliHLTUInt32_t& size,
351 std::vector<AliHLTComponentBlockData>& outputBlocks
352 )
353{
6253e09b 354 ///
355 /// Inherited from AliHLTProcessor. Processes the new event data.
356 ///
357
227e7192 358 // Process an event
359 unsigned long totalSize = 0; // Amount of memory currently consumed in bytes.
6efe69e7 360
227e7192 361 HLTDebug("Processing event %llu with %u input data blocks.",
362 evtData.fEventID, evtData.fBlockCnt
363 );
6efe69e7 364
227e7192 365 // Loop over all input blocks in the event and run the trigger DDL
366 // reconstruction algorithm on the raw data.
367 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
368 {
450e0b36 369 HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
370 n, DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fPtr, blocks[n].fSize
227e7192 371 );
372
668eee9f 373 if (blocks[n].fDataType != AliHLTMUONConstants::DDLRawDataType()
374 or not AliHLTMUONUtils::IsTriggerDDL(blocks[n].fSpecification)
375 )
227e7192 376 {
377 // Log a message indicating that we got a data block that we
378 // do not know how to handle.
5d1682b9 379 if (fWarnForUnexpecedBlock)
450e0b36 380 HLTWarning("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
381 DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification
5d1682b9 382 );
383 else
450e0b36 384 HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
385 DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification
5d1682b9 386 );
387
227e7192 388 continue;
389 }
390
a6b16447 391 if (fDDL != -1)
b39b98c8 392 {
a6b16447 393 bool ddl[22];
394 AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
395 if (not ddl[fDDL])
396 {
397 HLTWarning("Received raw data from an unexpected DDL.");
398 }
b39b98c8 399 }
400
227e7192 401 // Create a new output data block and initialise the header.
402 AliHLTMUONTriggerRecordsBlockWriter block(outputPtr+totalSize, size-totalSize);
403 if (not block.InitCommonHeader())
404 {
405 HLTError("There is not enough space in the output buffer for the new data block.",
b39b98c8 406 " We require at least %ufTrigRec->GetkDDLHeaderSize() bytes, but have %u bytes left.",
227e7192 407 sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType),
408 block.BufferSize()
409 );
410 break;
411 }
412
413 AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t);
b39b98c8 414 AliHLTUInt32_t ddlRawDataSize = totalDDLSize - 8;
415 AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr) + 8;
227e7192 416 AliHLTUInt32_t nofTrigRec = block.MaxNumberOfEntries();
417
80590aa1 418 bool runOk = fTrigRec->Run(
419 buffer, ddlRawDataSize,
420 block.GetArray(), nofTrigRec,
421 fSuppressPartialTrigs
422 );
423 if (not runOk)
227e7192 424 {
425 HLTError("Error while processing of trigger DDL reconstruction algorithm.");
426 size = totalSize; // Must tell the framework how much buffer space was used.
a6b16447 427 return -EIO;
227e7192 428 }
429
430 // nofTrigRec should now contain the number of triggers actually found
431 // and filled into the output data block, so we can set this number.
432 assert( nofTrigRec <= block.MaxNumberOfEntries() );
433 block.SetNumberOfEntries(nofTrigRec);
434
435 HLTDebug("Number of trigger records found is %d", nofTrigRec);
436
437 // Fill a block data structure for our output block.
438 AliHLTComponentBlockData bd;
439 FillBlockData(bd);
440 bd.fPtr = outputPtr;
441 // This block's start (offset) is after all other blocks written so far.
442 bd.fOffset = totalSize;
443 bd.fSize = block.BytesUsed();
444 bd.fDataType = AliHLTMUONConstants::TriggerRecordsBlockDataType();
445 bd.fSpecification = blocks[n].fSpecification;
446 outputBlocks.push_back(bd);
447
448 HLTDebug("Created a new output data block at fPtr = %p,"
449 " with fOffset = %u (0x%.X) and fSize = %u bytes.",
450 bd.fPtr, bd.fOffset, bd.fOffset, bd.fSize
451 );
452
453 // Increase the total amount of data written so far to our output memory.
454 totalSize += block.BytesUsed();
455 }
960d54ad 456
227e7192 457 // Finally we set the total size of output memory we consumed.
458 size = totalSize;
459 return 0;
960d54ad 460}
461
6efe69e7 462
c95cf30c 463int AliHLTMUONTriggerReconstructorComponent::ReadLookUpTable(const char* lutpath)
6efe69e7 464{
6253e09b 465 ///
466 /// Read in the lookup table from file.
467 ///
468
b39b98c8 469 assert(fTrigRec != NULL);
6efe69e7 470
b39b98c8 471 fstream file;
472 file.open(lutpath, fstream::binary | fstream::in);
473 if (not file)
474 {
475 HLTError("Could not open file: %s", lutpath);
c95cf30c 476 return -ENOENT;
b39b98c8 477 }
478
479 file.read(reinterpret_cast<char*>(fTrigRec->LookupTableBuffer()), fTrigRec->LookupTableSize());
480 if (file.eof())
481 {
482 HLTError("The file %s was too short to contain a valid lookup table for this component.", lutpath);
483 file.close();
c95cf30c 484 return -EIO;
b39b98c8 485 }
c95cf30c 486 if (file.fail())
b39b98c8 487 {
488 HLTError("Could not read from file: %s", lutpath);
489 file.close();
c95cf30c 490 return -EIO;
491 }
492
493 file.close();
494 return 0;
495}
496
497
498int AliHLTMUONTriggerReconstructorComponent::ReadCDB(const char* cdbPath, Int_t run)
499{
500 /// Loads the lookup table containing channel and geometrical position
501 /// information about trigger strips from CDB.
502 /// \param cdbPath This specifies the CDB path to use to load from.
503 /// Can be set to NULL meaning the default storage is used.
504 /// \param run Specifies the run number to use. If set to -1 then the
505 /// default / current run number set for the CDB is used.
506 /// \return 0 on success and non zero codes for errors.
507
508 if (fDDL == -1)
509 {
510 HLTError("No DDL number specified for which to load LUT data from CDB.");
511 return -EINVAL;
512 }
513
514 Bool_t warn = kFALSE;
515
516 AliCDBManager* cdbManager = AliCDBManager::Instance();
517 if (cdbManager == NULL)
518 {
519 HLTError("CDB manager instance does not exist.");
520 return -EIO;
521 }
522
523 const char* cdbPathUsed = "unknown (not set)";
524 if (cdbPath != NULL)
525 {
526 cdbManager->SetDefaultStorage(cdbPath);
527 cdbPathUsed = cdbPath;
528 }
529 else
530 {
531 AliCDBStorage* store = cdbManager->GetDefaultStorage();
532 if (store != NULL) cdbPathUsed = store->GetURI().Data();
533 }
534
535 if (run != -1) cdbManager->SetRun(run);
536 Int_t runUsed = cdbManager->GetRun();
537
538 if (not AliMpCDB::LoadDDLStore(warn))
539 {
540 HLTError("Failed to load DDL store specified for CDB path '%s' and run no. %d",
541 cdbPathUsed, runUsed
542 );
543 return -ENOENT;
544 }
545 AliMpDDLStore* ddlStore = AliMpDDLStore::Instance();
546 if (ddlStore == NULL)
547 {
548 HLTError("Could not find DDL store instance.");
549 return -EIO;
550 }
551 AliMpSegmentation* segmentation = AliMpSegmentation::Instance();
552 if (segmentation == NULL)
553 {
554 HLTError("Could not find segmentation mapping (AliMpSegmentation) instance.");
555 return -EIO;
556 }
557
558 AliGeomManager::LoadGeometry();
559 AliMUONGeometryTransformer transformer;
560 if (not transformer.LoadGeometryData())
561 {
562 HLTError("Could not load geometry into transformer.");
563 return -ENOENT;
564 }
565
566 AliHLTMUONTriggerRecoLookupTable* lookupTable = fTrigRec->LookupTableBuffer();
567
568 for (Int_t i = 0; i < 8; i++)
569 for (Int_t j = 0; j < 16; j++)
570 for (Int_t k = 0; k < 4; k++)
571 for (Int_t n = 0; n < 2; n++)
572 for (Int_t m = 0; m < 16; m++)
573 {
574 lookupTable->fRow[i][j][k][n][m].fX = 0;
575 lookupTable->fRow[i][j][k][n][m].fY = 0;
576 lookupTable->fRow[i][j][k][n][m].fZ = 0;
577 }
578
579 AliMpDEIterator detElemIter;
580 for (Int_t iReg = 0; iReg < 8; iReg++)
581 {
582 AliMpTriggerCrate* crate = ddlStore->GetTriggerCrate(fDDL, iReg);
583 if (crate == NULL)
584 {
585 cerr << "ERROR: Could not get crate for regional header = " << iReg
586 << ", and DDL ID = " << fDDL << endl;
587 continue;
588 }
589
590 for (Int_t iLocBoard = 0; iLocBoard < 16; iLocBoard++)
591 {
592 Int_t boardId = crate->GetLocalBoardId(iLocBoard);
593 if (boardId == 0) continue;
594
595 AliMpLocalBoard* localBoard = ddlStore->GetLocalBoard(boardId);
596 if (localBoard == NULL)
597 {
598 cerr << "ERROR: Could not get loacl board: " << boardId << endl;
599 continue;
600 }
601
602 // skip copy cards
603 if (! localBoard->IsNotified()) continue;
604
605 for (Int_t iChamber = 0; iChamber < 4; iChamber++)
606 {
607 Int_t detElemId = ddlStore->GetDEfromLocalBoard(boardId, iChamber);
608
609 const AliMUONGeometryDetElement* detElemTransform = transformer.GetDetElement(detElemId);
610 if (detElemTransform == NULL)
611 {
612 cerr << "ERROR: Got NULL pointer for geometry transformer for detection element ID = "
613 << detElemId << endl;
614 continue;
615 }
616
617 for (Int_t iCathode = 0; iCathode <= 1; iCathode++)
618 {
619 const AliMpVSegmentation* seg = segmentation->GetMpSegmentation(
620 detElemId, AliMp::GetCathodType(iCathode)
621 );
622
623 for (Int_t bitxy = 0; bitxy < 16; bitxy++)
624 {
625 Int_t offset = 0;
626 if (iCathode && localBoard->GetSwitch(6)) offset = -8;
627
628 AliMpPad pad = seg->PadByLocation(AliMpIntPair(boardId, bitxy+offset), kFALSE);
629
630 if (! pad.IsValid())
631 {
632 // There is no pad associated with the given local board and bit pattern.
633 continue;
634 }
635
636 // Get the global coodinates of the pad.
637 Float_t lx = pad.Position().X();
638 Float_t ly = pad.Position().Y();
639 Float_t gx, gy, gz;
640 detElemTransform->Local2Global(lx, ly, 0, gx, gy, gz);
641
642 // Fill the LUT
643 lookupTable->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fX = gx;
644 lookupTable->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fY = gy;
645 lookupTable->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fZ = gz;
646 }
647 }
648 }
649 }
650 }
651
652 return 0;
653}
654
655
656bool AliHLTMUONTriggerReconstructorComponent::GenerateLookupTable(
657 AliHLTInt32_t ddl, const char* filename,
658 const char* cdbPath, Int_t run
659 )
660{
661 /// Generates a binary file containing the lookup table (LUT) from the
662 /// CDB, which can be used for the trigger reconstructor component later.
663 /// @param ddl Must be the DDL for which to generate the DDL,
664 /// in the range [20..21].
665 /// @param filename The name of the LUT file to generate.
666 /// @param cdbPath The CDB path to use.
667 /// @param run The run number to use for the CDB.
668 /// @return True if the generation of the LUT file succeeded.
669
670 AliHLTMUONTriggerReconstructorComponent comp;
671
672 if (ddl < 20 or 21 < ddl)
673 {
674 std::cerr << "ERROR: the DDL number must be in the range [20..21]." << std::endl;
675 return false;
676 }
677
678 char ddlNum[32];
679 char runNum[32];
680 sprintf(ddlNum, "%d", ddl+1);
681 sprintf(runNum, "%d", run);
682 const char* argv[7] = {"-ddl", ddlNum, "-cdbpath", cdbPath, "-run", runNum, NULL};
683 int result = comp.DoInit(6, argv);
684 if (result != 0)
685 {
686 // Error message already generated in DoInit.
b39b98c8 687 return false;
688 }
689
c95cf30c 690 std::fstream file(filename, std::ios::out);
691 if (not file)
692 {
693 std::cerr << "ERROR: could not open file: " << filename << std::endl;
694 return false;
695 }
696
697 file.write(
698 reinterpret_cast<char*>(comp.fTrigRec->LookupTableBuffer()),
699 comp.fTrigRec->LookupTableSize()
700 );
701 if (not file)
702 {
703 cerr << "ERROR: There was a problem writing to the file: " << filename << endl;
704 return false;
705 }
b39b98c8 706 file.close();
c95cf30c 707
708 comp.DoDeinit();
709
b39b98c8 710 return true;
960d54ad 711}