]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STARLIGHT/starlight/include/reportingUtils.h
Switching from CMAKE_SOURCE_DIR to AliRoot_SOURCE_DIR
[u/mrichter/AliRoot.git] / STARLIGHT / starlight / include / reportingUtils.h
CommitLineData
da32329d
AM
1///////////////////////////////////////////////////////////////////////////
2//
3// Copyright 2010
4//
5// This file is part of starlight.
6//
7// starlight is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// starlight is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with starlight. If not, see <http://www.gnu.org/licenses/>.
19//
20///////////////////////////////////////////////////////////////////////////
21//
22// File and Version Information:
23// $Rev:: 29 $: revision of last commit
24// $Author:: bgrube $: author of last commit
25// $Date:: 2010-12-30 20:05:42 +0100 #$: date of last commit
26//
27// Description:
28// some simple streams for reporting plus some stream operators
29// for common STL classes
30//
31//
32///////////////////////////////////////////////////////////////////////////
33
34
35#ifndef REPORTINGUTILS_H
36#define REPORTINGUTILS_H
37
38
39#include <iostream>
40#include <iomanip>
41#include <string>
42#include <vector>
43
44
45//////////////////////////////////////////////////////////////////////////////
46// macros for printing errors, warnings, and infos
47
48// cuts out block "className::methodName" from __PRETTY_FUNCTION__ output
49inline
50std::string
51getClassMethod__(std::string prettyFunction)
52{
53 size_t pos = prettyFunction.find("(");
54 if (pos == std::string::npos)
55 return prettyFunction; // something is not right
56 prettyFunction.erase(pos); // cut away signature
57 pos = prettyFunction.rfind(" ");
58 if (pos == std::string::npos)
59 return prettyFunction; // something is not right
60 prettyFunction.erase(0, pos + 1); // cut away return type
61 return prettyFunction;
62}
63
64#define printErr std::cerr << "!!! " << __PRETTY_FUNCTION__ << " [" << __FILE__ << ":" << __LINE__ << "]: error: " << std::flush
65#define printWarn std::cerr << "??? " << __PRETTY_FUNCTION__ << " [" << __FILE__ << ":" << __LINE__ << "]: warning: " << std::flush
66#define printInfo std::cout << ">>> " << getClassMethod__(__PRETTY_FUNCTION__) << "(): info: " << std::flush
67
68
69//////////////////////////////////////////////////////////////////////////////
70// functions to print version and compilation info
71
72#ifndef SVN_VERSION // SVN_VERSION set by Makefile
73#define SVN_VERSION "undefined"
74#endif
75inline std::string svnVersion() { return SVN_VERSION; }
76
77inline
78void
79printSvnVersion()
80{
81 const std::string ver = svnVersion();
82 if (ver == "")
83 printInfo << "subversion repository revision is unknown." << std::endl;
84 else
85 printInfo << "subversion repository revision is '" << ver << "'" << std::endl;
86}
87
88
427d561c 89#ifndef AliRoot_SOURCE_DIR // AliRoot_SOURCE_DIR set by Makefile
90#define AliRoot_SOURCE_DIR "undefined"
da32329d 91#endif
427d561c 92inline std::string compileDir() { return AliRoot_SOURCE_DIR; }
da32329d
AM
93
94inline
95void
96printCompilerInfo()
97{
98 const std::string date = __DATE__;
99 const std::string time = __TIME__;
100 const std::string ver = __VERSION__;
101 const std::string dir = compileDir();
102 printInfo << "this executable was compiled in ";
103 if (dir != "")
104 std::cout << "'" << dir << "'";
105 else
106 std::cout << "unknown directory";
107 std::cout << " on " << date << " " << time << " by compiler " << ver << std::endl;
108}
109
110
111//////////////////////////////////////////////////////////////////////////////
112// simple stream operators for some STL classes
113
114template<typename T1, typename T2>
115inline
116std::ostream&
117operator << (std::ostream& out,
118 const std::pair<T1, T2>& pair)
119{
120 return out << "(" << pair.first << ", " << pair.second << ")";
121}
122
123
124template<typename T>
125inline
126std::ostream&
127operator << (std::ostream& out,
128 const std::vector<T>& vec)
129{
130 out << "{";
131 for (unsigned int i = 0; i < (vec.size() - 1); ++i)
132 out << "[" << i << "] = " << vec[i] << ", ";
133 return out << "[" << vec.size() - 1 << "] = " << vec[vec.size() - 1] << "}";
134}
135
136
137//////////////////////////////////////////////////////////////////////////////
138// various stuff
139
140// indicates progess by printing relative or absolute progress in regular intervals
141inline
142std::ostream&
143progressIndicator(const unsigned int currentPos,
144 const unsigned int nmbTotal,
145 const bool absolute = false,
146 const unsigned int fieldWidth = 3,
147 const unsigned int nmbSteps = 10,
148 std::ostream& out = std::cout)
149{
150 const double step = nmbTotal / (double)nmbSteps;
151 if ((int)(currentPos / step) - (int)((currentPos - 1) / step) != 0) {
152 if (absolute)
153 out << " " << std::setw(fieldWidth) << currentPos << " of " << nmbTotal << std::endl;
154 else
155 out << " " << std::setw(fieldWidth) << (int)(currentPos / step) * nmbSteps << " %" << std::endl;
156 }
157 return out;
158}
159
160
161// converts bool to "true"/"false" string
162inline
163std::string trueFalse(const bool val)
164{
165 if (val)
166 return "true";
167 else
168 return "false";
169}
170
171// converts bool to "yes"/"no" string
172inline
173std::string yesNo(const bool val)
174{
175 if (val)
176 return "yes";
177 else
178 return "no";
179}
180
181// converts bool to "on"/"off" string
182inline
183std::string onOff(const bool val)
184{
185 if (val)
186 return "on";
187 else
188 return "off";
189}
190
191// converts bool to "enabled"/"disabled" string
192inline
193std::string enDisabled(const bool val)
194{
195 if (val)
196 return "enabled";
197 else
198 return "disabled";
199}
200
201
202#endif // REPORTINGUTILS_H