ROOT logo
// $Id$
// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007

/**************************************************************************
 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
 * full copyright notice.                                                 *
 **************************************************************************/

#ifndef AliEveTPCSectorData_H
#define AliEveTPCSectorData_H

#include <TObject.h>

#include <vector>

class AliTPCParam;

//------------------------------------------------------------------------------
// AliEveTPCSectorData
//
// Constainer for pad-data of a single TPC sector.
//  Also stores relevant geometry information in static data-members.
//

class AliEveTPCSectorData : public TObject
{
public:
  // --- Inner classes ---

  class PadData
  {
  public:
    PadData(Short_t* d=0, Short_t l=0) : fData(d), fLength(l) {}

    PadData(const PadData& p) : fData(p.fData), fLength(p.fLength) {}
    PadData& operator=(const PadData& p)
      { if(this!=&p){fData = p.fData; fLength = p.fLength;} return *this; }

    Short_t* Data()   const { return fData; }
    Short_t  Length() const { return fLength; }

    void SetDataLength(Short_t* d, Short_t l) { fData = d; fLength = l; }

    void Print(Option_t* opt="");

  protected:
    Short_t* fData;   // Data for given pad.
    Short_t  fLength; // Length of pad-data.
  };

  class PadIterator
  {
  public:
    PadIterator(const PadData& pd, Short_t thr=0) :
      fBeg(pd.Data()), fEnd(pd.Data() + pd.Length()), fPos(pd.Data()),
      fTime(-1), fSignal(-1), fThreshold(thr), fNChunk(0)
    {}
    PadIterator(const PadIterator& i) :
      fBeg(i.fBeg), fEnd(i.fEnd), fPos(i.fPos),
      fTime(i.fTime), fSignal(i.fSignal), fThreshold(i.fThreshold), fNChunk(i.fNChunk)
    {}
    virtual ~PadIterator() {}

    PadIterator& operator=(const PadIterator& i) {if(this!=&i){
      fBeg = i.fBeg; fEnd = i.fEnd; fPos = i.fPos;
      fTime = i.fTime; fSignal = i.fSignal; fThreshold = i.fThreshold; fNChunk = i.fNChunk;
      }return *this;
    }

    Bool_t Next();
    void   Reset();
    void   Reset(const PadData& pd);

    Short_t Time()   const { return fTime; }
    Short_t Signal() const { return fSignal; }

    Short_t Threshold()    const { return fThreshold; }
    void SetThreshold(Short_t t) { fThreshold = t; }

    void Test();

  protected:
    Short_t *fBeg, *fEnd;    // Begin and end of data.
    Short_t *fPos;           // Current position.
    Short_t  fTime, fSignal; // Current time and signal.
    Short_t  fThreshold;     // Threshold for data iteration. 
    Short_t  fNChunk;        // Number of contiguous signals still to read.
  };

  class RowIterator : public PadIterator
  {
  public:
    RowIterator(const PadData* first, Short_t npads, Short_t thr=0) :
      PadIterator(*first, thr),
      fPadArray(first), fNPads(npads),
      fPad(-1)
    {}
    RowIterator(const RowIterator& i) :
      PadIterator(i),
      fPadArray(i.fPadArray), fNPads(i.fNPads), fPad(i.fPad)
    {}

    RowIterator& operator=(const RowIterator& i) {if(this!=&i){
      fPadArray = i.fPadArray; fNPads = i.fNPads; fPad = i.fPad;
      }return *this;
    }

    Bool_t NextPad();
    void   ResetRow();
    void   ResetRow(const PadData* first, Short_t npads);

    Short_t TEvePad() const { return fPad; }

  protected:
    const PadData *fPadArray; // Pointer to array of pad-data.
    Short_t        fNPads;    // Number of pads in row.
    Short_t        fPad;      // Current pad.
  };

  class SegmentInfo : public TObject
  {
    friend class AliEveTPCSectorData;

  public:
    SegmentInfo();

    Float_t GetPadWidth()  const { return fPadWidth; }
    Float_t GetPadHeight() const { return fPadHeight; }
    Float_t GetRLow()      const { return fRLow; }
    Int_t   GetNRows()     const { return fNRows; }
    Int_t   GetFirstRow()  const { return fFirstRow; }
    Int_t   GetLastRow()   const { return fLastRow; }
    Int_t   GetNMaxPads()  const { return fNMaxPads; }
    Int_t   GetNYSteps()   const { return fNYSteps; }
    Float_t GetYStep(Int_t step) const { return fYStep[step]; }

