ROOT logo
// $Id$
/**
 * @file cal-hlt-tpc-offline.C
 * @brief Test macro for the HLT TPC offline calibration.
 *
 * The macro runs an HLT chain of TPC analysis, using the offline
 * algorithms and appropriate wrappers. The final output is
 * processed by the TPCOfflineCalibration component.
 *
 * Usage:
 * <pre>
 *   aliroot -b -q cal-hlt-tpc-offline.C | tee cal-hlt-tpc-offline.log
 * </pre>
 *
 * The chain to be run is defined by the macro given to the parameter
 * 'config='
 *
 * The macro asumes raw data to be available in the rawx folders, either
 * simulated or real data. A different input can be specified as parameter
 * <pre>
 *   aliroot -b -q cal-hlt-tpc-offline.C'("input.root")'
 * </pre>
 *
 * In the first section, an analysis chain is defined. The scale of the
 * chain can be defined by choosing the range of sectors and partitions.
 *
 * The reconstruction is steered by the AliReconstruction object in the
 * usual way.
 *
 * @ingroup alihlt_tpc
 * @author Jacek Otwinowski <J.Otwinowski@gsi.de>, Matthias.Richter@ift.uib.no
 */
void cal_hlt_tpc_offline(const char* input="./")
{
  if (!input) {
    cerr << "please specify input or run without arguments" << endl;
    return;
  }

  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // init the HLT system in order to define the analysis chain below
  //
  AliHLTSystem* gHLT=AliHLTPluginBase::GetInstance();

  //gHLT.SwitchAliLog(0);

  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // define the analysis chain to be run
  //

  bool sectorClusterer=true; // run clusterer on sector or DDL level
  // check if the AliRawReaderMemory supports multiple buffers
  TClass* info=TClass::GetClass("AliRawReaderMemory");
  TList* methods=info->GetListOfAllPublicMethods();
  if (sectorClusterer && !methods->FindObject("AddBuffer")) {
    cerr << "warning: AliRawReaderMemory does not support multiple buffers, falling back to run clusterer on DDL level" << endl;
    sectorClusterer=false;
  }
 
  int iMinSlice=0;
  int iMaxSlice=35;
  int iMinPart=0;
  int iMaxPart=5;

  int DDLNoFromSlicePatch(int, int);

  TString writerInput;
  TString trackerInput;
  TString calibratorInput;

  for (int slice=iMinSlice; slice<=iMaxSlice; slice++) {
    TString arg, clustererInput;
    for (int part=iMinPart; part<=iMaxPart; part++) {
      TString publisher, cf;

      // raw data publisher components
      int ddlno=DDLNoFromSlicePatch(slice, part);
      arg.Form("-minid %d -datatype 'DDL_RAW ' 'TPC '  -dataspec 0x%02x%02x%02x%02x -verbose", ddlno, slice, slice, part, part);
      publisher.Form("DP_%02d_%d", slice, part);
      AliHLTConfiguration pubconf(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());

      if (!sectorClusterer) {
      // cluster finder components
      cf.Form("CF_%02d_%d", slice, part);
      AliHLTConfiguration cfconf(cf.Data(), "TPCOfflineClusterer", publisher.Data(), "");

      if (trackerInput.Length()>0) trackerInput+=" ";
      trackerInput+=cf;
      //if (writerInput.Length()>0) writerInput+=" ";
      //writerInput+=cf;
      } else {
	if (clustererInput.Length()>0) clustererInput+=" ";
	clustererInput+=publisher;
      }
    }
    if (sectorClusterer) {
      // cluster finder components
      cf.Form("CF_%02d", slice);
      AliHLTConfiguration cfconf(cf.Data(), "TPCOfflineClusterer", clustererInput.Data(), "");

      if (trackerInput.Length()>0) trackerInput+=" ";
      trackerInput+=cf;
    }
  }

  // one global tracker component
  TString tracker;
  tracker.Form("Global_TR");
  AliHLTConfiguration trackerconf(tracker.Data(), "TPCOfflineTrackerCalib", trackerInput.Data(), "");
  if (writerInput.Length()>0) writerInput+=" ";
  calibratorInput+=tracker;

  // one global calibration component
  TString calibrator;
  calibrator.Form("Global_Calib");
  AliHLTConfiguration calibconf(calibrator.Data(), "TPCOfflineCalibration", calibratorInput.Data(), "");
  if (writerInput.Length()>0) writerInput+=" ";
  writerInput+=calibrator;

  // the writer configuration
  AliHLTConfiguration rootfwconf("sink1", "ROOTFileWriter", writerInput.Data(), "-specfmt=_%d -subdir=out_%d -idfmt=_0x%08x");
  //AliHLTConfiguration esdwconf("sink1", "EsdCollector"   , writerInput.Data(), "-directory hlt-tpc-offline");

  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // Init and run the reconstruction
  // All but HLT reconstructio is switched off
  //
  AliReconstruction rec;
  rec.SetInput(input);
  rec.SetRunVertexFinder(kFALSE);
  rec.SetRunLocalReconstruction("HLT");
  rec.SetRunTracking("");
  rec.SetLoadAlignFromCDB(0);
  rec.SetFillESD("");
  rec.SetRunQA(":");
  rec.SetRunGlobalQA(kFALSE);
  rec.SetFillTriggerESD(kFALSE);
  rec.SetOption("HLT", "libAliHLTUtil.so libAliHLTRCU.so libANALYSIS.so libANALYSISalice.so libTPCcalib.so libAliHLTTPC.so loglevel=0x7c chains=sink1");
  rec.Run();
}

