ROOT logo
//-*- Mode: C++ -*-
// $Id$

#ifndef ALIHLTMISC_H
#define ALIHLTMISC_H
//* This file is property of and copyright by the                          * 
//* ALICE Experiment at CERN, All rights reserved.                         *
//* See cxx source for full Copyright notice                               */

/// @file   AliHLTMisc.h
/// @author Matthias Richter
/// @date   
/// @brief  Definition of various glue functions implemented in dynamically
///         loaded libraries

#include "TObject.h"
#include "AliHLTStdIncludes.h"
#include "AliHLTDataTypes.h"
#include "AliHLTLogging.h"
#include "TClass.h"
#include "TSystem.h"

class AliCDBManager;
class AliCDBEntry;
class AliRawReader;
struct AliHLTComponentDataType;
class AliHLTGlobalTriggerDecision;
class TMap;

/**
 * @class AliHLTMisc
 * Abstract interface of various glue functions implemented in dynamically
 * loaded libraries.
 *
 * The HLT base library is independent from AliRoot and binds AliRoot
 * functionality via dynamic libraries. The provided methods can be used
 * from any module library without introducing additional dependencies.
 */
class AliHLTMisc : public TObject {
 public:
  AliHLTMisc();
  ~AliHLTMisc();

  /// dynamically load a class from a library
  template<class T>
  static T* LoadInstance(const T* dummy, const char* classname, const char* library=NULL);

  /// the global instance of the interface implementation
  static AliHLTMisc& Instance();

  /// init the CDB patch
  virtual int InitCDB(const char* cdbpath);

  /// init the CDB run number
  virtual int SetCDBRunNo(int runNo);
  /// get the run number from CDB manager
  virtual int GetCDBRunNo() const;

  /// Load an OCDB object
  virtual AliCDBEntry* LoadOCDBEntry(const char* path, int runNo=-1) const;

  // Extract the TObject instance from the CDB object
  virtual TObject* ExtractObject(AliCDBEntry* entry) const;

  /// check the availability of the OCDB entry descriptions in the TMap
  ///  key : complete OCDB path of the entry
  ///  value : auxiliary object - short description
  virtual int CheckOCDBEntries(const TMap* const pMap) const;

  /// init the global magnetic field
  virtual int InitMagneticField() const;

  /// extract the triggermask from the rawreader
  /// NOTE: not to be used in the online system
  virtual AliHLTTriggerMask_t GetTriggerMask(AliRawReader* rawReader) const;

  /// extract the timestamp from the rawreader
  /// NOTE: not to be used in the online system, use AliHLTComponent::GetTimeStamp()
  virtual AliHLTUInt32_t GetTimeStamp(AliRawReader* rawReader) const;

  /// extract the event type from the rawreader
  /// NOTE: not to be used in the online system
  virtual AliHLTUInt32_t GetEventType(AliRawReader* rawReader) const;

  virtual Double_t GetBz();
  virtual Double_t GetBz(const Double_t *r);
  virtual void GetBxByBz(const Double_t r[3], Double_t b[3]);

  virtual const TClass* IsAliESDHLTDecision() const;
  
  using TObject::Copy;  // Needed since the declaration of AliHLTMisc::Copy below is ambiguous to the compiler.
  
  virtual int Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* pESDHLTDecision) const;

  /// Init streamer info from ocdb entry
  virtual int InitStreamerInfos(const char* ocdbEntry) const;

  /// Init streamer info for a collection of classes
  virtual int InitStreamerInfos(TObjArray* pSchemas) const;

  /// merge streamer info entries from source array to target array
  /// add all existing infos if not existing in the current one, or having
  /// different class version
  /// return 1 if target array has been changed
  virtual int MergeStreamerInfo(TObjArray* tgt, const TObjArray* src, int iVerbosity=0) const;

  /// set the online mode flag of AliESDtrack
  virtual void SetAliESDtrackOnlineModeFlag(bool mode) const;

  /// get status of the online mode flag of AliESDtrack
  virtual bool GetAliESDtrackOnlineModeFlag() const;

  /// guard class for switching offline software to online mode
  class AliOnlineGuard {
  public:
    AliOnlineGuard(bool mode=true);
    ~AliOnlineGuard();

  private:
    bool fMode; //! old value to be restored
  };

 private:
  static AliHLTMisc* fgInstance; //! global instance

  ClassDef(AliHLTMisc, 0)
};

#define ALIHLTMISC_LIBRARY "libHLTrec.so"
#define ALIHLTMISC_INIT_CDB "AliHLTMiscInitCDB"
#define ALIHLTMISC_SET_CDB_RUNNO "AliHLTMiscSetCDBRunNo"

