ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

/// \ingroup macros
/// \file UpdateCDBCTPConfig.C
/// \brief The macro writes a new GRP/CTP/Config trigger configuration file
/// from the GRP/CTP/MUON.cfg trigger descriptor, corresponding to a
/// run where only MUON is used as a trigger detector.
/// 
/// The macro writes a new GRP/CTP/Config trigger configuration file
/// from the GRP/CTP/MUON.cfg trigger descriptor, corresponding to a
/// run where only MUON is used as a trigger detector. The
/// compatibility is check against the Config.C used in the simulation
/// (which means that the MUON detector must be there). When "check"
/// is "true", the macro only shows the last CTP configuration stored in
/// the GRP.
/// This is necessary because at the first step of the simulation (digits)
/// the trigger configuration is guessed from the detectors defined in the
/// Config.C, while the reconstruction is performed in a second separate
/// step, having no more knowledge of the Config.C file.
/// This has to be done before starting the simulations, only once after
/// the installation of AliRoot:
/// 
/// <pre> 
///.L $ALICE_ROOT/MUON/UpdateCDBCTPConfig.C+
/// UpdateCDBCTPConfig(1);    // just checking
/// UpdateCDBCTPConfig();     // update the GRP/CDB entry
/// </pre>
///
/// AliRoot comes with a default entry corresponding to a pp trigger. In
/// this case, at the reconstruction phase error messages will appear (without
/// breaking the reconstruction): \n
///
/// E-AliCentralTrigger::CheckTriggeredDetectors: Wrong cluster mask from trigger
/// classes (7ffff), expecting (20c00)! Loaded trigger configuration is possibly wrong!
///
/// \author B. Vulpescu, LPC Clermont-Ferrand

#if !defined(__CINT__) || defined(__MAKECINT__)
#include "ARVersion.h"
#include "AliCDBManager.h"
#include "AliCDBStorage.h"
#include "AliCDBEntry.h"
#include "AliCDBId.h"
#include "AliCDBMetaData.h"
#include "AliTriggerConfiguration.h"
#include "AliTriggerUtils.h"
#include "AliSimulation.h"
#include <TROOT.h>
#include <TString.h>
#include <TSystem.h>
#endif

