00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4SimpleEvent.h"
00017
00018 #include "Riostream.h"
00019
00020 #include "Go4EventServer.h"
00021
00022 #include "TGo4Log.h"
00023 #include "TGo4SimpleEventProcessor.h"
00024 #include "TGo4SimpleSubEvent.h"
00025
00026
00027 TGo4SimpleEvent::TGo4SimpleEvent(Int_t subevtnum)
00028 : fiCount(0), fiLastSlot(0), fiMaxSlot(subevtnum), fxIterator(0)
00029 {
00030 TRACE((12,"TGo4SimpleEvent::TGo4SimpleEvent(Int_t)",__LINE__, __FILE__));
00031
00032 fxSubEventArray=new TClonesArray("TGo4SimpleSubEvent", subevtnum);
00033 fxIterator=fxSubEventArray->MakeIterator();
00034
00035 fiArrLen=10;
00036 for(Int_t z=0; z<10; ++z)
00037 {
00038 fiTestArray[z]=z*5;
00039 }
00040
00041
00042 TGo4SimpleSubEvent* subeve;
00043 for (Int_t t=0;t<subevtnum;++t)
00044 {
00045 subeve= new( (*fxSubEventArray) [t] ) TGo4SimpleSubEvent();
00046
00047 }
00048
00049
00050 }
00051
00052
00053 TGo4SimpleEvent::TGo4SimpleEvent()
00054 : fiCount(0), fiLastSlot(0),fiMaxSlot(5), fxIterator(0)
00055 {
00056 TRACE((12,"TGo4SimpleEvent::TGo4SimpleEvent()",__LINE__, __FILE__));
00057
00058 fxSubEventArray=new TClonesArray("TGo4SimpleSubEvent", fiMaxSlot );
00059 fxIterator=fxSubEventArray->MakeIterator();
00060
00061 }
00062
00063
00064
00065
00066 TGo4SimpleEvent::~TGo4SimpleEvent()
00067 {
00068 TRACE((12,"TGo4SimpleEvent::~TGo4SimpleEvent()",__LINE__, __FILE__));
00069 delete fxIterator;
00070 fxSubEventArray->Delete();
00071 delete fxSubEventArray;
00072
00073
00074 }
00075
00076
00077
00078
00079
00080 void TGo4SimpleEvent::PrintEvent() {
00081 TRACE((11,"TGo4SimpleEvent::PrintEvent()",__LINE__, __FILE__));
00082
00083 TGo4EventElement::PrintEvent();
00084 TGo4Log::Debug( " Simple Event Header printout: ");
00085 TGo4Log::Debug( "\tCount: %d ", GetCount() );
00086 TGo4SimpleSubEvent* sub;
00087 ResetIterator();
00088
00089 while ((sub = NextSubEvent() ) !=0)
00090 {
00091 sub->PrintEvent();
00092 }
00093
00094 }
00095
00096 void TGo4SimpleEvent::Clear(Option_t *t)
00097 {
00098 TRACE((11,"TGo4SimpleEvent::Clear()",__LINE__, __FILE__));
00099
00100 TGo4SimpleSubEvent* sub;
00101
00102
00103
00104
00105
00106
00107 Int_t i=0;
00108
00109 for(i=0;i<fiMaxSlot; ++i )
00110 {
00111 sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->UncheckedAt(i));
00112 sub->Clear();
00113 }
00114 fiCount=0;
00115 }
00116
00117
00118 Int_t TGo4SimpleEvent::Fill()
00119 {
00120 TRACE((11,"TGo4SimpleEvent::Fill()",__LINE__, __FILE__));
00121
00122
00123 Int_t rev=-1;
00124 TGo4SimpleEventProcessor* proc;
00125 if(CheckEventSource("TGo4SimpleEventProcessor"))
00126 {
00127 proc = (TGo4SimpleEventProcessor*) GetEventSource();
00128 proc->BuildSimpleEvent(this);
00129 rev=0;
00130 }
00131 else if(CheckEventSource("TGo4TreeSource"))
00132 {
00133
00134
00135 TGo4TreeSource* source = (TGo4TreeSource*) GetEventSource();
00136 Clear();
00137 if(source->BuildEvent(this))
00138 {
00139 rev=0;
00140 }
00141 else
00142 {
00143
00144 rev = 1;
00145 }
00146 }
00147 else if(CheckEventSource("TGo4FileSource"))
00148 {
00149
00150
00151 TGo4FileSource* source = (TGo4FileSource*) GetEventSource();
00152 Clear();
00153 if(source->BuildEvent(this))
00154 {
00155 rev=0;
00156 }
00157 else
00158 {
00159
00160 rev = 1;
00161 }
00162 }
00163
00164
00165 else
00166 {
00167 rev=1;
00168 }
00169
00170 return rev;
00171
00172 }
00173
00174
00175 TGo4SimpleSubEvent * TGo4SimpleEvent::GetSubEvent(Short_t procid)
00176 {
00177 TRACE((11,"TGo4SimpleEvent::GetSubEvent(Short_t)",__LINE__, __FILE__));
00178 TGo4SimpleSubEvent* result=0;
00179 TGo4SimpleSubEvent* sub;
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 Int_t i=0;
00193
00194 for(i=0;i<fiMaxSlot; ++i )
00195 {
00196 sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->UncheckedAt(i));
00197 if(sub->fsProcid==procid)
00198 {
00199 result=sub;
00200 break;
00201 }
00202 else
00203 { }
00204 }
00205
00206 return result;
00207 }
00208
00209 Int_t TGo4SimpleEvent::GetCount() const
00210 {
00211 return fiCount;
00212 }
00213 TGo4SimpleSubEvent * TGo4SimpleEvent::AddSubEvent(Short_t procid)
00214 {
00215 TRACE((11,"TGo4SimpleEvent::AddSubEvent(Short_t)",__LINE__, __FILE__));
00216
00217 TGo4SimpleSubEvent* result=0;
00218 if( (result=GetSubEvent(procid)) != 0 )
00219 {
00220
00221 }
00222 else
00223 {
00224
00225 if(fiLastSlot+1<fiMaxSlot)
00226 {
00227 fiLastSlot++;
00228 result=new( (*fxSubEventArray) [fiLastSlot] ) TGo4SimpleSubEvent();
00229 result->fsProcid=procid;
00230
00231 TGo4Log::Debug(" SimpleEvent: Added subevent with procid %d: ", procid);
00232 }
00233 else
00234 {
00235 cout << "simple event: clonesarray is full, cannot add another subevent"<<endl;
00236 result=0;
00237 }
00238
00239 }
00240
00241 return result;
00242 }
00243 void TGo4SimpleEvent::ResetIterator()
00244 {
00245 TRACE((11,"TGo4SimpleEvent::ResetIterator()",__LINE__, __FILE__));
00246 delete fxIterator;
00247 fxIterator = fxSubEventArray->MakeIterator();
00248
00249
00250 }
00251
00252 TGo4SimpleSubEvent* TGo4SimpleEvent::NextSubEvent()
00253 {
00254 TRACE((11,"TGo4SimpleEvent::NextSubEvent()",__LINE__, __FILE__));
00255 TGo4SimpleSubEvent* sub = (TGo4SimpleSubEvent*) fxIterator ->Next();
00256 return sub;
00257 }
00258
00259