ROOT logo
//-*- Mode: C++ -*-
// $Id$

#ifndef ALIHLTTTREEPROCESSOR_H
#define ALIHLTTTREEPROCESSOR_H
//* This file is property of and copyright by the ALICE HLT Project        * 
//* ALICE Experiment at CERN, All rights reserved.                         *
//* See cxx source for full Copyright notice                               *

/// @file   AliHLTTTreeProcessor.h
/// @author Timur Pocheptsov, Matthias Richter
/// @date   05.07.2010
/// @brief  Generic component for data collection in a TTree

#include <list>

#include <TString.h>

#include "AliHLTProcessor.h"

class TTree;
class TH1;
class TStopwatch;

/**
 * @class AliHLTTTreeProcessor
 * Generic component for data collection in a TTree, or as a special case
 * in a TNtuple (which is a tree with only float branches). Child components
 * implement the creation and filling of the tree, which is dependent on the
 * data itself.
 *
 * Child components have to implement the basic component property methods
 * like GetComponentID(), GetInputDataTypes(), and Spawn(). Default
 * implementations of GetOutputDataSize() and GetOutputDataType() are already
 * provided by the base class.
 * 
 * The base class keeps a circular TTree of a specific event count. Histograms
 * are periodically generated by applying a table of selections and cuts. The
 * table can be configured and changed at run-time and the data sample in the
 * tree can be reset.
 *
 * @ingroup alihlt_base
 */
class AliHLTTTreeProcessor : public AliHLTProcessor {
private:
  enum EDefaults {
    kMaxEntries = 1000,
    kDefaultNBins = 200,
    kInterval = 5
  };
public:
  /// default constructor
  AliHLTTTreeProcessor();
  /// destructor
  virtual ~AliHLTTTreeProcessor();

  /// inherited from AliHLTComponent, get the output data type
  virtual AliHLTComponentDataType GetOutputDataType();

  /// inherited from AliHLTComponent, get the output data size estimator
  virtual void GetOutputDataSize(unsigned long& constBase, double& inputMultiplier);

protected:
  /// initialization, overloaded from AliHLTComponent
  int DoInit(int argc, const char** argv);
  /// deinitialization, overloaded from AliHLTComponent
  int DoDeinit();
  /// inherited from AliHLTProcessor, data processing
  int DoEvent(const AliHLTComponentEventData& evtData,
              AliHLTComponentTriggerData& trigData);
  using AliHLTProcessor::DoEvent;
  /// inherited from AliHLTComponent, scan argument
  virtual int ScanConfigurationArgument(int argc, const char** argv);

  class AliHLTHistogramDefinition {
  public:
    AliHLTHistogramDefinition()
      : fName(), fSize(0), fExpr(), fTitle(), fCut(), fOpt()
    {
    }

	const TString& GetName()const{return fName;}
	void SetName(const TString& name){fName = name;}

	int GetSize()const{return fSize;}
	void SetSize(int size){fSize = size;}

	const TString& GetExpression()const{return fExpr;}
	void SetExpression(const TString& expr){fExpr = expr;}

	const TString& GetTitle()const{return fTitle;}
	void SetTitle(const TString& title){fTitle = title;}

	const TString& GetCut()const{return fCut;}
	void SetCut(const TString& cut){fCut = cut;}

	const TString& GetDrawOption()const{return fOpt;}
	void SetDrawOption(const TString& opt){fOpt = opt;}

  private:

    TString fName;
    int     fSize;
    TString fExpr;
    TString fTitle;
    TString fCut;
    TString fOpt;
  };

  std::list<AliHLTHistogramDefinition> fDefinitions;
  typedef std::list<AliHLTHistogramDefinition>::iterator list_iterator;
  typedef std::list<AliHLTHistogramDefinition>::const_iterator list_const_iterator;

private:
  /// create the tree instance and all branches
  virtual TTree* CreateTree(int argc, const char** argv) = 0;
  /// process input blocks and fill tree
  virtual int FillTree(TTree* pTree, const AliHLTComponentEventData& evtData, 
                       AliHLTComponentTriggerData& trigData ) = 0;
  /// dtOrigin for PushBack.
  virtual AliHLTComponentDataType GetOriginDataType()const = 0;
  /// spec for PushBack
  virtual AliHLTUInt32_t GetDataSpec()const {return fUniqueId;}
  /// default histogram definitions.
  virtual void FillHistogramDefinitions() = 0;

  /// create a histogram from the tree
  TH1* CreateHistogram(const AliHLTHistogramDefinition& def);
  /// parse arguments, containing histogram definition.
  int ParseHistogramDefinition(int argc, const char** argv, int pos, AliHLTHistogramDefinition& dst)const;

  /// the TTree
  TTree* fTree; //! the tree instance
  /// max entries
  int fMaxEntries; //! maximum number of entries in the circular tree
  /// publish interval in s
  unsigned fPublishInterval; //! publish interval in s
  /// time stamp - publish or not.
  unsigned fLastTime; //! last time the histogramms were published

  TStopwatch* fpEventTimer; //! stopwatch for event processing
  TStopwatch* fpCycleTimer; //! stopwatch for event cycle
  AliHLTUInt32_t fMaxMemory; //! maximum memory consumption allowed for the process
  AliHLTUInt32_t fMaxEventTime; //! allowed maximum processing time in usec
  AliHLTUInt32_t fNofEventsForce; //! number of events to ignore the processing time
  AliHLTUInt32_t fForcedEventsCount; //! event count for the forced events
  AliHLTUInt32_t fSkippedEventsCount; //! number of skipped events
  AliHLTUInt32_t fNewEventsCount; //! number of new events since last publishing
  AliHLTUInt32_t fUniqueId; //! a unique id for this process used to identify the output of multiple processes
  AliHLTUInt32_t fIgnoreCycleTime; //! ignore cycle time for n seconds
  float          fCycleTimeFactor; //! weight for the cycle time

  static const AliHLTUInt32_t fgkTimeScale;

  /// copy constructor prohibited
  AliHLTTTreeProcessor(const AliHLTTTreeProcessor&);
  /// assignment operator prohibited
  AliHLTTTreeProcessor& operator = (const AliHLTTTreeProcessor&);

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