ROOT logo
// $Id$
/**
 * @file recraw-local.C
 * @brief Run reconstruction of raw data locally
 *
 * <pre>
 * Usage: aliroot -b -q -l \
 *     recraw-local.C'("file", "cdb", minEvent, maxEvent, modules)'
 *
 * Examples:
 *     recraw-local.C'("alien:///alice/data/2009/.../....root")' 
 *     recraw-local.C'("raw://run12345")'
 *     recraw-local.C'("raw://run12345", minEvent, MaxEvent)'
 *     recraw-local.C'("raw.root", "local://$PWD", minEvent, MaxEvent)'
 *     recraw-local.C'("10000135031045.10..root", "raw://", -1, -1)'
 *     recraw-local.C'("alien:///alice/data/2010/LHC10f/000135031/raw/10000135031045.10.root", "raw://", -1, -1)'
 *
 * Defaults
 *     cdb="raw://"  -> take OCDB from GRID
 *     minEvent=-1   -> no lower event selection
 *     maxEvent=-1   -> no upper event selection
 *     modules="ALL" -> all modules
 *     hltOption="loglevel=0x7c" -> logging level info and above
 *
 * </pre>
 *
 * The input file can be a file on the grid, indicated by the tag
 * 'alien://' indicates. By default also the OCDB is set to the GRID.
 * If either the file or the OCDB is taken from the GRID, the macros
 * connects to the Grid in the beginning.
 *
 * Input files can be specified via te run number when using the tag
 * 'raw://' followed by the string 'run12345' where the number needs
 * to be adjusted.
 *
 * As for the OCDB it is always a good idea to use the OCDB from the
 * Grid as this will contain all the necessary objects and the latest
 * calibration. The special URI 'raw://' is most advisable as it selects
 * the storage automatically from the run number. Other options are e.g.
 * - "alien://folder=/alice/data/2010/OCDB"
 * - "local://$ALICE_ROOT/OCDB"
 *
 * Re-running the HLT reconstruction
 * By specifying the hlt options, the HLT chain can be re-run instead
 * of just extracting the online result. E.g. the following options
 * specify to ignore the HLTOUT payload and run the two chains defined
 * in the agents. The translation of the online configuration into
 * an HLT offline chain is under development.
 * <pre>
 *   ignore-hltout chains=GLOBAL-esd-converter,TPC-clusters
 * <pre>
 *
 * Note: You need a valid GRID token, use 'alien-token-init' of your
 * alien installation.
 *
 * @author Matthias.Richter@ift.uib.no
 * @ingroup alihlt_qa
 */
void recraw_local(const char *filename,
		  const char *cdbURI,
		  int minEvent=-1,
		  int maxEvent=-1,
		  const char *modules="ALL",
		  const char *hltOptions="loglevel=0x7c",
		  const char *cdbDrain=NULL)
{
  if(!gSystem->AccessPathName("galice.root")){
    cerr << "AliReconstruction on raw data requires to delete galice.root, or run at different place." << endl;
    cerr << "!!! DO NOT DELETE the galice.root of your simulation, but create a subfolder !!!!" << endl;
    return;
  }

  // connect to the GRID if we use a file or OCDB from the GRID
  TString struri=cdbURI;
  TString strfile=filename;
  if (struri.BeginsWith("raw://") ||
      strfile.Contains("://") && !strfile.Contains("local://")) {
    TGrid::Connect("alien");
  }

  // Set the CDB storage location
  AliCDBManager * man = AliCDBManager::Instance();
  man->SetDefaultStorage(cdbURI);
  if (struri.BeginsWith("local://")) {
    // set specific storage for GRP entry
    // search in the working directory and one level above, the latter
    // follows the standard simulation setup like e.g. in test/ppbench
    if (!gSystem->AccessPathName("GRP/GRP/Data")) {
      man->SetSpecificStorage("GRP/GRP/Data", "local://$PWD");
    } else if (!gSystem->AccessPathName("../GRP/GRP/Data")) {
      man->SetSpecificStorage("GRP/GRP/Data", "local://$PWD/..");      
    }
  }
  if (cdbDrain) man->SetDrain(cdbDrain);

  // Reconstruction settings
  AliReconstruction rec;

  if (minEvent>=0 || maxEvent>minEvent) {
    if (minEvent<0) minEvent=0;
    if (maxEvent<minEvent) maxEvent=minEvent;
    rec.SetEventRange(minEvent,maxEvent);
  }

  TString strModules=modules;
  if (modules)
    rec.SetRunReconstruction(modules);
  else
    rec.SetRunReconstruction("ALL");

  // QA options
  TString qaOptions="HLT TPC";
  if (!strModules.Contains("TPC")) qaOptions.ReplaceAll("TPC", "");
  qaOptions+=":ALL";
  rec.SetRunQA(qaOptions) ;
  //rec.SetQARefDefaultStorage("local://$ALICE_ROOT/QAref") ;

  // AliReconstruction settings
  rec.SetWriteESDfriend(kTRUE);
  rec.SetRunVertexFinder(strModules.Contains("ITS"));
  rec.SetRunMultFinder(strModules.Contains("ITS"));
  rec.SetInput(filename);
  rec.SetOption("HLT", hltOptions);

  rec.SetRunPlaneEff(kFALSE);

  // switch off cleanESD
  rec.SetCleanESD(kFALSE);

  AliLog::Flush();
  rec.Run();

}

void recraw_local(const char *filename,
		  int minEvent=-1,
		  int maxEvent=-1,
		  const char *modules="ALL",
		  const char *hltOptions="loglevel=0x7f")
{
  recraw_local(filename, "raw://", minEvent, maxEvent, modules, hltOptions);
}

