GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4MsgList.cxx
Go to the documentation of this file.
1// $Id$
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 fuer 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(),
25{
26}
27
28TGo4MsgList::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(),
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
50void 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 == nullptr) 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) return;
62
63 fMsgs.AddFirst(new TObjString(msg));
64 fCounter++;
65}
66
67TList *TGo4MsgList::Select(Int_t max, Long64_t id)
68{
69 TIter iter(&fMsgs);
70 TObject *obj = nullptr;
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()) != nullptr) && (--curr >= id) && (--max >= 0))
81 fSelect.Add(obj);
82
83 return &fSelect;
84}
85
TGo4MsgList()
current id stored in the string
TList fSelect
Definition TGo4MsgList.h:28
TList * Select(Int_t max=0, Long64_t id=0)
void AddMsg(const char *msg)
Long64_t fCounter
Definition TGo4MsgList.h:27
virtual ~TGo4MsgList()
Int_t GetLimit() const
Definition TGo4MsgList.h:42
TObjString fStrCounter
temporary list used for selection
Definition TGo4MsgList.h:29