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$ */

// Selector base class for analysis based on ESD
// Please derive your selector-based analysis from this class, if you just want to use
// information from the ESD.
//
// The ESD is available as member fESD
//
// The following methods can be overrriden. Please do not forgot to call the base class function.
//
//    Begin():        called everytime a loop on the tree starts,
//                    a convenient place to create your histograms.
//    SlaveBegin():   called after Begin(), when on PROOF called only on the
//                    slave servers.
//    Init():         called for each new tree. Enable/Disable branches here.
//    Process():      called for each event, in this function you decide what
//                    to read and fill your histograms.
//    SlaveTerminate: called at the end of the loop on the tree, when on PROOF
//                    called only on the slave servers.
//    Terminate():    called at the end of the loop on the tree,
//                    a convenient place to draw/fit your histograms.
//
//  Author: Jan.Fiete.Grosse-Oetringhaus@cern.ch

#include "AliSelector.h"

#include <TStyle.h>
#include <TSystem.h>
#include <TCanvas.h>
#include <TRegexp.h>
#include <TTime.h>
#include <TFriendElement.h>
#include <TTree.h>
#include <TChain.h>
#include <TFile.h>
#include <TTimeStamp.h>

#include "AliLog.h"
#include "AliESD.h"

ClassImp(AliSelector)

AliSelector::AliSelector() :
  TSelector(),
  fTree(0),
  fESD(0),
  fCountFiles(0)
{
  //
  // Constructor. Initialization of pointers
  //
}

AliSelector::~AliSelector()
{
  //
  // Destructor
  //

 if (fTree)
   fTree->ResetBranchAddresses();

 if (fESD)
 {
   delete fESD;
   fESD = 0;
 }
}

void AliSelector::CheckOptions()
{
  // checks the option string for the debug flag

  AliLog::SetClassDebugLevel(ClassName(), AliLog::kInfo);

  TString option = GetOption();

  if (option.Contains("moredebug"))
  {
    printf("Enabling verbose debug mode for %s\n", ClassName());
    AliLog::SetClassDebugLevel(ClassName(), AliLog::kDebug+1);
    AliInfo(Form("Called with option %s.", option.Data()));
  }
  else if (option.Contains("debug"))
  {
    printf("Enabling debug mode for %s\n", ClassName());
    AliLog::SetClassDebugLevel(ClassName(), AliLog::kDebug);
    AliInfo(Form("Called with option %s.", option.Data()));
  }
}

void AliSelector::Begin(TTree*)
{
  // The Begin() function is called at the start of the query.
  // When running with PROOF Begin() is only called on the client.
  // The tree argument is deprecated (on PROOF 0 is passed).

  CheckOptions();

  AliDebug(AliLog::kDebug, "============BEGIN===========");
}

void AliSelector::SlaveBegin(TTree* tree)
{
  // The SlaveBegin() function is called after the Begin() function.
  // When running with PROOF SlaveBegin() is called on each slave server.
  // The tree argument is deprecated (on PROOF 0 is passed).

  CheckOptions();

  AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
  AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
  AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));

  if (tree != 0)
    Init(tree);
}

void AliSelector::Init(TTree *tree)
{
  // The Init() function is called when the selector needs to initialize
  // a new tree or chain. Typically here the branch addresses of the tree
  // will be set. It is normaly not necessary to make changes to the
  // generated code, but the routine can be extended by the user if needed.
  // Init() will be called many times when running with PROOF.

  AliDebug(AliLog::kDebug, "=========Init==========");

  fTree = tree;

  if (fTree == 0)
  {
    AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
    return;
  }

  // Set branch address
  fTree->SetBranchAddress("ESD", &fESD);
  if (fESD != 0)
    AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
}

Bool_t AliSelector::Notify()
{
  // The Notify() function is called when a new file is opened. This
  // can be either for a new TTree in a TChain or when when a new TTree
  // is started when using PROOF. Typically here the branch pointers
  // will be retrieved. It is normaly not necessary to make changes
  // to the generated code, but the routine can be extended by the
  // user if needed.

  AliDebug(AliLog::kDebug, "=========NOTIFY==========");
  AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
  AliDebug(AliLog::kDebug, Form("Time: %s", TTimeStamp(time(0)).AsString()));

  ++fCountFiles;
  if (fTree)
  {
    TFile *f = fTree->GetCurrentFile();
    if (f)
    {
      AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
    }
    else
      AliDebug(AliLog::kError, "fTree->GetCurrentFile() is 0");
  }
  else
  {
    AliDebug(AliLog::kError, "fTree not available");
  }

  return kTRUE;
}

