GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TDataLoop.h
Go to the documentation of this file.
1#ifndef TDATALOOP_H
2#define TDATALOOP_H
3
4/** \addtogroup Loops
5 * @{
6 */
7
8////////////////////////////////////////////////////////////////////////////////
9///
10/// \class TDataLoop
11///
12/// This loop reads raw events from a raw file.
13///
14////////////////////////////////////////////////////////////////////////////////
15
16#ifndef __CINT__
17#include <atomic>
18#include <condition_variable>
19#include <memory>
20#include <thread>
21#endif
22
23#include <cstdlib>
24#include <iostream>
25#include <map>
26
27#include "StoppableThread.h"
28#include "ThreadsafeQueue.h"
29#include "TRawFile.h"
30#include "TRawEvent.h"
31
32class TDataLoop : public StoppableThread {
33public:
34 static TDataLoop* Get(std::string name = "", TRawFile* source = nullptr);
35 TDataLoop(const TDataLoop&) = delete;
36 TDataLoop(TDataLoop&&) noexcept = delete;
37 TDataLoop& operator=(const TDataLoop&) = delete;
38 TDataLoop& operator=(TDataLoop&&) noexcept = delete;
39 ~TDataLoop() = default;
40
41#ifndef __CINT__
42 std::shared_ptr<ThreadsafeQueue<std::shared_ptr<TRawEvent>>>& OutputQueue()
43 {
44 return fOutputQueue;
45 }
46#endif
47
48 const TRawFile& GetSource() const
49 {
50 return *fSource;
51 }
52
53 void ClearQueue() override;
54
55 bool Iteration() override;
56 void OnEnd() override;
57
58 size_t GetItemsPushed() override { return fOutputQueue->ItemsPushed(); }
59 size_t GetItemsPopped() override { return fOutputQueue->ItemsPopped(); }
60 size_t GetItemsCurrent() override { return fOutputQueue->Size(); }
61 size_t GetRate() override { return 0; }
62
63 void ReplaceSource(TRawFile* new_source);
64
65 void SetSelfStopping(bool self_stopping) { fSelfStopping = self_stopping; }
66 bool GetSelfStopping() const { return fSelfStopping; }
67
68private:
69 TDataLoop(std::string name, TRawFile* source);
71
75
76#ifndef __CINT__
77 std::shared_ptr<ThreadsafeQueue<std::shared_ptr<TRawEvent>>> fOutputQueue;
78 std::mutex fSourceMutex;
79#endif
80
81 /// \cond CLASSIMP
82 ClassDefOverride(TDataLoop, 0) // NOLINT(readability-else-after-return)
83 /// \endcond
84};
85
86/*! @} */
87#endif /* _TDATALOOP_H_ */
size_t GetRate() override
Definition TDataLoop.h:61
size_t GetItemsCurrent() override
Definition TDataLoop.h:60
size_t GetItemsPushed() override
Definition TDataLoop.h:58
TRawFile * fSource
Definition TDataLoop.h:72
void ReplaceSource(TRawFile *new_source)
Definition TDataLoop.cxx:41
bool fSelfStopping
Definition TDataLoop.h:73
std::shared_ptr< ThreadsafeQueue< std::shared_ptr< TRawEvent > > > fOutputQueue
Definition TDataLoop.h:77
static TDataLoop * Get(std::string name="", TRawFile *source=nullptr)
Definition TDataLoop.cxx:21
std::shared_ptr< ThreadsafeQueue< std::shared_ptr< TRawEvent > > > & OutputQueue()
Definition TDataLoop.h:42
size_t GetItemsPopped() override
Definition TDataLoop.h:59
void SetSelfStopping(bool self_stopping)
Definition TDataLoop.h:65
void OnEnd() override
Definition TDataLoop.cxx:48
size_t fEventsRead
Definition TDataLoop.h:74
void ClearQueue() override
Definition TDataLoop.cxx:33
bool GetSelfStopping() const
Definition TDataLoop.h:66
TDataLoop(const TDataLoop &)=delete
const TRawFile & GetSource() const
Definition TDataLoop.h:48
std::mutex fSourceMutex
Definition TDataLoop.h:78
bool Iteration() override
Definition TDataLoop.cxx:53
TDataLoop(TDataLoop &&) noexcept=delete
Reader for raw files.
Definition TRawFile.h:31