#ifndef __TUsrEvent_h__
#define __TUsrEvent_h__
#include "TObject.h"
#include "TSystem.h"
#include "TTree.h"
#include "TBranch.h"
#include "TObjArray.h"
#include "mbsio.h"
#include "TUsrHit.h"
#include "TUsrHBX.h"
class TUsrEvent : public TObject {
public:
TUsrEvent();
~TUsrEvent() { fLofSubevents.Delete(); fLofHBXs.Delete(); };
const UShort_t * NextSubevent(MBSDataIO * BaseAddr, Int_t NofWords = 0, Bool_t RawMode = kFALSE) const;
UInt_t NextSubeventHeader(MBSDataIO * BaseAddr) const;
const UShort_t * NextSubeventData(MBSDataIO * BaseAddr, Int_t NofWords = 0, Bool_t RawMode = kFALSE) const;
inline void SetScaleDown(Int_t ScaleDown) { fScaleDown = ScaleDown; };
inline Int_t GetScaleDown() const { return(fScaleDown); };
inline Int_t GetClockSecs() const { return(fClockSecs); };
inline Int_t GetClockNsecs() const { return(fClockNsecs); };
inline Int_t GetTimeStamp() const { return(GetUniqueID()); };
inline Int_t GetTimeRS() const { return(fTimeRS); };
Int_t CalcTimeDiff(TUsrEvent * Event) const;
inline TTree * GetTreeIn() const { return(fTreeIn); };
inline TTree * GetTreeOut() const { return(fTreeOut); };
inline void WriteTree(const Bool_t WriteFlag = kTRUE) {
fWriteTree = (fTreeOut == NULL) ? kFALSE : WriteFlag;
};
inline Bool_t TreeToBeWritten() const { return(fWriteTree); };
inline void SetReplayMode(const Bool_t ReplayMode = kTRUE) {
fReplayMode = (fTreeIn == NULL) ? kFALSE : ReplayMode;
};
inline Bool_t IsReplayMode() const { return(fReplayMode); };
inline void SetFakeMode(const Bool_t FakeMode = kTRUE) {
fReplayMode = fFakeMode = FakeMode;
};
inline Bool_t IsFakeMode() const { return(fFakeMode); };
inline Int_t GetNofEvents() const { return(fNofEvents); };
inline Bool_t IsModScaleDown() const { return((fNofEvents % fScaleDown) == 0); };
inline void AddSubevent(TObject * Subevent, Int_t SevtSerial = -1) {
if (SevtSerial == -1) fLofSubevents.AddLast(Subevent);
else fLofSubevents.AddAtAndExpand(Subevent, SevtSerial);
};
inline TObjArray * GetLofSubevents() { return(&fLofSubevents); };
inline TObject * GetSubevent(Int_t SevtSerial) { return(fLofSubevents.At(SevtSerial)); };
inline Int_t GetNofSubevents() const { return(fLofSubevents.GetEntries()); };
inline void AddHBX(TUsrHBX * HBX, Int_t SevtSerial = -1) {
if (SevtSerial == -1) fLofHBXs.AddLast(HBX);
else fLofHBXs.AddAtAndExpand(HBX, SevtSerial);
};
inline TUsrHBX * GetHBX(Int_t SevtSerial) { return((TUsrHBX *) fLofHBXs.At(SevtSerial)); };
Int_t FillSevtFromHB(TUsrHBX * HBX, Int_t Hidx, Bool_t FillHisto = kTRUE, Int_t Didx = TUsrHit::kHitEnergy);
Int_t FillSevtFromHB(TUsrHBX * HBX, Int_t Hidx, Int_t DeltaTS, Bool_t FillHisto = kTRUE, Int_t Didx = TUsrHit::kHitEnergy);
Bool_t FillEventFromHB(TArrayI & LofIndices, Bool_t FillHisto = kTRUE, Int_t Didx = TUsrHit::kHitEnergy, Int_t InitValue = 0);
Bool_t FillEventFromHB(TArrayI & LofIndices, Int_t DeltaTS, Bool_t FillHisto = kTRUE, Int_t Didx = TUsrHit::kHitEnergy, Int_t InitValue = 0);
Int_t FillArrayFromHB(TUsrHBX * HBX, ULong64_t & TimeStamp, TArrayI & Data, Int_t Hidx, Int_t Didx = TUsrHit::kHitEnergy, Int_t InitValue = 0);
virtual void Reset(Int_t InitValue = 0, Bool_t DataOnly = kFALSE) {};
void Print(const Char_t * Text, UInt_t TimeStamp = 0);
inline void Help() { gSystem->Exec(Form("mrbHelp %s", this->ClassName())); };
protected:
Int_t CalcTimeRS();
inline void SetTimeStamp(Int_t TimeStamp) { SetUniqueID(TimeStamp); };
protected:
TBranch * fBranch;
TTree * fTreeOut;
TTree * fTreeIn;
Bool_t fReplayMode;
Bool_t fFakeMode;
Bool_t fWriteTree;
Int_t fNofEntries;
UInt_t fType;
UInt_t fSubtype;
Int_t fTrigger;
Int_t fEventNumber;
Int_t fNofEvents;
Int_t fScaleDown;
Int_t fClockRes;
Int_t fClockSecs;
Int_t fClockNsecs;
Int_t fTimeRS;
TObjArray fLofHBXs;
TObjArray fLofSubevents;
ClassDef(TUsrEvent, 1)
};
#endif