CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
86 {
87 public:
88  // --- birth/death:
89 
90  // ChangeLog 12
92  explicit MessageLoggerScribe(std::shared_ptr<ThreadQueue> queue);
93 
94  virtual ~MessageLoggerScribe();
95 
96  // --- receive and act on messages:
97  virtual
98  void run();
99  virtual // changelog 10
100  void runCommand(MessageLoggerQ::OpCode opcode, void * operand);
101  // changeLog 9
102 
103 private:
104  // --- convenience typedefs
106  typedef std::vector<String> vString;
108 
109  // --- log one consumed message
110  void log(ErrorObj * errorobj_p);
111 
112  // --- cause statistics destinations to output
114  void triggerFJRmessageSummary(std::map<std::string, double> & sm);
115 
116  // --- handle details of configuring via a ParameterSet:
117  void configure_errorlog( );
118  void configure_ordinary_destinations( ); // Change Log 3
119  void configure_statistics( ); // Change Log 3
120  void configure_dest( ELdestControl & dest_ctrl
121  , String const & filename
122  );
123  void configure_external_dests( );
124 
125 #define VALIDATE_ELSEWHERE // ChangeLog 11
126 
127 #ifdef OLDSTYLE
128  template <class T>
129  T getAparameter ( PSet const& p, std::string const & id, T const & def )
130  {
131  T t;
132  try {
133  t = p.template getUntrackedParameter<T>(id, def);
134  } catch (...) {
135  t = p.template getParameter<T>(id);
136  std::cerr << "Tracked parameter " << id
137  << " used in MessageLogger configuration.\n"
138  << "Use of tracked parameters for the message service "
139  << "is deprecated.\n"
140  << "The .cfg file should be modified to make this untracked.\n";
141  }
142  return t;
143  }
144 #else
145 #ifdef SIMPLESTYLE
146  template <class T>
147  T getAparameter ( PSet const& p, std::string const & id, T const & def )
148  {
149  T t;
150  t = p.template getUntrackedParameter<T>(id, def);
151  return t;
152  } // changelog 2
153 #else
154 #ifdef VALIDATE_ELSEWHERE
155  template <class T> // ChangeLog 11
156  T getAparameter ( PSet const& p, std::string const & id, T const & def )
157  {
158  T t = def;
159  try {
160  t = p.template getUntrackedParameter<T>(id, def);
161  } catch (...) {
162  try {
163  t = p.template getParameter<T>(id);
164  } catch (...) {
165  // Since PSetValidation will catch such errors, we simply proceed as
166  // best we can in case we are setting up the logger just to contain the
167  // validation-caught error messages.
168  }
169  }
170  return t;
171  }
172 #else // Do not tolerate errors
173  template <class T>
174  T getAparameter ( PSet const& p, std::string const & id, T const & def )
175  { // changelog 7
176  T t;
177  try {
178  t = p.template getUntrackedParameter<T>(id, def);
179  } catch (cms::Exception& e) {
180  try {
181  t = p.template getParameter<T>(id);
182  } catch (...) {
183  // if we get here, this was NOT a simple tracked parameter goof.
184  // we should just rethrow the ORIGINAL error
185  e.raise();
186  }
187  std::cerr << "Tracked parameter " << id
188  << " used in MessageLogger configuration.\n"
189  << "Use of tracked parameters for the message service "
190  << "is not allowed.\n"
191  << "The .cfg file should be modified to make this untracked.\n";
192  e.raise();
193  } catch (...) {
194  // This is not the usual tracked/untracked error; we can't add useful info
195  throw;
196  }
197  return t;
198  }
199 
200 #endif // VALIDATE_ELSEWHERE
201 #endif // SIMPLESTYLE
202 #endif // OLD_STYLE and the else Do not tolerate errors
203 
204 #ifdef REMOVE
205  template <class T>
206  T getCategoryDefault ( PSet * p,
207  std::string const & id,
208  std::string const & def )
209  {
210  T t;
211  t = p->template getUntrackedParameter<T>(id, def);
212  return t;
213  }
214 #endif
215 
216 
217  // --- other helpers
218  void parseCategories (std::string const & s, std::vector<std::string> & cats);
219 
220  // --- data:
223  std::vector<edm::propagate_const<std::shared_ptr<std::ofstream>>> file_ps;
225  std::vector<NamedDestination *> extern_dests;
226  std::map<String,edm::propagate_const<std::ostream*>> stream_ps;
227  std::vector<String> ordinary_destination_filenames;
228  std::vector<ELdestControl> statisticsDestControls;
229  std::vector<bool> statisticsResets;
232  bool active;
233  bool singleThread; // changeLog 9
234  bool done; // changeLog 9
235  bool purge_mode; // changeLog 9
236  int count; // changeLog 9
238 
239 }; // MessageLoggerScribe
240 
241 
242 } // end of namespace service
243 } // namespace edm
244 
245 
246 #endif // FWCore_MessageService_MessageLoggerScribe_h
std::map< String, edm::propagate_const< std::ostream * > > stream_ps
virtual void runCommand(MessageLoggerQ::OpCode opcode, void *operand)
void raise()
Definition: Exception.h:105
std::vector< String > ordinary_destination_filenames
edm::propagate_const< std::shared_ptr< ELadministrator > > admin_p
std::vector< NamedDestination * > extern_dests
std::vector< edm::propagate_const< std::shared_ptr< std::ofstream > > > file_ps
void configure_dest(ELdestControl &dest_ctrl, String const &filename)
void parseCategories(std::string const &s, std::vector< std::string > &cats)
edm::propagate_const< std::shared_ptr< PSet > > job_pset_p
std::vector< ELdestControl > statisticsDestControls
MessageLoggerScribe(std::shared_ptr< ThreadQueue > queue)
— If queue is NULL, this sets singleThread true
void triggerFJRmessageSummary(std::map< std::string, double > &sm)
tuple filename
Definition: lut2db_cfg.py:20
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