]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/AliHLTMUONProcessor.cxx
USE_ROOT instead of use_root
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONProcessor.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        *
3  * All rights reserved.                                                   *
4  *                                                                        *
5  * Primary Authors:                                                       *
6  *   Artur Szostak <artursz@iafrica.com>                                  *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 // $Id: $
18
19 ///
20 /// @file   AliHLTMUONProcessor.cxx
21 /// @author Artur Szostak <artursz@iafrica.com>
22 /// @date   19 May 2008
23 /// @brief  Implementation of the abstract base dHLT processor component.
24 ///
25 /// This component is the abstract base class of dHLT specific components.
26 /// It implements some common methods used by all the dHLT components.
27 ///
28
29 #include "AliHLTMUONProcessor.h"
30 #include "AliHLTMUONConstants.h"
31 #include "AliHLTMisc.h"
32 #include "AliMUONRecoParam.h"
33 #include "AliCDBManager.h"
34 #include "AliCDBStorage.h"
35 #include "AliCDBEntry.h"
36 #include "AliGRPManager.h"
37 #include "AliGRPObject.h"
38 #include "AliMagF.h"
39 #include "AliMpCDB.h"
40 #include "AliMpDDLStore.h"
41 #include "AliMpDEStore.h"
42 #include "TGeoGlobalMagField.h"
43 #include "TMap.h"
44 #include "TObjString.h"
45 #include "TString.h"
46 #include <string>
47 #include <cstdlib>
48 #include <fstream>
49
50
51 ClassImp(AliHLTMUONProcessor)
52
53
54 AliHLTMUONProcessor::AliHLTMUONProcessor() :
55         AliHLTProcessor(),
56         fWarnForUnexpecedBlock(false),
57         fDelaySetup(false),
58         fDumpDataOnError(false),
59         fDumpPath("./")
60 {
61         /// Default constructor.
62 }
63
64
65 int AliHLTMUONProcessor::DoInit(int argc, const char** argv)
66 {
67         /// Parses common dHLT component arguments.
68
69         // Set the default values for various arguments comming from the command line.
70         fDelaySetup = false;
71         fDumpDataOnError = false;
72         fDumpPath = "./";
73         const char* cdbPath = NULL;
74         Int_t run = -1;
75
76         for (int i = 0; i < argc; i++)
77         {
78                 // Ignore the argument if the child class indicates to do so.
79                 if (IgnoreArgument(argv[i])) continue;
80         
81                 if (strcmp(argv[i], "-cdbpath") == 0)
82                 {
83                         if (cdbPath != NULL)
84                         {
85                                 HLTWarning("CDB path was already specified. Will"
86                                         " replace previous value given by -cdbpath."
87                                 );
88                         }
89                         if (argc <= i+1)
90                         {
91                                 HLTError("The CDB path was not specified." );
92                                 return -EINVAL;
93                         }
94                         cdbPath = argv[i+1];
95                         i++;
96                         continue;
97                 }
98         
99                 if (strcmp(argv[i], "-run") == 0)
100                 {
101                         if (run != -1)
102                         {
103                                 HLTWarning("Run number was already specified. Will"
104                                         " replace previous value given by -run."
105                                 );
106                         }
107                         if (argc <= i+1)
108                         {
109                                 HLTError("The run number was not specified.");
110                                 return -EINVAL;
111                         }
112                         
113                         char* cpErr = NULL;
114                         run = Int_t( strtol(argv[i+1], &cpErr, 0) );
115                         if (cpErr == NULL or *cpErr != '\0' or run < 0)
116                         {
117                                 HLTError("Cannot convert '%s' to a valid run number."
118                                         " Expected a positive integer value.", argv[i+1]
119                                 );
120                                 return -EINVAL;
121                         }
122                         
123                         i++;
124                         continue;
125                 }
126                 
127                 if (strcmp(argv[i], "-delaysetup") == 0)
128                 {
129                         fDelaySetup = true;
130                         continue;
131                 }
132                 
133                 if (strcmp(argv[i], "-dumponerror") == 0)
134                 {
135                         fDumpDataOnError = true;
136                         continue;
137                 }
138                 
139                 if (strcmp(argv[i], "-dumppath") == 0)
140                 {
141                         if (fDumpPath != NULL)
142                         {
143                                 HLTWarning("The dump path was already specified. Will"
144                                         " replace previous value given by -dumppath."
145                                 );
146                         }
147                         if (argc <= i+1)
148                         {
149                                 HLTError("The dump path was not specified.");
150                                 return -EINVAL;
151                         }
152                         fDumpPath = argv[i+1];
153                         i++;
154                         continue;
155                 }
156         }
157         
158         if (cdbPath != NULL or run != -1)
159         {
160                 int result = SetCDBPathAndRunNo(cdbPath, run);
161                 if (result != 0)
162                 {
163                         // Error messages already generated in SetCDBPathAndRunNo.
164                         return result;
165                 }
166         }
167
168         return 0;
169 }
170
171
172 bool AliHLTMUONProcessor::ArgumentAlreadyHandled(int& i, const char* argi) const
173 {
174         /// This method can be used by the derivind child class to check if a particular
175         /// argument in argv was already processed.
176
177         if (strcmp(argi, "-cdbpath") == 0)
178         {
179                 if (IgnoreArgument(argi)) return false;
180                 i++;  // argument takes one parameter
181                 return true;
182         }
183
184         if (strcmp(argi, "-run") == 0)
185         {
186                 if (IgnoreArgument(argi)) return false;
187                 i++;  // argument takes one parameter
188                 return true;
189         }
190         
191         if (strcmp(argi, "-delaysetup") == 0)
192         {
193                 if (IgnoreArgument(argi)) return false;
194                 return true;
195         }
196         
197         if (strcmp(argi, "-dumponerror") == 0)
198         {
199                 if (IgnoreArgument(argi)) return false;
200                 return true;
201         }
202         
203         if (strcmp(argi, "-dumppath") == 0)
204         {
205                 if (IgnoreArgument(argi)) return false;
206                 i++;  // argument takes one parameter
207                 return true;
208         }
209
210         return false;
211 }
212
213
214 int AliHLTMUONProcessor::SetCDBPathAndRunNo(
215                 const char* cdbPath, Int_t run, bool useDefault
216         ) const
217 {
218         /// Sets the CDB path and run number to read from.
219         /// \param cdbPath  The CDB path to use. If set to NULL and the path has
220         ///      not been set in the CDB manager then the default path
221         ///      "local://$ALICE_ROOT/OCDB" is used if the 'useDefault' flag is also true.
222         /// \param run  The run number to use. If set to -1 and the run number has
223         ///      not been set in the CDB manager then a value of zero is used if
224         ///      the 'useDefault' flag is also true.
225         /// \param useDefault  If set to true then a default CDB path and/or run number
226         ///      is used if they have not been set and 'cdbPath' == NULL or
227         ///      'run' == -1.
228         /// \return Zero if the object could be loaded. Otherwise an error code,
229         ///      compatible with the HLT framework, is returned.
230         
231         const char* defaultPath = "local://$ALICE_ROOT/OCDB";
232         Int_t defaultRun = 0;
233         
234         AliCDBManager* cdbManager = AliCDBManager::Instance();
235         if (cdbManager == NULL)
236         {
237                 HLTError("CDB manager instance does not exist.");
238                 return -EIO;
239         }
240         
241         // Setup the CDB path.
242         if (cdbPath != NULL)
243         {
244                 cdbManager->SetDefaultStorage(cdbPath);
245         }
246         else if (not cdbManager->IsDefaultStorageSet() and useDefault)
247         {
248                 cdbManager->SetDefaultStorage(defaultPath);
249         }
250         
251         // Now setup the run number.
252         if (run != -1)
253         {
254                 cdbManager->SetRun(run);
255         }
256         else
257         {
258                 if (useDefault) cdbManager->SetRun(defaultRun);
259         }
260         
261         return 0;
262 }
263
264
265 int AliHLTMUONProcessor::FetchMappingStores() const
266 {
267         /// Fetches the DDL and detector element store objects for MUON mapping.
268         /// \return Zero if the objects could be loaded. Otherwise an error code,
269         ///      which is compatible with the HLT framework, is returned.
270         /// \note AliMpDDLStore::Instance() and AliMpDEStore::Instance() must be used
271         ///      to fetch the objects after this method returns a code equal to zero.
272         
273         Bool_t warn = kFALSE;
274         
275         // Check if the objects are already loaded. If they are then exit early,
276         // otherwise we need to try load the objects.
277         if (AliMpDDLStore::Instance(warn) != NULL and AliMpDEStore::Instance(warn) != NULL)
278                 return 0;
279         
280         AliCDBManager* cdbManager = AliCDBManager::Instance();
281         if (cdbManager == NULL)
282         {
283                 HLTError("CDB manager instance does not exist.");
284                 return -EIO;
285         }
286         
287         const char* cdbPathUsed = "unknown (not set)";
288         AliCDBStorage* store = cdbManager->GetDefaultStorage();
289         if (store != NULL) cdbPathUsed = store->GetURI().Data();
290         
291         Int_t runUsed = cdbManager->GetRun();
292         
293         // Now we can try load the DDL and DE store objects.
294         if (AliHLTMisc::Instance().LoadOCDBEntry("MUON/Calib/MappingData", runUsed) == NULL)
295         {
296                 HLTError("Could not find entry in CDB path '%s/MUON/Calib/MappingData' and run no. %d.",
297                         cdbPathUsed, runUsed
298                 );
299                 return -ENOENT;
300         }
301         if (AliHLTMisc::Instance().LoadOCDBEntry("MUON/Calib/Gains", runUsed) == NULL)
302         {
303                 HLTError("Could not find entry in CDB path '%s/MUON/Calib/Gains' and run no. %d.",
304                         cdbPathUsed, runUsed
305                 );
306                 return -ENOENT;
307         }
308         if (AliHLTMisc::Instance().LoadOCDBEntry("MUON/Calib/Pedestals", runUsed) == NULL)
309         {
310                 HLTError("Could not find entry in CDB path '%s/MUON/Calib/Pedestals' and run no. %d.",
311                         cdbPathUsed, runUsed
312                 );
313                 return -ENOENT;
314         }
315         if (not AliMpCDB::LoadDDLStore(warn))
316         {
317                 HLTError("Failed to load DDL or detector element store specified"
318                          " for CDB path '%s' and run no. %d.",
319                         cdbPathUsed, runUsed
320                 );
321                 return -EIO;
322         }
323         
324         if (AliMpDDLStore::Instance(warn) == NULL or AliMpDEStore::Instance(warn) == NULL)
325         {
326                 HLTError("Could not find or load the DDL or detector element store instance.");
327                 return -EIO;
328         }
329         
330         return 0;
331 }
332
333
334 int AliHLTMUONProcessor::FetchTMapFromCDB(const char* pathToEntry, TMap*& map) const
335 {
336         /// Fetches a TMap object from the CDB.
337         /// \param [in] pathToEntry  The relative path to the entry in the CDB to fetch.
338         /// \param [out] map  This will be filled with the TMap object found if
339         ///      a successful status code is returned. Otherwise it will be unchanged.
340         /// \return Zero if the object could be found. Otherwise an error code,
341         ///      which is compatible with the HLT framework, is returned.
342         
343         TObject* obj = LoadAndExtractOCDBObject(pathToEntry);
344         if (obj == NULL)
345         {
346                 HLTError("Configuration object for \"%s\" is missing.", pathToEntry);
347                 return -ENOENT;
348         }
349         
350         if (obj->IsA() != TMap::Class())
351         {
352                 HLTError("Wrong type for configuration object in \"%s\". Found a %s but we need a TMap.",
353                         pathToEntry, obj->ClassName()
354                 );
355                 return -EPROTO;
356         }
357         map = static_cast<TMap*>(obj);
358         
359         return 0;
360 }
361
362
363 int AliHLTMUONProcessor::GetValueFromTMap(
364                 TMap* map, const char* paramName, TString& value,
365                 const char* pathToEntry, const char* prettyName
366         ) const
367 {
368         /// Tries to find the string value associated with a certain parameter in a TMap.
369         /// \param [in] map  The TMap object to search in.
370         /// \param [in] paramName  The name of the parameter to search for.
371         /// \param [out] value  Will be filled with the object found.
372         /// \param [in] pathToEntry  The relative path to the entry in the CDB.
373         ///      Used when printing error messages. If set to NULL then a string of
374         ///      "(unknown)" is used. (default is NULL).
375         /// \param [in] prettyName  Should be the name of the parameter which will
376         ///      be used when printing error messages. If this is set to NULL then
377         ///      the paramName will be used instead (default is NULL).
378         /// \return Zero if the object could be found. Otherwise an error code,
379         ///      which is compatible with the HLT framework, is returned.
380         
381         if (pathToEntry == NULL) pathToEntry = "(unknown)";
382         if (prettyName == NULL) prettyName = paramName;
383         
384         TPair* pair = static_cast<TPair*>(map->FindObject(paramName));
385         if (pair == NULL)
386         {
387                 HLTError("Configuration object for \"%s\" does not contain the %s value.",
388                         pathToEntry, prettyName
389                 );
390                 return -ENOENT;
391         }
392         TObject* valueObj = pair->Value();
393         if (valueObj->IsA() != TObjString::Class())
394         {
395                 HLTError("The %s parameter found in configuration object \"%s\""
396                         " is not a TObjString. Found an object of type %s instead.",
397                         prettyName, pathToEntry, valueObj->ClassName()
398                 );
399                 return -EPROTO;
400         }
401         value = static_cast<TObjString*>(valueObj)->GetString();
402         
403         return 0;
404 }
405
406
407 int AliHLTMUONProcessor::GetIntFromTMap(
408                 TMap* map, const char* paramName, Int_t& value,
409                 const char* pathToEntry, const char* prettyName
410         ) const
411 {
412         /// Tries to find a certain parameter in the TMap object and convert it to
413         /// an integer value.
414         /// \param [in] map  The TMap object to search in.
415         /// \param [in] paramName  The name of the parameter to search for.
416         /// \param [out] value  Will be filled with the integer value for the parameter,
417         ///       if it was found and it was an integer value.
418         /// \param [in] pathToEntry  The relative path to the entry in the CDB.
419         ///      Used when printing error messages. If set to NULL then a string of
420         ///      "(unknown)" is used. (default is NULL).
421         /// \param [in] prettyName  Should be the name of the parameter which will
422         ///      be used when printing error messages. If this is set to NULL then
423         ///      the paramName will be used instead (default is NULL).
424         /// \return Zero if the object could be found and is valid. Otherwise an
425         ///       error code, which is compatible with the HLT framework, is returned.
426         
427         if (pathToEntry == NULL) pathToEntry = "(unknown)";
428         if (prettyName == NULL) prettyName = paramName;
429         
430         TString valueStr;
431         int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName);
432         if (result != 0) return result;
433         
434         if (not valueStr.IsDigit())
435         {
436                 HLTError("The %s parameter found in configuration object \"%s\""
437                         "is not a valid integer number string; found \"%s\".",
438                         prettyName, pathToEntry, valueStr.Data()
439                 );
440                 return -EPROTO;
441         }
442         value = valueStr.Atoi();
443         
444         return 0;
445 }
446
447
448 int AliHLTMUONProcessor::GetPositiveIntFromTMap(
449                 TMap* map, const char* paramName, Int_t& value,
450                 const char* pathToEntry, const char* prettyName
451         ) const
452 {
453         /// Tries to find a certain parameter in the TMap object and convert it to
454         /// a positive integer value.
455         /// \param [in] map  The TMap object to search in.
456         /// \param [in] paramName  The name of the parameter to search for.
457         /// \param [out] value  Will be filled with the integer value for the parameter,
458         ///       if it was found and it was a positive integer value.
459         /// \param [in] pathToEntry  The relative path to the entry in the CDB.
460         ///      Used when printing error messages. If set to NULL then a string of
461         ///      "(unknown)" is used. (default is NULL).
462         /// \param [in] prettyName  Should be the name of the parameter which will
463         ///      be used when printing error messages. If this is set to NULL then
464         ///      the paramName will be used instead (default is NULL).
465         /// \return Zero if the object could be found and is valid. Otherwise an
466         ///       error code, which is compatible with the HLT framework, is returned.
467         
468         if (pathToEntry == NULL) pathToEntry = "(unknown)";
469         if (prettyName == NULL) prettyName = paramName;
470         
471         TString valueStr;
472         int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName);
473         if (result != 0) return result;
474         
475         if (not valueStr.IsDigit())
476         {
477                 HLTError("The %s parameter found in configuration object \"%s\""
478                         "is not a valid integer number string; found \"%s\".",
479                         prettyName, pathToEntry, valueStr.Data()
480                 );
481                 return -EPROTO;
482         }
483         Int_t val = valueStr.Atoi();
484         if (val < 0)
485         {
486                 HLTError("The %s parameter found in configuration object \"%s\""
487                         "is not a positive integer number; found \"%d\".",
488                         prettyName, pathToEntry, val
489                 );
490                 return -EPROTO;
491         }
492         value = val;
493         
494         return 0;
495 }
496
497
498 int AliHLTMUONProcessor::GetFloatFromTMap(
499                 TMap* map, const char* paramName, Double_t& value,
500                 const char* pathToEntry, const char* prettyName
501         ) const
502 {
503         /// Tries to find a certain parameter in the TMap object and convert it to
504         /// an floating point value.
505         /// \param [in] map  The TMap object to search in.
506         /// \param [in] paramName  The name of the parameter to search for.
507         /// \param [out] value  Will be filled with the floating point value for the
508         ///       parameter, if it was found and it was a floating point value.
509         /// \param [in] pathToEntry  The relative path to the entry in the CDB.
510         ///      Used when printing error messages. If set to NULL then a string of
511         ///      "(unknown)" is used. (default is NULL).
512         /// \param [in] prettyName  Should be the name of the parameter which will
513         ///      be used when printing error messages. If this is set to NULL then
514         ///      the paramName will be used instead (default is NULL).
515         /// \return Zero if the object could be found and is valid. Otherwise an
516         ///       error code, which is compatible with the HLT framework, is returned.
517         
518         if (pathToEntry == NULL) pathToEntry = "(unknown)";
519         if (prettyName == NULL) prettyName = paramName;
520         
521         TString valueStr;
522         int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName);
523         if (result != 0) return result;
524         
525         if (not valueStr.IsFloat())
526         {
527                 HLTError("The %s parameter found in configuration object \"%s\""
528                         "is not a valid floating point number string; found \"%s\".",
529                         prettyName, pathToEntry, valueStr.Data()
530                 );
531                 return -EPROTO;
532         }
533         value = valueStr.Atof();
534         
535         return 0;
536 }
537
538
539 int AliHLTMUONProcessor::GetPositiveFloatFromTMap(
540                 TMap* map, const char* paramName, Double_t& value,
541                 const char* pathToEntry, const char* prettyName
542         ) const
543 {
544         /// Tries to find a certain parameter in the TMap object and convert it to
545         /// an positive floating point value.
546         /// \param [in] map  The TMap object to search in.
547         /// \param [in] paramName  The name of the parameter to search for.
548         /// \param [out] value  Will be filled with the floating point value for the
549         ///       parameter, if it was found and it was a positive floating point value.
550         /// \param [in] pathToEntry  The relative path to the entry in the CDB.
551         ///      Used when printing error messages. If set to NULL then a string of
552         ///      "(unknown)" is used. (default is NULL).
553         /// \param [in] prettyName  Should be the name of the parameter which will
554         ///      be used when printing error messages. If this is set to NULL then
555         ///      the paramName will be used instead (default is NULL).
556         /// \return Zero if the object could be found and is valid. Otherwise an
557         ///       error code, which is compatible with the HLT framework, is returned.
558         
559         if (pathToEntry == NULL) pathToEntry = "(unknown)";
560         if (prettyName == NULL) prettyName = paramName;
561         
562         TString valueStr;
563         int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName);
564         if (result != 0) return result;
565         
566         if (not valueStr.IsFloat())
567         {
568                 HLTError("The %s parameter found in configuration object \"%s\""
569                         "is not a valid floating point number string; found \"%s\".",
570                         prettyName, pathToEntry, valueStr.Data()
571                 );
572                 return -EPROTO;
573         }
574         Double_t val = valueStr.Atof();
575         if (val < 0)
576         {
577                 HLTError("The %s parameter found in configuration object \"%s\""
578                         "is not a positive floating point number; found \"%d\".",
579                         prettyName, pathToEntry, val
580                 );
581                 return -EPROTO;
582         }
583         value = val;
584         
585         return 0;
586 }
587
588
589 int AliHLTMUONProcessor::FetchFieldIntegral(Double_t& bfieldintegral) const
590 {
591         // Fetches the correct dipole magnetic field integral to use.
592         
593         Float_t currentL3 = 0;
594         Float_t currentDip = 0;
595         
596         if (TGeoGlobalMagField::Instance() == NULL or
597             (TGeoGlobalMagField::Instance() != NULL and TGeoGlobalMagField::Instance()->GetField() == NULL)
598            )
599         {
600                 HLTWarning("The magnetic field has not been set in TGeoGlobalMagField."
601                         " Will try and load the GRP entry directly."
602                 );
603                 
604                 AliGRPManager grpman;
605                 if (not grpman.ReadGRPEntry() or grpman.GetGRPData() == NULL)
606                 {
607                         HLTError("GRP entry could not be loaded.");
608                         return -EIO;
609                 }
610                 
611                 const AliGRPObject* grp = grpman.GetGRPData();
612                 Char_t polarityL3 = grp->GetL3Polarity();
613                 Char_t polarityDip = grp->GetDipolePolarity();
614                 currentL3 = grp->GetL3Current(AliGRPObject::kMean);
615                 currentDip = grp->GetDipoleCurrent(AliGRPObject::kMean);
616                 if (polarityL3 == AliGRPObject::GetInvalidChar())
617                 {
618                         HLTError("L3 polarity in GRP is invalid.");
619                         return -EPROTO;
620                 }
621                 if (polarityDip == AliGRPObject::GetInvalidChar())
622                 {
623                         HLTError("Dipole polarity in GRP is invalid.");
624                         return -EPROTO;
625                 }
626                 if (currentL3 == AliGRPObject::GetInvalidFloat())
627                 {
628                         HLTError("L3 current in GRP is invalid.");
629                         return -EPROTO;
630                 }
631                 if (currentDip == AliGRPObject::GetInvalidFloat())
632                 {
633                         HLTError("Dipole current in GRP is invalid.");
634                         return -EPROTO;
635                 }
636                 if (grp->IsPolarityConventionLHC())
637                 {
638                         currentL3 *= (polarityL3 ? -1:1);
639                         currentDip *= (polarityDip ? -1:1);
640                 }
641                 else
642                 {
643                         currentL3 *= (polarityL3 ? -1:1);
644                         currentDip *= (polarityDip ? 1:-1);
645                 }
646         }
647         else
648         {
649                 TVirtualMagField* vfield = TGeoGlobalMagField::Instance()->GetField();
650                 AliMagF* field = dynamic_cast<AliMagF*>(vfield);
651                 if (vfield->IsA() != AliMagF::Class() or field == NULL)
652                 {
653                         HLTError(Form(
654                                 "The magnetic field is not of type AliMagF."
655                                 " Do not know how to handle class of type '%s'.",
656                                 vfield->ClassName()
657                         ));
658                         return -EPROTO;
659                 }
660                 currentL3 = field->GetCurrentSol();
661                 currentDip = field->GetCurrentDip();
662         }
663         
664         const char* path = AliHLTMUONConstants::FieldIntegralsCDBPath();
665         TMap* map = NULL;
666         int result = FetchTMapFromCDB(path, map);
667         if (result != 0) return result;
668         const char* paramName = Form("L3_current=%0.2e;Dipole_current=%0.2e", currentL3, currentDip);
669         Double_t value;
670         result = GetFloatFromTMap(map, paramName, value, path);
671         if (result != 0) return result;
672         bfieldintegral = value;
673         return 0;
674 }
675
676
677 int AliHLTMUONProcessor::LoadRecoParamsFromCDB(AliMUONRecoParam*& params) const
678 {
679         /// Fetches the reconstruction parameters object from the CDB for MUON.
680         /// \param [out] params  This will be filled with the reconstruction
681         ///      parameters object found if a successful status code is returned.
682         ///      Otherwise it will be unchanged.
683         /// \return Zero if the object could be found. Otherwise an error code,
684         ///      which is compatible with the HLT framework, is returned.
685         
686         const char* pathToEntry = "MUON/Calib/RecoParam";
687         TObject* obj = LoadAndExtractOCDBObject(pathToEntry);
688         if (obj == NULL)
689         {
690                 HLTError("Reconstruction parameters object for \"%s\" is missing.", pathToEntry);
691                 return -ENOENT;
692         }
693         
694         TObjArray* objarr = dynamic_cast<TObjArray*>(obj);
695         if (objarr != NULL)
696         {
697                 obj = objarr->Last();
698         }
699         
700         AliMUONRecoParam* par = dynamic_cast<AliMUONRecoParam*>(obj);
701         if (par == NULL)
702         {
703                 HLTError("No AliMUONRecoParam class found for entry \"%s\". Found a %s class instead.",
704                         pathToEntry, obj->ClassName()
705                 );
706                 return -EPROTO;
707         }
708         
709         params = par;
710         return 0;
711 }
712
713
714 void AliHLTMUONProcessor::DumpBuffer(
715                 const void* buffer, AliHLTUInt32_t size, const char* filename
716         ) const
717 {
718         /// Dumps the data contained in a buffer to file as is.
719
720         using std::fstream;
721
722         fstream file(filename, fstream::out | fstream::trunc | fstream::binary);
723         if (file.good())
724         {
725                 file.write(reinterpret_cast<const char*>(buffer), size);
726                 if (file.fail())
727                 {
728                         HLTError("Could not write data block to file %s during"
729                                 " dumping operation!",
730                                 filename
731                         );
732                 }
733         }
734         else
735         {
736                 HLTError("Could not open file %s for dumping data block!", filename);
737         }
738 }
739
740
741 void AliHLTMUONProcessor::DumpBlock(
742                 const AliHLTComponentBlockData* block, const char* fileNamePrefix
743         ) const
744 {
745         /// Dumps the data block and meta information to file.
746
747         std::string filename = fDumpPath;
748         filename += fileNamePrefix;
749         filename += "-blockmeta.bin";
750         DumpBuffer(block, sizeof(AliHLTComponentBlockData), filename.c_str());
751         filename = fDumpPath;
752         filename += fileNamePrefix;
753         filename += "-data.bin";
754         DumpBuffer(block->fPtr, block->fSize, filename.c_str());
755 }
756
757
758 void AliHLTMUONProcessor::DumpEvent(
759                 const AliHLTComponentEventData& evtData,
760                 const AliHLTComponentBlockData* blocks,
761                 AliHLTComponentTriggerData& trigData,
762                 AliHLTUInt8_t* outputPtr,
763                 AliHLTUInt32_t& size,
764                 AliHLTComponentBlockDataList& outputBlocks
765         ) const
766 {
767         /// Dumps the event information to files in the dump path given by the
768         /// method DumpPath, which can be set by the command line argument -dumppath.
769
770         using std::fstream;
771         char strbuf[1024];
772
773         std::string filename = fDumpPath;
774         sprintf(strbuf, "dump_event-0x%16.16llX.log", evtData.fEventID);
775         filename += strbuf;
776         fstream logfile(filename.c_str(), fstream::out | fstream::trunc);
777         if (logfile.fail())
778         {
779                 HLTError("Could not open log file '%s' for dump information.", filename.c_str());
780                 return;
781         }
782
783         filename = fDumpPath;
784         sprintf(strbuf, "dump_event-0x%16.16llX-eventdata.bin", evtData.fEventID);
785         filename += strbuf;
786         logfile << "Dumping event data structure to file: " << filename << std::endl;
787         DumpBuffer(&evtData, sizeof(AliHLTComponentEventData), filename.c_str());
788
789         filename = fDumpPath;
790         sprintf(strbuf, "dump_event-0x%16.16llX-triggerdata.bin", evtData.fEventID);
791         filename += strbuf;
792         logfile << "Dumping trigger data structure to file: " << filename << std::endl;
793         DumpBuffer(&trigData, sizeof(AliHLTComponentTriggerData), filename.c_str());
794
795         for (unsigned int n = 0; n < evtData.fBlockCnt; n++)
796         {
797                 sprintf(strbuf, "dump_event-0x%16.16llX-block-0x%8.8X", evtData.fEventID, n);
798                 filename = strbuf;
799                 sprintf(strbuf, "0x%8.8X", blocks[n].fSpecification);
800                 logfile << "Found block with data type = " << DataType2Text(blocks[n].fDataType)
801                         << ", specification = " << strbuf << ". Dumping to file: "
802                         << filename << "-data.bin" << std::endl;
803                 DumpBlock(&blocks[n], filename.c_str());
804         }
805
806         filename = fDumpPath;
807         sprintf(strbuf, "dump_event-0x%16.16llX-output-buffer.bin", evtData.fEventID);
808         filename += strbuf;
809         logfile << "Dumping output buffer to file: " << filename << std::endl;
810         DumpBuffer(outputPtr, size, filename.c_str());
811
812         for (size_t i = 0; i < outputBlocks.size(); i++)
813         {
814                 sprintf(strbuf, "dump_event-0x%16.16llX-output-block-0x%8.8X", evtData.fEventID, int(i));
815                 filename = strbuf;
816                 sprintf(strbuf, "0x%8.8X", outputBlocks[i].fSpecification);
817                 logfile << "Generated output data block with type = "
818                         << DataType2Text(outputBlocks[i].fDataType)
819                         << ", specification = " << strbuf << ". Dumping to file: "
820                         << filename << "-data.bin" << std::endl;
821                 DumpBlock(&outputBlocks[i], filename.c_str());
822         }
823 }
824
825
826 void AliHLTMUONProcessor::DumpEvent(
827                 const AliHLTComponentEventData& evtData,
828                 AliHLTComponentTriggerData& trigData
829         ) const
830 {
831         /// Dumps the event information to files in the dump path given by the
832         /// method DumpPath, which can be set by the command line argument -dumppath.
833
834         using std::fstream;
835         char strbuf[1024];
836
837         std::string filename = fDumpPath;
838         sprintf(strbuf, "dump_event-0x%16.16llX.log", evtData.fEventID);
839         filename += strbuf;
840         fstream logfile(filename.c_str(), fstream::out | fstream::trunc);
841         if (logfile.fail())
842         {
843                 HLTError("Could not open log file '%s' for dump information.", filename.c_str());
844                 return;
845         }
846
847         filename = fDumpPath;
848         sprintf(strbuf, "dump_event-0x%16.16llX-eventdata.bin", evtData.fEventID);
849         filename += strbuf;
850         logfile << "Dumping event data structure to file: " << filename << std::endl;
851         DumpBuffer(&evtData, sizeof(AliHLTComponentEventData), filename.c_str());
852
853         filename = fDumpPath;
854         sprintf(strbuf, "dump_event-0x%16.16llX-triggerdata.bin", evtData.fEventID);
855         filename += strbuf;
856         logfile << "Dumping trigger data structure to file: " << filename << std::endl;
857         DumpBuffer(&trigData, sizeof(AliHLTComponentTriggerData), filename.c_str());
858
859         for (int i = 0; i < GetNumberOfInputBlocks(); i++)
860         {
861                 const AliHLTComponentBlockData* block = GetInputBlock(i);
862                 sprintf(strbuf, "dump_event-0x%16.16llX-block-0x%8.8X", evtData.fEventID, i);
863                 filename = strbuf;
864                 sprintf(strbuf, "0x%8.8X", block->fSpecification);
865                 logfile << "Found block with data type = " << DataType2Text(block->fDataType)
866                         << ", specification = " << strbuf << ". Dumping to file: "
867                         << filename << "-data.bin" << std::endl;
868                 DumpBlock(block, filename.c_str());
869         }
870 }
871