ROOT logo
// $Id$
/**
 * @file rec-hlt-globalhisto.C
 * @brief Run reconstruction and fill the global histograms
 *
 * <pre>
 * Usage: aliroot -b -q -l \
 *     rec-hlt-globalhisto.C'("file", "cdb", minEvent, maxEvent)'
 * Example:
 *   aliroot -b -q -l \
 *     rec-hlt-globalhisto.C'("raw.root", "local://$ALICE_ROOT/OCDB")'
 * </pre>
 * 
 * Macro runs HLT reconstruction on raw data, all other AliRoot
 * modules switched off. The output of the GlobalEsdConverter is filled
 * into the GlobalHisto component, it's output is attached to a Root file
 * writer producing the file histo.root.
 *
 * A raw file, either simulated or real, is needed and the corresponding
 * OCDB has to be specified.
 *
 * Can also run on an AliESDs.root file instead of running the reconstruction
 *
 * aliroot -b -q -l \
 *   rec-hlt-globalhisto.C'("./","HLTesdTree","local://$ALICE_ROOT/OCDB/",5)' | tee log
 *
 * @author Matthias.Richter@ift.uib.no
 * @ingroup alihlt_qa
 */
void rec_hlt_globalhisto(const char *filename,
		         const char *cdbURI,
		         int minEvent=-1,
		         int maxEvent=-1)
{
  // 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/..");      
    }
  }

  //////////////////////////////////////////////////////////////////////////////////////
  //
  // setup the HLT system
  AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();

  AliHLTConfiguration globalhisto("globalhisto", "GlobalHisto", "GLOBAL-esd-converter","");
  AliHLTConfiguration writer("writer", "ROOTFileWriter", "globalhisto", "-datafile histo.root -overwrite -concatenate-events");

  TString hltOptions="loglevel=0x7c ignore-hltout chains=writer";

  // Reconstruction settings
  AliReconstruction rec;

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

  rec.SetRunReconstruction("HLT");

  // QA options
  TString qaOptions="HLT";
  qaOptions+=":ALL";
  rec.SetRunQA(qaOptions) ;
  //rec.SetQARefDefaultStorage("local://$ALICE_ROOT/QAref") ;

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

  rec.SetRunPlaneEff(kFALSE);

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

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

 }

void rec_hlt_globalhisto(const char *esdfilename,
		         const char *treename,
			 const char *cdbURI,
		         int nofEvents=-1
			 )

