GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4MsgList.cxx
Go to the documentation of this file.
1 // $Id: TGo4MsgList.cxx 1542 2015-06-12 14:59:12Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4MsgList.h"
15 
16 #include "TDatime.h"
17 
19  TNamed(),
20  fMsgs(),
21  fLimit(0),
22  fCounter(0),
23  fSelect(),
24  fStrCounter()
25 {
26 }
27 
28 TGo4MsgList::TGo4MsgList(const char* name, const char* title, Int_t limit) :
29  TNamed(name, title),
30  fMsgs(),
31  fLimit(limit > 0 ? limit : 1),
32  fCounter(0),
33  fSelect(),
34  fStrCounter()
35 {
36  fMsgs.SetOwner(kTRUE);
37 
38  // counter initialized from current time
39  // if application restarted, id will be bigger and request from GUI will not lead to messages lost
40  // of course, if more than 1000 messages per second are generated, one could have mismatch
41 
42  fCounter = ((Long64_t) TDatime().Get()) * 1000;
43 }
44 
46 {
47  fMsgs.Clear();
48 }
49 
50 void TGo4MsgList::AddMsg(const char* msg)
51 {
52  // add message to the list
53  // if number of stored messages bigger than configured, old messages will be removed
54  // zero (msg==0) messages will not be add to the list
55 
56  while (fMsgs.GetSize() >= GetLimit()) {
57  TObject* last = fMsgs.Last();
58  fMsgs.RemoveLast();
59  delete last;
60  }
61  if (msg==0) return;
62 
63  fMsgs.AddFirst(new TObjString(msg));
64  fCounter++;
65 }
66 
67 TList* TGo4MsgList::Select(Int_t max, Long64_t id)
68 {
69  TIter iter(&fMsgs);
70  TObject* obj = 0;
71  Long64_t curr = fCounter;
72  fSelect.Clear();
73 
74  if (max<=0) max = fMsgs.GetSize() + 1;
75 
76  // add current id as first string in the list
77  fStrCounter.SetString(TString::LLtoa(fCounter, 10));
78 
79  fSelect.Add(&fStrCounter);
80  while (((obj = iter()) != 0) && (--curr >= id) && (--max >= 0))
81  fSelect.Add(obj);
82 
83  return &fSelect;
84 }
85 
TList fSelect
Definition: TGo4MsgList.h:28
TList fMsgs
Definition: TGo4MsgList.h:25
TObjString fStrCounter
temporary list used for selection
Definition: TGo4MsgList.h:29
TList * Select(Int_t max=0, Long64_t id=0)
Definition: TGo4MsgList.cxx:67
TGo4MsgList()
current id stored in the string
Definition: TGo4MsgList.cxx:18
Int_t GetLimit() const
Definition: TGo4MsgList.h:38
void AddMsg(const char *msg)
Definition: TGo4MsgList.cxx:50
virtual ~TGo4MsgList()
Definition: TGo4MsgList.cxx:45
string msg
Definition: go4init.py:11
Long64_t fCounter
Definition: TGo4MsgList.h:27