00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4FileSource.h"
00017
00018 #include <iostream.h>
00019
00020 #include "TKey.h"
00021 #include "TGo4FileStore.h"
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
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");
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;
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
00087
00088
00089 TString topname;
00090 Bool_t masterbranch=kFALSE;
00091 fxBranchName=dest->GetName();
00092 if(!fxBranchName.Contains("."))
00093 {
00094 fxBranchName+=".";
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
00103 fxTopEvent=dest;
00104 fxTree->SetBranchAddress(topname.Data(),&fxTopEvent);
00105
00106 }
00107 fxTree->SetBranchStatus("*",0);
00108 fxTree->SetBranchStatus(topname.Data(),1);
00109 TString wildbranch=fxBranchName;
00110 wildbranch+="*";
00111 fxTree->SetBranchStatus(wildbranch.Data(),1);
00112
00113 wildbranch=fxBranchName;
00114 if(!masterbranch) wildbranch+=".";
00115 wildbranch+="*";
00116 fxTree->SetBranchStatus(wildbranch.Data(),1);
00117
00118 fbActivated=kTRUE;
00119 }
00120
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
00131
00132 gTree = fxTree;
00133
00134 if (!fbActivated ){
00135 dest->synchronizeWithTree( fxTree );
00136 fbActivated = kTRUE;
00137 }
00138 fxTree->GetEntry(fiCurrentEvent++);
00139
00140
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