ROOT logo
// $Id$
/**
 * @file sample-component1.C
 * @brief Sample macro for the component initialization and configuration.
 *
 * Usage:
 * <pre>
 *   aliroot -b -q sample-component1.C | tee sample-component1.log
 * </pre>
 *
 * This macro illustrates the creation of an HLT component and it's
 * initialization and configuration, including update of values from
 * DCS.
 *
 * A component can be initialized by command line arguments. The scan
 * and interpretation of those arguments must be implemented in the
 * DoInit function of the component. The command line arguments are
 * specified in the chain configuration. In this example, it is an
 * AliRoot HLT chain. The same applies for PubSub online HLT chains.
 *
 * Configuration of components is done from configuration objects in
 * the CDB. It's the responsibility of the component to retrieve the
 * CDB entry from the CDB and interprete it. The CDB initialization
 * is done by the framework.
 *
 * The component can also decide if it wants to configure already during
 * initialization (DoInit) from configuration objects.
 *
 * The Sample-component1 (AliHLTSampleComponent1) implements configuration
 * via a string of arguments like e.g. '-config1 config-param -config2'.
 * Two different ways of configuration are implemented:
 * - configuration arguments can be part of the initialization arguments.
 *   All arguments not known to the argument scan in DoInit are treated
 *   as configuration arguments. Scanning of those remaining arguments
 *   is done at the end of the DoInit
 * - if there are no configuration arguments, the configuration is done
 *   from the default object in the CDB
 * - The implemented Reconfigure method retrieves either the object
 *   specified in the reconfiguration event or the default object.
 *
 * The macro defines the CDB in the /tmp folder and creates an object
 * in the CDB. Then it defines a very simple chain, which models the
 * respons of the component to the reconfiguration event.
 *
 * @author Matthias.Richter@ift.uib.no
 * @ingroup alihlt_tutorial
 */
{
  /////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////
  // some parameters for this test macro

  // the path of a temporary file needed to send the reconfigure event
  const char* tmpFile1="/tmp/samplecomponent1-comconf.dat";
  const char* tmpFile2="/tmp/samplecomponent1-updtdcs.dat";

  // path of the cdb entry
  const char* cdbEntryPath="HLT/ConfigSample/SampleComponent1";

  // path of detectors with 'active' preprocessors
  const char* prepDetectors="TPC PHOS";

  // path of the CDB to be created
  const char* cdbLocation="/tmp/OCDB";
  TString cdbUri; cdbUri.Form("local://%s", cdbLocation);

  // initialization arguments for the component
  const char* componentInit="-mandatory1 testarg -mandatory2";

  // configuration arguments for the component
  const char* componentConfig="-config1 config-param -config2";


  /////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////
  // global initialization of the HLT

  // this is just a tool to switch the logging systems
  AliHLTLogging log;
  //log.SwitchAliLog(0);

  AliHLTSystem gHLT;
  gHLT.SetGlobalLoggingLevel(0x7c);

  // load the component library
  gHLT.LoadComponentLibraries("libAliHLTUtil.so");
  gHLT.LoadComponentLibraries("libAliHLTSample.so");

  /////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////
  // CDB initialization

  // this is a tool to send the reconfiguration event and the
  // path of the cdb entry
  FILE* fp = fopen(tmpFile1, "w");
  if (fp) {
    fprintf(fp, cdbEntryPath);
    fclose(fp);
  }

  // this is a tool to send the update DCS event and the
  // path of the cdb entry
  FILE* fp = fopen(tmpFile2, "w");
  if (fp) {
    fprintf(fp, prepDetectors);
    fclose(fp);
  }

  // now we create the actual entry in the CDB
  // the CDB is created in /tmp
  AliCDBManager* man = AliCDBManager::Instance();
  if (!man->IsDefaultStorageSet())
  {
    man->SetDefaultStorage(cdbUri);
    man->SetRun(0);
    
    // here is the actual content of the configuration object
    TObjString obj=componentConfig;
    AliCDBPath cdbPath(cdbEntryPath);
    AliCDBId cdbId(cdbPath, 0, 0);
    AliCDBMetaData cdbMetaData;
    man->Put(&obj, cdbId, &cdbMetaData);
  }

  /////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////
  // now we build up a small chain

  // publisher for the reconfigure event
  TString arg;
  arg.Form("-datatype COM_CONF PRIV -datafile %s -nextevent "
	   "-datatype UPDT_DCS PRIV -datafile %s", tmpFile1, tmpFile2);
  AliHLTConfiguration sep("steeringevents", "FilePublisher", NULL , arg.Data());

  AliHLTConfiguration sc1("sc1", "Sample-component1", "steeringevents" , componentInit);

  // build the chain
  gHLT.BuildTaskList("sc1");

  // run two events, in the 1st event the component reconfiguration is emulated
  // in the 2nd one the update of Preprocessor values
  gHLT.Run(2);

  /////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////
  // cleanup

  // delete temporary file
  TString cmd;
  cmd.Form("rm -r %s %s %s", tmpFile1, tmpFile2, cdbLocation);
  gSystem->Exec(cmd.Data());
}
 sample-component1.C:1
 sample-component1.C:2
 sample-component1.C:3
 sample-component1.C:4
 sample-component1.C:5
 sample-component1.C:6
 sample-component1.C:7
 sample-component1.C:8
 sample-component1.C:9
 sample-component1.C:10
 sample-component1.C:11
 sample-component1.C:12
 sample-component1.C:13
 sample-component1.C:14
 sample-component1.C:15
 sample-component1.C:16
 sample-component1.C:17
 sample-component1.C:18
 sample-component1.C:19
 sample-component1.C:20
 sample-component1.C:21
 sample-component1.C:22
 sample-component1.C:23
 sample-component1.C:24
 sample-component1.C:25
 sample-component1.C:26
 sample-component1.C:27
 sample-component1.C:28
 sample-component1.C:29
 sample-component1.C:30
 sample-component1.C:31
 sample-component1.C:32
 sample-component1.C:33
 sample-component1.C:34
 sample-component1.C:35
 sample-component1.C:36
 sample-component1.C:37
 sample-component1.C:38
 sample-component1.C:39
 sample-component1.C:40
 sample-component1.C:41
 sample-component1.C:42
 sample-component1.C:43
 sample-component1.C:44
 sample-component1.C:45
 sample-component1.C:46
 sample-component1.C:47
 sample-component1.C:48
 sample-component1.C:49
 sample-component1.C:50
 sample-component1.C:51
 sample-component1.C:52
 sample-component1.C:53
 sample-component1.C:54
 sample-component1.C:55
 sample-component1.C:56
 sample-component1.C:57
 sample-component1.C:58
 sample-component1.C:59
 sample-component1.C:60
 sample-component1.C:61
 sample-component1.C:62
 sample-component1.C:63
 sample-component1.C:64
 sample-component1.C:65
 sample-component1.C:66
 sample-component1.C:67
 sample-component1.C:68
 sample-component1.C:69
 sample-component1.C:70
 sample-component1.C:71
 sample-component1.C:72
 sample-component1.C:73
 sample-component1.C:74
 sample-component1.C:75
 sample-component1.C:76
 sample-component1.C:77
 sample-component1.C:78
 sample-component1.C:79
 sample-component1.C:80
 sample-component1.C:81
 sample-component1.C:82
 sample-component1.C:83
 sample-component1.C:84
 sample-component1.C:85
 sample-component1.C:86
 sample-component1.C:87
 sample-component1.C:88
 sample-component1.C:89
 sample-component1.C:90
 sample-component1.C:91
 sample-component1.C:92
 sample-component1.C:93
 sample-component1.C:94
 sample-component1.C:95
 sample-component1.C:96
 sample-component1.C:97
 sample-component1.C:98
 sample-component1.C:99
 sample-component1.C:100
 sample-component1.C:101
 sample-component1.C:102
 sample-component1.C:103
 sample-component1.C:104
 sample-component1.C:105
 sample-component1.C:106
 sample-component1.C:107
 sample-component1.C:108
 sample-component1.C:109
 sample-component1.C:110
 sample-component1.C:111
 sample-component1.C:112
 sample-component1.C:113
 sample-component1.C:114
 sample-component1.C:115
 sample-component1.C:116
 sample-component1.C:117
 sample-component1.C:118
 sample-component1.C:119
 sample-component1.C:120
 sample-component1.C:121
 sample-component1.C:122
 sample-component1.C:123
 sample-component1.C:124
 sample-component1.C:125
 sample-component1.C:126
 sample-component1.C:127
 sample-component1.C:128
 sample-component1.C:129
 sample-component1.C:130
 sample-component1.C:131
 sample-component1.C:132
 sample-component1.C:133
 sample-component1.C:134
 sample-component1.C:135
 sample-component1.C:136
 sample-component1.C:137
 sample-component1.C:138
 sample-component1.C:139
 sample-component1.C:140
 sample-component1.C:141
 sample-component1.C:142
 sample-component1.C:143
 sample-component1.C:144
 sample-component1.C:145
 sample-component1.C:146
 sample-component1.C:147
 sample-component1.C:148
 sample-component1.C:149
 sample-component1.C:150
 sample-component1.C:151
 sample-component1.C:152
 sample-component1.C:153
 sample-component1.C:154
 sample-component1.C:155
 sample-component1.C:156
 sample-component1.C:157
 sample-component1.C:158