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

#ifndef ALIHLTCONFIGURATIONHANDLER_H
#define ALIHLTCONFIGURATIONHANDLER_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   AliHLTConfigurationHandler.h
/// @author Matthias Richter
/// @date   
/// @brief  Global handling of HLT configurations.
///

#include <TList.h>

#include "AliHLTLogging.h"
class AliHLTConfiguration;
class TMap;

/**
 * @class AliHLTConfigurationHandler
 * @brief Global Handling of HLT configurations.
 *
 * This class implements the global handling of @ref AliHLTConfiguration objects.
 * It is a list of all configuration descriptors currently available in the system.
 * Each @ref AliHLTConfiguration object is registered automatically with the
 * handler and put into the list.
 *
 * @note This class is only used for the @ref alihlt_system.
 *
 * @ingroup alihlt_system
 */
class AliHLTConfigurationHandler : public AliHLTLogging {
 public:
  /** standard constructor */
  AliHLTConfigurationHandler();
  
  /** destructor */
  virtual ~AliHLTConfigurationHandler();

  /*****************************************************************************
   * singleton handling
   */

  /**
   * Create an instance from the global sigleton.
   * Instance has to be destroyed by the Destroy function
   */
  static AliHLTConfigurationHandler* CreateHandler();

  /**
   * Destroy an instance of the global singleton retrieved by
   * AliHLTConfigurationHandler::CreateHandler()
   */
  int Destroy();

  /**
   * Get the instance of the global singleton.
   * Does not create the global instance.
   */
  static AliHLTConfigurationHandler* Instance() {
    if (!fgpInstance) return NULL;
    return fgpInstance;
  }

  /*****************************************************************************
   * activation, affects if the handler will accept new registrations
   */

  /**
   * Deactivate the handler, AliHLTConfiguration objects will not register
   * @param schedule     Store and schedule registrations pending reactivation
   */
  int Deactivate(bool schedule=false);

  /**
   * Activate the handler, AliHLTConfiguration objects will register again
   */
  int Activate();

  /// check if active
  bool IsActive() const {return (fFlags&kInactive)==0;}
  
  /// check if scheduling
  bool IsScheduling() const {return (fFlags&kScheduling)>0;}
  
  /// clear scheduled registrations
  void ClearScheduledRegistrations() {fgListScheduledRegistrations.Delete();}

  /// signal a missed registration
  static int MissedRegistration(const char* name=NULL);

  /*****************************************************************************
   * registration
   */

  /**
   * Register a configuration to the global list of configurations.
   * @param pConf     The configuration to register
   */
  int RegisterConfiguration(AliHLTConfiguration* pConf);

  /**
   * Create a configuration and register it.
   * @param id
   * @param component
   * @param sources
   * @param arguments
   */
  int CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments);

  /**
   * Remove a configuration from the global list.
   * @param pConf     The configuration to remove
   */
  int RemoveConfiguration(AliHLTConfiguration* pConf);

  /**
   * Remove a configuration from the global list.
   * @param id     The configuration to remove
   */
  int RemoveConfiguration(const char* id);

  /**
   * Find a configuration from the global list.
   * @param id     Id of the configuration to find
   */
  AliHLTConfiguration* FindConfiguration(const char* id);

  /**
   * Print the registered configurations to the logging function.
   */
  void PrintConfigurations();

  /**
   * Print info
   * Options:
   * -  treeroot=configuration  print the dependency tree for a configuration
   * default PrintConfigurations
   */
  void Print(const char* option="");

  /**
   * Add a component substitution by component id.
   * All components of the specified component id will be replaced by the
   * substitution component, the component arguments are replaced accordingly.
   * Component substitution is in particular useful if the input to a specific
   * component should be written to file.
   */
  static int AddSubstitution(const char* componentId, const AliHLTConfiguration& subst);

  /**
   * Add a component substitution by configuration id.
   * The component of the specified configuration will be replaced by the
   * substitution component, the component arguments are replaced accordingly.
   * Component substitution is in particular useful if the input to a specific
   * component should be written to file.
   */
  static int AddSubstitution(const AliHLTConfiguration& conf , const AliHLTConfiguration& subst);

  /**
   * Find component substitution.
   */
  static const AliHLTConfiguration* FindSubstitution(const AliHLTConfiguration& conf);

 private:
  enum {
    kInactive = 0x1,
    kScheduling = 0x2
  };

  /** the list of registered configurations */
  TList fgListConfigurations;                                      // see above
  
  /** list of configurations scheduled to be registered */
  TList fgListScheduledRegistrations;                              // see above

  /** status of the handler */
  unsigned fFlags;                                                 //! transient

  /** the global singleton */
  static AliHLTConfigurationHandler* fgpInstance;                  //!transient
  /** number of used instances of the global singleton */
  static int fgNofInstances;                                       //!transient 

  /// component substitution map
  /// key: either TObjString with component id or AliHLTConfiguration object
  static TMap* fgpSubstitutions;                                   //!transient 

  ClassDef(AliHLTConfigurationHandler, 0);
};

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