#ifdef __cplusplus
extern "C" {
#endif

  /**
   * Init the CDB access for the running instance.
   * The method is used from the C wrapper interface utilized by the  on-line
   * framework. The path of the (H)CDB is set to the specified path.<br>
   * When running from AliRoot, the CDB path is set in the startup of the
   * reconstruction.<br>
   * If cdbpath is nil or empty and the CDB is not already initialized, the
   * CDB storage is set to local://$ALICE_ROOT/OCDB and the run no to 0.
   * @param cdbpath     path to the CDB
   * @return neg. error code if failed
   * @note function implemented in libHLTrec
   */
  int AliHLTMiscInitCDB(const char* cdbpath);
  typedef int (*AliHLTMiscInitCDB_t)(const char* cdbpath);

  /**
   * Init the Run no for the CDB access.
   * @param runNo       the run no
   * @return neg. error code if failed
   * @note function implemented in libHLTrec
   */
  int AliHLTMiscSetCDBRunNo(int runNo);
  typedef int (*AliHLTMiscSetCDBRunNo_t)(int runNo);

#ifdef __cplusplus
}
#endif

template<class T>
T* AliHLTMisc::LoadInstance(const T* /*t*/, const char* classname, const char* library)
{
  /// dynamically load a class from a library
  int iLibResult=0;
  T* pInstance=NULL;
  AliHLTLogging log;
  TClass* pCl=NULL;
  ROOT::NewFunc_t pNewFunc=NULL;
  do {
    pCl=TClass::GetClass(classname);
  } while (!pCl && library!=NULL && (iLibResult=gSystem->Load(library))==0);
  if (iLibResult>=0) {
    if (pCl && (pNewFunc=pCl->GetNew())!=NULL) {
      void* p=(*pNewFunc)(NULL);
      if (p) {
	pInstance=reinterpret_cast<T*>(p);
      } else {
	log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not create instance of type %s from class descriptor", classname);
      }
    } else {
      log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not find TClass descriptor %s", classname);
    }
  } else {
    log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not load %s library in order to find class descriptor %s", library, classname);
  }
  return pInstance;
}

// direct printout of data type struct
ostream  &operator<<(ostream &str, const AliHLTComponentDataType&);

