GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TFragDiagnosticsLoop.h
Go to the documentation of this file.
1#ifndef TFRAGDIAGNOSTICSLOOP_H
2#define TFRAGDIAGNOSTICSLOOP_H
3
4/** \addtogroup Loops
5 * @{
6 */
7
8////////////////////////////////////////////////////////////////////////////////
9///
10/// \class TFragDiagnosticsLoop
11///
12/// This loop writes fragments to a root-file.
13///
14////////////////////////////////////////////////////////////////////////////////
15
16#include "TTree.h"
17
18#include "StoppableThread.h"
19#include "ThreadsafeQueue.h"
20#include "TFragment.h"
21#include "TBadFragment.h"
22#include "TEpicsFrag.h"
23#include "TH2.h"
24
26public:
27 static TFragDiagnosticsLoop* Get(std::string name = "", std::string fOutputFilename = "");
28
31 TFragDiagnosticsLoop& operator=(const TFragDiagnosticsLoop&) = delete;
32 TFragDiagnosticsLoop& operator=(TFragDiagnosticsLoop&&) noexcept = delete;
34
35#ifndef __CINT__
36 std::shared_ptr<ThreadsafeQueue<std::shared_ptr<const TFragment>>>& InputQueue() { return fInputQueue; }
37#endif
38
39 void ClearQueue() override;
40
41 void Write();
42
43 // there is no output queue for this loop, so we assume that all items handled (= all good fragments written)
44 // are also the number of items popped and that we have no current items
45 size_t GetItemsPushed() override { return ItemsPopped(); }
46 size_t GetItemsPopped() override { return ItemsPopped(); }
47 size_t GetItemsCurrent() override { return 0; }
48 size_t GetRate() override { return 0; }
49
50 std::string EndStatus() override;
51
52protected:
53 bool Iteration() override;
54
55private:
56 TFragDiagnosticsLoop(std::string name, const std::string& fOutputFilename);
57#ifndef __CINT__
58 void Process(const std::shared_ptr<const TFragment>& event);
59#endif
60 bool CreateHistograms();
61
62 TFile* fOutputFile{nullptr};
63
67
68 //--------------- parameters for dealing with the roll-over of the AcceptedChannelId ----------------------//
69 uint64_t fAcceptedMax{0x1 << 14}; // = 2^14 = this is the maximum number that the AcceptedChannelId can be
70 std::map<unsigned int, int> fNofRollovers; // this is how many roll-overs we have had
71 std::map<unsigned int, bool> fRolling; // array that tells us if we're rolling over in that channel
72 std::map<unsigned int, int> fRollnum; // array that tells us how many times we've had accepted ID over the threshold
73 unsigned int fRollingThreshold{1000};
74 int fRollnumThreshold{20}; // if we have this many numbers above the threshold, turn rolling on or off
75
76 // these are all 2 to store the last and second to last instances of these variables (per channel for the first three)
77 std::map<unsigned int, std::array<int64_t, 2>> fChannelIds;
78 std::map<unsigned int, std::array<int64_t, 2>> fAcceptedChannelIds;
79 std::map<unsigned int, std::array<int64_t, 2>> fTimeStamps;
80 std::array<int, 2> fNetworkPacketNumber{{0, 0}};
81 std::array<int64_t, 2> fNetworkPacketTimeStamp{{0, 0}};
82
83 // time binning of histograms
84 int fRunLength{0};
85
86 // histograms
87 TH2D* fAccepted{nullptr};
88 TH1D* fLostNetworkPackets{nullptr};
89 TH2D* fLostChannelIds{nullptr};
90 TH2D* fLostAcceptedIds{nullptr};
91 TH2D* fLostChannelIdsTime{nullptr};
92 TH2D* fLostAcceptedIdsTime{nullptr};
93
94#ifndef __CINT__
95 std::shared_ptr<ThreadsafeQueue<std::shared_ptr<const TFragment>>> fInputQueue;
96#endif
97
98 /// \cond CLASSIMP
99 ClassDefOverride(TFragDiagnosticsLoop, 0) // NOLINT(readability-else-after-return)
100 /// \endcond
101};
102
103/*! @} */
104#endif /* _TFRAGDIAGNOSTICSLOOP_H_ */
std::atomic_size_t & ItemsPopped()
void Process(const std::shared_ptr< const TFragment > &event)
TFragDiagnosticsLoop(const TFragDiagnosticsLoop &)=delete
TBadFragment * fBadEventAddress
size_t GetItemsCurrent() override
size_t GetRate() override
std::map< unsigned int, std::array< int64_t, 2 > > fTimeStamps
size_t GetItemsPopped() override
size_t GetItemsPushed() override
std::map< unsigned int, std::array< int64_t, 2 > > fChannelIds
std::array< int64_t, 2 > fNetworkPacketTimeStamp
static TFragDiagnosticsLoop * Get(std::string name="", std::string fOutputFilename="")
TFragDiagnosticsLoop(TFragDiagnosticsLoop &&) noexcept=delete
std::map< unsigned int, std::array< int64_t, 2 > > fAcceptedChannelIds
std::map< unsigned int, int > fNofRollovers
std::shared_ptr< ThreadsafeQueue< std::shared_ptr< const TFragment > > > & InputQueue()
std::map< unsigned int, bool > fRolling
std::array< int, 2 > fNetworkPacketNumber
std::string EndStatus() override
std::shared_ptr< ThreadsafeQueue< std::shared_ptr< const TFragment > > > fInputQueue
std::map< unsigned int, int > fRollnum