ROOT logo
// $Id$

#if !defined(__CINT__)
#include "TString.h"
#include "TGrid.h"
#include "AliCDBManager.h"
#include "AliSimulation.h"
#include <iostream>
using namespace std;
#endif

/**
 * @file simhlt.C
 * @brief Run HLT reconstruction embedded into AliSimulation
 *
 * <pre>
 * Usage: aliroot -b -q -l \
 *     aliroot -b -q -l simhlt.C'("hltoption", "rawdataoptions", nofEvents, runNo, "cdbUri")'
 *
 * Examples:
 *     simhlt.C'("loglevel=0x7c chains=GLOBAL-esd-converter")'
 *       load all default libraries and run the chain 'GLOBAL-esd-converter'
 *     simhlt.C'("loglevel=0x7c !libAliHLTITS.so")'
 *       load all default libraries but the libAliHLTITS.so and run the
 *       default chain, skips the ITS tracking
 *     simhlt.C'("loglevel=0x7c rawfile=")'
 *       run explicitly on digit data
 *
 * Defaults
 *     rawdataoptions=""         -> skip generation of raw data
 *     nofEvents=-1              -> take event count from simulated sample
 *     runNo=-1                  -> take run number from simulated sample
 *     cdbUri="local://$ALICE_ROOT/OCDB"
 *
 * Running with precompiled macro:
 *     gSystem->AddIncludePath("-I$ROOTSYS/include -I$ALICE_ROOT/include");
 *     gROOT->LoadMacro("$ALICE_ROOT/HLT/exa/simhlt.C++");
 *     simhlt("loglevel=0x7c");
 *
 * </pre>
 *
 * This macro can be used to run the 'HLT simulation' standalone with an
 * already simulated data sample. 'HLT simulation' means HLT reconstruction
 * on simulated data, and is carried out at the end of the AliSimulation
 * sequence.
 *
 * The definition of the HLT reconstruction chain depends on the available
 * module plugins (component libraries). Each library defines a number of
 * component configurations identified by a unique string. Here are a couple
 * of definitions, but the list is by far not complete:
 * - libAliHLTTPC.so:     TPC-clusters, TPC-globalmerger
 * - libAliHLTITS.so:     ITS-tracker, ITS-SPD-vertexer
 * - libAliHLTGlobal.so:  GLOBAL-esd-converter, GLOBAL-vertexhisto
 * - libAliHLTTrigger.so: GLOBAL-Trigger
 *
 * This list will certainly develop over time, it is planned to add some
 * helper functionality to AliHLTSystem for querying of such information.
 *
 * The definition of the chain depends on the availability of simulated raw
 * data. If raw data is available, the HLT chain runs on this, otherwise on
 * the digit data. \b NOTE: propagation of MC information is only possible
 * for the latter case. Raw data generation must be either switched of, i.e.
 * rawdataoptions is empty, or explicitly explicitly ignored by the HLT
 * option 'rawfile=' (note the empty argument to the option).
 *
 * The output of the simulation are the HLT.Digits.root file and (if enabled)
 * the HLT raw data files. You must run AliReconstruction in order to extract
 * the simulated HLT data. A typical test sequence can be like:
 *
 * <pre>
 * cd $ALICE_ROOT/test/ppbench
 * ./runtest.sh
 * aliroot -b -q -l simhlt.C'("loglevel=0x7c chains=GLOBAL-esd-converter")' \
 *         | tee simhlt.C
 * aliroot -b -q -l rec.C | tee rec.log
 * </pre>
 *
 * @author Matthias.Richter@ift.uib.no
 * @ingroup alihlt_tutorial
 */
