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

TGo4FileSource.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 "TGo4FileSource.h"
00017 
00018 #include "Riostream.h"
00019 
00020 #include "TKey.h"
00021 #include "snprintf.h"
00022 #include "TFile.h"
00023 #include "TTree.h"
00024 
00025 #include "TGo4FileSourceParameter.h"
00026 #include "TGo4CompositeEvent.h"
00027 // get static name constants from here
00028 #include "TGo4FileStore.h"
00029 
00030 R__EXTERN TTree *gTree;
00031 
00032 TGo4FileSource::TGo4FileSource(const char* name)
00033 : TGo4EventSource(name), fxFile(0), fxTree(0), fiMaxEvents(0), fiCurrentEvent(0),fbActivated(kFALSE),
00034   fxTopEvent(0)
00035 {
00036    Open();
00037 }
00038 
00039 TGo4FileSource::TGo4FileSource(TGo4FileSourceParameter* par)
00040 : TGo4EventSource(par->GetName()), fxFile(0), fxTree(0), fiMaxEvents(0),
00041 fiCurrentEvent(0), fbActivated(kFALSE),
00042 fxTopEvent(0)
00043 {
00044 Open();
00045 }
00046 
00047 
00048 TGo4FileSource::TGo4FileSource()
00049 : TGo4EventSource("Go4FileSource"), fxFile(0), fxTree(0), fiMaxEvents(0), fiCurrentEvent(0), fbActivated(kFALSE),
00050 fxTopEvent(0)
00051 {
00052    // for streamer, do not open here!
00053 }
00054 
00055 Int_t TGo4FileSource::Open()
00056 {
00057    TString buffer(GetName());
00058    if(strstr(buffer.Data(),TGo4FileStore::fgcFILESUF)==0)
00059         buffer+=TGo4FileStore::fgcFILESUF;
00060    fxFile = TFile::Open(buffer.Data(), "READ"); // in such way rfio etc is also supported!
00061    if(! ( fxFile && fxFile->IsOpen() )) ThrowError(66,0,"!!! ERROR: FILE not found !!!");
00062 
00063    TKey* kee=0;
00064    TIter iter(fxFile->GetListOfKeys());
00065    while ( ( kee=dynamic_cast<TKey*>(iter()) ) !=0 ) {
00066       fxTree = dynamic_cast<TTree*>(kee->ReadObj());
00067       if (fxTree)
00068          break; // we take first Tree in file, disregarding its name...
00069    }
00070    if (fxTree==0)
00071       {
00072          ThrowError(77,0,"!!! ERROR: Tree not found !!!");
00073       }
00074    else
00075       {
00076          SetCreateStatus(0);
00077          fiMaxEvents= (Int_t )fxTree->GetEntries();
00078       }
00079    return 0;
00080 }
00081 
00082 TGo4FileSource::~TGo4FileSource()
00083 {
00084    delete fxFile;
00085 }
00086 
00087 Bool_t TGo4FileSource::BuildEvent(TGo4EventElement* dest)
00088 {
00089    Bool_t rev=kTRUE;
00090    if(dest==0) ThrowError(0,22,"!!! ERROR BuildEvent: no destination event!!!");
00091    if (fxTree==0) ThrowError(0,33,"!!! ERROR BuildEvent: no Tree !!!");
00092    if(!fbActivated)
00093       {
00094          // Event dest should be full event as filled into the tree
00095          // the name of the event element may indicate the subpart
00096          //(tree branchname) that should be read partially only
00097          TString topname;
00098          Bool_t masterbranch=kFALSE;
00099          fxBranchName=dest->GetName();
00100          if(!fxBranchName.Contains("."))
00101             {
00102                fxBranchName+="."; // for master branch, add dot. Subbranch names with dot separators do not get final dot
00103                masterbranch=kTRUE;
00104             }
00105          TObjArray* blist = fxTree->GetListOfBranches();
00106          TBranch* topb= (TBranch*) blist->At(0);
00107          if(topb)
00108             {
00109                topname=topb->GetName();
00110                //cout <<"Activating top branch "<<topname.Data() << endl;
00111                fxTopEvent=dest;
00112                fxTree->SetBranchAddress(topname.Data(),&fxTopEvent);
00113                //topb->SetAddress(&fxTopEvent); // this will not set address of possible cloned tree. we use the set address of the tree
00114              }
00115          fxTree->SetBranchStatus("*",0); // note: only deactivate subleafs _after_ address of top branch is set!
00116          fxTree->SetBranchStatus(topname.Data(),1); // required to process any of the subbranches!
00117          TString wildbranch=fxBranchName;
00118          wildbranch+="*";
00119          fxTree->SetBranchStatus(wildbranch.Data(),1);
00120          //cout <<"Build event activates: "<<wildbranch.Data() << endl;
00121          wildbranch=fxBranchName;
00122          if(!masterbranch) wildbranch+=".";
00123          wildbranch+="*";
00124          fxTree->SetBranchStatus(wildbranch.Data(),1);
00125          //cout <<"Build event activates: "<<wildbranch.Data() << endl;
00126          fbActivated=kTRUE;
00127       }  //  if(!fbActivated)
00128    // end init section ////////////
00129    fxTree->GetEntry(fiCurrentEvent++);
00130    if(fiCurrentEvent>fiMaxEvents) ThrowError(0,44,"END OF TREE at event %d !!!",fiCurrentEvent);
00131    return rev;
00132 }
00133 
00134 Bool_t TGo4FileSource::BuildCompositeEvent(TGo4CompositeEvent* dest){
00135   if(dest==0) ThrowError(0,22,"!!! ERROR BuildEvent: no destination event!!!");
00136   if (fxTree==0) ThrowError(0,33,"!!! ERROR BuildEvent: no Tree !!!");
00137 
00138   // added by S.Linev 21.11.2003   This is important for Composite event activation/deactivation
00139   // of course better, if event do not use gTree pointer
00140   gTree = fxTree;
00141 
00142   if (!fbActivated ){
00143     dest->synchronizeWithTree( fxTree );
00144    fbActivated = kTRUE;
00145   }
00146   fxTree->GetEntry(fiCurrentEvent++);
00147 
00148   // !!! Added by S.Linev 20.11.2003
00149   if(fiCurrentEvent>fiMaxEvents) ThrowError(0,44,"END OF TREE at event %d !!!",fiCurrentEvent);
00150 
00151   return kTRUE;
00152 }
00153 
00154 
00155 
00156 
00157 //----------------------------END OF GO4 SOURCE FILE ---------------------

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