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