GSI Object Oriented Online Offline (Go4) GO4-6.4.5
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 fSelect.Clear("nodelete");
48 fMsgs.Clear();
49}
50
51void TGo4MsgList::AddMsg(const char *msg)
52{
53 // add message to the list
54 // if number of stored messages bigger than configured, old messages will be removed
55 // zero (msg == nullptr) message will not be add to the list
56
57 while (fMsgs.GetSize() >= GetLimit()) {
58 TObject *last = fMsgs.Last();
59 fMsgs.RemoveLast();
60 delete last;
61 }
62 if (!msg)
63 return;
64
65 fMsgs.AddFirst(new TObjString(msg));
66 fCounter++;
67}
68
69TList *TGo4MsgList::Select(Int_t max, Long64_t id)
70{
71 TIter iter(&fMsgs);
72 TObject *obj = nullptr;
73 Long64_t curr = fCounter;
74 fSelect.Clear("nodelete");
75
76 if (max <= 0)
77 max = fMsgs.GetSize() + 1;
78
79 // add current id as first string in the list
80 fStrCounter.SetString(TString::LLtoa(fCounter, 10));
81
82 fSelect.Add(&fStrCounter);
83 while (((obj = iter()) != nullptr) && (--curr >= id) && (--max >= 0))
84 fSelect.Add(obj);
85
86 return &fSelect;
87}
88
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