Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4SimpleEvent.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 "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    // cout << "simple event ctor with "<< subevtnum << "subevents"<< endl;
00032    fxSubEventArray=new TClonesArray("TGo4SimpleSubEvent", subevtnum);
00033    fxIterator=fxSubEventArray->MakeIterator();
00034 // start test section
00035    fiArrLen=10;
00036    for(Int_t z=0; z<10; ++z)
00037       {
00038          fiTestArray[z]=z*5;
00039       }
00040 // end test section
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    //cout << "simple event default ctor"<< endl;
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    // here iterate all subevents and clear them
00100    TGo4SimpleSubEvent* sub;
00101 // too slow!!
00102 //   ResetIterator();
00103 //   while ((sub = NextSubEvent() ) !=0)
00104 //      {
00105 //         sub->Clear();
00106 //      }
00107    Int_t i=0;
00108 //   while ((sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->At(i++)) ) !=0)
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    // check for different source types
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          // find out here if tree contains correct event structure...
00134          // under constr.
00135          TGo4TreeSource* source = (TGo4TreeSource*) GetEventSource();
00136          Clear();
00137          if(source->BuildEvent(this))
00138             {
00139                rev=0;
00140             }
00141          else
00142             {
00143                // error, may be end of tree..
00144                rev = 1;
00145             }
00146       }
00147  else if(CheckEventSource("TGo4FileSource"))
00148       {
00149          // find out here if tree contains correct event structure...
00150          // under constr.
00151          TGo4FileSource* source = (TGo4FileSource*) GetEventSource();
00152          Clear();
00153          if(source->BuildEvent(this))
00154             {
00155                rev=0;
00156             }
00157          else
00158             {
00159                // error, may be end of tree..
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 // this is slow:
00181 //   ResetIterator();
00182 //   while ((sub = NextSubEvent() ) !=0)
00183 //      {
00184 //         if(sub->fsProcid==procid)
00185 //            {
00186 //               result=sub;
00187 //               break;
00188 //            }
00189 //         else
00190 //            { }
00191 //      }
00192    Int_t i=0;
00193 //   while ((sub = dynamic_cast<TGo4SimpleSubEvent*>( fxSubEventArray->At(i++)) ) !=0)
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          // we found the entry, return this one
00221       }
00222    else
00223       {
00224          // nothing found, use the last one
00225          if(fiLastSlot+1<fiMaxSlot)
00226             {
00227                fiLastSlot++;
00228                result=new( (*fxSubEventArray) [fiLastSlot] ) TGo4SimpleSubEvent();
00229                result->fsProcid=procid;
00230                //cout << "simple event: added subevent with procid " << procid <<endl;
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    // note: a mere Iterator Reset fails when run with events read from streamer ??
00249    //fxIterator->Reset();
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 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:09 2008 for Go4-v3.04-1 by  doxygen 1.4.2