244 Analysis(
const char *configfilename);
251 template <
typename LE>
252 std::shared_ptr<ResultGroup>
ProcessEventLoop(
const char *filelist,
bool dosave =
true);
253 template <
typename LE>
254 std::shared_ptr<ResultGroup>
SubmitEventLoop(
const char *filelist,
bool dosave =
true);
256 template <
typename LE>
260 template <
typename J,
typename... Args>
261 std::shared_ptr<ResultGroup>
SubmitJob(
bool doSave, Args &&...args);
262 template <
typename J,
typename JS,
typename... Args>
263 std::shared_ptr<ResultGroup>
SubmitJob(
bool doSave, Args &&...args);
265 std::shared_ptr<MSGTool>
MSGUser();
277 std::shared_ptr<MSGTool>
msg;
279 std::shared_ptr<ThreadPool>
pool;
280 std::vector<std::future<StatusCode>>
vf;
283 template <
typename F,
typename... Args>
299 template <
typename LE>
315 template <
typename LE>
319 static_assert(!std::is_pointer<LE>::value,
"Analysis::SubmitEventLoop : type can not be a pointer");
320 static_assert(std::is_base_of<LoopEvent, LE>::value,
"Analysis::SubmitEventLoop : Input type must be or be inherited from LoopEvent class");
322 std::ifstream infile;
323 infile.open(
filelist, std::ios::in);
324 if (!infile.is_open())
326 MSGUser()->StartTitle(
"Analysis::SubmitEventLoop");
327 MSGUser()->MSG_WARNING(
"file list ",
filelist,
" does not exist, returning a null result");
341 auto result = std::make_shared<ResultGroup>(this->
msg, this->
config);
344 while (std::getline(infile,
line))
360 if (
line.back() ==
'\r')
368 else if (
line.size() != 0)
370 MSGUser()->StartTitle(
"Analysis::SubmitEventLoop");
371 MSGUser()->MSG_WARNING(
"file ",
line,
" does not exist, will skip this file");
391 template <
typename LE>
395 static_assert(!std::is_pointer<LE>::value,
"Analysis::SubmitEventLoop : type can not be a pointer");
396 static_assert(std::is_base_of<LoopEvent, LE>::value,
"Analysis::SubmitEventLoop : Input type must be or be inherited from LoopEvent class");
400 auto r = std::make_shared<ResultGroup>(this->
msg, this->
config);
415 template <
typename J,
typename... Args>
418 static_assert(!std::is_pointer<J>::value,
"Analysis::SubmitJob : type can not be a pointer");
419 static_assert(std::is_base_of<Job, J>::value,
"Analysis::SubmitJob : Input type must be or be inherited from Job class");
424 configCopy.SetMSG(std::make_shared<MSGTool>());
433 auto r = std::make_shared<ResultGroup>(this->
msg, this->
config);
454 template <
typename J,
typename JS,
typename... Args>
457 static_assert(!std::is_pointer<J>::value,
"Analysis::SubmitJob : type can not be a pointer");
458 static_assert(std::is_base_of<Job, J>::value,
"Analysis::SubmitJob : Input type must be or be inherited from Job class");
463 configCopy.SetMSG(std::make_shared<MSGTool>());
472 auto r = std::make_shared<ResultGroup>(this->
msg, this->
config);
487 template <
typename F,
typename... Args>
493 pool = std::make_shared<ThreadPool>(1);
502 vf.emplace_back(
pool->enqueue(
f, std::forward<Args>(
args)...));
Provide multi-thread interface to manipulate with Job.
std::shared_ptr< ResultGroup > ProcessEventLoopMainThread(const char *filename, bool dosave=true)
Single-thread mode of processing the user defined event loop. The event loop will be run in the main ...
std::shared_ptr< Timer > TimerUser()
return the Timer
std::vector< std::shared_ptr< ResultGroup > > ResultsToSave
~Analysis()
destructor of the Analysis class.
Analysis()
Default constructor of the Analysis class.
void ConfigThreadPool()
Config the thread pool using the info from ConfigTool.
std::vector< int > SubmittedJobCount
Analysis(Analysis &&ana)=delete
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...
Analysis & operator=(const Analysis &ana)=delete
void Join()
Join the threads in the thread pool.
std::shared_ptr< ResultGroup > SubmitJob(bool doSave, Args &&...args)
Submit the user defined job. The Analysis will process the submitted jobs in multi-thread mode.
std::shared_ptr< ConfigTool > config
Analysis(const Analysis &ana)=delete
void SetThreadNumber(int num)
Set the thread number of the thread pool. Can only be set once.
Analysis & operator=(Analysis &&ana)=delete
std::shared_ptr< ConfigTool > ConfigUser()
return the ConfigTool
std::shared_ptr< MSGTool > MSGUser()
return the MSGTool
std::shared_ptr< ResultGroup > ProcessEventLoop(const char *filelist, bool dosave=true)
Process the user defined event loop. This function will automatically call Join() after submit the ev...
void ThreadPoolEnqueue(F &&f, Args &&...args)
General function to enqueue a function into the thread pool inside Analysis class.
std::vector< std::future< StatusCode > > vf
std::shared_ptr< Timer > timer
std::shared_ptr< ThreadPool > pool
std::shared_ptr< MSGTool > msg