void simhlt(const char *hltOptions,
	    const char *rawDataSelection="",
	    int nofEvents=-1,
	    int runNo=-1,
	    const char *cdbURI="local://$ALICE_ROOT/OCDB"
	    )
{
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // connect to the GRID if we use a file or OCDB from the GRID
  TString struri=cdbURI;
  if (struri.Contains("://") && !struri.Contains("local://")) {
    TGrid::Connect("alien");
  }

  // Set the CDB storage location
  AliCDBManager * man = AliCDBManager::Instance();
  man->SetDefaultStorage(cdbURI);

  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // Init and run the HLT simulation
  // All but HLT simulation is switched off
  //
  AliSimulation sim;
 
  // switch of simulation and data generation
  // comment all that stuff to also simulate the events and data
  sim.SetRunGeneration(kFALSE);
  sim.SetMakeDigits("");
  sim.SetMakeSDigits("");
  sim.SetMakeDigitsFromHits("");
  //sim.SetMakeTrigger("");
  sim.SetRunQA("HLT:ALL");

  // the normal simulation sets the specific storage for the GRP entry
  if (gSystem->AccessPathName("GRP/GRP/Data")) {
    cerr << "*********************************************************" << endl;
    cerr << "error: no GRP entry found in the currect directory, simulation might be incomplete. Skip setting specific storage for GRP entry" << endl;
    cerr << "*********************************************************" << endl << endl;
  } else {
    sim.SetSpecificStorage("GRP/GRP/Data",
			   Form("local://%s",gSystem->pwd()));
  }

  // set the options for writing raw data, possible values e.g. ALL; HLT
  if (rawDataSelection && rawDataSelection[0]!=0) {
    sim.SetWriteRawData(rawDataSelection, "raw.root", kTRUE);
  }

  // set the options for the HLT simulation
  sim.SetRunHLT(hltOptions);

  if (runNo>=0) sim.SetRunNumber(runNo);

  if (nofEvents>0) sim.Run(nofEvents);
  else sim.Run();
}

