20 #include "StMessageManager.h"
21 #include "StMessageStream.h"
29 std::ostream& StMessageManager::OperatorShift(std::ostream& os,
StMessage* stm)
31 if (((&os) == (ostream*) gMessMgr) && (stm == endm)) {
34 if (stm) os << stm->GetMessage();
39 static const char defaultMessType =
'I';
40 static char emptyString[] =
"";
41 static char oOpt [] =
"O";
43 static char eOpt [] =
"E";
46 static int sMessLength;
47 static const int maxLOMP = 65536;
48 static const int maxLOMP1 = (maxLOMP-1);
49 static int lastLOMP = 0;
50 static char* listOfMessPtrs[maxLOMP];
51 static size_t listOfMessLens[maxLOMP];
54 StMessMgr* StMessageManager::mInstance = 0;
59 StMessageManager::StMessageManager() :
StMessMgr()
68 curType =
new char[ 2]; curType[0] = 0; curType[1] = 0;
69 curOpt =
new char[32]; curOpt [0] = 0;
73 messTypeList = StMessTypeList::Instance();
74 messCounter = StMessageCounter::Instance();
75 messCounter->AddType(emptyString);
77 messCollection.push_back(&messList);
79 AddType(
"W",
"Warning");
82 AddType(
"Q",
"QAInfo");
83 AddType(
"U",
"UCMInfo");
86 memset(listOfMessPtrs,0,(maxLOMP *
sizeof(
char*)));
90 StMessageManager::~StMessageManager() {
95 for (current=messList.begin(); current!=messList.end(); current++)
97 for (
size_t i=1; i<messCollection.size(); i++)
98 delete (messCollection[i]);
99 myout <<
"WARNING!!! DELETING StMessageManager!" << endl;
103 StMessMgr* StMessageManager::Instance() {
108 if (gMessMgr)
return gMessMgr;
115 std::ostringstream& StMessageManager::Message(
const char* mess,
const char* type,
116 const char* opt,
const char *,
int) {
122 size_t messSize = strlen(mess);
125 if (sMessLength == 1) {
126 for (
int i=lastLOMP; i>=0; i--) {
127 if (mess == listOfMessPtrs[i]) {
128 (listOfMessPtrs[i])[(listOfMessLens[i]-1)]=0;
133 if (lastLOMP==maxLOMP1) {
134 BuildMessage(
"StMessageManager - maximum depth reached on ptr list",
138 listOfMessPtrs[lastLOMP] =
const_cast<char*
> (mess);
139 listOfMessLens[lastLOMP] = messSize;
145 BuildMessage(mess, type, opt);
155 void StMessageManager::BuildMessage(
const char* mess,
const char* type,
162 static char dash =
'-';
163 const char* cptr = strchr(mess,dash);
165 *curType = *(++cptr);
167 *curType = defaultMessType;
169 if (!building) *curType = *type;
172 if ((*type ==
'E') || (*type ==
'W'))
177 if (!building) strcpy(curOpt,opt);
178 int typeN = messTypeList->FindTypeNum(curType);
180 *curType = defaultMessType;
183 if ((!remember) || strchr(curOpt,
'-')) {
187 gMessage =
new StMessage(mess, curType, curOpt);
188 #ifndef i386_redhat60
189 messList.push_back(gMessage);
190 messCollection[typeN]->push_back(gMessage);
196 void StMessageManager::Print() {
204 BuildMessage(str().c_str(), curType, curOpt);
212 myout <<
"No current message." << endl;
217 int StMessageManager::PrintList(messVec* list) {
223 for (current=list->begin(); current!=list->end(); current++)
224 {(*current)->Print(-1); i++;}
228 messVecIter StMessageManager::FindMessageIter(
const char* s1,
const char* s2,
229 const char* s3,
const char* s4, messVec* list) {
234 if (!list) list = &messList;
237 for (current=list->begin(); current!=list->end(); current++) {
238 curMess = (*current)->GetMessage();
239 if ((strstr(curMess,s1)) && (strstr(curMess,s2)) &&
240 (strstr(curMess,s3)) && (strstr(curMess,s4)))
return current;
245 StMessage* StMessageManager::FindMessage(
const char* s1,
const char* s2,
246 const char* s3,
const char* s4, messVec* list) {
251 messVecIter current = FindMessageIter(s1,s2,s3,s4,list);
252 return (current!=list->end()) ? (*current) : 0 ;
255 messVec* StMessageManager::FindMessageList(
const char* s1,
const char* s2,
256 const char* s3,
const char* s4, messVec* list) {
261 size_t s1_len = strlen(s1);
262 if ((s1_len==1) && (!list)) {
263 int typeN = messTypeList->FindTypeNum(s1);
265 list = messCollection[typeN];
269 if (!list) list = &messList;
270 if (!((s1_len) || (strlen(s2)) || (strlen(s3)) || (strlen(s4))))
272 messVec* newList =
new messVec();
275 for (current=list->begin(); current!=list->end(); current++) {
276 curMess = (*current)->GetMessage();
277 if ((strstr(curMess,s1)) && (strstr(curMess,s2)) &&
278 (strstr(curMess,s3)) && (strstr(curMess,s4)))
279 newList->push_back(*current);
284 int StMessageManager::RemoveMessage(
StMessage* mess) {
289 const char* curMess = mess->GetMessage();
290 messVecIter current = FindMessageIter(curMess);
291 if (current==messList.end())
return 1;
292 messList.erase(current);
293 int typeN = messTypeList->FindTypeNum(mess->GetType());
294 current = FindMessageIter(curMess,emptyString,emptyString,
295 emptyString,messCollection[typeN]);
296 if (current==messCollection[typeN]->end())
return 2;
297 messCollection[typeN]->erase(current);
299 if (mess==gMessage) gMessage = 0;
303 void StMessageManager::Summary(
size_t nTerms) {
314 const size_t mmax = 81;
315 size_t max = mmax - 12;
316 size_t messmax = mmax - 1;
317 size_t nMess = messList.size();
319 typedef StVector(
char*) CharPtrVec;
321 CharPtrVec messBlocks;
322 StVector(CharPtrVec) toks;
330 for (i=0; i<nMess; i++) {
332 temp =
const_cast<char*
> (messList[i]->GetType());
333 mType.push_back(temp);
334 messBlocks.push_back(
new char[mmax]);
335 temp = strncpy(messBlocks[i],(messList[i]->GetMessage()),messmax);
336 temp = strtok(temp,
" ");
337 toks[i].push_back(temp);
338 while (temp != NULL) {
339 temp = strtok(NULL,
" ");
340 toks[i].push_back(temp);
342 for (j=toks[i].size(); j<nTerms; j++) toks[i].push_back(temp);
344 for (i=0; i<nMess; i++) {
347 for (j=(i+1); j<nMess; j++) {
348 if ((*(mType[i]))==(*(mType[j]))) {
350 for (k=0; k<nTerms; k++) {
351 if (toks[i][k] != NULL) {
352 if ((toks[j][k] == NULL) ||
353 strcmp(toks[i][k],toks[j][k])) agree = 0;
355 else if (toks[j][k] != NULL) agree = 0;
364 for (j = messList[i]->Print(max); j<max; j++) myout <<
".";
367 *
this << count << std::ends;
371 for (j=tellp(); j<6; j++) myout <<
".";
372 myout <<
" " << count << endl;
376 memset(messBlocks[i],0,mmax);
377 delete [] messBlocks[i];
383 void StMessageManager::MemorySummary() {
388 unsigned int gsize=0;
389 size_t nMess = messList.size();
390 for (
size_t i=0; i<nMess; i++) {
391 gsize += (messList[i]->GetMemoryUsage() + 2*
sizeof(messList[i]));
393 printf(
" ***** StMessageManager memory usage = %u bytes (%u kb) *****\n",
398 int StMessageManager::AddType(
const char* type,
const char* text) {
408 int typeN = messTypeList->AddType(type,text);
410 messVec* temp =
new messVec();
411 messCollection.push_back(temp);
412 messCounter->AddType(type);
417 void StMessageManager::PrintInfo() {
418 printf(
"**************************************************************\n");
419 printf(
"* $Id: StMessageManager.cxx,v 1.51 2016/06/14 06:25:45 genevb Exp $\n");
421 printf(
"**************************************************************\n");
424 void StMessageManager::SetLevel(Int_t)
426 fprintf(stderr,
"StMessageManager class provides no implementation SetLevel method\n");
429 Int_t StMessageManager::GetLevel(Int_t)
const
431 fprintf(stderr,
"StMessageManager class provides no implementation GetLevel method\n");
435 const char *StMessageManager::GetName()
const
437 fprintf(stderr,
"StMessageManager class provides no implementation GetName method\n");
444 static StMessMgr* temp=StMessageManager::Instance();