Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4EventServerExample/TGo4SimpleEvent.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4SimpleEvent.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TGo4SimpleEventProcessor.h"
00021 #include "Go4EventServer/Go4EventServer.h"
00022 
00023 TGo4SimpleEvent::TGo4SimpleEvent(Int_t subevtnum)
00024 : fiCount(0), fiLastSlot(0), fiMaxSlot(subevtnum), fxIterator(0)
00025 {
00026   TRACE((12,"TGo4SimpleEvent::TGo4SimpleEvent(Int_t)",__LINE__, __FILE__));
00027    // cout << "simple event ctor with "<< subevtnum << "subevents"<< endl;
00028    fxSubEventArray=new TClonesArray("TGo4SimpleSubEvent", subevtnum);
00029    fxIterator=fxSubEventArray->MakeIterator();
00030 // start test section
00031    fiArrLen=10;
00032    for(Int_t z=0; z<10; ++z)
00033       {
00034          fiTestArray[z]=z*5;
00035       }
00036 // end test section
00037 
00038    TGo4SimpleSubEvent* subeve;
00039    for (Int_t t=0;t<subevtnum;++t)
00040       {
00041          subeve= new( (*fxSubEventArray) [t] ) TGo4SimpleSubEvent();
00042 
00043       }
00044 
00045 
00046 }
00047 
00048 
00049 TGo4SimpleEvent::TGo4SimpleEvent()
00050 : fiCount(0), fiLastSlot(0),fiMaxSlot(5), fxIterator(0)
00051 {
00052 TRACE((12,"TGo4SimpleEvent::TGo4SimpleEvent()",__LINE__, __FILE__));
00053    //cout << "simple event default ctor"<< endl;
00054    fxSubEventArray=new TClonesArray("TGo4SimpleSubEvent", fiMaxSlot );
00055    fxIterator=fxSubEventArray->MakeIterator();
00056 
00057 }
00058 
00059 
00060 
00061 
00062 TGo4SimpleEvent::~TGo4SimpleEvent()
00063 {
00064 TRACE((12,"TGo4SimpleEvent::~TGo4SimpleEvent()",__LINE__, __FILE__));
00065    delete fxIterator;
00066    fxSubEventArray->Delete();
00067    delete fxSubEventArray;
00068 
00069 
00070 }
00071 
00072 
00073 
00074 
00075 
00076 void TGo4SimpleEvent::PrintEvent() {
00077    TRACE((11,"TGo4SimpleEvent::PrintEvent()",__LINE__, __FILE__));
00078 
00079    TGo4EventElement::PrintEvent();
00080    TGo4Log::Debug( " Simple Event Header printout: ");
00081    TGo4Log::Debug( "\tCount:    %d ", GetCount() );
00082    TGo4SimpleSubEvent* sub;
00083    ResetIterator();
00084 
00085    while ((sub = NextSubEvent() ) !=0)
00086       {
00087          sub->PrintEvent();
00088       }
00089 
00090 }
00091 
00092 void TGo4SimpleEvent::Clear(Option_t *t)
00093 {
00094    TRACE((11,"TGo4SimpleEvent::Clear()",__LINE__, __FILE__));
00095    // here iterate all subevents and clear them
00096    TGo4SimpleSubEvent* sub;
00097 // too slow!!
00098 //   ResetIterator();
00099 //   while ((sub = NextSubEvent() ) !=0)
00100 //      {
00101 //         sub->Clear();
00102 //      }
00103    Int_t i=0;
00104 //   while ((sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->At(i++)) ) !=0)
00105    for(i=0;i<fiMaxSlot; ++i )
00106       {
00107          sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->UncheckedAt(i));
00108          sub->Clear();
00109       }
00110    fiCount=0;
00111 }
00112 
00113 
00114 Int_t TGo4SimpleEvent::Fill()
00115 {
00116    TRACE((11,"TGo4SimpleEvent::Fill()",__LINE__, __FILE__));
00117    //
00118    // check for different source types
00119    Int_t rev=-1;
00120    TGo4SimpleEventProcessor* proc;
00121    if(CheckEventSource("TGo4SimpleEventProcessor"))
00122       {
00123          proc = (TGo4SimpleEventProcessor*) GetEventSource();
00124          proc->BuildSimpleEvent(this);
00125          rev=0;
00126       }
00127    else if(CheckEventSource("TGo4TreeSource"))
00128       {
00129          // find out here if tree contains correct event structure...
00130          // under constr.
00131          TGo4TreeSource* source = (TGo4TreeSource*) GetEventSource();
00132          Clear();
00133          if(source->BuildEvent(this))
00134             {
00135                rev=0;
00136             }
00137          else
00138             {
00139                // error, may be end of tree..
00140                rev = 1;
00141             }
00142       }
00143  else if(CheckEventSource("TGo4FileSource"))
00144       {
00145          // find out here if tree contains correct event structure...
00146          // under constr.
00147          TGo4FileSource* source = (TGo4FileSource*) GetEventSource();
00148          Clear();
00149          if(source->BuildEvent(this))
00150             {
00151                rev=0;
00152             }
00153          else
00154             {
00155                // error, may be end of tree..
00156                rev = 1;
00157             }
00158       }
00159 
00160 
00161    else
00162       {
00163          rev=1;
00164       }
00165 
00166    return rev;
00167 
00168 }
00169 
00170 
00171 TGo4SimpleSubEvent * TGo4SimpleEvent::GetSubEvent(Short_t procid)
00172 {
00173    TRACE((11,"TGo4SimpleEvent::GetSubEvent(Short_t)",__LINE__, __FILE__));
00174    TGo4SimpleSubEvent* result=0;
00175    TGo4SimpleSubEvent* sub;
00176 // this is slow:
00177 //   ResetIterator();
00178 //   while ((sub = NextSubEvent() ) !=0)
00179 //      {
00180 //         if(sub->fsProcid==procid)
00181 //            {
00182 //               result=sub;
00183 //               break;
00184 //            }
00185 //         else
00186 //            { }
00187 //      }
00188    Int_t i=0;
00189 //   while ((sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->At(i++)) ) !=0)
00190    for(i=0;i<fiMaxSlot; ++i )
00191       {
00192          sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->UncheckedAt(i));
00193          if(sub->fsProcid==procid)
00194             {
00195                result=sub;
00196                break;
00197             }
00198          else
00199             { }
00200       }
00201 
00202    return result;
00203 }
00204 
00205 Int_t  TGo4SimpleEvent::GetCount() const
00206 {
00207    return fiCount;
00208 }
00209 TGo4SimpleSubEvent * TGo4SimpleEvent::AddSubEvent(Short_t procid)
00210 {
00211    TRACE((11,"TGo4SimpleEvent::AddSubEvent(Short_t)",__LINE__, __FILE__));
00212 
00213    TGo4SimpleSubEvent* result=0;
00214    if( (result=GetSubEvent(procid)) != 0 )
00215       {
00216          // we found the entry, return this one
00217       }
00218    else
00219       {
00220          // nothing found, use the last one
00221          if(fiLastSlot+1<fiMaxSlot)
00222             {
00223                fiLastSlot++;
00224                result=new( (*fxSubEventArray) [fiLastSlot] ) TGo4SimpleSubEvent();
00225                result->fsProcid=procid;
00226                //cout << "simple event: added subevent with procid " << procid <<endl;
00227                TGo4Log::Debug(" SimpleEvent: Added subevent with procid %d:  ", procid);
00228             }
00229          else
00230             {
00231                cout << "simple event: clonesarray is full, cannot add another subevent"<<endl;
00232                result=0;
00233             }
00234 
00235       }
00236 
00237    return result;
00238 }
00239 void TGo4SimpleEvent::ResetIterator()
00240 {
00241    TRACE((11,"TGo4SimpleEvent::ResetIterator()",__LINE__, __FILE__));
00242    delete fxIterator;
00243    fxIterator = fxSubEventArray->MakeIterator();
00244    // note: a mere Iterator Reset fails when run with events read from streamer ??
00245    //fxIterator->Reset();
00246 }
00247 
00248 TGo4SimpleSubEvent* TGo4SimpleEvent::NextSubEvent()
00249 {
00250    TRACE((11,"TGo4SimpleEvent::NextSubEvent()",__LINE__, __FILE__));
00251    TGo4SimpleSubEvent*   sub = (TGo4SimpleSubEvent*) fxIterator ->Next();
00252    return sub;
00253 }
00254 
00255 
00256    ClassImp(TGo4SimpleEvent)
00257 
00258 
00259 
00260 
00261 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:54 2005 for Go4-v2.10-5 by doxygen1.2.15