[go: up one dir, main page]

Menu

[r1120]: / trunk / src / TimeCounter.h  Maximize  Restore  History

Download this file

100 lines (89 with data), 3.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef GUARD_TimeCounter_h
#define GUARD_TimeCounter_h
//Time count header of Mesmer
//This header must be be p_thread safe and parallel computing safe
#include <sstream>
#include <iostream>
#include <ctime>
#include <vector>
#include "error.h"
//------------------------
//Usage:
//
// Variable decalaration
// \code
// TimeCount events; unsigned int timeElapsed;
// std::string thisEvent;
// \endcode
//
// Time stamping
// \code
// thisEvent = "Build Collison Matrix";
// cout << thisEvent << " at " << events.setTimeStamp(thisEvent) << endl;
// \endcode
//
// OR
//
// \code
// thisEvent = "Build Collison Matrix";
// std::cout << thisEvent << " at " << events.setTimeStamp(thisEvent, timeElapsed) << " -- Time elapsed: " << timeElapsed << " seconds.\n";
// \endcode
//
// Time stamp dumping
// \code
// cout << events << endl;
// \endcode
//
//------------------------
template<typename T>
std::string toString(T t)
{
std::ostringstream s; s << t; return s.str();
}
namespace mesmer
{
class EventObj
{
public:
time_t timeStamp;
std::string stampName;
EventObj(const time_t& tt, const std::string& name):timeStamp(tt), stampName(name){}
};
class TimeCount
{
private:
std::vector<EventObj> TimeMap;
typedef std::vector<EventObj>::iterator TimeIter;
public:
std::string setTimeStamp(const std::string& timeStampName);
std::string setTimeStamp(const std::string& timeStampName, unsigned int &timeElapsed);
std::string getTimeStamp(const std::string& timeStampName);
std::string getTimeStamp(const std::string& timeStampName, unsigned int &timeElapsed);
friend std::ostream& operator<<(std::ostream& os, TimeCount& MTC);
};
};
//---------------------------------------------------------------------------------------------------------
//The idea:
//
// The format of a time stamp should look like "20071002_093401" and will be attached to the file.
// The file name will be "<reaction_name>.<time_previous>.<time_current>.xml" to indicate
// that this file is completed at time <time_current> and it was created from the calculation of the date
// from a file completed at <time_previous>.
//
// So, practically a Mesmer XML file will contain a reaction name, a previous time stamp, and a current
// (completed) time stamp. If the file was created from a file without a time stamp, it will set
// its <time_previous> to the initiation time of its calculation.
//
// For example, a filename could look like:
//
// pentyl_isomerization.20071002_093401.20071002_094825.xml
//
// It could have initiated itself from from a file called something like the followings:
//
// pentyl_isomerization.20071002_092341.20071002_093401.xml
// pentyl_isomerization.20071002_093401.xml
// pentyl_isomerization.xml
//
// In this way, the files can be sorted easily.
//---------------------------------------------------------------------------------------------------------
#endif //GUARD_TimeCounter_h