  private:
    Float_t   fPadWidth;  // Width of pad in this segment.
    Float_t   fPadHeight; // Height of pad in this segment.
    Float_t   fRLow;      // Radius at the bottom of first row.
    Int_t     fNRows;     // Number of rows in this segment.
    Int_t     fFirstRow;  // First row index within sector.
    Int_t     fLastRow;   // Last row index within sector.
    Int_t     fNMaxPads;  // Maximum number of pads in a row.
    Int_t     fNYSteps;   // Number of steps in pad-count.
    Float_t   fYStep[64]; // Y coords where pad-count changes.

    ClassDef(SegmentInfo, 0);
  };

  // --- Interface ---

  AliEveTPCSectorData(Int_t sector, Int_t bsize=65536);
  virtual ~AliEveTPCSectorData();

  void DropData();

  virtual void Print(Option_t* opt="") const;

  void BeginPad(Int_t row, Int_t pad, Bool_t reverseTime=kFALSE);
  void RegisterData(Short_t time, Short_t signal);
  void EndPad(Bool_t autoPedestal=kFALSE, Short_t threshold=0);

  const PadData& GetPadData(Int_t padAddr) const;
  const PadData& GetPadData(Int_t row, Int_t pad) const;

  PadIterator MakePadIterator(Int_t padAddr, Short_t thr=0);
  PadIterator MakePadIterator(Int_t row, Int_t pad, Short_t thr=0);

  RowIterator MakeRowIterator(Int_t row, Short_t thr=0);

  // --- Static functions

  static const AliTPCParam& GetParam() { return *fgParam; }
  static Float_t GetZLength()  { return fgZLength;  }
  static Int_t   GetNAllRows() { return fgNAllRows; }
  static Int_t   GetNAllPads() { return fgNAllPads; }

  static Int_t GetNPadsInRow(Int_t row);

  static const SegmentInfo& GetInnSeg()  { return fgInnSeg;  }
  static const SegmentInfo& GetOut1Seg() { return fgOut1Seg; }
  static const SegmentInfo& GetOut2Seg() { return fgOut2Seg; }

  static const SegmentInfo& GetSeg(Int_t seg);

  static void InitStatics();


protected:
  Int_t                 fSectorID;      // Sector id.
  Int_t                 fNPadsFilled;   // Number of filled pads.
  std::vector<PadData>  fPads;          // Vector of pad-data.

  // Blocks of pad-data.
  const Int_t           fkBlockSize;    // Size of pad-data block.
  Int_t                 fBlockPos;      // Position in current block.
  std::vector<Short_t*> fBlocks;        // Vector of blocks.

  void NewBlock();


  // Intermediate buffer/vars used during filling of pad-data.
  Short_t fPadBuffer[2048];     // Buffer for current pad.
  Int_t   fCurrentRow;          // Current row.
  Int_t   fCurrentPad;          // Current pad.
  Int_t   fCurrentPos;          // Current position in pad-buffer.
  Int_t   fCurrentStep;         // Step, can be -2 or +2, depending on fill direction.

  Int_t PadIndex(Int_t row, Int_t pad) const { return fgRowBegs[row] + pad; }


private:
  static AliTPCParam *fgParam;     // Global TPC parameters.
  static Float_t      fgZLength;   // Z-length of a sector.
  static Int_t        fgNAllRows;  // Number of rows in all segments.
  static Int_t        fgNAllPads;  // Number of pads in all segments.
  static Int_t       *fgRowBegs;   // Ids of pads at row-beginnings.

  static SegmentInfo  fgInnSeg;    // Geometry information for inner segment.
  static SegmentInfo  fgOut1Seg;   // Geometry information for middle segment.
  static SegmentInfo  fgOut2Seg;   // Geometry information for outer segment.

  static SegmentInfo* fgSegInfoPtrs[3]; // Array of geometry information objects, for access by segment id.

  AliEveTPCSectorData(const AliEveTPCSectorData&);            // Not implemented
  AliEveTPCSectorData& operator=(const AliEveTPCSectorData&); // Not implemented

  ClassDef(AliEveTPCSectorData, 0); // Holds pad-data of a single TPC sector. Also stores geometry information in static data-members.
};


inline void AliEveTPCSectorData::RegisterData(Short_t time, Short_t signal)
{
  // Register data for given time.

  fPadBuffer[fCurrentPos]   = time;
  fPadBuffer[fCurrentPos+1] = signal;
  fCurrentPos += fCurrentStep;
}

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