int DDLNoFromSlicePatch(int slice, int part)
{
  int ddlno=768;
  if (part>1) ddlno+=72+4*slice+(part-2);
  else ddlno+=2*slice+part;

  return ddlno;
}
 cal-hlt-tpc-offline.C:1
 cal-hlt-tpc-offline.C:2
 cal-hlt-tpc-offline.C:3
 cal-hlt-tpc-offline.C:4
 cal-hlt-tpc-offline.C:5
 cal-hlt-tpc-offline.C:6
 cal-hlt-tpc-offline.C:7
 cal-hlt-tpc-offline.C:8
 cal-hlt-tpc-offline.C:9
 cal-hlt-tpc-offline.C:10
 cal-hlt-tpc-offline.C:11
 cal-hlt-tpc-offline.C:12
 cal-hlt-tpc-offline.C:13
 cal-hlt-tpc-offline.C:14
 cal-hlt-tpc-offline.C:15
 cal-hlt-tpc-offline.C:16
 cal-hlt-tpc-offline.C:17
 cal-hlt-tpc-offline.C:18
 cal-hlt-tpc-offline.C:19
 cal-hlt-tpc-offline.C:20
 cal-hlt-tpc-offline.C:21
 cal-hlt-tpc-offline.C:22
 cal-hlt-tpc-offline.C:23
 cal-hlt-tpc-offline.C:24
 cal-hlt-tpc-offline.C:25
 cal-hlt-tpc-offline.C:26
 cal-hlt-tpc-offline.C:27
 cal-hlt-tpc-offline.C:28
 cal-hlt-tpc-offline.C:29
 cal-hlt-tpc-offline.C:30
 cal-hlt-tpc-offline.C:31
 cal-hlt-tpc-offline.C:32
 cal-hlt-tpc-offline.C:33
 cal-hlt-tpc-offline.C:34
 cal-hlt-tpc-offline.C:35
 cal-hlt-tpc-offline.C:36
 cal-hlt-tpc-offline.C:37
 cal-hlt-tpc-offline.C:38
 cal-hlt-tpc-offline.C:39
 cal-hlt-tpc-offline.C:40
 cal-hlt-tpc-offline.C:41
 cal-hlt-tpc-offline.C:42
 cal-hlt-tpc-offline.C:43
 cal-hlt-tpc-offline.C:44
 cal-hlt-tpc-offline.C:45
 cal-hlt-tpc-offline.C:46
 cal-hlt-tpc-offline.C:47
 cal-hlt-tpc-offline.C:48
 cal-hlt-tpc-offline.C:49
 cal-hlt-tpc-offline.C:50
 cal-hlt-tpc-offline.C:51
 cal-hlt-tpc-offline.C:52
 cal-hlt-tpc-offline.C:53
 cal-hlt-tpc-offline.C:54
 cal-hlt-tpc-offline.C:55
 cal-hlt-tpc-offline.C:56
 cal-hlt-tpc-offline.C:57
 cal-hlt-tpc-offline.C:58
 cal-hlt-tpc-offline.C:59
 cal-hlt-tpc-offline.C:60
 cal-hlt-tpc-offline.C:61
 cal-hlt-tpc-offline.C:62
 cal-hlt-tpc-offline.C:63
 cal-hlt-tpc-offline.C:64
 cal-hlt-tpc-offline.C:65
 cal-hlt-tpc-offline.C:66
 cal-hlt-tpc-offline.C:67
 cal-hlt-tpc-offline.C:68
 cal-hlt-tpc-offline.C:69
 cal-hlt-tpc-offline.C:70
 cal-hlt-tpc-offline.C:71
 cal-hlt-tpc-offline.C:72
 cal-hlt-tpc-offline.C:73
 cal-hlt-tpc-offline.C:74
 cal-hlt-tpc-offline.C:75
 cal-hlt-tpc-offline.C:76
 cal-hlt-tpc-offline.C:77
 cal-hlt-tpc-offline.C:78
 cal-hlt-tpc-offline.C:79
 cal-hlt-tpc-offline.C:80
 cal-hlt-tpc-offline.C:81
 cal-hlt-tpc-offline.C:82
 cal-hlt-tpc-offline.C:83
 cal-hlt-tpc-offline.C:84
 cal-hlt-tpc-offline.C:85
 cal-hlt-tpc-offline.C:86
 cal-hlt-tpc-offline.C:87
 cal-hlt-tpc-offline.C:88
 cal-hlt-tpc-offline.C:89
 cal-hlt-tpc-offline.C:90
 cal-hlt-tpc-offline.C:91
 cal-hlt-tpc-offline.C:92
 cal-hlt-tpc-offline.C:93
 cal-hlt-tpc-offline.C:94
 cal-hlt-tpc-offline.C:95
 cal-hlt-tpc-offline.C:96
 cal-hlt-tpc-offline.C:97
 cal-hlt-tpc-offline.C:98
 cal-hlt-tpc-offline.C:99
 cal-hlt-tpc-offline.C:100
 cal-hlt-tpc-offline.C:101
 cal-hlt-tpc-offline.C:102
 cal-hlt-tpc-offline.C:103
 cal-hlt-tpc-offline.C:104
 cal-hlt-tpc-offline.C:105
 cal-hlt-tpc-offline.C:106
 cal-hlt-tpc-offline.C:107
 cal-hlt-tpc-offline.C:108
 cal-hlt-tpc-offline.C:109
 cal-hlt-tpc-offline.C:110
 cal-hlt-tpc-offline.C:111
 cal-hlt-tpc-offline.C:112
 cal-hlt-tpc-offline.C:113
 cal-hlt-tpc-offline.C:114
 cal-hlt-tpc-offline.C:115
 cal-hlt-tpc-offline.C:116
 cal-hlt-tpc-offline.C:117
 cal-hlt-tpc-offline.C:118
 cal-hlt-tpc-offline.C:119
 cal-hlt-tpc-offline.C:120
 cal-hlt-tpc-offline.C:121
 cal-hlt-tpc-offline.C:122
 cal-hlt-tpc-offline.C:123
 cal-hlt-tpc-offline.C:124
 cal-hlt-tpc-offline.C:125
 cal-hlt-tpc-offline.C:126
 cal-hlt-tpc-offline.C:127
 cal-hlt-tpc-offline.C:128
 cal-hlt-tpc-offline.C:129
 cal-hlt-tpc-offline.C:130
 cal-hlt-tpc-offline.C:131
 cal-hlt-tpc-offline.C:132
 cal-hlt-tpc-offline.C:133
 cal-hlt-tpc-offline.C:134
 cal-hlt-tpc-offline.C:135
 cal-hlt-tpc-offline.C:136
 cal-hlt-tpc-offline.C:137
 cal-hlt-tpc-offline.C:138
 cal-hlt-tpc-offline.C:139
 cal-hlt-tpc-offline.C:140
 cal-hlt-tpc-offline.C:141
 cal-hlt-tpc-offline.C:142
 cal-hlt-tpc-offline.C:143
 cal-hlt-tpc-offline.C:144
 cal-hlt-tpc-offline.C:145
 cal-hlt-tpc-offline.C:146
 cal-hlt-tpc-offline.C:147
 cal-hlt-tpc-offline.C:148
 cal-hlt-tpc-offline.C:149
 cal-hlt-tpc-offline.C:150
 cal-hlt-tpc-offline.C:151
 cal-hlt-tpc-offline.C:152
 cal-hlt-tpc-offline.C:153