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