Loading [MathJax]/extensions/tex2jax.js
Tomographerv4.1
Tomographer C++ Framework Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
signal_status_report.h
Go to the documentation of this file.
1 /* This file is part of the Tomographer project, which is distributed under the
2  * terms of the MIT license.
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2016 ETH Zurich, Institute for Theoretical Physics, Philippe Faist
7  * Copyright (c) 2017 Caltech, Institute for Quantum Information and Matter, Philippe Faist
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  */
27 
28 
29 #ifndef TOMOGRAPHER_TOOLS_SIGNAL_STATUS_REPORT
30 #define TOMOGRAPHER_TOOLS_SIGNAL_STATUS_REPORT
31 
32 
41 #include <tomographer/multiproc.h>
42 
43 
44 namespace Tomographer
45 {
46 namespace Tools
47 {
48 
52 template<typename TaskDispatcher, typename Logger>
53 TOMOGRAPHER_EXPORT struct SigHandlerTaskDispatcherStatusReporter
54  : public SignalHandler
55 {
58 
59  SigHandlerTaskDispatcherStatusReporter(TaskDispatcher * tasks_, Logger & logger_)
60  : tasks(tasks_), logger(logger_)
61  {
62  tasks->setStatusReportHandler(
63  [this](const FullStatusReportType& report) {
64  logger.debug("SigHandlerStatusReporter/lambda", "intermediate progress report lambda called");
65  this->intermediateProgressReport(report);
66  });
67  }
68 
69  TaskDispatcher * tasks;
70  Logger & logger;
71 
72  virtual void handleSignal(int /*sig*/)
73  {
74  tasks->requestStatusReport();
75  }
76 
80  void intermediateProgressReport(const FullStatusReportType& report)
81  {
82  std::string human_report = report.getHumanReport();
83  fprintf(stderr, "\n%s\n", human_report.c_str());
84  };
85 
86 };
87 
88 template<typename TaskDispatcher, typename LoggerT>
90 makeSigHandlerTaskDispatcherStatusReporter(TaskDispatcher * tasks, LoggerT & logger)
91 {
93 }
94 
95 
96 } // namespace Tools
97 } // namespace Tomographer
98 
99 
100 #endif
Base namespace for the Tomographer project.
Definition: densellh.h:45
STL class.
An abstract signal handler (C++ interface)
Some common definitions for multiprocessing interfaces.
A generic handler which requests a status report from an OMPTaskDispatcher.
T c_str(T... args)
std::string getHumanReport() const
Produce a text-based human-readable short representation of the status report.
Definition: multiproc.h:154
void intermediateProgressReport(const FullStatusReportType &report)
Format a nice intermediate progress report.
Basic common code for intercepting a signal and basic interfacing to C++.
A complete status report, abstract version.
Definition: multiproc.h:85