Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JLoggerMessage.hh
Go to the documentation of this file.
1#ifndef __JDB_JLOGGERMESSAGE__
2#define __JDB_JLOGGERMESSAGE__
3
4#include <string>
5#include <istream>
6#include <ostream>
7#include <sstream>
8#include <iomanip>
9
11
12#include "JNet/JTag.hh"
13
14#include "JLang/JException.hh"
15#include "JLang/JManip.hh"
16
18#include "JDAQ/JDAQTags.hh"
19
20#include "JDatalogString.hh"
21
22
23namespace JDB {}
24namespace JPP { using namespace JDB; }
25
26namespace JDB {
27
31
32
33 /**
34 * Auxiliary data structure for logger message.
35 */
37 /**
38 * Default constructor.
39 */
42
43
44 /**
45 * Copy constructor.
46 *
47 * \param datalog data log
48 */
50 {
51 using namespace std;
52 using namespace JPP;
53 using namespace KM3NETDAQ;
54
55 if (datalog.source == MESSAGE_TAG) {
56
57 this->tag = datalog.source;
58
59 istringstream is(datalog.data);
60
61 if (is >> this->datim >> this->ip >> this->nickname >> this->level) {
62
63 this->datim.set(datalog.utc / 1000, (float) (datalog.utc%1000) * 1.0e-3, true);
64
65 while (is.peek() != EOF && isspace((char) is.peek())) { is.ignore(1); }
66
67 getline(is, this->data);
68
69 } else {
70
71 THROW(JParseError, "Invalid string " << datalog.source << " " << datalog.data);
72 }
73
74 } else {
75
76 THROW(JParseError, "Invalid source " << datalog.source);
77 }
78 }
79
80
81 /**
82 * Get match.
83 *
84 * \param message message
85 * \return true if message matches; else false
86 */
87 bool match(const JLoggerMessage& message) const
88 {
89 using namespace std;
90
91 if (!message.tag .empty() && message.tag != tag) { return false; }
92 if (!message.process .empty() && message.process != process) { return false; }
93 if (!message.nickname.empty() && message.nickname != nickname) { return false; }
94 if (!message.ip .empty() && message.ip != ip) { return false; }
95 if (!message.fullname.empty() && message.fullname != fullname) { return false; }
96 if (!message.level .empty() && message.level != level) { return false; }
97 if (!message.data .empty() && !regex_match(data, regex(message.data))) { return false; }
98
99 return true;
100 }
101
102
103 /**
104 * Check if message has date and time.
105 *
106 * \return true if messages has date and time; else false
107 */
108 bool hasTime() const
109 {
110 using namespace JPP;
111
112 return (tag != DISPTAG_Born.toString() &&
113 tag != DISPTAG_Died.toString());
114 }
115
116
117 /**
118 * Get UTC time.
119 *
120 * \return time [ms]
121 */
122 long int getTime() const
123 {
124 return (long int) 1000 * (long int) datim.getTime() + (long int) 500;
125 }
126
127
128 /**
129 * Read message from input.
130 *
131 * \param in input stream
132 * \param object message
133 * \return input stream
134 */
135 friend inline std::istream& operator>>(std::istream& in, JLoggerMessage& object)
136 {
137 using namespace JPP;
138
139 object = JLoggerMessage();
140
141 in >> object.file_name
142 >> object.tag
143 >> object.process;
144
145 if (object.tag != DISPTAG_Born.toString() &&
146 object.tag != DISPTAG_Died.toString()) {
147
148 in >> object.datim
149 >> object.ip
150 >> object.nickname
151 >> object.level;
152
153 while (in.peek() != EOF && isspace((char) in.peek())) { in.ignore(1); }
154
155 return getline(in, object.data);
156
157 } else {
158
159 return in >> object.fullname;
160 }
161 }
162
163
164 /**
165 * Write message to output.
166 *
167 * \param out output stream
168 * \param object message
169 * \return output stream
170 */
171 friend inline std::ostream& operator<<(std::ostream& out, const JLoggerMessage& object)
172 {
173 using namespace std;
174 using namespace JPP;
175
176 if (object.tag != DISPTAG_Born.toString() &&
177 object.tag != DISPTAG_Died.toString()) {
178
179 out << LEFT(8)
180 << object.tag << ' ' << right;
181 out << object.datim << ' ';
182 //out << object.getTime() << ' ';
183 //out << object.ip << ' ';
184 out << object.nickname << ' ';
185 //out << object.level << ' ';
186 out << object.data;
187
188 } else {
189
190 out << object.tag << ' ';
191 //out << object.process << ' ';
192 out << object.fullname;
193 }
194
195 return out;
196 }
197
198
199 std::string file_name;
200 std::string tag;
201 std::string process;
203 std::string ip;
204 std::string nickname;
205 std::string fullname;
206 std::string level;
207 std::string data;
208 };
209}
210
211#endif
Fixed parameters and ControlHost tags for KM3NeT DAQ.
Date and time functions.
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
I/O manipulators.
General purpose message reporting.
ControlHost tag.
Exception for opening of file.
Exception for parsing value.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
Auxiliary data structure for datalog strings.
Auxiliary data structure for logger message.
bool hasTime() const
Check if message has date and time.
long int getTime() const
Get UTC time.
friend std::istream & operator>>(std::istream &in, JLoggerMessage &object)
Read message from input.
JLoggerMessage()
Default constructor.
bool match(const JLoggerMessage &message) const
Get match.
friend std::ostream & operator<<(std::ostream &out, const JLoggerMessage &object)
Write message to output.
JLoggerMessage(const JDatalogString &datalog)
Copy constructor.
Auxiliary class for date and time.
time_t getTime() const
time
void set(const bool utc=false)
Set to current local time.
Auxiliary data structure for alignment of data.
Definition JManip.hh:266