#ifndef ALITOFCLUSTERFINDER_H
#define ALITOFCLUSTERFINDER_H
#include "TTask.h"
#include "AliTOFRawStream.h"
class TClonesArray;
class TFile;
class TTree;
class AliLoader;
class AliRunLoader;
class AliRawReader;
class AliTOFrawData;
class AliTOFGeometry;
class AliTOFcluster;
class AliTOFcalib;
class AliTOFClusterFinder : public TTask
{
enum {kTofMaxCluster=77777};
public:
AliTOFClusterFinder(AliTOFcalib *calib);
AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib);
AliTOFClusterFinder(const AliTOFClusterFinder &source);
AliTOFClusterFinder& operator=(const AliTOFClusterFinder &source);
virtual ~AliTOFClusterFinder();
void Digits2RecPoints(TTree* digitsTree, TTree* clusterTree);
void Digits2RecPoints(Int_t ievt);
void Digits2RecPoints(AliRawReader *rawReader, TTree *clustersTree);
void Digits2RecPoints(Int_t ievt, AliRawReader *rawReader);
void Raw2Digits(Int_t ievt, AliRawReader *rawReader);
void Raw2Digits(AliRawReader *rawReader, TTree* digitsTree);
void FillRecPoint();
void ResetRecpoint();
void Load();
void LoadClusters();
void UnLoad();
void UnLoadClusters();
void SetVerbose(Int_t Verbose){fVerbose=Verbose;}
void SetDecoderVersion(Int_t version){fDecoderVersion=version;}
Int_t GetDecoderVersion() const {return fDecoderVersion;}
UShort_t GetClusterVolIndex(const Int_t * const ind) const;
void GetClusterPars(Int_t *ind, Double_t *pos, Double_t *cov) const;
Int_t GetNumberOfTOFclusters() const {return fNumberOfTofClusters;}
Int_t GetNumberOfTOFtrgPads() const {return fNumberOfTofTrgPads;}
protected:
AliRunLoader *fRunLoader;
AliLoader *fTOFLoader;
TTree *fTreeD;
TTree *fTreeR;
AliTOFcluster *fTofClusters[kTofMaxCluster];
TClonesArray *fDigits;
TClonesArray *fRecPoints;
Int_t fNumberOfTofClusters;
Int_t fNumberOfTofTrgPads;
private:
void FillTOFtriggerMap(Int_t iDDL, AliTOFrawData *tofRawDatum);
Int_t InsertCluster(AliTOFcluster *tofCluster);
Int_t FindClusterIndex(Double_t z) const;
void CalibrateRecPoint(UInt_t timestamp = 0);
Int_t fVerbose;
Int_t fDecoderVersion;
AliTOFcalib *fTOFcalib;
AliTOFRawStream fTOFRawStream;
ClassDef(AliTOFClusterFinder,8)
};
#endif