Message handling in/with ROOT

From: Thomas Hadig (hadig@toots.physik.rwth-aachen.de)
Date: Thu Jan 27 2000 - 11:52:46 MET


Dear Rooters,

I learned from Rene, that several users/collaborations are thinking
about a "global" ROOT messaging system. I have come up with a simple
idea and would like know your opinion.

I admit that the classes I use will not match the current definition.

A message will go through TROOT to the message handler. The message
handler will be set with
  TROOT->SetMessageHandler(TMessageHandler *)
If the Message handler is not set (or set to 0), a "standard" message 
should be written to cout.

There will be two kinds of messages:
 - "one-time" messages and
 - message that will appear more often.
and several levels of messages
 - Debug messages
 - Informational messages
 - Warning messages
 - Error messages
 - Fatal messages
 -... (startup messages, etc....)

The message level can be an enumeration TMessageLevel

In the first case, the message will be send to TROOT with
  TROOT->SendMessage(Char_t *, TMessageLevel)
and will be given to the message handler.

In the latter case it should be possible to "register" the message with
the handler. 
  Int_t handler->Register(Char_t *, TMessageLevel)
The handler then stores the message string and returns a 
(unique) message number a. The message will then be called with
  TROOT->SendMessage(Int_t a)
or
  TROOT->SendMessage(Int_t a, Char_t *)
where the longer version allows to make additional "output".

The message handler can do with these messages, what he likes to do.
A simple handler might only print the message. A more complex one
will also count how often a register message occures and will be able
to print a statistics at the end. Also a message handler might be
able to suppress messages below a certain level or a set of levels.

Examples:

ofstream *errout = new ofstream("outputfile");
TMessageHandler *h = new TMessageHandler (errout);
int e1 = h->Register("Negative cluster energy", kMessageWarning);
int e2 = h->Register("Cell number out of range : ", kMessageError);
h->Suppress(kMessageDebug);
TROOT->SetMessageHandler(h);

...
TROOT->SendMessage("Entering cluster routine",kMessageDebug);
    { will print nothing, because kMessageDebug messages are suppressed }
...
TROOT->SendMessage(e1);
    { will print : Error: Negative cluster energy }
...
char buffer[200]; sprintf (buffer,"%d",num);
TROOT->SendMessage(e2,buffer);
    { will print : Error: Cell number out of range : 100 }
...
h->PrintStatistics();
    { will print : #of occurences Error
                   10   Negative cluster energy
                   2    Cell number out of range : }

Of course this is only a first idea and the interface for the message
handler should be defined for thorougly.

Ciao
Thomas

----------------------------------------------------------------------------
Thomas Hadig, Ottensen, Donnerstr. 20, 22763 Hamburg       (+49 40 39901186)
     office : I. Phys. Institut AAC, Room 1c354, Notkestr. 85, 22607 Hamburg
           hadig@rwth-aachen.de                        Tel. +49 40 8998 2312
http://www-h1.desy.de/~hadig/                          FAX  +49 40 8998 4385
----------------------------------------------------------------------------
  The way to get rich with Object Orientied Programming  ---  Inheritance
----------------------------------------------------------------------------



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:17 MET