ROOT logo
// $Id$
/**
 * @file makeComponentConfigurationObject.C
 * @brief Creation of HLT component configuration objects in OCDB
 *
 * <pre>
 * Usage:
 *  aliroot -b -q makeComponentConfigurationObject.C'("path", "param", "uri", runmin, runmax)'
 *  aliroot -b -q makeComponentConfigurationObject.C'("path", "key", "param", "uri", runmin, runmax)'
 * </pre>
 *
 * Create an OCDB entry with a TObjString containing param.
 * Many HLT components understand configuration strings containing
 * arguments and parameters just like the command line arguments.
 * This macro facilitates the creation of an appropriate object
 * from a parameter string.
 * As another approach the TObjString parameters are stored in a TMap
 * associated to a key. A TMap object is generated if 'key' is specified.
 *
 * Parameters: <br>
 * - path           path of the entry within the OCDB
 * - param (opt)    string to be stored in the TObjSting, default empty
 * - uri   (opt)    the OCDB URI, default $ALICE_ROOT   
 * - runmin (opt)   default 0
 * - runmax (opt)   default 999999999
 *
 * Note: The configuration procedure of an HLT component is not
 * restricted to that scheme. The implementation is up to the
 * developer and more complex objects are possible.
 *
 * @author Matthias.Richter@ift.uib.no
 * @ingroup alihlt_tutorial
 */
void makeComponentConfigurationObject(const char* path, 
				      const char* key,
				      const char* param,
				      const char* cdbUri,
				      int runmin=0,
				      int runmax=AliCDBRunRange::Infinity(),
				      int runNo=0)
{
  AliCDBManager* man = AliCDBManager::Instance();
  if (!man) {
    cerr << "can not get AliCDBManager" << end;
    exit;
  }
  TString storage;
  if (!man->IsDefaultStorageSet()) {
    if (cdbUri) {
      storage=cdbUri;
      if (storage.Contains("://")==0) {
	storage="local://"; storage+=cdbUri;
      }
    } else {
      storage="local://$ALICE_ROOT/OCDB";
    }
    man->SetDefaultStorage(storage);
  } else {
    storage = man->GetDefaultStorage()->GetURI();
  }

  TMap* pMap=NULL;

  // load existing object and init TMap
  AliCDBEntry* pExisting=NULL;
  AliCDBStorage* pStorage=AliCDBManager::Instance()->GetDefaultStorage();
  if (key && pStorage->GetLatestVersion(path, runNo)>=0) {
    pExisting=pStorage->Get(path, runNo);
    if (pExisting->GetObject()->IsA() == TMap::Class()) {
      pMap=(TMap*)pExisting->GetObject()->Clone();
    }
  }  

  if (key && !pMap) pMap=new TMap;

  // here is the actual content of the configuration object
  TObject* obj=new TObjString(param);
  if (pMap) {
    if (pMap->FindObject(key)) {
      pMap->Remove(new TObjString(key));
    }
    pMap->Add(new TObjString(key), obj);
    obj=pMap;
  }

  AliCDBPath cdbPath(path);
  AliCDBId cdbId(cdbPath, runmin, runmax);
  AliCDBMetaData* cdbMetaData=NULL;
  if (pExisting) cdbMetaData=pExisting->GetMetaData();
  else cdbMetaData=new AliCDBMetaData;
  man->Put(obj, cdbId, cdbMetaData);
}

void makeComponentConfigurationObject(const char* path, const char* param="",
				      const char* cdbUri=NULL,
				      int runmin=0,
				      int runmax=AliCDBRunRange::Infinity())
{
  makeComponentConfigurationObject(path, NULL, param, cdbUri, runmin, runmax);
}

void makeComponentConfigurationObject(const char* path, 
				      int runNo,
				      const char* key,
				      const char* param)
{
  makeComponentConfigurationObject(path, key, param, NULL, 0, AliCDBRunRange::Infinity(), runNo);
}

