00001 #include "Event/IOfileServer.h"
00002
00003 #include "Event/messageManager.h"
00004 #include "Event/optionManager.h"
00005
00006
00007 IOfileServer::IOfileServer()
00008
00009 {
00010 m_ifile = -1;
00011 m_InFileList.clear();
00012 m_InFile ="";
00013 m_histoFile ="";
00014 m_OutFile ="";
00015 m_displayFreq = 100;
00016
00017 m_input = 0;
00018 m_output = 0;
00019 m_histo = 0;
00020
00021 m_server = new serverVI<IOfileVI>();
00022
00025 defineIOfiles();
00026
00027 setName("IOfileServer");
00028 }
00029
00030 IOfileServer::~IOfileServer()
00031
00032 {
00033 }
00034
00035 IOfileVI* IOfileServer::getIOfile(std::string name) const
00036
00037 {
00038 if (m_server->search(name)) return m_server->get(name);
00039 else messageManager::instance()->message("Not found IOfileV "+name);
00040 return 0;
00041 }
00042
00043 void IOfileServer::open()
00044
00045 {
00047 std::string name = getNextInFileName();
00048 if (name !="") {
00049 getIOfile("input")->setFileName(name);
00050 getIOfile("input")->setMode(IOBase::READ);
00051 getIOfile("input")->open();
00052 if (getIOfile("input")->isOpen()) {
00053 message(" opened input file "+name);
00054 m_input = getIOfile("input");
00055 } else message(" could not open input file "+name);
00056 setNumEvents(getIOfile("input")->numEvents());
00057 }
00058
00060 name = getHistoFileName();
00061 if (name !="") {
00062 getIOfile("histo")->setFileName(name);
00063 getIOfile("histo")->setMode(IOBase::WRITE);
00064 getIOfile("histo")->open();
00065 if (getIOfile("histo")->isOpen()) {
00066 message(" opened histo file "+name);
00067 m_histo = getIOfile("histo");
00068 } else message(" could not open histo file "+name);
00069 }
00070
00072 name = getOutFileName();
00073 if (name !="") {
00074 getIOfile("output")->setFileName(name);
00075 getIOfile("output")->setMode(IOBase::WRITE);
00076 getIOfile("output")->open();
00077 if (getIOfile("output")->isOpen()) {
00078 message(" opened output file "+name);
00079 m_output = getIOfile("output");
00080 } else message(" could not open output file "+name);
00081 }
00082 }
00083
00084 bool IOfileServer::nextEvent()
00085
00086 {
00087 if (search("input")) return getIOfile("input")->nextEvent();
00088 return false;
00089 }
00090
00091 void IOfileServer::readEvent()
00092
00093 {
00094 increase();
00095 if (displayFrequency()) message(" reading event ",eventNumber(),"GENERAL");;
00096 if (m_input) m_input->readEvent();
00097 }
00098
00099 void IOfileServer::writeEvent()
00100
00101 {
00102 if (m_output) m_output->writeEvent();
00103 }
00104
00105
00106 void IOfileServer::skipEvent()
00107
00108 {
00109 increase();
00110 if (displayFrequency()) message(" skiping event ",eventNumber(),"GENERAL");
00111 if (m_input) m_input->skipEvent();
00112 }
00113
00114 void IOfileServer::close()
00115
00116 {
00117 if (search("input")) getIOfile("input")->close();
00118 if (search("output")) getIOfile("output")->close();
00119 if (search("histo")) getIOfile("histo")->close();
00120 }
00121
00122
00123 bool IOfileServer::displayFrequency() const
00124
00125 {
00126 return (eventNumber()%m_displayFreq == 0);
00127 }
00128
00129 std::string IOfileServer::getNextInFileName()
00130
00131 {
00132 m_ifile++;
00133 std::string empty = "";
00134 if (m_ifile >= m_InFileList.size()) return empty;
00135 else return m_InFileList[m_ifile];
00136 }
00137
00138 void IOfileServer::defineOption()
00139
00140 {
00141 optionVI::defineOption("InFile",&m_InFile);
00142 optionVI::defineOption("histoFile",&m_histoFile);
00143 optionVI::defineOption("OutFile",&m_OutFile);
00144
00145 optionVI::defineOption("displayFrequency",&m_displayFreq);
00146 }
00147
00148 void IOfileServer::setOption(std::string par, std::string v)
00149
00150 {
00151 optionVI::setOption(par,v);
00153 if (par == "InFile") m_InFileList.push_back(v);
00154 }
00155
00156 void IOfileServer::writeOut() const
00157
00158 {
00159 if (!acceptLevel()) return;
00160 messageVI::writeOut();
00162 std::ostream& out = messageManager::instance()->out();
00163 out << " input file name = " << m_InFile <<"\n";
00164 out << " output file name = " << m_OutFile <<"\n";
00165 out << " histos file name = " << m_histoFile <<"\n";
00166
00167 }