CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ELrecv.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // ELrecv.cc This is the global method which the server-side program calls
4 // when it receives a message which originated from ELsend on the
5 // client process.
6 //
7 // This file defines ELrecv() and its pet context supplier ELservConSup class.
8 //
9 // ----------------------------------------------------------------------
10 
11 
16 
17 #ifndef CSTRING_INCLUDED
18  #include <cstring>
19 #endif
20 
21 
22 namespace edm {
23 namespace service {
24 
26 
27 public:
28  ELstring context() const { return con_; }
29  ELstring summaryContext() const { return sumcon_; }
30  ELstring fullContext() const { return fullcon_; }
31  void setContext ( const ELstring & s ) { con_ = s; }
32  void setSummaryContext ( const ELstring & s ) { sumcon_ = s; }
33  void setFullContext ( const ELstring & s ) { fullcon_ = s; }
34  ELservConSup * clone() const { return new ELservConSup ( *this ); }
35 private:
39 
40 };
41 
42 void ELrecv ( int nbytes, const char * data ) {
43  ELrecv ( nbytes, data, "*ELrecv*" );
44 }
45 
46 
47 void ELrecv ( int nbytes, const char * data, ELstring localModule ) {
48 
49  static const int MAXITEMCOUNT = 100;
50 
51  static ErrorLog errlog;
52  static ELservConSup con;
54 
55  // Pull out the extended id. Carefully look at ELcollected::emitXid to
56  // make certain we take things out in the proper order.
57 
60  ELstring subroutine;
61  ELstring id;
62  ELstring sevString;
63  int sevLevel;
64 
65  const char * nextItem = data;
66 
67  process = nextItem;
68  nextItem += strlen(nextItem) + 1;
69 
70  if (localModule == "*ELrecv*") module = nextItem;
71  else module = localModule + ":" + nextItem;
72  nextItem += strlen(nextItem) + 1;
73 
74  subroutine = nextItem;
75  nextItem += strlen(nextItem) + 1;
76 
77  id = nextItem;
78  nextItem += strlen(nextItem) + 1;
79 
80  sevString = nextItem;
81  nextItem += strlen(nextItem) + 1;
82  std::istringstream ist (sevString);
83  if ( ! (ist >> sevLevel) ) {
84  // This should not be possible. But if it does, we don't want to
85  // kill off the probably critical error monitoring job!
86  errlog ( ELerror2, "Collection Error" ) <<
87  "An error message received has an unreadable value of severity level"
88  << sevString << endmsg;
90  }
91  if ( sevLevel < ELseverityLevel::ELsev_zeroSeverity ||
93  // Again, this should not be possible.
94  errlog ( ELerror2, "Collection Error" ) <<
95  "An error message received has an out-of-range value of severity level"
96  << sevString << endmsg;
98  }
99 
100  // Pull out the context strings and set up the special supplier.
101 
102  ELstring context;
103 
104  context = nextItem;
105  nextItem += strlen(nextItem) + 1;
106  con.setSummaryContext( context );
107 
108  context = nextItem;
109  nextItem += strlen(nextItem) + 1;
110  con.setContext( context );
111 
112  context = nextItem;
113  nextItem += strlen(nextItem) + 1;
114  con.setFullContext( context );
115 
116  // Remember the context supplier, and substitute the special supplier.
117 
118  ELcontextSupplier & oldCS = logger->swapContextSupplier(con);
119 
120  // Set the module, subroutine, and process according to this xid.
121 
122  ELstring oldProcess = logger->swapProcess(process);
123  errlog.setModule (module);
124  errlog.setSubroutine(subroutine);
125 
126  // Instantiate a message with the appropriate severity level and id.
127 
128  errlog ( ELseverityLevel( ELseverityLevel::ELsev_(sevLevel)), id );
129 
130  // Add the remaining items to this message.
131  // To avoid any possibility of a completely runaway message, we limit
132  // the number of items output to 100 by doing a for instead of a while
133  // loop.
134 
135  ELstring item;
136  int itemCount;
137  for ( itemCount = 0; itemCount < MAXITEMCOUNT; itemCount++ ) {
138  if (*nextItem == 0) break;
139  item = nextItem;
140  nextItem += strlen(nextItem) + 1;
141  errlog << item;
142  }
143 
144  // If the direct ELrecv form was used, end the message,
145  // thus causing the logging. If the errlog (nbytes, data) form was
146  // used, the user will supply the endmsg.
147 
148  if ( localModule == "*ELrecv*" ) {
149  errlog << endmsg;
150  }
151 
152  if ( *nextItem++ != 0 ) {
153  errlog << endmsg;
154  errlog ( ELerror2, "Collection Error" ) <<
155  "Apparent runaway error message on the previous message!" <<
156  "Truncated after " << MAXITEMCOUNT << "items." << endmsg;
157  }
158  int diff = nextItem - data;
159  if ( diff != nbytes ) {
160  errlog << endmsg;
161  errlog ( ELerror2, "Collection Error" ) <<
162  "Apparent corrupted transmission of error message"
163  << "on the previous message!"
164  << "Total length was" << diff << "nbytes transmitted was" << nbytes
165  << endmsg;
166  }
167 
168  // End the message, before we swap back the context and process.
169  // (This is what makes the endmsg in errlog(nbytes, data) << endmsg
170  // superfluous.)
171 
172  errlog << endmsg;
173 
174  // Reset the context supplier and process to the remembered value.
175 
176  logger->swapContextSupplier(oldCS);
177  logger->swapProcess(oldProcess);
178 
179 } // ELrecv()
180 
181 
182 } // end of namespace service
183 } // end of namespace edm
void setModule(const ELstring &modName)
Definition: ErrorLog.cc:236
ELstring swapProcess(const ELstring &process)
ELstring fullContext() const
Definition: ELrecv.cc:30
void setFullContext(const ELstring &s)
Definition: ELrecv.cc:33
std::ostream & logger()
Definition: fwLog.cc:41
void setSummaryContext(const ELstring &s)
Definition: ELrecv.cc:32
void endmsg(ErrorLog &log)
Definition: ErrorLog.cc:357
ELcontextSupplier & swapContextSupplier(ELcontextSupplier &cs)
void setSubroutine(const ELstring &subName)
Definition: ErrorLog.cc:149
ELstring summaryContext() const
Definition: ELrecv.cc:29
ELslProxy< ELerror2Gen > const ELerror2
static ELadministrator * instance()
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void setContext(const ELstring &s)
Definition: ELrecv.cc:31
ELstring context() const
Definition: ELrecv.cc:28
void ELrecv(int nbytes, const char *data)
Definition: ELrecv.cc:42
tuple process
Definition: LaserDQM_cfg.py:3
std::string ELstring
Definition: ELstring.h:26
ELservConSup * clone() const
Definition: ELrecv.cc:34