void makeComponentConfigurationObject()
{
  cout << "===============================================================" << endl;
  cout << "usage: aliroot -b -q -l makeComponentConfigurationObject.C'(\"path\", \"param\", \"uri\", rangemin, rangemax)'" << endl << endl;
  cout << "  path           path of the entry within the OCDB" << endl;
  cout << "  param (opt)    string to be stored in the TObjSting, default empty" << endl;
  cout << "  uri   (opt)    the OCDB URI, default $ALICE_ROOT/OCDB   " << endl;
  cout << "  rangemin (opt) default 0" << endl;
  cout << "  rangemax (opt) default AliCDBRunRange::Infinity()" << endl;
  cout << "===============================================================" << endl;
  cout << "usage: aliroot -b -q -l makeComponentConfigurationObject.C'(\"path\", \"key\", \"param\", \"uri\", rangemin, rangemax)'" << endl << endl;
  cout << "  path           path of the entry within the OCDB" << endl;
  cout << "  param (opt)    string to be stored in the TObjSting, default empty" << endl;
  cout << "  uri   (opt)    the OCDB URI, default $ALICE_ROOT/OCDB   " << endl;
  cout << "  rangemin (opt) default 0" << endl;
  cout << "  rangemax (opt) default AliCDBRunRange::Infinity()" << endl;
  cout << "===============================================================" << endl;
}
 makeComponentConfigurationObject.C:1
 makeComponentConfigurationObject.C:2
 makeComponentConfigurationObject.C:3
 makeComponentConfigurationObject.C:4
 makeComponentConfigurationObject.C:5
 makeComponentConfigurationObject.C:6
 makeComponentConfigurationObject.C:7
 makeComponentConfigurationObject.C:8
 makeComponentConfigurationObject.C:9
 makeComponentConfigurationObject.C:10
 makeComponentConfigurationObject.C:11
 makeComponentConfigurationObject.C:12
 makeComponentConfigurationObject.C:13
 makeComponentConfigurationObject.C:14
 makeComponentConfigurationObject.C:15
 makeComponentConfigurationObject.C:16
 makeComponentConfigurationObject.C:17
 makeComponentConfigurationObject.C:18
 makeComponentConfigurationObject.C:19
 makeComponentConfigurationObject.C:20
 makeComponentConfigurationObject.C:21
 makeComponentConfigurationObject.C:22
 makeComponentConfigurationObject.C:23
 makeComponentConfigurationObject.C:24
 makeComponentConfigurationObject.C:25
 makeComponentConfigurationObject.C:26
 makeComponentConfigurationObject.C:27
 makeComponentConfigurationObject.C:28
 makeComponentConfigurationObject.C:29
 makeComponentConfigurationObject.C:30
 makeComponentConfigurationObject.C:31
 makeComponentConfigurationObject.C:32
 makeComponentConfigurationObject.C:33
 makeComponentConfigurationObject.C:34
 makeComponentConfigurationObject.C:35
 makeComponentConfigurationObject.C:36
 makeComponentConfigurationObject.C:37
 makeComponentConfigurationObject.C:38
 makeComponentConfigurationObject.C:39
 makeComponentConfigurationObject.C:40
 makeComponentConfigurationObject.C:41
 makeComponentConfigurationObject.C:42
 makeComponentConfigurationObject.C:43
 makeComponentConfigurationObject.C:44
 makeComponentConfigurationObject.C:45
 makeComponentConfigurationObject.C:46
 makeComponentConfigurationObject.C:47
 makeComponentConfigurationObject.C:48
 makeComponentConfigurationObject.C:49
 makeComponentConfigurationObject.C:50
 makeComponentConfigurationObject.C:51
 makeComponentConfigurationObject.C:52
 makeComponentConfigurationObject.C:53
 makeComponentConfigurationObject.C:54
 makeComponentConfigurationObject.C:55
 makeComponentConfigurationObject.C:56
 makeComponentConfigurationObject.C:57
 makeComponentConfigurationObject.C:58
 makeComponentConfigurationObject.C:59
 makeComponentConfigurationObject.C:60
 makeComponentConfigurationObject.C:61
 makeComponentConfigurationObject.C:62
 makeComponentConfigurationObject.C:63
 makeComponentConfigurationObject.C:64
 makeComponentConfigurationObject.C:65
 makeComponentConfigurationObject.C:66
 makeComponentConfigurationObject.C:67
 makeComponentConfigurationObject.C:68
 makeComponentConfigurationObject.C:69
 makeComponentConfigurationObject.C:70
 makeComponentConfigurationObject.C:71
 makeComponentConfigurationObject.C:72
 makeComponentConfigurationObject.C:73
 makeComponentConfigurationObject.C:74
 makeComponentConfigurationObject.C:75
 makeComponentConfigurationObject.C:76
 makeComponentConfigurationObject.C:77
 makeComponentConfigurationObject.C:78
 makeComponentConfigurationObject.C:79
 makeComponentConfigurationObject.C:80
 makeComponentConfigurationObject.C:81
 makeComponentConfigurationObject.C:82
 makeComponentConfigurationObject.C:83
 makeComponentConfigurationObject.C:84
 makeComponentConfigurationObject.C:85
 makeComponentConfigurationObject.C:86
 makeComponentConfigurationObject.C:87
 makeComponentConfigurationObject.C:88
 makeComponentConfigurationObject.C:89
 makeComponentConfigurationObject.C:90
 makeComponentConfigurationObject.C:91
 makeComponentConfigurationObject.C:92
 makeComponentConfigurationObject.C:93
 makeComponentConfigurationObject.C:94
 makeComponentConfigurationObject.C:95
 makeComponentConfigurationObject.C:96
 makeComponentConfigurationObject.C:97
 makeComponentConfigurationObject.C:98
 makeComponentConfigurationObject.C:99
 makeComponentConfigurationObject.C:100
 makeComponentConfigurationObject.C:101
 makeComponentConfigurationObject.C:102
 makeComponentConfigurationObject.C:103
 makeComponentConfigurationObject.C:104
 makeComponentConfigurationObject.C:105
 makeComponentConfigurationObject.C:106
 makeComponentConfigurationObject.C:107
 makeComponentConfigurationObject.C:108
 makeComponentConfigurationObject.C:109
 makeComponentConfigurationObject.C:110
 makeComponentConfigurationObject.C:111
 makeComponentConfigurationObject.C:112
 makeComponentConfigurationObject.C:113
 makeComponentConfigurationObject.C:114
 makeComponentConfigurationObject.C:115
 makeComponentConfigurationObject.C:116
 makeComponentConfigurationObject.C:117
 makeComponentConfigurationObject.C:118
 makeComponentConfigurationObject.C:119
 makeComponentConfigurationObject.C:120
 makeComponentConfigurationObject.C:121
 makeComponentConfigurationObject.C:122
 makeComponentConfigurationObject.C:123
 makeComponentConfigurationObject.C:124
 makeComponentConfigurationObject.C:125
 makeComponentConfigurationObject.C:126
 makeComponentConfigurationObject.C:127
 makeComponentConfigurationObject.C:128