FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairWriteoutBuffer.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
32 #ifndef FairWriteoutBuffer_H_
33 #define FairWriteoutBuffer_H_
34 
35 #include "FairLogger.h" // for FairLogger
36 #include "FairRootManager.h" // for FairRootManager
37 #include "FairTimeStamp.h" // for FairTimeStamp
38 
39 #include <Rtypes.h> // for Bool_t, Int_t, etc
40 #include <TClonesArray.h> // for TClonesArray
41 #include <TObject.h> // for TObject
42 #include <TString.h> // for TString
43 #include <iostream> // for cout, ostream
44 #include <map> // for multimap
45 #include <utility> // for pair
46 #include <vector> // for vector
47 
48 class FairWriteoutBuffer : public TObject
49 {
50  public:
52  : TObject()
53  , fStartTime_map()
54  , fDeadTime_map()
55  , fBranchName()
56  , fClassName()
57  , fTreeSave(false)
58  , fActivateBuffering(kFALSE)
59  , fVerbose(0)
60  , fLogger(FairLogger::GetLogger()){};
61  FairWriteoutBuffer(TString branchName, TString className, TString folderName, Bool_t persistance);
62  virtual ~FairWriteoutBuffer(){};
63 
64  virtual void SaveDataToTree(Bool_t val = kTRUE)
65  {
66  fTreeSave = val;
67  }
69  virtual void ActivateBuffering(Bool_t val = kTRUE)
70  {
71  fActivateBuffering = val;
72  }
74 
76 
80  virtual void FillNewData(FairTimeStamp* data, double startTime, double activeTime);
81 
82  virtual Int_t GetNData() { return fDeadTime_map.size(); }
83  virtual std::vector<FairTimeStamp*> GetRemoveOldData(double time);
84  virtual std::vector<FairTimeStamp*> GetAllData();
85 
86  virtual void SetVerbose(Int_t val) { fVerbose = val; }
87 
88  virtual void DeleteOldData()
89  {
90  if (fBranchName.Length() > 0) {
91  TClonesArray* myArray = FairRootManager::Instance()->GetTClonesArray(fBranchName);
92  myArray->Delete();
93  }
94  }
95 
96  virtual void WriteOutData(double time);
97  virtual void WriteOutAllData();
98 
99  protected:
100  virtual void AddNewDataToTClonesArray(
101  FairTimeStamp* data) = 0;
102  virtual double FindTimeForData(
104  FairTimeStamp* data) = 0;
105  virtual void FillDataMap(FairTimeStamp* data, double activeTime) = 0;
107  virtual void EraseDataFromDataMap(
108  FairTimeStamp* data) = 0;
109 
113  virtual std::vector<std::pair<double, FairTimeStamp*>> Modify(std::pair<double, FairTimeStamp*> oldData,
114  std::pair<double, FairTimeStamp*>)
115  {
116  std::vector<std::pair<double, FairTimeStamp*>> result;
117  result.push_back(oldData);
118  return result;
119  }
120 
121  virtual void WriteOutDataDeadTimeMap(double time);
122  virtual void MoveDataFromStartTimeMapToDeadTimeMap(double time);
123  virtual void FillDataToDeadTimeMap(FairTimeStamp* data, double activeTime, double startTime);
124 
125  virtual void PrintData(FairTimeStamp* data)
126  {
127  std::cout << data->GetTimeStamp();
128  };
129  virtual void PrintDeadTimeMap();
130  virtual void PrintStartTimeMap();
131 
132  std::multimap<double, std::pair<double, FairTimeStamp*>> fStartTime_map;
133  std::multimap<double, FairTimeStamp*> fDeadTime_map;
134 
135  TString fBranchName;
136  TString fClassName;
137  Bool_t fTreeSave;
139  Int_t fVerbose;
141 
142  private:
144  FairWriteoutBuffer& operator=(const FairWriteoutBuffer&);
145 
146  ClassDef(FairWriteoutBuffer, 1);
147 };
148 
149 #endif /* FairWriteoutBuffer_H_ */
virtual void MoveDataFromStartTimeMapToDeadTimeMap(double time)
virtual void AddNewDataToTClonesArray(FairTimeStamp *data)=0
virtual Int_t GetNData()
virtual void FillDataMap(FairTimeStamp *data, double activeTime)=0
add a new element in the search buffer
virtual void PrintData(FairTimeStamp *data)
virtual void FillNewData(FairTimeStamp *data, double startTime, double activeTime)
virtual std::vector< FairTimeStamp * > GetAllData()
static FairRootManager * Instance()
virtual std::vector< std::pair< double, FairTimeStamp * > > Modify(std::pair< double, FairTimeStamp * > oldData, std::pair< double, FairTimeStamp * >)
std::multimap< double, FairTimeStamp * > fDeadTime_map
virtual void WriteOutData(double time)
virtual std::vector< FairTimeStamp * > GetRemoveOldData(double time)
virtual void DeleteOldData()
virtual double FindTimeForData(FairTimeStamp *data)=0
virtual void SaveDataToTree(Bool_t val=kTRUE)
TClonesArray * GetTClonesArray(TString branchName)
virtual void EraseDataFromDataMap(FairTimeStamp *data)=0
delete the element from the search buffer (see PndSdsDigiPixelWriteoutBuffer)
virtual void PrintDeadTimeMap()
Method should be overwritten in derived classes to print the data of an object stored in the buffer...
Double_t GetTimeStamp() const
Definition: FairTimeStamp.h:44
virtual void SetVerbose(Int_t val)
virtual void ActivateBuffering(Bool_t val=kTRUE)
std::multimap< double, std::pair< double, FairTimeStamp * > > fStartTime_map
virtual void WriteOutDataDeadTimeMap(double time)
virtual void FillDataToDeadTimeMap(FairTimeStamp *data, double activeTime, double startTime)
A container class to store digi data during events.
virtual void PrintStartTimeMap()
virtual void WriteOutAllData()