GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TFragHistLoop.cxx
Go to the documentation of this file.
1#include <utility>
2
3#include "TFragHistLoop.h"
4
5#include "TFile.h"
6
7#include "TGRSIint.h"
8#include "TGRSIOptions.h"
10#include "GValue.h"
11#include "TChannel.h"
12
14{
15 if(name.length() == 0) {
16 name = "histo_loop";
17 }
18 auto* loop = static_cast<TFragHistLoop*>(StoppableThread::Get(name));
19 if(loop == nullptr) {
20 loop = new TFragHistLoop(name);
21 }
22 return loop;
23}
24
26 : StoppableThread(std::move(name)), fOutputFile(nullptr), fOutputFilename("last.root"),
27 fInputQueue(std::make_shared<ThreadsafeQueue<std::shared_ptr<const TFragment>>>())
28{
29 LoadLibrary(TGRSIOptions::Get()->FragmentHistogramLib());
30}
31
36
38{
39 while(fInputQueue->Size() != 0u) {
40 std::shared_ptr<const TFragment> event;
41 fInputQueue->Pop(event);
42 }
43}
44
46{
47 std::shared_ptr<const TFragment> event;
48 InputSize(fInputQueue->Pop(event));
49
50 if(event) {
51 if(fOutputFile == nullptr) {
52 OpenFile();
53 }
54
57 return true;
58 }
59 if(fInputQueue->IsFinished()) {
60 return false;
61 }
62 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
63 return true;
64}
65
70
72{
73 TPreserveGDirectory preserve;
75 fOutputFile->SetTitle("Fragment Histograms");
77}
78
80{
81 Write();
82
83 if(fOutputFile != nullptr) {
84 fOutputFile->Close();
85 fOutputFile = nullptr;
86 fOutputFilename = "last.root";
87 }
88}
89
91{
92 if(GetOutputFilename() == "/dev/null") {
93 return;
94 }
95
96 TPreserveGDirectory preserve;
97 if(fOutputFile != nullptr) {
98 fOutputFile->cd();
100 if(GValue::Size() != 0) {
101 GValue::Get()->Write();
102 std::cout << BLUE << "\t" << GValue::Size() << " GValues written to file " << gDirectory->GetName() << RESET_COLOR << std::endl;
103 }
106 std::cout << BLUE << "\t" << TChannel::GetNumberOfChannels() << " TChannels written to file " << gDirectory->GetName() << RESET_COLOR << std::endl;
107 }
108 }
109}
110
111void TFragHistLoop::LoadLibrary(const std::string& library)
112{
113 fCompiledHistograms.Load(library, "MakeFragmentHistograms");
114}
115
117{
119}
120
125
127{
129}
130
131void TFragHistLoop::SetOutputFilename(const std::string& name)
132{
133 fOutputFilename = name;
134}
135
137{
138 return fOutputFilename;
139}
140
141void TFragHistLoop::AddCutFile(TFile* cut_file)
142{
144}
#define BLUE
Definition Globals.h:6
#define RESET_COLOR
Definition Globals.h:5
static int Size()
Definition GValue.h:63
static GValue * Get(const std::string &name="")
Definition GValue.h:39
std::atomic_long & InputSize()
static StoppableThread * Get(const std::string &name)
void IncrementItemsPopped()
static TChannel * GetDefaultChannel()
Definition TChannel.cxx:413
static size_t GetNumberOfChannels()
Definition TChannel.h:68
void AddCutFile(TFile *cut_file)
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) override
void Fill(std::shared_ptr< const TFragment > frag)
void SetDefaultDirectory(TDirectory *dir)
std::string GetLibraryName() const
void Load(const std::string &libName, const std::string &funcName)
void LoadLibrary(const std::string &library)
std::string GetLibraryName() const
static TFragHistLoop * Get(std::string name="")
void ClearQueue() override
std::shared_ptr< ThreadsafeQueue< std::shared_ptr< const TFragment > > > fInputQueue
bool Iteration() override
TFragHistLoop(const TFragHistLoop &)=delete
TList * GetObjects()
std::string fOutputFilename
TCompiledHistograms fCompiledHistograms
void AddCutFile(TFile *cut_file)
std::string GetOutputFilename() const
void SetOutputFilename(const std::string &name)
TFile * fOutputFile
static TGRSIOptions * Get(int argc=0, char **argv=nullptr)
Do not use!
TFile * OpenRootFile(const std::string &filename, Option_t *opt="read")
Definition TGRSIint.cxx:299
static TGRSIint * instance(int argc=0, char **argv=nullptr, void *options=nullptr, int numOptions=-1, bool noLogo=false, const char *appClassName="grsisort")
Definition TGRSIint.cxx:53