GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4SimpleEvent.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 "TGo4SimpleEvent.h"
15
16#include "Go4EventServer.h"
17
18#include "TGo4Log.h"
20#include "TGo4SimpleSubEvent.h"
21
24{
25 GO4TRACE((12,"TGo4SimpleEvent::TGo4SimpleEvent()",__LINE__, __FILE__));
26
27 fiMaxSlot = 5;
28 fxSubEventArray = new TClonesArray("TGo4SimpleSubEvent", fiMaxSlot);
29 fxIterator = fxSubEventArray->MakeIterator();
30}
31
32
35{
36 GO4TRACE((12,"TGo4SimpleEvent::TGo4SimpleEvent(Int_t)",__LINE__, __FILE__));
37
38 fiMaxSlot = subevtnum;
39 fxSubEventArray = new TClonesArray("TGo4SimpleSubEvent", fiMaxSlot);
40 fxIterator = fxSubEventArray->MakeIterator();
41 // start test section
42 fiArrLen = 10;
43 for (Int_t z = 0; z < 10; ++z) {
44 fiTestArray[z] = z * 5;
45 }
46 // end test section
47
48 for (Int_t t = 0; t < subevtnum; ++t) {
49 new ((*fxSubEventArray)[t]) TGo4SimpleSubEvent();
50 }
51}
52
54{
55 GO4TRACE((12,"TGo4SimpleEvent::~TGo4SimpleEvent()",__LINE__, __FILE__));
56 delete fxIterator;
57 fxSubEventArray->Delete();
58 delete fxSubEventArray;
59}
60
61
63{
64 GO4TRACE((11,"TGo4SimpleEvent::PrintEvent()",__LINE__, __FILE__));
65
67 TGo4Log::Debug( " Simple Event Header printout: ");
68 TGo4Log::Debug( "\tCount: %d ", GetCount() );
69
71 while (auto sub = NextSubEvent())
72 sub->PrintEvent();
73}
74
75void TGo4SimpleEvent::Clear(Option_t *)
76{
77 GO4TRACE((11,"TGo4SimpleEvent::Clear()",__LINE__, __FILE__));
78 // here iterate all subevents and clear them
79 // too slow!!
80 // ResetIterator();
81 // while (auto sub = NextSubEvent())
82 // {
83 // sub->Clear();
84 // }
85 for (Int_t i = 0; i < fiMaxSlot; ++i) {
86 auto sub = dynamic_cast<TGo4SimpleSubEvent *>(fxSubEventArray->UncheckedAt(i));
87 sub->Clear();
88 }
89 fiCount = 0;
90}
91
92
94{
95 GO4TRACE((11,"TGo4SimpleEvent::Fill()",__LINE__, __FILE__));
96 //
97 // check for different source types
98 Int_t rev = -1;
99
100 if(CheckEventSource("TGo4SimpleEventProcessor")) {
102 if (proc->BuildSimpleEvent(this))
103 rev = 0;
104 else
105 rev = 1;
106 } else if(CheckEventSource("TGo4TreeSource")) {
107 // find out here if tree contains correct event structure...
108 // under constr.
109 auto source = (TGo4TreeSource *) GetEventSource();
110 Clear();
111 if(source->BuildEvent(this))
112 rev = 0;
113 else
114 rev = 1; // error, may be end of tree..
115 } else if(CheckEventSource("TGo4FileSource")) {
116 // find out here if tree contains correct event structure...
117 // under constr.
118 auto source = (TGo4FileSource *) GetEventSource();
119 Clear();
120 if(source->BuildEvent(this))
121 rev = 0;
122 else
123 rev = 1; // error, may be end of tree..
124 } else {
125 rev = 1;
126 }
127
128 return rev;
129}
130
132{
133 GO4TRACE((11,"TGo4SimpleEvent::GetSubEvent(Short_t)",__LINE__, __FILE__));
134 // this is slow:
135 // ResetIterator();
136 // while (auto sub = NextSubEvent())
137 // {
138 // if(sub->fsProcid == procid)
139 // return sub;
140 // }
141 // Int_t i = 0;
142 // while ((sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->At(i++)) ) != nullptr)
143 for (Int_t i = 0; i < fiMaxSlot; ++i) {
144 auto sub = dynamic_cast<TGo4SimpleSubEvent *>(fxSubEventArray->UncheckedAt(i));
145 if (sub->fsProcid == procid)
146 return sub;
147 }
148
149 return nullptr;
150}
151
153{
154 return fiCount;
155}
156
158{
159 GO4TRACE((11,"TGo4SimpleEvent::AddSubEvent(Short_t)",__LINE__, __FILE__));
160
161 TGo4SimpleSubEvent* result = GetSubEvent(procid);
162 if(!result) {
163 // nothing found, use the last one
165 {
166 fiLastSlot++;
167 result = new( (*fxSubEventArray) [fiLastSlot] ) TGo4SimpleSubEvent();
168 result->fsProcid = procid;
169 TGo4Log::Debug(" SimpleEvent: Added subevent with procid %d: ", procid);
170 }
171 else
172 {
173 TGo4Log::Error("simple event: clonesarray is full, cannot add another subevent");
174 result = nullptr;
175 }
176
177 }
178 return result;
179}
180
182{
183 GO4TRACE((11,"TGo4SimpleEvent::ResetIterator()",__LINE__, __FILE__));
184 delete fxIterator;
185 fxIterator = fxSubEventArray->MakeIterator();
186 // note: a mere Iterator Reset fails when run with events read from streamer ??
187 //fxIterator->Reset();
188}
189
191{
192 GO4TRACE((11,"TGo4SimpleEvent::NextSubEvent()",__LINE__, __FILE__));
193 return (TGo4SimpleSubEvent *) fxIterator ->Next();
194}
#define GO4TRACE(X)
Definition TGo4Log.h:25
TGo4EventSource * GetEventSource() const
virtual void PrintEvent()
Method prints content of the event.
Bool_t CheckEventSource(const char *classname)
Check if event source is valid.
Raw event source which reads entries from a root TTree in a TFile.
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:281
static void Error(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 3.
Definition TGo4Log.cxx:320
TClonesArray * fxSubEventArray
aggregation 1 1..* TClonesArray
Int_t Fill() override
Method called by the event owner (analysis step) to fill the event element from the set event source.
void PrintEvent() override
Method prints content of the event.
virtual ~TGo4SimpleEvent()
void ResetIterator()
Set the internal iterator of the subevent array to the beginning of the array.
TGo4SimpleSubEvent * NextSubEvent()
Iterator for subevent array.
Int_t fiMaxSlot
Index of last existing slot in the clonesarray.
Int_t GetCount() const
friend class TGo4SimpleEventProcessor
TGo4SimpleSubEvent * GetSubEvent(Short_t procid)
Access to subevent in list by procid.
TIterator * fxIterator
Iterator for array.
TGo4SimpleSubEvent * AddSubEvent(Short_t procid)
Add subevent ito clonesarray with new procid.
void Clear(Option_t *opt="") override
Method called by the event owner (analysis step) to clear the event element.
Int_t fiLastSlot
Index of last used slot in the clonesarray.
void Clear(Option_t *opt="") override
Method called by the event owner (analysis step) to clear the event element.
Short_t fsProcid
Processor ID [from setup].
Raw event source which reads entries from a root TTree.