1 | #ifndef MARS_MLog
|
---|
2 | #define MARS_MLog
|
---|
3 |
|
---|
4 | #ifndef ROOT_TObject
|
---|
5 | #include <TObject.h>
|
---|
6 | #endif
|
---|
7 |
|
---|
8 | #include <iostream.h> // base classes for MLog
|
---|
9 |
|
---|
10 | #define bsz 160 // two standard lines
|
---|
11 |
|
---|
12 | enum ELogBits {
|
---|
13 | kHasChanged = BIT(14) // if gui has changed
|
---|
14 | };
|
---|
15 |
|
---|
16 |
|
---|
17 | class TGListBox;
|
---|
18 |
|
---|
19 | class MLog : public streambuf, public ostream, public TObject
|
---|
20 | {
|
---|
21 | public:
|
---|
22 | typedef enum _flags { eStdout = 0x1, eStderr = 0x2, eFile = 0x4, eGui = 0x8 } Flags_t;
|
---|
23 |
|
---|
24 | private:
|
---|
25 | char fBuffer; //!
|
---|
26 | char fBase[bsz]; //! Buffer to store the data in
|
---|
27 | char *fPPtr; //! Pointer to present position in buffer
|
---|
28 | const char *fEPtr; //! Pointer to end of buffer
|
---|
29 |
|
---|
30 | UInt_t fOutputLevel; //! Present output level of the stream
|
---|
31 | UInt_t fDebugLevel; //! Present global debug level
|
---|
32 | UInt_t fDevice; //! Flag to indicate the present streams
|
---|
33 |
|
---|
34 | Bool_t fIsNull; //! Switch output completely off
|
---|
35 |
|
---|
36 | Int_t fGuiLineId;
|
---|
37 |
|
---|
38 | ofstream *fout; //! possible file output stream
|
---|
39 | Bool_t fOutAllocated; //! flag if fout is created by MLogging
|
---|
40 | TGListBox *fgui; //! Listbox output
|
---|
41 |
|
---|
42 | Bool_t fIsDirectGui; //! Pipe text directly to the GUI (for single threaded environments)
|
---|
43 | char **fGuiLines; //! Lines to pipe to gui
|
---|
44 | Int_t fNumLines;
|
---|
45 |
|
---|
46 | #ifdef _REENTRANT
|
---|
47 | void *fMuxGui; //! Mutex locking access of TGListBox
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | void Init();
|
---|
51 |
|
---|
52 | void WriteBuffer();
|
---|
53 | int sync();
|
---|
54 | int overflow(int i); // i=EOF means not a real overflow
|
---|
55 |
|
---|
56 | void AllocateFile(const char *f);
|
---|
57 | void DeallocateFile();
|
---|
58 | void ReallocateFile(const char *f);
|
---|
59 | void CheckFlag(Flags_t chk, int flag);
|
---|
60 |
|
---|
61 | public:
|
---|
62 | MLog(int i=eStdout);
|
---|
63 | MLog(ofstream &out);
|
---|
64 | MLog(TGListBox &out);
|
---|
65 | MLog(const char *fname, int flag=-1);
|
---|
66 |
|
---|
67 | MLog(MLog &log);
|
---|
68 | ~MLog();
|
---|
69 |
|
---|
70 | void Lock();
|
---|
71 | void UnLock();
|
---|
72 |
|
---|
73 | void EnableDirectGui() { fIsDirectGui = kTRUE; }
|
---|
74 | void DisableDirectGui() { fIsDirectGui = kFALSE; }
|
---|
75 | void UpdateGui();
|
---|
76 |
|
---|
77 | void SetDebugLevel(int i) { fDebugLevel = i; }
|
---|
78 | int GetDebugLevel() const { return fDebugLevel; }
|
---|
79 | void SetOutputLevel(int i) { fOutputLevel = i; }
|
---|
80 | void SetOutputDevice(int i) { fDevice = i; }
|
---|
81 | void EnableOutputDevice(Flags_t f) { fDevice |= f; }
|
---|
82 | void DisableOutputDevice(Flags_t f) { fDevice &= ~f; }
|
---|
83 | void operator=(ofstream &out) { SetOutputFile(out); }
|
---|
84 | void operator=(TGListBox *out) { SetOutputGui(out); }
|
---|
85 |
|
---|
86 | Bool_t IsOutputDeviceEnabled(int i) const { return fDevice & i; }
|
---|
87 |
|
---|
88 | void SetOutputGui(TGListBox *out, int flag=-1)
|
---|
89 | {
|
---|
90 | fgui = out;
|
---|
91 | CheckFlag(eGui, flag);
|
---|
92 | }
|
---|
93 |
|
---|
94 | void SetOutputFile(ofstream &out, int flag=-1)
|
---|
95 | {
|
---|
96 | //
|
---|
97 | // Set new output file by a given stream. The new output
|
---|
98 | // file is not deleted automatically. If no flag is specified
|
---|
99 | // the state of the file-device stream is unchanged.
|
---|
100 | // if the a flag is specified the state is changed
|
---|
101 | // in correspondance to the flag
|
---|
102 | //
|
---|
103 | DeallocateFile();
|
---|
104 | fout = &out;
|
---|
105 | CheckFlag(eFile, flag);
|
---|
106 | }
|
---|
107 |
|
---|
108 | void SetOutputFile(const char *f=NULL, int flag=-1)
|
---|
109 | {
|
---|
110 | //
|
---|
111 | // Set new output file by name. The new output file must
|
---|
112 | // not be deleted by the user. If no flag is specified
|
---|
113 | // the state of the file-device stream is unchanged.
|
---|
114 | // if the a flag is specified the state is changed
|
---|
115 | // in correspondance to the flag
|
---|
116 | //
|
---|
117 | ReallocateFile(f);
|
---|
118 | CheckFlag(eFile, flag);
|
---|
119 | }
|
---|
120 |
|
---|
121 | ofstream &GetOutputFile()
|
---|
122 | {
|
---|
123 | //
|
---|
124 | // Get the file output stream from MLogging
|
---|
125 | // if no file output stream is existing yet it will be created.
|
---|
126 | // For the creating a C-Temporary file name is used.
|
---|
127 | // if the stream is created here the user must not delete it
|
---|
128 | //
|
---|
129 | // What a pitty, but it seems, that there is now way to ask
|
---|
130 | // an ofstream for the corresponding file name. Elsewhise
|
---|
131 | // I would implement a GetFileName-function, too.
|
---|
132 | //
|
---|
133 | if (!fout)
|
---|
134 | ReallocateFile(NULL);
|
---|
135 | return *fout;
|
---|
136 | }
|
---|
137 |
|
---|
138 | void SetNullOutput(Bool_t n=kTRUE) { fIsNull = n; }
|
---|
139 |
|
---|
140 | ClassDef(MLog, 0) // This is what we call 'The logging system'
|
---|
141 | };
|
---|
142 |
|
---|
143 | #endif
|
---|