void recraw_local()
{
  cout << "recraw-local: Run AliRoot reconstruction locally" << endl;
  cout << " Usage: aliroot -b -q -l \\" << endl;
  cout << "     recraw-local.C'(\"file\", \"cdb\", minEvent, maxEvent, modules, hltOptions)'" << endl;
  cout << "" << endl;
  cout << " Examples:" << endl;
  cout << "     recraw-local.C'(\"alien:///alice/data/2009/.../....root\")' " << endl;
  cout << "     recraw-local.C'(\"raw://run12345\")'" << endl;
  cout << "     recraw-local.C'(\"raw://run12345\", minEvent, MaxEvent)'" << endl;
  cout << "     recraw-local.C'(\"raw.root\", \"local://$PWD\", minEvent, MaxEvent)'" << endl;
  cout << "" << endl;
  cout << " Defaults" << endl;
  cout << "     cdb=\"raw://\"  -> take OCDB from GRID" << endl;
  cout << "     minEvent=-1   -> no lower event selection" << endl;
  cout << "     maxEvent=-1   -> no upper event selection" << endl;
  cout << "     modules=\"ALL\" -> all modules" << endl;
  cout << "     hltOption=\"loglevel=0x7c\" -> logging level info and above" << endl;
}
 recraw-local.C:1
 recraw-local.C:2
 recraw-local.C:3
 recraw-local.C:4
 recraw-local.C:5
 recraw-local.C:6
 recraw-local.C:7
 recraw-local.C:8
 recraw-local.C:9
 recraw-local.C:10
 recraw-local.C:11
 recraw-local.C:12
 recraw-local.C:13
 recraw-local.C:14
 recraw-local.C:15
 recraw-local.C:16
 recraw-local.C:17
 recraw-local.C:18
 recraw-local.C:19
 recraw-local.C:20
 recraw-local.C:21
 recraw-local.C:22
 recraw-local.C:23
 recraw-local.C:24
 recraw-local.C:25
 recraw-local.C:26
 recraw-local.C:27
 recraw-local.C:28
 recraw-local.C:29
 recraw-local.C:30
 recraw-local.C:31
 recraw-local.C:32
 recraw-local.C:33
 recraw-local.C:34
 recraw-local.C:35
 recraw-local.C:36
 recraw-local.C:37
 recraw-local.C:38
 recraw-local.C:39
 recraw-local.C:40
 recraw-local.C:41
 recraw-local.C:42
 recraw-local.C:43
 recraw-local.C:44
 recraw-local.C:45
 recraw-local.C:46
 recraw-local.C:47
 recraw-local.C:48
 recraw-local.C:49
 recraw-local.C:50
 recraw-local.C:51
 recraw-local.C:52
 recraw-local.C:53
 recraw-local.C:54
 recraw-local.C:55
 recraw-local.C:56
 recraw-local.C:57
 recraw-local.C:58
 recraw-local.C:59
 recraw-local.C:60
 recraw-local.C:61
 recraw-local.C:62
 recraw-local.C:63
 recraw-local.C:64
 recraw-local.C:65
 recraw-local.C:66
 recraw-local.C:67
 recraw-local.C:68
 recraw-local.C:69
 recraw-local.C:70
 recraw-local.C:71
 recraw-local.C:72
 recraw-local.C:73
 recraw-local.C:74
 recraw-local.C:75
 recraw-local.C:76
 recraw-local.C:77
 recraw-local.C:78
 recraw-local.C:79
 recraw-local.C:80
 recraw-local.C:81
 recraw-local.C:82
 recraw-local.C:83
 recraw-local.C:84
 recraw-local.C:85
 recraw-local.C:86
 recraw-local.C:87
 recraw-local.C:88
 recraw-local.C:89
 recraw-local.C:90
 recraw-local.C:91
 recraw-local.C:92
 recraw-local.C:93
 recraw-local.C:94
 recraw-local.C:95
 recraw-local.C:96
 recraw-local.C:97
 recraw-local.C:98
 recraw-local.C:99
 recraw-local.C:100
 recraw-local.C:101
 recraw-local.C:102
 recraw-local.C:103
 recraw-local.C:104
 recraw-local.C:105
 recraw-local.C:106
 recraw-local.C:107
 recraw-local.C:108
 recraw-local.C:109
 recraw-local.C:110
 recraw-local.C:111
 recraw-local.C:112
 recraw-local.C:113
 recraw-local.C:114
 recraw-local.C:115
 recraw-local.C:116
 recraw-local.C:117
 recraw-local.C:118
 recraw-local.C:119
 recraw-local.C:120
 recraw-local.C:121
 recraw-local.C:122
 recraw-local.C:123
 recraw-local.C:124
 recraw-local.C:125
 recraw-local.C:126
 recraw-local.C:127
 recraw-local.C:128
 recraw-local.C:129
 recraw-local.C:130
 recraw-local.C:131
 recraw-local.C:132
 recraw-local.C:133
 recraw-local.C:134
 recraw-local.C:135
 recraw-local.C:136
 recraw-local.C:137
 recraw-local.C:138
 recraw-local.C:139
 recraw-local.C:140
 recraw-local.C:141
 recraw-local.C:142
 recraw-local.C:143
 recraw-local.C:144
 recraw-local.C:145
 recraw-local.C:146
 recraw-local.C:147
 recraw-local.C:148
 recraw-local.C:149
 recraw-local.C:150
 recraw-local.C:151
 recraw-local.C:152
 recraw-local.C:153
 recraw-local.C:154
 recraw-local.C:155
 recraw-local.C:156
 recraw-local.C:157
 recraw-local.C:158
 recraw-local.C:159
 recraw-local.C:160
 recraw-local.C:161
 recraw-local.C:162
 recraw-local.C:163