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

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

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