1    	/*!
2    	  \class StMessageManager
3    	  \author G. Van Buren, BNL
4    	
5    	  This class manages the messages in STAR software. It is a singleton.
6    	  It inherits from StMessMgr, which provides the external interface.
7    	  Messages are stored in a vector, and come in several types
8    	  (i.e. info, error, debug ). The types "I" (info), "W" (warning),
9    	  "E" (error), "D" (debug), and "Q" (QAInfo) are predefined.
10   	  Message finding and summary tools are also available.
11   	  \sa http://www.star.bnl.gov/STAR/comp/pkg/dev/StRoot/StUtilities/doc/StMessMgr.html
12   	
13   	*/
14   	
15   	#ifndef ClassStMessageManager
16   	#define ClassStMessageManager
17   	
18   	#include "StMessage.h"
19   	#include "StMessTypeList.h"
20   	#include "StMessageCounter.h"
21   	
22   	#ifndef ClassMessVec
23   	#define ClassMessVec
24   	typedef StVector(StMessage*) messVec;
25   	typedef StVector(StMessage*)::iterator messVecIter;
26   	typedef StVector(messVec*) messTypeVec;
27   	#endif
28   	
29   	#include "StMessMgr.h"
30   	
31   	class StMessageManager : public StMessMgr {
32   	
33   	 private:
34   	   static StMessMgr* mInstance;       //!
35   	   StMessTypeList* messTypeList;      //!
36   	   StMessageCounter* messCounter;     //!
37   	   char* curType;                     //!
38   	   char* curOpt;                      //!
39   	   int building;
40   	   int remember;
41   	
42   	 protected:
43   	   StMessageManager();
44   	   StMessageManager(const StMessageManager&);
45   	   messVec messList;
46   	   messTypeVec messCollection;
47   	   virtual messVecIter FindMessageIter(const char* s1, const char* s2="",
48   	         const char* s3="", const char* s4="", messVec* list=0);
49   	   virtual        void BuildMessage(const char* mess="", const char* type="",
50   	         const char* opt=0);
51   	   virtual void IgnoreRepeats() { StMessage::IgnoreRepeats(); }
52   	   virtual void AllowRepeats() { StMessage::AllowRepeats(); }
53   	
54   	
55   	 public:
56   	   virtual ~StMessageManager();
57   	   static StMessMgr* Instance();      //!
58   	
59   	   virtual std::ostream& OperatorShift(std::ostream& os, StMessage* stm);
60   	
61   	// Generic Messages:
62   	   virtual ostrstream& Message(const char* mess="", const char* type="",
63   	         const char* opt=0,const char *sourceFileName=0, int lineNumber=-1);
64   	   virtual       void Print();
65   	   virtual        int PrintList(messVec* list);
66   	   virtual        int PrintAll() {return PrintList(&messList); }
67   	   virtual const messVec* GetAll() {return (&messList);}
68   	   virtual StMessage* FindMessage(const char* s1, const char* s2="",
69   	         const char* s3="", const char* s4="", messVec* list=0);
70   	   virtual   messVec* FindMessageList(const char* s1, const char* s2="",
71   	         const char* s3="", const char* s4="", messVec* list=0);
72   	   virtual        int RemoveMessage(StMessage* mess);
73   	   virtual        int RemoveMessage(const char* s1, const char* s2="",
74   	         const char* s3="", const char* s4="")
75   	         {return RemoveMessage(FindMessage(s1,s2,s3,s4));}
76   	   virtual       void SetLimit(const char* str, int n=0)
77   	         {messCounter->SetLimit(str,n);}
78   	   virtual        int GetLimit(const char* str)
79   	         {return messCounter->GetLimit(str);}
80   	   virtual       void ListLimits() {messCounter->ListLimits();}
81   	   virtual       void RemoveLimit(const char* str) {SetLimit(str,-1);}
82   	   virtual       void SetLevel(Int_t logLevel);
83   	   virtual      Int_t GetLevel(Int_t logLevel) const;
84   	   virtual const char *GetName() const;
85   	   virtual       void SwitchOff(const char* str) {SetLimit(str,0);}
86   	   virtual       void SwitchOn(const char* str) {RemoveLimit(str);}
87   	   virtual       void FixOn(const char* str) {SetLimit(str,-5);}
88   	   virtual       void NoLimits() {messCounter->NoLimits();}
89   	   virtual       void Summary(size_t nTerms=1);
90   	   virtual       void MemorySummary();
91   	   virtual       void MemoryOn() {remember=1;}
92   	   virtual       void MemoryOff() {remember=0;}
93   	   virtual        int AddType(const char* type, const char* text);
94   	   virtual        int ListTypes() {return messTypeList->ListTypes();}
95   	
96   	// Info Messages:
97   	   virtual ostrstream& Info(const char* mess="", const char* opt="O",const char *sourceFileName=0, int lineNumber=-1)
98   	         { return Message(mess, "I", opt);}
99   	   virtual        int PrintInfos() {return PrintList(messCollection[1]); }
100  	   virtual const messVec* GetInfos() {return (messCollection[1]);}
101  	   virtual StMessage* FindInfo(const char* s1, const char* s2="",
102  	         const char* s3="", const char* s4="")
103  		 {return FindMessage(s1,s2,s3,s4,messCollection[1]);}
104  	   virtual messVec* FindInfoList(const char* s1, const char* s2="",
105  	         const char* s3="", const char* s4="")
106  		 {return FindMessageList(s1,s2,s3,s4,messCollection[1]);}
107  	
108  	// Warning Messages:
109  	   virtual ostrstream& Warning(const char* mess="", const char* opt="E",const char *sourceFileName=0, int lineNumber=-1)
110  	         { return Message(mess, "W", opt,sourceFileName,lineNumber);}
111  	   virtual        int PrintWarnings() {return PrintList(messCollection[2]); }
112  	   virtual const messVec* GetWarnings() {return (messCollection[2]);}
113  	   virtual StMessage* FindWarning(const char* s1, const char* s2="",
114  	         const char* s3="", const char* s4="")
115  		 {return FindMessage(s1,s2,s3,s4,messCollection[2]);}
116  	   virtual messVec* FindWarningList(const char* s1, const char* s2="",
117  	         const char* s3="", const char* s4="")
118  		 {return FindMessageList(s1,s2,s3,s4,messCollection[2]);}
119  	
120  	// Error Messages:
121  	   virtual ostrstream& Error(const char* mess="", const char* opt="E",const char *sourceFileName=0, int lineNumber=-1)
122  	         { return Message(mess, "E", opt,sourceFileName,lineNumber);}
123  	   virtual        int PrintErrors() {return PrintList(messCollection[3]); }
124  	   virtual const messVec* GetErrors() {return (messCollection[3]);}
125  	   virtual StMessage* FindError(const char* s1, const char* s2="",
126  	         const char* s3="", const char* s4="")
127  		 {return FindMessage(s1,s2,s3,s4,messCollection[3]);}
128  	   virtual messVec* FindErrorList(const char* s1, const char* s2="",
129  	         const char* s3="", const char* s4="")
130  		 {return FindMessageList(s1,s2,s3,s4,messCollection[3]);}
131  	
132  	// Debug Messages:
133  	   virtual ostrstream& Debug(const char* mess="", const char* opt="OT",const char *sourceFileName=0, int lineNumber=-1)
134  	         { return Message(mess, "D", opt,sourceFileName,lineNumber);}
135  	   virtual        int PrintDebug() {return PrintList(messCollection[4]); }
136  	   virtual const messVec* GetDebugs() {return (messCollection[4]);}
137  	   virtual StMessage* FindDebug(const char* s1, const char* s2="",
138  	         const char* s3="", const char* s4="")
139  		 {return FindMessage(s1,s2,s3,s4,messCollection[4]);}
140  	   virtual messVec* FindDebugList(const char* s1, const char* s2="",
141  	         const char* s3="", const char* s4="")
142  		 {return FindMessageList(s1,s2,s3,s4,messCollection[4]);}
143  	
144  	// QAInfo Messages:
145  	   virtual ostrstream& QAInfo(const char* mess="", const char* opt="OS",const char *sourceFileName=0, int lineNumber=-1)
146  	         { return Message(mess, "Q", opt,sourceFileName,lineNumber);}
147  	   virtual        int PrintQAInfo() {return PrintList(messCollection[5]); }
148  	   virtual const messVec* GetQAInfos() {return (messCollection[5]);}
149  	   virtual StMessage* FindQAInfo(const char* s1, const char* s2="",
150  	         const char* s3="", const char* s4="")
151  		 {return FindMessage(s1,s2,s3,s4,messCollection[5]);}
152  	   virtual messVec* FindQAInfoList(const char* s1, const char* s2="",
153  	         const char* s3="", const char* s4="")
154  		 {return FindMessageList(s1,s2,s3,s4,messCollection[5]);}
155  	
156  	// UCMInfo Messages:
157  	   virtual ostrstream& UCMInfo(const char* mess="", const char* opt="OS",const char *sourceFileName=0, int lineNumber=-1)
158  	         { return Message(mess, "U", opt,sourceFileName,lineNumber);}
159  	   virtual        int PrintUCMInfo() {return PrintList(messCollection[6]); }
160  	   virtual const messVec* GetUCMInfos() {return (messCollection[6]);}
161  	   virtual StMessage* FindUCMInfo(const char* s1, const char* s2="",
162  	         const char* s3="", const char* s4="")
163  		 {return FindMessage(s1,s2,s3,s4,messCollection[6]);}
164  	   virtual messVec* FindUCMInfoList(const char* s1, const char* s2="",
165  	         const char* s3="", const char* s4="")
166  		 {return FindMessageList(s1,s2,s3,s4,messCollection[6]);}
167  	
168  	// "As is" Messages:
169  	   virtual ostrstream& out(const char* mess="")
170  		 {return Message(mess,"I","OP-");}
171  	   virtual ostrstream& err(const char* mess="")
172  		 {return Message(mess,"E","EP-");}
173  	
174  	   virtual       void PrintInfo();
175  	// Fatal Messages:
176  	   virtual ostrstream& Fatal(const char* mess="", const char* opt="E",const char *sourceFileName=0, int lineNumber=-1)
177  	   { return Message(mess, "E", opt,sourceFileName,lineNumber);}
178  	
179  	};
180  	
181  	
182  	#endif
183  	
184  	// $Id: StMessageManager.h,v 1.29 2009/06/22 22:36:01 fine Exp $
185  	// $Log: StMessageManager.h,v $
186  	// Revision 1.29  2009/06/22 22:36:01  fine
187  	// Add the new dedicated UCM logger, It should force the recompilation of many STAR packages
188  	//
189  	// Revision 1.28  2008/05/15 23:40:24  fine
190  	// Change the abstarct class return type to separate the different STAR streams
191  	//
192  	// Revision 1.27  2007/01/25 06:28:06  fine
193  	// connect Logger and Maker debug levels
194  	//
195  	// Revision 1.26  2007/01/25 06:11:37  fine
196  	// Add the new StMess abstarct interfaces GetLevel/SetLevel
197  	//
198  	// Revision 1.25  2004/04/15 21:28:02  fine
199  	// Remove the redundant StMessageManager RootCint dictionary. User shoudl use the base StMessMgr class anyway
200  	//
201  	// Revision 1.24  2004/04/15 16:03:38  fine
202  	// move StMessMgr class to St_base and change the interface
203  	//
204  	// Revision 1.22  2004/01/28 00:09:14  genevb
205  	// Messages (except Debug) default to no time-date stamp
206  	//
207  	// Revision 1.21  2003/09/25 21:19:22  genevb
208  	// Some new cout-like functions and friend functions, some doxygen-ization
209  	//
210  	// Revision 1.20  2001/05/14 20:53:20  genevb
211  	// Add features to examine memory use, switch from TDatime to time_t
212  	//
213  	// Revision 1.19  2000/06/07 00:05:36  genevb
214  	// Added FixOn(), enforcing no limits on a specific message type/string
215  	//
216  	// Revision 1.18  2000/05/23 19:03:38  genevb
217  	// Correct interface for MessageOut(), update docs
218  	//
219  	// Revision 1.17  2000/03/30 16:12:55  genevb
220  	// Add NoLimits() capability to turn off message limiting.
221  	//
222  	// Revision 1.16  2000/02/29 16:41:57  genevb
223  	// Fortran-compliant interface
224  	//
225  	// Revision 1.15  2000/01/25 16:01:29  fisyak
226  	// Devorce with StAF
227  	//
228  	// Revision 1.14  2000/01/05 19:53:46  genevb
229  	// Fixed CC5 warnings, and several other small improvements under the hood
230  	//
231  	// Revision 1.13  1999/08/10 22:07:35  genevb
232  	// Added QAInfo message types
233  	//
234  	// Revision 1.12  1999/07/23 16:56:40  genevb
235  	// Fix extern C prototypes, default options for omitted types, Linux bug with multi-line messages
236  	//
237  	// Revision 1.11  1999/07/17 00:23:24  genevb
238  	// Fixed bug when option fields are empty in FORTRAN, and let type limits be set before types are even added
239  	//
240  	// Revision 1.10  1999/07/08 22:58:18  genevb
241  	// Created an abstract interface with StMessMgr.h hiding template implementation from others, a few other small fixes
242  	//
243  	// Revision 1.9  1999/07/01 23:32:53  genevb
244  	// Change default message typing
245  	//
246  	// Revision 1.8  1999/07/01 01:24:46  genevb
247  	// Fixed FORTRAN character string bug on linux, removed a memory leak from Summary()
248  	//
249  	// Revision 1.7  1999/06/29 23:32:42  genevb
250  	// Handle multi-line calls to fortran routines better
251  	//
252  	// Revision 1.5  1999/06/28 15:42:13  genevb
253  	// Added Debug message class
254  	//
255  	// Revision 1.4  1999/06/28 02:40:56  genevb
256  	// Additional backward compatibilit with MSG (msg_enable, msg_enabled, msg_disable
257  	//
258  	// Revision 1.3  1999/06/24 23:23:59  genevb
259  	// Added message call for compatibility with old fortran code
260  	//
261  	// Revision 1.2  1999/06/24 16:30:43  genevb
262  	// Fixed some memory leaks
263  	//
264  	// Revision 1.1  1999/06/23 15:17:53  genevb
265  	// Introduction of StMessageManager
266  	//
267  	//
268