StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMessMgr.cxx
1 #include "StMessMgr.h"
2 #include <string.h>
3 
4 #ifdef __ROOT__
5 ClassImp(StMessMgr)
6 #endif
7 
8 StMessMgr* gMessMgr = 0;
9 StMessage* endm = 0;
10 StMessage* gMessage = 0;
11 
12 //______________________________________________________________________________
13 StMessMgr::StMessMgr() : std::ostringstream() {}
14 
15 // Manager factory
16 // The default version of the manager factory provide the singleton object
17 //______________________________________________________________________________
18 StMessMgr* StMessMgr::CurrentMessager() { return gMessMgr;}
19 //______________________________________________________________________________
20 StMessMgr* StMessMgr::Instance() { return (gMessMgr)?gMessMgr->Instantiate():0;}
21 //______________________________________________________________________________
22 StMessMgr* StMessMgr::Instance(const char *loggerName)
23 {return (gMessMgr)?gMessMgr->Instantiate(loggerName):0; }
24 //______________________________________________________________________________
25 StMessMgr* StMessMgr::SetCurrentMessager(StMessMgr *mgr)
26 {
27  // Set the new value for the current logger manager and return the previous one
28  StMessMgr* old = gMessMgr;
29  gMessMgr=mgr;
30  return old;
31 }
32 //______________________________________________________________________________
33 StMessMgr* StMessMgr::Instantiate() {return gMessMgr; }
34 //______________________________________________________________________________
35 StMessMgr* StMessMgr::Instantiate(const char *){return Instantiate();}
36 
37 //______________________________________________________________________________
38 bool StMessMgr::isDebugEnabled() const{ return true; }
39 //______________________________________________________________________________
40 bool StMessMgr::isWarnEnabled() const{ return true; }
41 //______________________________________________________________________________
42 bool StMessMgr::isWarningEnabled() const{ return isWarnEnabled(); }
43 //______________________________________________________________________________
44 bool StMessMgr::isErrorEnabled() const{ return true; }
45 //______________________________________________________________________________
46 bool StMessMgr::isInfoEnabled() const{ return true; }
47 //______________________________________________________________________________
48 bool StMessMgr::isFatalEnabled() const{ return true; }
49 //______________________________________________________________________________
50 bool StMessMgr::isEnabledFor() const{ return true; }
51 //______________________________________________________________________________
52 bool StMessMgr::isQAInfoEnabled() const{ return true; }
53 //______________________________________________________________________________
54 bool StMessMgr::isUCMInfoEnabled()const{ return true; }
55 
56 //
57 // C and Fortran routines:
58 //________________________________________
59 static const char defaultMessType = 'I';
60 static char emptyString[] = "";
61 static char oOpt[] = "O";
62 static char otsOpt[] = "OTS";
63 static char eOpt[] = "E";
64 static char nullMess[] = "Null message!!!";
65 #ifdef __linux__
66 static int sMessLength;
67 #endif
68 
69 void type_of_call Message_(const char* mess, int* lines, int*, size_t len) {
70  static char space = ' ';
71  static const char* messReturnChar = "\n";
72  size_t messSize = strlen(mess);
73  char* mess2=const_cast<char*> (mess);
74  int del_mess = 0;
75  if (*lines>1) {
76  char* mess1 = const_cast<char*> (mess);
77  mess2 = new char[(messSize+1)]{}; // Build a new version of the
78  // message with trailing spaces
79  for (int i=(*lines); i>0; i--) { // removed, and \n's inserted.
80  int clen = len; // Now trusting line length argument.
81  while (mess1[--clen] == space) {}
82  strncat(mess2,mess1,(++clen));
83  if (i>1) {
84  strcat(mess2,messReturnChar);
85  mess1 = &(mess1[len]);
86  }
87  }
88  strcat(mess2,emptyString);
89  del_mess = 1;
90  } else {
91 #ifdef __linux__
92  sMessLength = len;
93 #endif
94  if ((len>1) && (messSize > len)) {
95  mess2 = new char[(len+1)]{};
96  strncpy(mess2,mess,len);
97  del_mess = 1;
98  }
99  }
100  gMessMgr->Message(mess2);
101  if (del_mess) delete [] mess2;
102 }
103 //________________________________________
104 void type_of_call Msg_Enable_(const char* mess, size_t len) {
105  size_t messlen = strlen(mess);
106  if ((len>1) && (messlen > len)) {
107  char* mess2 = new char[(len+1)]{};
108  strncpy(mess2,mess,len);
109  gMessMgr->SwitchOn(mess2);
110  delete [] mess2;
111  } else {
112  gMessMgr->SwitchOn(mess);
113  }
114 }
115 //________________________________________
116 int type_of_call Msg_Enabled_(const char* mess, int*, size_t len) {
117  size_t messlen = strlen(mess);
118  int ret_val = 1;
119  if ((len>1) && (messlen > len)) {
120  char* mess2 = new char[(len+1)]{};
121  strncpy(mess2,mess,len);
122  if ((gMessMgr->GetLimit(mess2))==0) ret_val = 0;
123  delete [] mess2;
124  } else {
125  if ((gMessMgr->GetLimit(mess))==0) ret_val = 0;
126  }
127  return ret_val;
128 }
129 //________________________________________
130 void type_of_call Msg_Disable_(const char* mess, size_t len) {
131  size_t messlen = strlen(mess);
132  if ((len>1) && (messlen > len)) {
133  char* mess2 = new char[(len+1)]{};
134  strncpy(mess2,mess,len);
135  gMessMgr->SwitchOff(mess2);
136  delete [] mess2;
137  } else {
138  gMessMgr->SwitchOff(mess);
139  }
140 }
141 //________________________________________
142 void type_of_call MessageOut( const char *msg ) {
143  gMessMgr->Message(msg);
144 }
145 //________________________________________
146 void type_of_call StCaller(const char* mess, const char* typString,
147  const char* opt, size_t len) {
148 #ifdef __linux__
149  sMessLength = len;
150 #endif
151  if (mess[0]==0) {
152  gMessMgr->Message(nullMess,"E",eOpt);
153  return;
154  }
155 
156  size_t messlen = strlen(mess);
157  if ((len>1) && (messlen > len)) messlen = len;
158  char* mess2 = new char[(messlen+1)]{};
159  strncpy(mess2,mess,messlen);
160 
161  gMessMgr->Message(mess2,typString,opt);
162  delete [] mess2;
163 }
164 //________________________________________
165 void type_of_call StCallerOpt(const char* mess, const char* typString,
166  const char* opt, size_t len1, size_t len2,
167  char* optString) {
168  char* opt2=const_cast<char*> (opt);
169  int del_opt=0;
170 
171  if (len2<=0) {
172  opt2=optString;
173  } else if (strlen(opt) > len2) {
174  opt2 = new char[(len2+1)]{};
175  strncpy(opt2,opt,len2);
176  del_opt = 1;
177  }
178 
179  StCaller(mess,typString,opt2,len1);
180  if (del_opt) delete [] opt2;
181 }
182 //________________________________________
183 void type_of_call StMessage_(const char* mess, const char* type,
184  const char* opt, size_t len1,
185  size_t len2, size_t len3) {
186  char* type2=const_cast<char*> (type);
187  int del_type=0;
188 
189  if (len2<=0) {
190  type2=emptyString;
191  } else if (strlen(type) > len2) {
192  type2 = new char[(len2+1)]{};
193  strncpy(type2,type,len2);
194  del_type = 1;
195  }
196 
197  StCallerOpt(mess,type2,opt,len1,len3,oOpt);
198  if (del_type) delete [] type2;
199 }
200 //________________________________________
201 void type_of_call StInfo_(const char* mess, size_t len) {
202  StCaller(mess,"I",oOpt,len);
203 }
204 //________________________________________
205 void type_of_call StWarning_(const char* mess, size_t len) {
206  StCaller(mess,"W",eOpt,len);
207 }
208 //________________________________________
209 void type_of_call StError_(const char* mess, size_t len) {
210  StCaller(mess,"E",eOpt,len);
211 }
212 //________________________________________
213 void type_of_call StDebug_(const char* mess, size_t len) {
214  StCaller(mess,"D",oOpt,len);
215 }
216 //________________________________________
217 void type_of_call QAInfo_(const char* mess, size_t len) {
218  StCaller(mess,"Q",otsOpt,len);
219 }
220 //________________________________________
221 void type_of_call UCMInfo_(const char* mess, size_t len) {
222  StCaller(mess,"U",otsOpt,len);
223 }
224 //________________________________________
225 void type_of_call StInfoOpt_(const char* mess, const char* opt,
226  size_t len1, size_t len2) {
227  StCallerOpt(mess,"I",opt,len1,len2,oOpt);
228 }
229 //________________________________________
230 void type_of_call StWarningOpt_(const char* mess, const char* opt,
231  size_t len1, size_t len2) {
232  StCallerOpt(mess,"W",opt,len1,len2,eOpt);
233 }
234 //________________________________________
235 void type_of_call StErrorOpt_(const char* mess, const char* opt,
236  size_t len1, size_t len2) {
237  StCallerOpt(mess,"E",opt,len1,len2,eOpt);
238 }
239 //________________________________________
240 void type_of_call StDebugOpt_(const char* mess, const char* opt,
241  size_t len1, size_t len2) {
242  StCallerOpt(mess,"D",opt,len1,len2,oOpt);
243 }
244 //________________________________________
245 void type_of_call QAInfoOpt_(const char* mess, const char* opt,
246  size_t len1, size_t len2) {
247  StCallerOpt(mess,"Q",opt,len1,len2,otsOpt);
248 }
249 //________________________________________
250 void type_of_call UCMInfoOpt_(const char* mess, const char* opt,
251  size_t len1, size_t len2) {
252  StCallerOpt(mess,"U",opt,len1,len2,otsOpt);
253 }
254 //________________________________________
255 void type_of_call StMessAddType_(const char* type, const char* text,
256  size_t len1, size_t len2) {
257  if (strlen(type) > len1) (const_cast<char*> (type))[len1] = 0;
258  if (strlen(text) > len2) (const_cast<char*> (text))[len2] = 0;
259  gMessMgr->AddType(type,text);
260 }
261 
262 //_____________________________________________________________________________
263 // $Id: StMessMgr.cxx,v 1.8 2016/06/16 17:52:50 genevb Exp $