Bool_t AliSelector::Process(Long64_t entry)
{
  // The Process() function is called for each entry in the tree (or possibly
  // keyed object in the case of PROOF) to be processed. The entry argument
  // specifies which entry in the currently loaded tree is to be processed.
  // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
  // to read either all or the required parts of the data. When processing
  // keyed objects with PROOF, the object is already loaded and is available
  // via the fObject pointer.
  //
  // This function should contain the "body" of the analysis. It can contain
  // simple or elaborate selection criteria, run algorithms on the data
  // of the event and typically fill histograms.

  // WARNING when a selector is used with a TChain, you must use
  //  the pointer to the current TTree to call GetEntry(entry).
  //  The entry is always the local entry number in the current tree.
  //  Assuming that fTree is the pointer to the TChain being processed,
  //  use fTree->GetTree()->GetEntry(entry).

  AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));

  if (!fTree)
  {
    AliDebug(AliLog::kError, "ERROR: fTree is 0.");
    return kFALSE;
  }

  fTree->GetTree()->GetEntry(entry);

  if (fESD)
    AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));

  return kTRUE;
}

void AliSelector::SlaveTerminate()
{
  // The SlaveTerminate() function is called after all entries or objects
  // have been processed. When running with PROOF SlaveTerminate() is called
  // on each slave server.

  AliDebug(AliLog::kDebug, "=======SLAVETERMINATE=======");
}

