NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
Analysis.cxx
Go to the documentation of this file.
1//**************************************************************************************
4//**************************************************************************************
5
6#include "NAGASH/Analysis.h"
7
8using namespace NAGASH;
9using namespace std;
10
19{
20 config = std::make_shared<ConfigTool>(c);
21 msg = config->MSGUser();
22 timer = std::make_shared<Timer>(msg);
23 msg->StartTitle("Analysis");
25}
26
29Analysis::Analysis(const char *configfilename)
30{
31 config = std::make_shared<ConfigTool>(configfilename);
32 msg = config->MSGUser();
33 timer = std::make_shared<Timer>(msg);
34 msg->StartTitle("Analysis");
36}
37
40{
41 config = std::make_shared<ConfigTool>();
42 msg = config->MSGUser();
43 timer = std::make_shared<Timer>(msg);
44 msg->StartTitle("Analysis");
46}
47
50{
51 // read thread number from file
52 auto origin = msg->OutputLevel;
53 bool existthreadnum = false;
54 msg->OutputLevel = MSGLevel::SILENT;
55 int threadnum = config->GetPar<int>("Nthread", &existthreadnum);
56 msg->OutputLevel = origin;
57 if (threadnum <= 0 && existthreadnum)
58 {
59 msg->MSG(MSGLevel::WARNING, "Thread number is set to less than one, will be ignored");
60 }
61 else if (existthreadnum)
62 {
65 }
66 else if (!existthreadnum)
67 {
68 msg->MSG(MSGLevel::WARNING, "Nthread in ConfigTool is not set, please call Analysis::SetThreadNumber to set thread number");
69 }
70}
71
74{
75 if (vf.size() > 0)
76 msg->MSG_WARNING("Threads are not finished during the destruction of Analysis, you should manually call Analysis::Join in the end");
77 Join(); // finish unfinished jobs
78 msg->EndTitle();
79}
80
84{
85 if (pool != nullptr)
86 {
87 msg->MSG(MSGLevel::WARNING, "Thread pool has been defined, the size of thread pool won't be changed");
88 }
89 else
90 {
93 }
94}
95
98{
99 if (pool != nullptr && vf.size() > 0)
100 {
101 for (size_t i = 0; i < vf.size(); i++)
102 {
103 auto status = vf[i].get();
105 msg->MSG(MSGLevel::WARNING, "Job ", SubmittedJobCount[i], " failed");
106 }
107 vf.clear();
108 for (size_t i = 0; i < ResultsToSave.size(); i++)
109 {
110 if (ResultsToSave[i] != nullptr)
111 ResultsToSave[i]->Write();
112 }
113 ResultsToSave.clear();
114 msg->MSG(MSGLevel::INFO, "Finished Job ", SubmittedJobCount.front(), "~", SubmittedJobCount.back());
115 TimerUser()->PrintCurrent("Finished Time : ");
117 record1.Form("(Finished Submitted Job %d~%d)", SubmittedJobCount.front(), SubmittedJobCount.back());
118 record2.Form("(Submit Job %d)", SubmittedJobCount.front());
119 TimerUser()->Record(record1);
120 TimerUser()->Duration(record2, record1);
121 SubmittedJobCount.clear();
122 }
123}
std::shared_ptr< Timer > TimerUser()
return the Timer
Definition Analysis.h:288
std::vector< std::shared_ptr< ResultGroup > > ResultsToSave
Definition Analysis.h:270
~Analysis()
destructor of the Analysis class.
Definition Analysis.cxx:73
Analysis()
Default constructor of the Analysis class.
Definition Analysis.cxx:39
void ConfigThreadPool()
Config the thread pool using the info from ConfigTool.
Definition Analysis.cxx:49
std::vector< int > SubmittedJobCount
Definition Analysis.h:275
std::shared_ptr< ResultGroup > SubmitEventLoop(const char *filelist, bool dosave=true)
Submit the user defined event loop. This function will not automatically call Join() after submit the...
Definition Analysis.h:316
void Join()
Join the threads in the thread pool.
Definition Analysis.cxx:97
std::shared_ptr< ConfigTool > config
Definition Analysis.h:269
void SetThreadNumber(int num)
Set the thread number of the thread pool. Can only be set once.
Definition Analysis.cxx:83
std::vector< std::future< StatusCode > > vf
Definition Analysis.h:280
std::shared_ptr< Timer > timer
Definition Analysis.h:278
std::shared_ptr< ThreadPool > pool
Definition Analysis.h:279
std::shared_ptr< MSGTool > msg
Definition Analysis.h:277
provide interface to config objects in NAGASH.
Definition ConfigTool.h:14