ATLAS Offline Software
Loading...
Searching...
No Matches
Event/xAOD/xAODCore/Root/Utils.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: Utils.cxx 672864 2015-06-05 16:55:45Z ssnyder $
6
7// System include(s):
8#include <cmath>
9#include <sstream>
10
11// Local include(s):
13
14namespace {
15
31 struct TimeStruct {
32 int miliseconds;
33 int seconds;
34 int minutes;
35 int hours;
36 int days;
37 }; // struct TimeStruct
38
48 TimeStruct timeToStruct( ::Double_t secs ) {
49
50 // Create the structure, fill its miliseconds variable,
51 // and reset all the rest:
52 TimeStruct result = {
53 static_cast< ::Int_t >( std::fmod( secs, 1.0 ) * 1000.0 ),
54 0, 0, 0, 0 };
55
56 // If the elapsed time was less than a second, finish here:
57 secs -= ( result.miliseconds * 1e-3 );
58 if( std::abs( secs ) < 0.5 ) return result;
59
60 // Calculate the number of seconds passed, and finish if the
61 // amount of time passed was less than a minute:
62 result.seconds =
63 static_cast< ::Int_t >( std::fmod( secs, 60.0 ) );
64 secs -= result.seconds;
65 if( std::abs( secs ) < 0.5 ) return result;
66
67 // Calculate the number of minutes passed, and finish if the
68 // amount of time passed was less than an hour:
69 result.minutes =
70 static_cast< ::Int_t >( std::fmod( secs, 3600.0 ) * (1./60.) );
71 secs -= result.minutes * 60.0;
72 if( std::abs( secs ) < 0.5 ) return result;
73
74 // Calculate the number of hours passed, and finish if the
75 // amount of time passed was less than a day:
76 result.hours =
77 static_cast< ::Int_t >( std::fmod( secs, 86400.0 ) * (1./3600.) );
78 secs -= result.hours * 3600.0;
79 if( std::abs( secs ) < 0.5 ) return result;
80
81 // Calculate the number of days passed. The function should
82 // not expect to have to express a larger order of magnitude...
83 result.days = static_cast< ::Int_t >( secs * (1./86400.));
84
85 return result;
86 }
87
88} // private namespace
89
90namespace xAOD {
91
99 std::string Utils::timeToString( ::Double_t secs ) {
100
101 // Do meat of the calculation:
102 const TimeStruct ts = timeToStruct( secs );
103
104 // Construct the string:
105 std::ostringstream result;
106 if( ts.days ) {
107 result << ts.days << "d ";
108 }
109 if( ts.hours || ts.days ) {
110 result << ts.hours << "h ";
111 }
112 if( ts.minutes || ts.hours || ts.days ) {
113 result << ts.minutes << "m ";
114 }
115 if( ts.seconds || ts.minutes || ts.hours || ts.days ) {
116 result << ts.seconds << "s ";
117 }
118 result << ts.miliseconds << "ms";
119
120 return result.str();
121 }
122
129 std::string Utils::sizeToString( ::Long64_t bytes ) {
130
131 std::ostringstream result;
132
133 if( std::abs( bytes ) > 1e12 ) {
134 result << ( bytes * 1e-12 ) << " TB";
135 } else if( std::abs( bytes ) > 1e9 ) {
136 result << ( bytes * 1e-9 ) << " GB";
137 } else if( std::abs( bytes ) > 1e6 ) {
138 result << ( bytes * 1e-6 ) << " MB";
139 } else if( std::abs( bytes ) > 1e3 ) {
140 result << ( bytes * 1e-3 ) << " kB";
141 } else {
142 result << bytes << " bytes";
143 }
144
145 return result.str();
146 }
147
151 std::string Utils::speedToString( ::Double_t bytespersec ) {
152
153 std::ostringstream result;
154
155 if( ::fabs( bytespersec ) > 1e12 ) {
156 result << ( bytespersec * 1e-12 ) << " TB/s";
157 } else if( ::fabs( bytespersec ) > 1e9 ) {
158 result << ( bytespersec * 1e-9 ) << " GB/s";
159 } else if( ::fabs( bytespersec ) > 1e6 ) {
160 result << ( bytespersec * 1e-6 ) << " MB/s";
161 } else if( ::fabs( bytespersec ) > 1e3 ) {
162 result << ( bytespersec * 1e-3 ) << " kB/s";
163 } else {
164 result << bytespersec << " B/s";
165 }
166
167 return result.str();
168 }
169
170} // namespace D3PDReader
int ts
Definition globals.cxx:24
std::string timeToString(::Double_t secs)
Function creating a human-readable elapsed time printout.
std::string speedToString(::Double_t bytespersec)
Function for printing data processing speeds in a human-readable format.
std::string sizeToString(::Long64_t bytes)
Function for printing data sizes in human-readable format.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.