void UpdateCDBCTPConfig(Bool_t check = false) {
  
  // AliSimulation object must exist, as it is used via AliMC
  // which is used in AliTriggerUtils::CheckConfiguration()
  AliSimulation sim;

  AliCDBManager* cdb = AliCDBManager::Instance();
  cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
  cdb->SetRun(0);

  if (check) {
    // current entry in GRP/CTP/Config trigger configuration
    AliCDBEntry *entry;
    entry = cdb->Get("GRP/CTP/Config");
    AliCDBMetaData *md = entry->GetMetaData();
    Printf("AliRoot version: %s",md->GetAliRootVersion());
    Printf("Comment: %s ",md->GetComment());
    Printf("Responsible: %s ",md->GetResponsible());
    return;
  }

  const Char_t* alice = gSystem->Getenv("ALICE_ROOT");

  // construct the CTP configuration starting from GRP/CTP/<CTPcfg>.cfg file

  // Config.C detector configuration
  TString cfgFile(Form("%s/MUON/Config.C",alice));

  // MUON.cfg trigger configuration
  TString cfgCTP(Form("%s/GRP/CTP/MUON.cfg",alice));

  AliTriggerConfiguration *trconfig = AliTriggerConfiguration::LoadConfiguration(cfgCTP);
  if (!trconfig) {
    Printf("Invalid cfg file! Exiting...");
    return;
  }

  // check if Config.C is compatible with the trigger configuration requested
  AliTriggerUtils tru;
  if (!tru.CheckConfiguration(cfgFile,trconfig)) {
    Printf("CTP configuration is incompatible with the specified Config.C and AliRoot version! Exiting...");
    return;
  }

  // put the new trigger configuration "trconfig" in the GRP/CTP/Config

  AliCDBId id("GRP/CTP/Config",0,AliCDBRunRange::Infinity());
  AliCDBMetaData *md= new AliCDBMetaData();

  // ROOT and AliRoot versions
  const char* rootv = gROOT->GetVersion();
  TString av(ALIROOT_BRANCH);
  TString revnum(ALIROOT_REVISION);

  Printf("root version: %s.  AliRoot %s, revision number %s",rootv,av.Data(),revnum.Data());

  md->SetAliRootVersion(av.Data());
  md->SetComment(Form("Default CTP configuration for MUON mode produced with root version %s and AliRoot version %s revision %s ",rootv,av.Data(),revnum.Data()));

  AliCDBStorage* storage = cdb->GetStorage("local://$ALICE_ROOT/OCDB");
  storage->Put(trconfig,id,md);
  
}
 UpdateCDBCTPConfig.C:1
 UpdateCDBCTPConfig.C:2
 UpdateCDBCTPConfig.C:3
 UpdateCDBCTPConfig.C:4
 UpdateCDBCTPConfig.C:5
 UpdateCDBCTPConfig.C:6
 UpdateCDBCTPConfig.C:7
 UpdateCDBCTPConfig.C:8
 UpdateCDBCTPConfig.C:9
 UpdateCDBCTPConfig.C:10
 UpdateCDBCTPConfig.C:11
 UpdateCDBCTPConfig.C:12
 UpdateCDBCTPConfig.C:13
 UpdateCDBCTPConfig.C:14
 UpdateCDBCTPConfig.C:15
 UpdateCDBCTPConfig.C:16
 UpdateCDBCTPConfig.C:17
 UpdateCDBCTPConfig.C:18
 UpdateCDBCTPConfig.C:19
 UpdateCDBCTPConfig.C:20
 UpdateCDBCTPConfig.C:21
 UpdateCDBCTPConfig.C:22
 UpdateCDBCTPConfig.C:23
 UpdateCDBCTPConfig.C:24
 UpdateCDBCTPConfig.C:25
 UpdateCDBCTPConfig.C:26
 UpdateCDBCTPConfig.C:27
 UpdateCDBCTPConfig.C:28
 UpdateCDBCTPConfig.C:29
 UpdateCDBCTPConfig.C:30
 UpdateCDBCTPConfig.C:31
 UpdateCDBCTPConfig.C:32
 UpdateCDBCTPConfig.C:33
 UpdateCDBCTPConfig.C:34
 UpdateCDBCTPConfig.C:35
 UpdateCDBCTPConfig.C:36
 UpdateCDBCTPConfig.C:37
 UpdateCDBCTPConfig.C:38
 UpdateCDBCTPConfig.C:39
 UpdateCDBCTPConfig.C:40
 UpdateCDBCTPConfig.C:41
 UpdateCDBCTPConfig.C:42
 UpdateCDBCTPConfig.C:43
 UpdateCDBCTPConfig.C:44
 UpdateCDBCTPConfig.C:45
 UpdateCDBCTPConfig.C:46
 UpdateCDBCTPConfig.C:47
 UpdateCDBCTPConfig.C:48
 UpdateCDBCTPConfig.C:49
 UpdateCDBCTPConfig.C:50
 UpdateCDBCTPConfig.C:51
 UpdateCDBCTPConfig.C:52
 UpdateCDBCTPConfig.C:53
 UpdateCDBCTPConfig.C:54
 UpdateCDBCTPConfig.C:55
 UpdateCDBCTPConfig.C:56
 UpdateCDBCTPConfig.C:57
 UpdateCDBCTPConfig.C:58
 UpdateCDBCTPConfig.C:59
 UpdateCDBCTPConfig.C:60
 UpdateCDBCTPConfig.C:61
 UpdateCDBCTPConfig.C:62
 UpdateCDBCTPConfig.C:63
 UpdateCDBCTPConfig.C:64
 UpdateCDBCTPConfig.C:65
 UpdateCDBCTPConfig.C:66
 UpdateCDBCTPConfig.C:67
 UpdateCDBCTPConfig.C:68
 UpdateCDBCTPConfig.C:69
 UpdateCDBCTPConfig.C:70
 UpdateCDBCTPConfig.C:71
 UpdateCDBCTPConfig.C:72
 UpdateCDBCTPConfig.C:73
 UpdateCDBCTPConfig.C:74
 UpdateCDBCTPConfig.C:75
 UpdateCDBCTPConfig.C:76
 UpdateCDBCTPConfig.C:77
 UpdateCDBCTPConfig.C:78
 UpdateCDBCTPConfig.C:79
 UpdateCDBCTPConfig.C:80
 UpdateCDBCTPConfig.C:81
 UpdateCDBCTPConfig.C:82
 UpdateCDBCTPConfig.C:83
 UpdateCDBCTPConfig.C:84
 UpdateCDBCTPConfig.C:85
 UpdateCDBCTPConfig.C:86
 UpdateCDBCTPConfig.C:87
 UpdateCDBCTPConfig.C:88
 UpdateCDBCTPConfig.C:89
 UpdateCDBCTPConfig.C:90
 UpdateCDBCTPConfig.C:91
 UpdateCDBCTPConfig.C:92
 UpdateCDBCTPConfig.C:93
 UpdateCDBCTPConfig.C:94
 UpdateCDBCTPConfig.C:95
 UpdateCDBCTPConfig.C:96
 UpdateCDBCTPConfig.C:97
 UpdateCDBCTPConfig.C:98
 UpdateCDBCTPConfig.C:99
 UpdateCDBCTPConfig.C:100
 UpdateCDBCTPConfig.C:101
 UpdateCDBCTPConfig.C:102
 UpdateCDBCTPConfig.C:103
 UpdateCDBCTPConfig.C:104
 UpdateCDBCTPConfig.C:105
 UpdateCDBCTPConfig.C:106
 UpdateCDBCTPConfig.C:107
 UpdateCDBCTPConfig.C:108
 UpdateCDBCTPConfig.C:109
 UpdateCDBCTPConfig.C:110
 UpdateCDBCTPConfig.C:111
 UpdateCDBCTPConfig.C:112
 UpdateCDBCTPConfig.C:113
 UpdateCDBCTPConfig.C:114
 UpdateCDBCTPConfig.C:115
 UpdateCDBCTPConfig.C:116
 UpdateCDBCTPConfig.C:117
 UpdateCDBCTPConfig.C:118
 UpdateCDBCTPConfig.C:119
 UpdateCDBCTPConfig.C:120
 UpdateCDBCTPConfig.C:121
 UpdateCDBCTPConfig.C:122
 UpdateCDBCTPConfig.C:123
 UpdateCDBCTPConfig.C:124
 UpdateCDBCTPConfig.C:125
 UpdateCDBCTPConfig.C:126
 UpdateCDBCTPConfig.C:127
 UpdateCDBCTPConfig.C:128
 UpdateCDBCTPConfig.C:129
 UpdateCDBCTPConfig.C:130
 UpdateCDBCTPConfig.C:131