#endif //ALIHLTMISC_H
 AliHLTMisc.h:1
 AliHLTMisc.h:2
 AliHLTMisc.h:3
 AliHLTMisc.h:4
 AliHLTMisc.h:5
 AliHLTMisc.h:6
 AliHLTMisc.h:7
 AliHLTMisc.h:8
 AliHLTMisc.h:9
 AliHLTMisc.h:10
 AliHLTMisc.h:11
 AliHLTMisc.h:12
 AliHLTMisc.h:13
 AliHLTMisc.h:14
 AliHLTMisc.h:15
 AliHLTMisc.h:16
 AliHLTMisc.h:17
 AliHLTMisc.h:18
 AliHLTMisc.h:19
 AliHLTMisc.h:20
 AliHLTMisc.h:21
 AliHLTMisc.h:22
 AliHLTMisc.h:23
 AliHLTMisc.h:24
 AliHLTMisc.h:25
 AliHLTMisc.h:26
 AliHLTMisc.h:27
 AliHLTMisc.h:28
 AliHLTMisc.h:29
 AliHLTMisc.h:30
 AliHLTMisc.h:31
 AliHLTMisc.h:32
 AliHLTMisc.h:33
 AliHLTMisc.h:34
 AliHLTMisc.h:35
 AliHLTMisc.h:36
 AliHLTMisc.h:37
 AliHLTMisc.h:38
 AliHLTMisc.h:39
 AliHLTMisc.h:40
 AliHLTMisc.h:41
 AliHLTMisc.h:42
 AliHLTMisc.h:43
 AliHLTMisc.h:44
 AliHLTMisc.h:45
 AliHLTMisc.h:46
 AliHLTMisc.h:47
 AliHLTMisc.h:48
 AliHLTMisc.h:49
 AliHLTMisc.h:50
 AliHLTMisc.h:51
 AliHLTMisc.h:52
 AliHLTMisc.h:53
 AliHLTMisc.h:54
 AliHLTMisc.h:55
 AliHLTMisc.h:56
 AliHLTMisc.h:57
 AliHLTMisc.h:58
 AliHLTMisc.h:59
 AliHLTMisc.h:60
 AliHLTMisc.h:61
 AliHLTMisc.h:62
 AliHLTMisc.h:63
 AliHLTMisc.h:64
 AliHLTMisc.h:65
 AliHLTMisc.h:66
 AliHLTMisc.h:67
 AliHLTMisc.h:68
 AliHLTMisc.h:69
 AliHLTMisc.h:70
 AliHLTMisc.h:71
 AliHLTMisc.h:72
 AliHLTMisc.h:73
 AliHLTMisc.h:74
 AliHLTMisc.h:75
 AliHLTMisc.h:76
 AliHLTMisc.h:77
 AliHLTMisc.h:78
 AliHLTMisc.h:79
 AliHLTMisc.h:80
 AliHLTMisc.h:81
 AliHLTMisc.h:82
 AliHLTMisc.h:83
 AliHLTMisc.h:84
 AliHLTMisc.h:85
 AliHLTMisc.h:86
 AliHLTMisc.h:87
 AliHLTMisc.h:88
 AliHLTMisc.h:89
 AliHLTMisc.h:90
 AliHLTMisc.h:91
 AliHLTMisc.h:92
 AliHLTMisc.h:93
 AliHLTMisc.h:94
 AliHLTMisc.h:95
 AliHLTMisc.h:96
 AliHLTMisc.h:97
 AliHLTMisc.h:98
 AliHLTMisc.h:99
 AliHLTMisc.h:100
 AliHLTMisc.h:101
 AliHLTMisc.h:102
 AliHLTMisc.h:103
 AliHLTMisc.h:104
 AliHLTMisc.h:105
 AliHLTMisc.h:106
 AliHLTMisc.h:107
 AliHLTMisc.h:108
 AliHLTMisc.h:109
 AliHLTMisc.h:110
 AliHLTMisc.h:111
 AliHLTMisc.h:112
 AliHLTMisc.h:113
 AliHLTMisc.h:114
 AliHLTMisc.h:115
 AliHLTMisc.h:116
 AliHLTMisc.h:117
 AliHLTMisc.h:118
 AliHLTMisc.h:119
 AliHLTMisc.h:120
 AliHLTMisc.h:121
 AliHLTMisc.h:122
 AliHLTMisc.h:123
 AliHLTMisc.h:124
 AliHLTMisc.h:125
 AliHLTMisc.h:126
 AliHLTMisc.h:127
 AliHLTMisc.h:128
 AliHLTMisc.h:129
 AliHLTMisc.h:130
 AliHLTMisc.h:131
 AliHLTMisc.h:132
 AliHLTMisc.h:133
 AliHLTMisc.h:134
 AliHLTMisc.h:135
 AliHLTMisc.h:136
 AliHLTMisc.h:137
 AliHLTMisc.h:138
 AliHLTMisc.h:139
 AliHLTMisc.h:140
 AliHLTMisc.h:141
 AliHLTMisc.h:142
 AliHLTMisc.h:143
 AliHLTMisc.h:144
 AliHLTMisc.h:145
 AliHLTMisc.h:146
 AliHLTMisc.h:147
 AliHLTMisc.h:148
 AliHLTMisc.h:149
 AliHLTMisc.h:150
 AliHLTMisc.h:151
 AliHLTMisc.h:152
 AliHLTMisc.h:153
 AliHLTMisc.h:154
 AliHLTMisc.h:155
 AliHLTMisc.h:156
 AliHLTMisc.h:157
 AliHLTMisc.h:158
 AliHLTMisc.h:159
 AliHLTMisc.h:160
 AliHLTMisc.h:161
 AliHLTMisc.h:162
 AliHLTMisc.h:163
 AliHLTMisc.h:164
 AliHLTMisc.h:165
 AliHLTMisc.h:166
 AliHLTMisc.h:167
 AliHLTMisc.h:168
 AliHLTMisc.h:169
 AliHLTMisc.h:170
 AliHLTMisc.h:171
 AliHLTMisc.h:172
 AliHLTMisc.h:173
 AliHLTMisc.h:174
 AliHLTMisc.h:175
 AliHLTMisc.h:176
 AliHLTMisc.h:177
 AliHLTMisc.h:178
 AliHLTMisc.h:179
 AliHLTMisc.h:180
 AliHLTMisc.h:181
 AliHLTMisc.h:182
 AliHLTMisc.h:183
 AliHLTMisc.h:184
 AliHLTMisc.h:185
 AliHLTMisc.h:186
 AliHLTMisc.h:187
 AliHLTMisc.h:188
 AliHLTMisc.h:189
 AliHLTMisc.h:190
 AliHLTMisc.h:191
 AliHLTMisc.h:192
 AliHLTMisc.h:193
 AliHLTMisc.h:194
 AliHLTMisc.h:195
 AliHLTMisc.h:196
 AliHLTMisc.h:197