00001
00002
00003
00004
00005
00006
00008 #include "IoModules/IoRerootStreamItr.h"
00009 #include "MessageService/MsgService.h"
00010 #include "Validity/VldContext.h"
00011
00012 #include <cassert>
00013
00014 CVSID("$Id: IoRerootStreamItr.cxx,v 1.8 2006/06/02 02:36:20 schubert Exp $");
00015
00016
00017
00018 IoRerootStreamItr::IoRerootStreamItr(const char* sourceName) : fIndex(-1),
00019 fBOFIndex(-1),fEOFIndex(-1),fIsValid(true)
00020 {
00021
00022 if (gMINFast == 0) {
00023
00024 gMINFast = new MINFast("gMinFast","MINFAST",kFALSE,"");
00025 static IoRerootStreamItr::Cleaner c; c.UseMe();
00026 assert(gMINFast);
00027 }
00028 this -> SetSourceName(sourceName);
00029
00030 }
00031
00032
00033
00034 IoRerootStreamItr::~IoRerootStreamItr()
00035 {
00036 this->CloseFile();
00037 }
00038
00039
00040
00041 int IoRerootStreamItr::LoadRecords(MomNavigator* )
00042 {
00043 if (!IsOpenFile() || fIndex<0 || fIndex>=fEOFIndex) return 0;
00044 MSG("Io",Msg::kDebug) << "IoRerootStreamItr::LoadRecord at index "
00045 << fIndex << endl;
00046 if (gMINFast->GetEvent(fIndex)) return 1;
00047 return 0;
00048 }
00049
00050
00051
00052 int IoRerootStreamItr::Increment(int n, MomNavigator* m)
00053 {
00054
00055 if (!IsOpenFile() || n<=0) return 0;
00056
00057
00058 if ((fIndex + n) >= fEOFIndex) {
00059 int isave = fIndex;
00060 fIndex = fEOFIndex;
00061 if (m) this->LoadRecords(m);
00062 return (fEOFIndex-isave-1);
00063 }
00064
00065
00066 fIndex += n;
00067 if (m) this->LoadRecords(m);
00068 return n;
00069 }
00070
00071
00072
00073 int IoRerootStreamItr::Decrement(int n, MomNavigator* m)
00074 {
00075
00076
00077
00078 if (!IsOpenFile() || n<=0) return 0;
00079
00080
00081 if ((fIndex - n) <= fBOFIndex) {
00082 int isave = fIndex;
00083 fIndex = fBOFIndex;
00084 if (m) this->LoadRecords(m);
00085 return (isave-fBOFIndex-1);
00086 }
00087
00088
00089 fIndex -= n;
00090 if (m) this->LoadRecords(m);
00091 return n;
00092 }
00093
00094
00095
00096 JobCResult IoRerootStreamItr::GoTo(const VldContext& vld, MomNavigator* m)
00097 {
00098
00099
00100
00101
00102 MSG("Io",Msg::kWarning) <<
00103 "GoTo(" << vld << ") not supported for REROOT data.\n";
00104 if (m) this->LoadRecords(m);
00105 return JobCResult::kWarning;
00106 }
00107
00108
00109
00110 int IoRerootStreamItr::GoToEOF() { fIndex = fEOFIndex; return 1;}
00111
00112
00113
00114 JobCResult IoRerootStreamItr::OpenFile()
00115 {
00116
00117
00118
00119 std::string fullfilepathname = this -> GetCurrentFile();
00120 if ( fullfilepathname == "" ) return JobCResult::kWarning;
00121 this -> SetSourceName(fullfilepathname.c_str());
00122
00123 gMINFast->OpenRerootFile(fullfilepathname.c_str());
00124
00125
00126 if ( !IsOpenFile() ) return JobCResult::kWarning;
00127
00128
00129 fBOFIndex = -1;
00130 fEOFIndex = gMINFast->GetMINFile()->Getnevts();
00131 fIndex = fBOFIndex;
00132
00133 return JobCResult::kAOK;
00134 }
00135
00136
00137
00138 void IoRerootStreamItr::CloseFile() {
00139
00140 this -> SetSourceName("");
00141 return;
00142 }
00143
00144 bool IoRerootStreamItr::IsOpenFile() const {
00145 bool isOpen = true;
00146 if (gMINFast->GetMINFile()==0 ||
00147 gMINFast->GetMINFile()->Getnevts() ==0) isOpen = false;
00148 return isOpen;
00149 }
00150
00151