CMS 3D CMS Logo

MessageLoggerScribe.h
Go to the documentation of this file.
1 #ifndef FWCore_MessageService_MessageLoggerScribe_h
2 #define FWCore_MessageService_MessageLoggerScribe_h
3 
6 
11 
13 
14 #include <memory>
15 
16 #include <iosfwd>
17 #include <vector>
18 #include <map>
19 
20 #include <iostream>
21 
22 namespace edm {
23  namespace service {
24 
25  // ----------------------------------------------------------------------
26  //
27  // MessageLoggerScribe.h
28  //
29  // Changes:
30  //
31  // 1 - 2/6/07 mf
32  // Set up ability to get a remembered pointer to the ErrorLog of an
33  // instance of MessageLoggerScribe, from a non-member function, via
34  // getErrorLog_ptr(), and a corresponding routine to remember the pointer
35  // as setStaticErrorLog_ptr(). Needed if we decide to send an explicit
36  // message from the scribe.
37  //
38  // 2 - ?/?/? before 3/1/07 jm
39  // Modify parameter getting template so as not to catch tracked ones
40  // (that is, to crash if user mistakenly does not say untracked)
41  //
42  // 3 - 3/13/07 mf
43  // Added configure_ordinary_destinations, configure_fwkJobReports,
44  // and configure_statistics to allow these to be broken out of
45  // configure_errorlog.
46  //
47  // 4 - 3/26/07 mf
48  // Added configure_default_fwkJobReport, which implements the config
49  // originally placed in the .cfi file.
50  //
51  // 5 - 6/15/07 mf
52  // Accommodations for use of MessageLoggerDefault structure
53  //
54  // 6 - 7/24/07 mf
55  // Instace variable indicating that we really are logging what is sent.
56  // This is to be able to supress the <generator> info sent at exit by
57  // the JobReport, in the case where no .cfg file was given.
58  //
59  // 7 - 4/8/08 mf
60  // Modified getAparameter behavior when tracked parameter is found,
61  // for nicer output message.
62  //
63  // 8 - 6/19/08 mf
64  // triggerFJRmessageSummary
65  //
66  // 9 - 10/21/08 mf
67  // variables and routines in preparation for single-thread
68  //
69  // 10 - 10/22/08 mf
70  // derivation from AbstractMLscribe to allow for single-thread calling
71  // from MessageLoggerQ without introducing coupling to MessageService
72  //
73  // 11 - 5/26/09 mf
74  // restore getAparameter behavior to NOT throw for tracked, since
75  // now this will be caught when validating the PSet.
76  //
77  // 12 - 8/10/09 mf, cj
78  // member data to hold shared pointer to thread queue
79  //
80  // -----------------------------------------------------------------------
81 
82  class ThreadQueue;
83  class ELadministrator;
84  class ELstatistics;
85 
87  public:
88  // --- birth/death:
89 
90  // ChangeLog 12
92  explicit MessageLoggerScribe(std::shared_ptr<ThreadQueue> queue);
93 
94  ~MessageLoggerScribe() override;
95 
96  // --- receive and act on messages:
97  virtual void run();
98  // changelog 10
99  void runCommand(MessageLoggerQ::OpCode opcode, void* operand) override;
100  // changeLog 9
101 
102  private:
103  // --- convenience typedefs
105  typedef std::vector<String> vString;
107 
108  // --- log one consumed message
109  void log(ErrorObj* errorobj_p);
110 
111  // --- cause statistics destinations to output
113  void triggerFJRmessageSummary(std::map<std::string, double>& sm);
114 
115  // --- handle details of configuring via a ParameterSet:
116  void configure_errorlog();
117  void configure_ordinary_destinations(); // Change Log 3
118  void configure_statistics(); // Change Log 3
119  void configure_dest(std::shared_ptr<ELdestination> dest_ctrl, String const& filename);
120 
121 #define VALIDATE_ELSEWHERE // ChangeLog 11
122 
123 #ifdef OLDSTYLE
124  template <class T>
125  T getAparameter(PSet const& p, std::string const& id, T const& def) {
126  T t;
127  try {
128  t = p.template getUntrackedParameter<T>(id, def);
129  } catch (...) {
130  t = p.template getParameter<T>(id);
131  std::cerr << "Tracked parameter " << id << " used in MessageLogger configuration.\n"
132  << "Use of tracked parameters for the message service "
133  << "is deprecated.\n"
134  << "The .cfg file should be modified to make this untracked.\n";
135  }
136  return t;
137  }
138 #else
139 #ifdef SIMPLESTYLE
140  template <class T>
141  T getAparameter(PSet const& p, std::string const& id, T const& def) {
142  T t;
143  t = p.template getUntrackedParameter<T>(id, def);
144  return t;
145  } // changelog 2
146 #else
147 #ifdef VALIDATE_ELSEWHERE
148  template <class T> // ChangeLog 11
149  T getAparameter(PSet const& p, std::string const& id, T const& def) {
150  T t = def;
151  try {
152  t = p.template getUntrackedParameter<T>(id, def);
153  } catch (...) {
154  try {
155  t = p.template getParameter<T>(id);
156  } catch (...) {
157  // Since PSetValidation will catch such errors, we simply proceed as
158  // best we can in case we are setting up the logger just to contain the
159  // validation-caught error messages.
160  }
161  }
162  return t;
163  }
164 #else // Do not tolerate errors
165  template <class T>
166  T getAparameter(PSet const& p, std::string const& id, T const& def) { // changelog 7
167  T t;
168  try {
169  t = p.template getUntrackedParameter<T>(id, def);
170  } catch (cms::Exception& e) {
171  try {
172  t = p.template getParameter<T>(id);
173  } catch (...) {
174  // if we get here, this was NOT a simple tracked parameter goof.
175  // we should just rethrow the ORIGINAL error
176  e.raise();
177  }
178  std::cerr << "Tracked parameter " << id << " used in MessageLogger configuration.\n"
179  << "Use of tracked parameters for the message service "
180  << "is not allowed.\n"
181  << "The .cfg file should be modified to make this untracked.\n";
182  e.raise();
183  } catch (...) {
184  // This is not the usual tracked/untracked error; we can't add useful info
185  throw;
186  }
187  return t;
188  }
189 
190 #endif // VALIDATE_ELSEWHERE
191 #endif // SIMPLESTYLE
192 #endif // OLD_STYLE and the else Do not tolerate errors
193 
194 #ifdef REMOVE
195  template <class T>
196  T getCategoryDefault(PSet* p, std::string const& id, std::string const& def) {
197  T t;
198  t = p->template getUntrackedParameter<T>(id, def);
199  return t;
200  }
201 #endif
202 
203  // --- other helpers
204  void parseCategories(std::string const& s, std::vector<std::string>& cats);
205 
206  // --- data:
208  std::shared_ptr<ELdestination> early_dest;
209  std::vector<edm::propagate_const<std::shared_ptr<std::ofstream>>> file_ps;
211  std::map<String, edm::propagate_const<std::ostream*>> stream_ps;
212  std::vector<String> ordinary_destination_filenames;
213  std::vector<std::shared_ptr<ELstatistics>> statisticsDestControls;
214  std::vector<bool> statisticsResets;
217  bool active;
218  bool singleThread; // changeLog 9
219  bool done; // changeLog 9
220  bool purge_mode; // changeLog 9
221  int count; // changeLog 9
223 
224  }; // MessageLoggerScribe
225 
226  } // end of namespace service
227 } // namespace edm
228 
229 #endif // FWCore_MessageService_MessageLoggerScribe_h
void raise()
Definition: Exception.h:98
std::vector< String > ordinary_destination_filenames
void runCommand(MessageLoggerQ::OpCode opcode, void *operand) override
std::map< String, edm::propagate_const< std::ostream * > > stream_ps
edm::propagate_const< std::shared_ptr< ELadministrator > > admin_p
void configure_dest(std::shared_ptr< ELdestination > dest_ctrl, String const &filename)
std::vector< std::shared_ptr< ELstatistics > > statisticsDestControls
std::vector< edm::propagate_const< std::shared_ptr< std::ofstream > > > file_ps
std::shared_ptr< ELdestination > early_dest
void parseCategories(std::string const &s, std::vector< std::string > &cats)
edm::propagate_const< std::shared_ptr< PSet > > job_pset_p
MessageLoggerScribe(std::shared_ptr< ThreadQueue > queue)
— If queue is NULL, this sets singleThread true
HLT enums.
void triggerFJRmessageSummary(std::map< std::string, double > &sm)
T getAparameter(PSet const &p, std::string const &id, T const &def)
edm::propagate_const< std::shared_ptr< ThreadQueue > > m_queue
long double T
JetCorrectorParameters::Definitions def
Definition: classes.h:6
value_ptr< MessageLoggerDefaults > messageLoggerDefaults