{
  // check the name of the tree
  TString strtree=treename;
  if (strtree.CompareTo("esdTree")==0) strtree="ESD";
  else if (strtree.CompareTo("HLTesdTree")==0) strtree="HLTESD";
  else {
    cerr << "invalid treename '" << treename << "', supported 'esdTree' and 'HLTesdTree'" << endl;
    return;
  }

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

  // open the ESD file and get the event count
  if (!strfile.EndsWith("/")) strfile+="/";
  strfile+="AliESDs.root";
  TFile* esdfile=TFile::Open(strfile);
  if (!esdfile || esdfile->IsZombie()) {
    cerr << "can not open file " << strfile << endl;
    return;
  }

  // get number of events
  TTree* pTree=NULL;
  esdfile->GetObject(treename, pTree);
  if (!pTree) {
    cerr << "can not find " << treename << " in file " << strfile << endl;
    return;
  }
  if (pTree->GetEntries()<=0) {
    cerr << "empty tree " << treename << " in file " << strfile << endl;
    return;
  }
  
  AliESDEvent* esd=new AliESDEvent;
  esd->ReadFromTree(pTree);
  pTree->GetEntry(0);

  if (nofEvents<0 || nofEvents>pTree->GetEntries())
    nofEvents=pTree->GetEntries();

  // Set the CDB storage location
  AliCDBManager * man = AliCDBManager::Instance();
  man->SetDefaultStorage(cdbURI);
  man->SetRun(esd->GetRunNumber());
  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/..");      
    }
  }

  //////////////////////////////////////////////////////////////////////////////////////
  //
  // setup the HLT system
  AliHLTSystem *pHLT = AliHLTPluginBase::GetInstance();
  
  gSystem->Load("libANALYSIS");
  gSystem->Load("libANALYSISalice");
  gSystem->Load("libPWG0base");
  gSystem->Load("libPWG0dep");

  TString arguments, histoinput;

  // ESD publisher component
  arguments=" -datapath "; arguments+=esdfilename;
  arguments+=" -entrytype "; arguments+=strtree;
  histoinput="ESD-publisher";

  AliHLTConfiguration esdpublisher(histoinput.Data(), "ESDMCEventPublisher", "", arguments.Data());  
  AliHLTConfiguration globalhisto("globalhisto", "GlobalHisto", histoinput.Data(),"");
  
  AliHLTConfiguration writer("writer1", "ROOTFileWriter", "globalhisto", "-datafile   histo.root -overwrite -concatenate-events");
  //AliHLTConfiguration writer("writer2", "ROOTFileWriter", "v0",          "-datafile v0histo.root -overwrite -concatenate-events");

  // set option for the HLT system
  // arguments
  //  - libraries to be used as plugins
  //  - loglevel=0x79 : Important, Warning, Error, Fatal
  pHLT->ScanOptions("libAliHLTUtil.so libAliHLTGlobal.so loglevel=0x79");

  pHLT->BuildTaskList("writer1");
  pHLT->Run(nofEvents);
}
	
 rec-hlt-globalhisto.C:1
 rec-hlt-globalhisto.C:2
 rec-hlt-globalhisto.C:3
 rec-hlt-globalhisto.C:4
 rec-hlt-globalhisto.C:5
 rec-hlt-globalhisto.C:6
 rec-hlt-globalhisto.C:7
 rec-hlt-globalhisto.C:8
 rec-hlt-globalhisto.C:9
 rec-hlt-globalhisto.C:10
 rec-hlt-globalhisto.C:11
 rec-hlt-globalhisto.C:12
 rec-hlt-globalhisto.C:13
 rec-hlt-globalhisto.C:14
 rec-hlt-globalhisto.C:15
 rec-hlt-globalhisto.C:16
 rec-hlt-globalhisto.C:17
 rec-hlt-globalhisto.C:18
 rec-hlt-globalhisto.C:19
 rec-hlt-globalhisto.C:20
 rec-hlt-globalhisto.C:21
 rec-hlt-globalhisto.C:22
 rec-hlt-globalhisto.C:23
 rec-hlt-globalhisto.C:24
 rec-hlt-globalhisto.C:25
 rec-hlt-globalhisto.C:26
 rec-hlt-globalhisto.C:27
 rec-hlt-globalhisto.C:28
 rec-hlt-globalhisto.C:29
 rec-hlt-globalhisto.C:30
 rec-hlt-globalhisto.C:31
 rec-hlt-globalhisto.C:32
 rec-hlt-globalhisto.C:33
 rec-hlt-globalhisto.C:34
 rec-hlt-globalhisto.C:35
 rec-hlt-globalhisto.C:36
 rec-hlt-globalhisto.C:37
 rec-hlt-globalhisto.C:38
 rec-hlt-globalhisto.C:39
 rec-hlt-globalhisto.C:40
 rec-hlt-globalhisto.C:41
 rec-hlt-globalhisto.C:42
 rec-hlt-globalhisto.C:43
 rec-hlt-globalhisto.C:44
 rec-hlt-globalhisto.C:45
 rec-hlt-globalhisto.C:46
 rec-hlt-globalhisto.C:47
 rec-hlt-globalhisto.C:48
 rec-hlt-globalhisto.C:49
 rec-hlt-globalhisto.C:50
 rec-hlt-globalhisto.C:51
 rec-hlt-globalhisto.C:52
 rec-hlt-globalhisto.C:53
 rec-hlt-globalhisto.C:54
 rec-hlt-globalhisto.C:55
 rec-hlt-globalhisto.C:56
 rec-hlt-globalhisto.C:57
 rec-hlt-globalhisto.C:58
 rec-hlt-globalhisto.C:59
 rec-hlt-globalhisto.C:60
 rec-hlt-globalhisto.C:61
 rec-hlt-globalhisto.C:62
 rec-hlt-globalhisto.C:63
 rec-hlt-globalhisto.C:64
 rec-hlt-globalhisto.C:65
 rec-hlt-globalhisto.C:66
 rec-hlt-globalhisto.C:67
 rec-hlt-globalhisto.C:68
 rec-hlt-globalhisto.C:69
 rec-hlt-globalhisto.C:70
 rec-hlt-globalhisto.C:71
 rec-hlt-globalhisto.C:72
 rec-hlt-globalhisto.C:73
 rec-hlt-globalhisto.C:74
 rec-hlt-globalhisto.C:75
 rec-hlt-globalhisto.C:76
 rec-hlt-globalhisto.C:77
 rec-hlt-globalhisto.C:78
 rec-hlt-globalhisto.C:79
 rec-hlt-globalhisto.C:80
 rec-hlt-globalhisto.C:81
 rec-hlt-globalhisto.C:82
 rec-hlt-globalhisto.C:83
 rec-hlt-globalhisto.C:84
 rec-hlt-globalhisto.C:85
 rec-hlt-globalhisto.C:86
 rec-hlt-globalhisto.C:87
 rec-hlt-globalhisto.C:88
 rec-hlt-globalhisto.C:89
 rec-hlt-globalhisto.C:90
 rec-hlt-globalhisto.C:91
 rec-hlt-globalhisto.C:92
 rec-hlt-globalhisto.C:93
 rec-hlt-globalhisto.C:94
 rec-hlt-globalhisto.C:95
 rec-hlt-globalhisto.C:96
 rec-hlt-globalhisto.C:97
 rec-hlt-globalhisto.C:98
 rec-hlt-globalhisto.C:99
 rec-hlt-globalhisto.C:100
 rec-hlt-globalhisto.C:101
 rec-hlt-globalhisto.C:102
 rec-hlt-globalhisto.C:103
 rec-hlt-globalhisto.C:104
 rec-hlt-globalhisto.C:105
 rec-hlt-globalhisto.C:106
 rec-hlt-globalhisto.C:107
 rec-hlt-globalhisto.C:108
 rec-hlt-globalhisto.C:109
 rec-hlt-globalhisto.C:110
 rec-hlt-globalhisto.C:111
 rec-hlt-globalhisto.C:112
 rec-hlt-globalhisto.C:113
 rec-hlt-globalhisto.C:114
 rec-hlt-globalhisto.C:115
 rec-hlt-globalhisto.C:116
 rec-hlt-globalhisto.C:117
 rec-hlt-globalhisto.C:118
 rec-hlt-globalhisto.C:119
 rec-hlt-globalhisto.C:120
 rec-hlt-globalhisto.C:121
 rec-hlt-globalhisto.C:122
 rec-hlt-globalhisto.C:123
 rec-hlt-globalhisto.C:124
 rec-hlt-globalhisto.C:125
 rec-hlt-globalhisto.C:126
 rec-hlt-globalhisto.C:127
 rec-hlt-globalhisto.C:128
 rec-hlt-globalhisto.C:129
 rec-hlt-globalhisto.C:130
 rec-hlt-globalhisto.C:131
 rec-hlt-globalhisto.C:132
 rec-hlt-globalhisto.C:133
 rec-hlt-globalhisto.C:134
 rec-hlt-globalhisto.C:135
 rec-hlt-globalhisto.C:136
 rec-hlt-globalhisto.C:137
 rec-hlt-globalhisto.C:138
 rec-hlt-globalhisto.C:139
 rec-hlt-globalhisto.C:140
 rec-hlt-globalhisto.C:141
 rec-hlt-globalhisto.C:142
 rec-hlt-globalhisto.C:143
 rec-hlt-globalhisto.C:144
 rec-hlt-globalhisto.C:145
 rec-hlt-globalhisto.C:146
 rec-hlt-globalhisto.C:147
 rec-hlt-globalhisto.C:148
 rec-hlt-globalhisto.C:149
 rec-hlt-globalhisto.C:150
 rec-hlt-globalhisto.C:151
 rec-hlt-globalhisto.C:152
 rec-hlt-globalhisto.C:153
 rec-hlt-globalhisto.C:154
 rec-hlt-globalhisto.C:155
 rec-hlt-globalhisto.C:156
 rec-hlt-globalhisto.C:157
 rec-hlt-globalhisto.C:158
 rec-hlt-globalhisto.C:159
 rec-hlt-globalhisto.C:160
 rec-hlt-globalhisto.C:161
 rec-hlt-globalhisto.C:162
 rec-hlt-globalhisto.C:163
 rec-hlt-globalhisto.C:164
 rec-hlt-globalhisto.C:165
 rec-hlt-globalhisto.C:166
 rec-hlt-globalhisto.C:167
 rec-hlt-globalhisto.C:168
 rec-hlt-globalhisto.C:169
 rec-hlt-globalhisto.C:170
 rec-hlt-globalhisto.C:171
 rec-hlt-globalhisto.C:172
 rec-hlt-globalhisto.C:173
 rec-hlt-globalhisto.C:174
 rec-hlt-globalhisto.C:175
 rec-hlt-globalhisto.C:176
 rec-hlt-globalhisto.C:177
 rec-hlt-globalhisto.C:178
 rec-hlt-globalhisto.C:179
 rec-hlt-globalhisto.C:180
 rec-hlt-globalhisto.C:181
 rec-hlt-globalhisto.C:182
 rec-hlt-globalhisto.C:183
 rec-hlt-globalhisto.C:184
 rec-hlt-globalhisto.C:185
 rec-hlt-globalhisto.C:186
 rec-hlt-globalhisto.C:187
 rec-hlt-globalhisto.C:188
 rec-hlt-globalhisto.C:189
 rec-hlt-globalhisto.C:190
 rec-hlt-globalhisto.C:191
 rec-hlt-globalhisto.C:192
 rec-hlt-globalhisto.C:193
 rec-hlt-globalhisto.C:194
 rec-hlt-globalhisto.C:195
 rec-hlt-globalhisto.C:196
 rec-hlt-globalhisto.C:197
 rec-hlt-globalhisto.C:198
 rec-hlt-globalhisto.C:199
 rec-hlt-globalhisto.C:200
 rec-hlt-globalhisto.C:201