GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4SimpleEvent.cxx
Go to the documentation of this file.
1 // $Id: TGo4SimpleEvent.cxx 1037 2013-11-06 13:39:24Z 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 "TGo4SimpleEvent.h"
15 
16 #include "Go4EventServer.h"
17 
18 #include "TGo4Log.h"
20 #include "TGo4SimpleSubEvent.h"
21 
24  fiCount(0),
25  fiLastSlot(0),
26  fiMaxSlot(5),
27  fxIterator(0)
28 {
29  GO4TRACE((12,"TGo4SimpleEvent::TGo4SimpleEvent()",__LINE__, __FILE__));
30  //std::cout << "simple event default ctor"<< std::endl;
31  fxSubEventArray=new TClonesArray("TGo4SimpleSubEvent", fiMaxSlot );
32  fxIterator=fxSubEventArray->MakeIterator();
33 }
34 
35 
38  fiCount(0),
39  fiLastSlot(0),
40  fiMaxSlot(subevtnum),
41  fxIterator(0)
42 {
43  GO4TRACE((12,"TGo4SimpleEvent::TGo4SimpleEvent(Int_t)",__LINE__, __FILE__));
44  // std::cout << "simple event ctor with "<< subevtnum << "subevents"<< std::endl;
45  fxSubEventArray = new TClonesArray("TGo4SimpleSubEvent", subevtnum);
46  fxIterator = fxSubEventArray->MakeIterator();
47  // start test section
48  fiArrLen=10;
49  for(Int_t z=0; z<10; ++z)
50  {
51  fiTestArray[z]=z*5;
52  }
53  // end test section
54 
55  for (Int_t t=0;t<subevtnum;++t)
56  {
57  new( (*fxSubEventArray) [t] ) TGo4SimpleSubEvent();
58  }
59 }
60 
62 {
63  GO4TRACE((12,"TGo4SimpleEvent::~TGo4SimpleEvent()",__LINE__, __FILE__));
64  delete fxIterator;
65  fxSubEventArray->Delete();
66  delete fxSubEventArray;
67 }
68 
69 
71  GO4TRACE((11,"TGo4SimpleEvent::PrintEvent()",__LINE__, __FILE__));
72 
74  TGo4Log::Debug( " Simple Event Header printout: ");
75  TGo4Log::Debug( "\tCount: %d ", GetCount() );
76  TGo4SimpleSubEvent* sub;
77  ResetIterator();
78 
79  while ((sub = NextSubEvent() ) !=0)
80  {
81  sub->PrintEvent();
82  }
83 
84 }
85 
86 void TGo4SimpleEvent::Clear(Option_t *t)
87 {
88  GO4TRACE((11,"TGo4SimpleEvent::Clear()",__LINE__, __FILE__));
89  // here iterate all subevents and clear them
90  TGo4SimpleSubEvent* sub;
91  // too slow!!
92  // ResetIterator();
93  // while ((sub = NextSubEvent() ) !=0)
94  // {
95  // sub->Clear();
96  // }
97  Int_t i=0;
98  // while ((sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->At(i++)) ) !=0)
99  for(i=0;i<fiMaxSlot; ++i )
100  {
101  sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->UncheckedAt(i));
102  sub->Clear();
103  }
104  fiCount=0;
105 }
106 
107 
109 {
110  GO4TRACE((11,"TGo4SimpleEvent::Fill()",__LINE__, __FILE__));
111  //
112  // check for different source types
113  Int_t rev=-1;
115  if(CheckEventSource("TGo4SimpleEventProcessor"))
116  {
118  proc->BuildSimpleEvent(this);
119  rev=0;
120  }
121  else if(CheckEventSource("TGo4TreeSource"))
122  {
123  // find out here if tree contains correct event structure...
124  // under constr.
126  Clear();
127  if(source->BuildEvent(this))
128  {
129  rev=0;
130  }
131  else
132  {
133  // error, may be end of tree..
134  rev = 1;
135  }
136  }
137  else if(CheckEventSource("TGo4FileSource"))
138  {
139  // find out here if tree contains correct event structure...
140  // under constr.
142  Clear();
143  if(source->BuildEvent(this))
144  {
145  rev=0;
146  }
147  else
148  {
149  // error, may be end of tree..
150  rev = 1;
151  }
152  }
153 
154 
155  else
156  {
157  rev=1;
158  }
159 
160  return rev;
161 
162 }
163 
164 
166 {
167  GO4TRACE((11,"TGo4SimpleEvent::GetSubEvent(Short_t)",__LINE__, __FILE__));
168  TGo4SimpleSubEvent* result=0;
169  TGo4SimpleSubEvent* sub;
170  // this is slow:
171  // ResetIterator();
172  // while ((sub = NextSubEvent() ) !=0)
173  // {
174  // if(sub->fsProcid==procid)
175  // {
176  // result=sub;
177  // break;
178  // }
179  // else
180  // { }
181  // }
182  Int_t i=0;
183  // while ((sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->At(i++)) ) !=0)
184  for(i=0;i<fiMaxSlot; ++i )
185  {
186  sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->UncheckedAt(i));
187  if(sub->fsProcid==procid)
188  {
189  result=sub;
190  break;
191  }
192  }
193 
194  return result;
195 }
196 
198 {
199  return fiCount;
200 }
201 
203 {
204  GO4TRACE((11,"TGo4SimpleEvent::AddSubEvent(Short_t)",__LINE__, __FILE__));
205 
206  TGo4SimpleSubEvent* result=0;
207  if( (result=GetSubEvent(procid)) != 0 )
208  {
209  // we found the entry, return this one
210  }
211  else
212  {
213  // nothing found, use the last one
214  if(fiLastSlot+1<fiMaxSlot)
215  {
216  fiLastSlot++;
217  result=new( (*fxSubEventArray) [fiLastSlot] ) TGo4SimpleSubEvent();
218  result->fsProcid=procid;
219  //std::cout << "simple event: added subevent with procid " << procid << std::endl;
220  TGo4Log::Debug(" SimpleEvent: Added subevent with procid %d: ", procid);
221  }
222  else
223  {
224  TGo4Log::Error("simple event: clonesarray is full, cannot add another subevent");
225  result=0;
226  }
227 
228  }
229  return result;
230 }
231 
233 {
234  GO4TRACE((11,"TGo4SimpleEvent::ResetIterator()",__LINE__, __FILE__));
235  delete fxIterator;
236  fxIterator = fxSubEventArray->MakeIterator();
237  // note: a mere Iterator Reset fails when run with events read from streamer ??
238  //fxIterator->Reset();
239 }
240 
242 {
243  GO4TRACE((11,"TGo4SimpleEvent::NextSubEvent()",__LINE__, __FILE__));
245  return sub;
246 }
TGo4EventSource * GetEventSource() const
virtual Int_t Fill()
TIterator * fxIterator
virtual void PrintEvent()
TGo4SimpleSubEvent * AddSubEvent(Short_t procid)
Bool_t CheckEventSource(const char *classname)
virtual void Clear(Option_t *t="")
TGo4SimpleSubEvent * GetSubEvent(Short_t procid)
virtual ~TGo4SimpleEvent()
void BuildSimpleEvent(TGo4SimpleEvent *target)
virtual Bool_t BuildEvent(TGo4EventElement *dest)
virtual void Clear(Option_t *t="")
TClonesArray * fxSubEventArray
#define GO4TRACE(X)
Definition: TGo4Log.h:26
Bool_t BuildEvent(TGo4EventElement *dest)
Int_t GetCount() const
TGo4SimpleSubEvent * NextSubEvent()
Int_t fiTestArray[10]
static void Error(const char *text,...)
Definition: TGo4Log.cxx:309
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:270