LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
LogEvent.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
34 #include <iomanip>
35 #include <sstream>
36 #include <stdexcept>
37 #include <limits>
38 #include <cstring>
39 
41 #include "lsst/ctrl/events/Event.h"
45 #include "lsst/pex/exceptions.h"
46 
47 namespace pexExceptions = lsst::pex::exceptions;
48 namespace pexLogging = lsst::pex::logging;
49 
50 
51 using namespace std;
52 
53 namespace lsst {
54 namespace ctrl {
55 namespace events {
56 
57 const std::string LogEvent::COMMENT = "COMMENT";
58 const std::string LogEvent::LEVEL = "LEVEL";
59 const std::string LogEvent::LOG = "LOG";
60 const std::string LogEvent::DELIMITER = "|@|";
61 
66 LogEvent::LogEvent() : Event() {
67  _init();
68 }
69 
70 
73  _keywords.insert(LogEvent::LEVEL);
74  _keywords.insert(LogEvent::LOG);
75 }
76 
77 LogEvent::LogEvent(cms::TextMessage *msg) : Event(msg) {
78  _init();
79 
80  vector<std::string>results;
81 
82  std::string str = msg->getStringProperty(LogEvent::COMMENT);
83 
84  std::string::size_type cutAt;
85 
86  std::string::size_type delim_len = LogEvent::DELIMITER.length();
87  while( (cutAt = str.find(LogEvent::DELIMITER)) != str.npos ) {
88  if(cutAt > 0) {
89  results.push_back(str.substr(0,cutAt));
90  }
91  str = str.substr(cutAt+delim_len);
92  }
93  if(str.length() > 0) {
94  results.push_back(str);
95  }
96 
97  _psp->set(LogEvent::COMMENT, results);
98 
99  _psp->set(LogEvent::LEVEL, msg->getIntProperty(LogEvent::LEVEL));
100 
101  _psp->set(LogEvent::LOG, msg->getStringProperty(LogEvent::LOG));
102 
103 }
104 
105 LogEvent::LogEvent( const std::string& runId, const pexLogging::LogRecord& rec) : Event(runId, rec.getProperties()) {
106  _init();
107 
108 
109  const PropertySet& ps = rec.getProperties();
110 
111  _psp->set(TYPE, EventTypes::LOG);
112 
113  if (!ps.exists(LogEvent::LOG))
114  _psp->set(LogEvent::LOG, "default");
115  else
117 
118  if (!ps.exists(LogEvent::LEVEL))
119  _psp->set(LogEvent::LEVEL, -1);
120  else
121  _psp->set(LogEvent::LEVEL, rec.getImportance());
122 
123 
124 
125  if (ps.exists(LogEvent::COMMENT)) {
126  std::vector<std::string> commentArray = ps.getArray<std::string>(LogEvent::COMMENT);
127 
128  _psp->set(LogEvent::COMMENT, commentArray);
129  } else {
130  _psp->set(LogEvent::COMMENT, "none|@|");
131  }
132 }
133 
134 void LogEvent::populateHeader(cms::TextMessage* msg) const {
136 
137  std::vector<std::string> vec = _psp->getArray<std::string>(LogEvent::COMMENT);
138  std::ostringstream comment;
139  std::vector<std::string>::iterator iter;
140  for (iter = vec.begin(); iter != vec.end(); iter++) {
141  comment << *iter << LogEvent::DELIMITER;
142  }
143 
144  msg->setStringProperty(LogEvent::COMMENT, comment.str());
145 
146  msg->setIntProperty(LogEvent::LEVEL, _psp->get<int>(LogEvent::LEVEL));
147 
148  msg->setStringProperty(LogEvent::LOG, _psp->get<std::string>(LogEvent::LOG));
149 
150 }
151 
152 std::vector<std::string> LogEvent::getComment() {
153  return _psp->getArray<std::string>(LogEvent::COMMENT);
154 }
155 
157  return _psp->get<int>(LogEvent::LEVEL);
158 }
159 
160 std::string LogEvent::getLog() {
161  return _psp->get<std::string>(LogEvent::LOG);
162 }
163 
167 }
168 
169 }
170 }
171 }
virtual void populateHeader(cms::TextMessage *msg) const
Definition: Event.cc:201
PropertySet::Ptr _psp
Definition: Event.h:117
int iter
defines EventTypes
static const std::string TYPE
Creates Event which contains a PropertySet.
Definition: Event.h:71
LogEvent()
Creates LogEvent which contains a PropertySet.
Definition: LogEvent.cc:66
vector< std::string > getComment()
Definition: LogEvent.cc:152
virtual void populateHeader(cms::TextMessage *msg) const
Definition: LogEvent.cc:134
a container for constructing a single Log record
Definition: LogRecord.h:99
static const std::string LOG
Definition: EventTypes.h:47
Include files required for standard LSST Exception handling.
defines the Event class
static const std::string DELIMITER
Definition: LogEvent.h:88
virtual ~LogEvent()
destructor
Definition: LogEvent.cc:166
defines the LogEvent class
static const std::string LEVEL
Definition: LogEvent.h:71
Representation of an LSST Event.
Definition: Event.h:67
Class for storing generic metadata.
Definition: PropertySet.h:82
std::string getAsString(std::string const &name) const
Definition: PropertySet.cc:444
Interface for PropertySet class.
std::vector< T > getArray(std::string const &name) const
const lsst::daf::base::PropertySet & getProperties() const
Definition: LogRecord.h:209
static const std::string COMMENT
Definition: LogEvent.h:70
set< std::string > _keywords
Definition: Event.h:118
defines the EventSystem class
bool exists(std::string const &name) const
Definition: PropertySet.cc:190
static const std::string LOG
Definition: LogEvent.h:72