void AliSelector::Terminate()
{
  // The Terminate() function is the last function to be called during
  // a query. It always runs on the client, it can be used to present
  // the results graphically or save the results to file.

  AliDebug(AliLog::kDebug, "=========TERMINATE==========");
}
 AliSelector.cxx:1
 AliSelector.cxx:2
 AliSelector.cxx:3
 AliSelector.cxx:4
 AliSelector.cxx:5
 AliSelector.cxx:6
 AliSelector.cxx:7
 AliSelector.cxx:8
 AliSelector.cxx:9
 AliSelector.cxx:10
 AliSelector.cxx:11
 AliSelector.cxx:12
 AliSelector.cxx:13
 AliSelector.cxx:14
 AliSelector.cxx:15
 AliSelector.cxx:16
 AliSelector.cxx:17
 AliSelector.cxx:18
 AliSelector.cxx:19
 AliSelector.cxx:20
 AliSelector.cxx:21
 AliSelector.cxx:22
 AliSelector.cxx:23
 AliSelector.cxx:24
 AliSelector.cxx:25
 AliSelector.cxx:26
 AliSelector.cxx:27
 AliSelector.cxx:28
 AliSelector.cxx:29
 AliSelector.cxx:30
 AliSelector.cxx:31
 AliSelector.cxx:32
 AliSelector.cxx:33
 AliSelector.cxx:34
 AliSelector.cxx:35
 AliSelector.cxx:36
 AliSelector.cxx:37
 AliSelector.cxx:38
 AliSelector.cxx:39
 AliSelector.cxx:40
 AliSelector.cxx:41
 AliSelector.cxx:42
 AliSelector.cxx:43
 AliSelector.cxx:44
 AliSelector.cxx:45
 AliSelector.cxx:46
 AliSelector.cxx:47
 AliSelector.cxx:48
 AliSelector.cxx:49
 AliSelector.cxx:50
 AliSelector.cxx:51
 AliSelector.cxx:52
 AliSelector.cxx:53
 AliSelector.cxx:54
 AliSelector.cxx:55
 AliSelector.cxx:56
 AliSelector.cxx:57
 AliSelector.cxx:58
 AliSelector.cxx:59
 AliSelector.cxx:60
 AliSelector.cxx:61
 AliSelector.cxx:62
 AliSelector.cxx:63
 AliSelector.cxx:64
 AliSelector.cxx:65
 AliSelector.cxx:66
 AliSelector.cxx:67
 AliSelector.cxx:68
 AliSelector.cxx:69
 AliSelector.cxx:70
 AliSelector.cxx:71
 AliSelector.cxx:72
 AliSelector.cxx:73
 AliSelector.cxx:74
 AliSelector.cxx:75
 AliSelector.cxx:76
 AliSelector.cxx:77
 AliSelector.cxx:78
 AliSelector.cxx:79
 AliSelector.cxx:80
 AliSelector.cxx:81
 AliSelector.cxx:82
 AliSelector.cxx:83
 AliSelector.cxx:84
 AliSelector.cxx:85
 AliSelector.cxx:86
 AliSelector.cxx:87
 AliSelector.cxx:88
 AliSelector.cxx:89
 AliSelector.cxx:90
 AliSelector.cxx:91
 AliSelector.cxx:92
 AliSelector.cxx:93
 AliSelector.cxx:94
 AliSelector.cxx:95
 AliSelector.cxx:96
 AliSelector.cxx:97
 AliSelector.cxx:98
 AliSelector.cxx:99
 AliSelector.cxx:100
 AliSelector.cxx:101
 AliSelector.cxx:102
 AliSelector.cxx:103
 AliSelector.cxx:104
 AliSelector.cxx:105
 AliSelector.cxx:106
 AliSelector.cxx:107
 AliSelector.cxx:108
 AliSelector.cxx:109
 AliSelector.cxx:110
 AliSelector.cxx:111
 AliSelector.cxx:112
 AliSelector.cxx:113
 AliSelector.cxx:114
 AliSelector.cxx:115
 AliSelector.cxx:116
 AliSelector.cxx:117
 AliSelector.cxx:118
 AliSelector.cxx:119
 AliSelector.cxx:120
 AliSelector.cxx:121
 AliSelector.cxx:122
 AliSelector.cxx:123
 AliSelector.cxx:124
 AliSelector.cxx:125
 AliSelector.cxx:126
 AliSelector.cxx:127
 AliSelector.cxx:128
 AliSelector.cxx:129
 AliSelector.cxx:130
 AliSelector.cxx:131
 AliSelector.cxx:132
 AliSelector.cxx:133
 AliSelector.cxx:134
 AliSelector.cxx:135
 AliSelector.cxx:136
 AliSelector.cxx:137
 AliSelector.cxx:138
 AliSelector.cxx:139
 AliSelector.cxx:140
 AliSelector.cxx:141
 AliSelector.cxx:142
 AliSelector.cxx:143
 AliSelector.cxx:144
 AliSelector.cxx:145
 AliSelector.cxx:146
 AliSelector.cxx:147
 AliSelector.cxx:148
 AliSelector.cxx:149
 AliSelector.cxx:150
 AliSelector.cxx:151
 AliSelector.cxx:152
 AliSelector.cxx:153
 AliSelector.cxx:154
 AliSelector.cxx:155
 AliSelector.cxx:156
 AliSelector.cxx:157
 AliSelector.cxx:158
 AliSelector.cxx:159
 AliSelector.cxx:160
 AliSelector.cxx:161
 AliSelector.cxx:162
 AliSelector.cxx:163
 AliSelector.cxx:164
 AliSelector.cxx:165
 AliSelector.cxx:166
 AliSelector.cxx:167
 AliSelector.cxx:168
 AliSelector.cxx:169
 AliSelector.cxx:170
 AliSelector.cxx:171
 AliSelector.cxx:172
 AliSelector.cxx:173
 AliSelector.cxx:174
 AliSelector.cxx:175
 AliSelector.cxx:176
 AliSelector.cxx:177
 AliSelector.cxx:178
 AliSelector.cxx:179
 AliSelector.cxx:180
 AliSelector.cxx:181
 AliSelector.cxx:182
 AliSelector.cxx:183
 AliSelector.cxx:184
 AliSelector.cxx:185
 AliSelector.cxx:186
 AliSelector.cxx:187
 AliSelector.cxx:188
 AliSelector.cxx:189
 AliSelector.cxx:190
 AliSelector.cxx:191
 AliSelector.cxx:192
 AliSelector.cxx:193
 AliSelector.cxx:194
 AliSelector.cxx:195
 AliSelector.cxx:196
 AliSelector.cxx:197
 AliSelector.cxx:198
 AliSelector.cxx:199
 AliSelector.cxx:200
 AliSelector.cxx:201
 AliSelector.cxx:202
 AliSelector.cxx:203
 AliSelector.cxx:204
 AliSelector.cxx:205
 AliSelector.cxx:206
 AliSelector.cxx:207
 AliSelector.cxx:208
 AliSelector.cxx:209
 AliSelector.cxx:210
 AliSelector.cxx:211
 AliSelector.cxx:212
 AliSelector.cxx:213
 AliSelector.cxx:214
 AliSelector.cxx:215
 AliSelector.cxx:216
 AliSelector.cxx:217
 AliSelector.cxx:218
 AliSelector.cxx:219
 AliSelector.cxx:220
 AliSelector.cxx:221
 AliSelector.cxx:222
 AliSelector.cxx:223
 AliSelector.cxx:224
 AliSelector.cxx:225
 AliSelector.cxx:226
 AliSelector.cxx:227
 AliSelector.cxx:228
 AliSelector.cxx:229
 AliSelector.cxx:230
 AliSelector.cxx:231
 AliSelector.cxx:232
 AliSelector.cxx:233
 AliSelector.cxx:234
 AliSelector.cxx:235
 AliSelector.cxx:236
 AliSelector.cxx:237
 AliSelector.cxx:238
 AliSelector.cxx:239
 AliSelector.cxx:240
 AliSelector.cxx:241
 AliSelector.cxx:242