void simhlt()
{
  cout << "recraw-local: Run HLT reconstruction embedded into AliSimulation" << endl;
  cout << " Usage: aliroot -b -q -l \\" << endl;
  cout << "     aliroot -q simhlt.C'(\"hltoption\", \"rawdataoptions\", nofEvents, runNo, \"cdbUri\")'" << endl;
  cout << "" << endl;
  cout << " Examples:" << endl;
  cout << "     aliroot -q simhlt.C'(\"loglevel=0x7c chains=GLOBAL-esd-converter\")'" << endl;
  cout << "     aliroot -q simhlt.C'(\"loglevel=0x7c !libAliHLTITS.so\")'		 " << endl;
  cout << "     aliroot -q simhlt.C'(\"loglevel=0x7c rawfile=\")'                   " << endl;
  cout << "" << endl;
  cout << " Defaults" << endl;
  cout << "     rawdataoptions=\"\"         -> skip generation of raw data	   " << endl;
  cout << "     nofEvents=-1              -> take event count from simulated sample" << endl;
  cout << "     runNo=-1                  -> take run number from simulated sample " << endl;
  cout << "     cdbUri=\"local://$ALICE_ROOT/OCDB\"                                " << endl;
  cout << "" << endl;
  cout << " The definition of the chain depends on the availability of simulated raw " << endl;
  cout << " data. If raw data is available, the HLT chain runs on this, otherwise on " << endl;
  cout << " the digit data. \b NOTE: propagation of MC information is only possible  " << endl;
  cout << " for the latter case. Raw data generation must be either switched of, i.e." << endl;
  cout << " rawdataoptions is empty, or explicitly explicitly ignored by the HLT	  " << endl;
  cout << " option 'rawfile=' (note the empty argument to the option).               " << endl;
}
 simhlt.C:1
 simhlt.C:2
 simhlt.C:3
 simhlt.C:4
 simhlt.C:5
 simhlt.C:6
 simhlt.C:7
 simhlt.C:8
 simhlt.C:9
 simhlt.C:10
 simhlt.C:11
 simhlt.C:12
 simhlt.C:13
 simhlt.C:14
 simhlt.C:15
 simhlt.C:16
 simhlt.C:17
 simhlt.C:18
 simhlt.C:19
 simhlt.C:20
 simhlt.C:21
 simhlt.C:22
 simhlt.C:23
 simhlt.C:24
 simhlt.C:25
 simhlt.C:26
 simhlt.C:27
 simhlt.C:28
 simhlt.C:29
 simhlt.C:30
 simhlt.C:31
 simhlt.C:32
 simhlt.C:33
 simhlt.C:34
 simhlt.C:35
 simhlt.C:36
 simhlt.C:37
 simhlt.C:38
 simhlt.C:39
 simhlt.C:40
 simhlt.C:41
 simhlt.C:42
 simhlt.C:43
 simhlt.C:44
 simhlt.C:45
 simhlt.C:46
 simhlt.C:47
 simhlt.C:48
 simhlt.C:49
 simhlt.C:50
 simhlt.C:51
 simhlt.C:52
 simhlt.C:53
 simhlt.C:54
 simhlt.C:55
 simhlt.C:56
 simhlt.C:57
 simhlt.C:58
 simhlt.C:59
 simhlt.C:60
 simhlt.C:61
 simhlt.C:62
 simhlt.C:63
 simhlt.C:64
 simhlt.C:65
 simhlt.C:66
 simhlt.C:67
 simhlt.C:68
 simhlt.C:69
 simhlt.C:70
 simhlt.C:71
 simhlt.C:72
 simhlt.C:73
 simhlt.C:74
 simhlt.C:75
 simhlt.C:76
 simhlt.C:77
 simhlt.C:78
 simhlt.C:79
 simhlt.C:80
 simhlt.C:81
 simhlt.C:82
 simhlt.C:83
 simhlt.C:84
 simhlt.C:85
 simhlt.C:86
 simhlt.C:87
 simhlt.C:88
 simhlt.C:89
 simhlt.C:90
 simhlt.C:91
 simhlt.C:92
 simhlt.C:93
 simhlt.C:94
 simhlt.C:95
 simhlt.C:96
 simhlt.C:97
 simhlt.C:98
 simhlt.C:99
 simhlt.C:100
 simhlt.C:101
 simhlt.C:102
 simhlt.C:103
 simhlt.C:104
 simhlt.C:105
 simhlt.C:106
 simhlt.C:107
 simhlt.C:108
 simhlt.C:109
 simhlt.C:110
 simhlt.C:111
 simhlt.C:112
 simhlt.C:113
 simhlt.C:114
 simhlt.C:115
 simhlt.C:116
 simhlt.C:117
 simhlt.C:118
 simhlt.C:119
 simhlt.C:120
 simhlt.C:121
 simhlt.C:122
 simhlt.C:123
 simhlt.C:124
 simhlt.C:125
 simhlt.C:126
 simhlt.C:127
 simhlt.C:128
 simhlt.C:129
 simhlt.C:130
 simhlt.C:131
 simhlt.C:132
 simhlt.C:133
 simhlt.C:134
 simhlt.C:135
 simhlt.C:136
 simhlt.C:137
 simhlt.C:138
 simhlt.C:139
 simhlt.C:140
 simhlt.C:141
 simhlt.C:142
 simhlt.C:143
 simhlt.C:144
 simhlt.C:145
 simhlt.C:146
 simhlt.C:147
 simhlt.C:148
 simhlt.C:149
 simhlt.C:150
 simhlt.C:151
 simhlt.C:152
 simhlt.C:153
 simhlt.C:154
 simhlt.C:155
 simhlt.C:156
 simhlt.C:157
 simhlt.C:158
 simhlt.C:159
 simhlt.C:160
 simhlt.C:161
 simhlt.C:162
 simhlt.C:163
 simhlt.C:164
 simhlt.C:165
 simhlt.C:166
 simhlt.C:167
 simhlt.C:168