Update of /cvsroot/nsclspectcl/SpecTcl/Filter In directory sc8-pr-cvs1:/tmp/cvs-serv13047 Modified Files: OutputEventStream.cpp OutputEventStream.h EventFilter.cpp EventFilter.h GatedEventFilter.cpp GatedEventFilter.h FilterDictionary.cpp Log Message: Modification for home directory (~) expansion using $HOME. Index: OutputEventStream.cpp =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Filter/OutputEventStream.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** OutputEventStream.cpp 20 Mar 2003 14:31:13 -0000 1.4 --- OutputEventStream.cpp 16 Apr 2003 19:03:26 -0000 1.5 *************** *** 8,13 **** // Header Files. #include <vector> ! #include <fstream.h> #include "Event.h" --- 8,14 ---- // Header Files. + //#include <stdlib.h> #include <vector> ! #include <fstream> #include "Event.h" *************** *** 17,31 **** // Constructors. ! COutputEventStream::COutputEventStream() : m_fActive(false), m_nMAXBUFFERSIZE(16) // Arbitrarily chosen. { Open(); } ! COutputEventStream::COutputEventStream(const CEvent& rEvent) : m_fActive(false), m_nMAXBUFFERSIZE(16) // Arbitrarily chosen. { Open(); } --- 18,42 ---- // Constructors. ! COutputEventStream::COutputEventStream() : // Should no longer be called due to the implementation and use of EventFilter::ParseFileName which sets the default file name. m_fActive(false), + m_sFileName(""), m_nMAXBUFFERSIZE(16) // Arbitrarily chosen. { + char* pHomeDir = getenv("HOME"); + if(pHomeDir) { + m_sFileName = string(pHomeDir); + } + m_sFileName += "/filteroutput.txt"; + + Buffer.clear(); // I just hope to * that this is not a necessary action in C++. Open(); } ! COutputEventStream::COutputEventStream(string& rFileName) : m_fActive(false), + m_sFileName(rFileName), m_nMAXBUFFERSIZE(16) // Arbitrarily chosen. { + Buffer.clear(); // I just hope to * that this is not a necessary action in C++. Open(); } *************** *** 36,43 **** // Operators. ! Bool_t COutputEventStream::operator()() { return kfTRUE; }; COutputEventStream& COutputEventStream::operator=(const COutputEventStream& rRhs) { return *this; --- 47,59 ---- // Operators. ! Bool_t COutputEventStream::operator()(const string& rFileName) { ! m_sFileName = rFileName; return kfTRUE; }; + Bool_t COutputEventStream::operator()(const CEvent& rEvent) { + return ReceiveEvent(rEvent); + }; + COutputEventStream& COutputEventStream::operator=(const COutputEventStream& rRhs) { return *this; *************** *** 45,71 **** // Additional functions. Bool_t COutputEventStream::Open() { // Always means that the file has been opened and the stream is active. if(!m_fActive) { ! if(!m_ofs.is_open()) { ! m_ofs.open("/tmp/coutputeventstream.txt"); //, fstream::app); ! } ! if(m_ofs.good()) { ! m_fActive = true; ! return true; ! } else { ! return false; ! } } } Bool_t COutputEventStream::Close() { ! if(m_fActive) { // Attempt to close only if not already so. ! if(m_ofs.is_open()) { ! SendBuffer(); // Send whatever is left. ! m_ofs.close(); // No return value. No exceptions likely. ! } ! m_fActive = false; } ! return !m_fActive; // true always means success with me, but this is arbitrary. } --- 61,85 ---- // Additional functions. + string COutputEventStream::getFileName() { + return m_sFileName; + } + Bool_t COutputEventStream::Open() { // Always means that the file has been opened and the stream is active. + Close(); // Clear everything. + if(!m_fActive) { ! m_ofs.open(m_sFileName.c_str(), ofstream:: out | ofstream::app); // open accepts only a char*. ! m_fActive = m_ofs.is_open(); //m_ofs.good(); } + return m_fActive; } Bool_t COutputEventStream::Close() { ! if(m_ofs.is_open()) { ! SendBuffer(); ! m_ofs.close(); } ! m_fActive = false; ! return !m_fActive; // Always true which always means success with me, but this is arbitrary. } *************** *** 82,86 **** } else { // ERROR! Trying to output an event to an inactive stream. ! cerr << "Error! Trying to output to inactive stream.\n"; return false; } --- 96,100 ---- } else { // ERROR! Trying to output an event to an inactive stream. ! cerr << "Error: Trying to output to inactive stream.\n"; return false; } *************** *** 92,100 **** //for(int i=0; i<Buffer.size(); i++) { // For each and every CEvent in Buffer, for(vector<CEvent>::iterator i=Buffer.begin(); i!=Buffer.end(); i++) { // Just trying. ! //for(int j=0; j<((CEvent)(Buffer[i])).size(); j++) { // For each and every Parameter in CEvent, ! for(CEventIterator j=(*i).begin(); j!=(*i).end(); j++) { // Just tryin' // Output the parameter in the event in the buffer. //m_ofs << ((CEvent)(Buffer[i]))[j] << " "; // Done with parameter. ! m_ofs << (*j) << " "; // Done with parameter. } // Done with event. --- 106,114 ---- //for(int i=0; i<Buffer.size(); i++) { // For each and every CEvent in Buffer, for(vector<CEvent>::iterator i=Buffer.begin(); i!=Buffer.end(); i++) { // Just trying. ! //for(int j=0; j<((CEvent)Buffer[i]).size(); j++) { // For each and every Parameter in CEvent, ! for(CEventIterator j=i->begin(); j!=i->end(); j++) { // Just tryin' // Output the parameter in the event in the buffer. //m_ofs << ((CEvent)(Buffer[i]))[j] << " "; // Done with parameter. ! //m_ofs << (*j) << " "; // Done with parameter. } // Done with event. Index: OutputEventStream.h =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Filter/OutputEventStream.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** OutputEventStream.h 20 Mar 2003 14:31:13 -0000 1.4 --- OutputEventStream.h 16 Apr 2003 19:03:28 -0000 1.5 *************** *** 39,42 **** --- 39,43 ---- class COutputEventStream { Bool_t m_fActive; + string m_sFileName; UInt_t m_nMAXBUFFERSIZE; vector<CEvent> Buffer; *************** *** 46,57 **** // Constructors. COutputEventStream(); ! COutputEventStream(const CEvent&); virtual ~COutputEventStream(); // Operators. ! Bool_t operator()(); COutputEventStream& operator=(const COutputEventStream&); // Additional functions. Bool_t COutputEventStream::Open(); Bool_t COutputEventStream::Close(); --- 47,60 ---- // Constructors. COutputEventStream(); ! COutputEventStream(string&); virtual ~COutputEventStream(); // Operators. ! Bool_t operator()(const string&); // To set file name. DO NOT ABUSE BY SENDING AN EVENT OR SOMETHING ELSE! ! Bool_t operator()(const CEvent&); // To receive and subsequently send an event. COutputEventStream& operator=(const COutputEventStream&); // Additional functions. + string COutputEventStream::getFileName(); Bool_t COutputEventStream::Open(); Bool_t COutputEventStream::Close(); Index: EventFilter.cpp =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Filter/EventFilter.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EventFilter.cpp 20 Mar 2003 14:31:13 -0000 1.4 --- EventFilter.cpp 16 Apr 2003 19:03:28 -0000 1.5 *************** *** 9,12 **** --- 9,13 ---- // Header Files. #include <vector> + #include <string> #include "Histogrammer.h" *************** *** 21,49 **** CEventFilter::CEventFilter() : m_fEnabled(false), m_pOutputEventStream((COutputEventStream*)kpNULL) ! {} ! CEventFilter::CEventFilter(COutputEventStream& rOutputEventStream) : m_fEnabled(false), ! m_pOutputEventStream(&rOutputEventStream) {} - CEventFilter::~CEventFilter() {} - - // Operators. /* ! void CEventFilter::operator()(CEventList& rEvents) { ! for(CEventListIterator i = rEvents.begin(); i != rEvents.end(); i++) { ! CEventFilter::operator()(**i); ! } ! } ! ! void CEventFilter::operator()(CEvent& rEvent) { ! if(CheckCondition(rEvent)) { // CAREFUL!!! *************************** ! FormatOutputEvent(rEvent); ! } } */ CEventFilter& CEventFilter::operator=(const CEventFilter& rRhs) { return *this; --- 22,54 ---- CEventFilter::CEventFilter() : m_fEnabled(false), + //m_sFileName(ParseFileName("")), // Initialized to default. m_pOutputEventStream((COutputEventStream*)kpNULL) ! { ! string sEmpty = ""; ! m_sFileName = ParseFileName(sEmpty); // Just to obtain the default file name. ! } ! CEventFilter::CEventFilter(string& rFileName) : m_fEnabled(false), ! m_sFileName(ParseFileName(rFileName)), ! m_pOutputEventStream((COutputEventStream*)kpNULL) {} /* ! CEventFilter::CEventFilter(COutputEventStream& rOutputEventStream) : ! m_fEnabled(false), ! m_sFileName("~/filteroutput.txt"), // Just a default. Will be reset. ! m_pOutputEventStream(rOutputEventStream) ! { ! // Allows the reuse of a previously defined output event stream. ! // Set the file name in the event filter to that already used in the output event stream. ! string sFileName = m_pOutputEventStream->getFileName(); ! setFileName(sFileName); } */ + CEventFilter::~CEventFilter() {} + + // Operators. CEventFilter& CEventFilter::operator=(const CEventFilter& rRhs) { return *this; *************** *** 52,75 **** // Additional functions. void CEventFilter::Enable() { ! if(!m_fEnabled) { ! if(m_pOutputEventStream == (COutputEventStream*)kpNULL) { ! m_pOutputEventStream = new COutputEventStream; ! } ! m_fEnabled = m_pOutputEventStream->Open(); ! } } void CEventFilter::Disable() { ! if(m_fEnabled) { ! if(m_pOutputEventStream != (COutputEventStream*)kpNULL) { ! if(m_pOutputEventStream->Close()) { // Successfully closed. ! delete m_pOutputEventStream; ! m_pOutputEventStream = (COutputEventStream*)kpNULL; // OTHERWISE, DELETE WOULD CAUSE A SEGMENTATION FAULT. ! m_fEnabled = false; ! } ! } else { // No outputeventstream. ! m_fEnabled = false; } } } --- 57,113 ---- // Additional functions. void CEventFilter::Enable() { ! // Actually does a re-enable to reset the configuration with any new parameters and be on the safe side. ! Disable(); // Clear everything. May be redundant, especially when the file name is reset, but prevents a potential problem. ! ! m_pOutputEventStream = new COutputEventStream(m_sFileName); ! m_fEnabled = m_pOutputEventStream->Open(); } void CEventFilter::Disable() { ! if(m_pOutputEventStream != (COutputEventStream*)kpNULL) { ! /* ! if(m_pOutputEventStream->Close()) { // Successfully closed. This should always be the case (as presently implemented). ! delete m_pOutputEventStream; // Prevent memory leaks! ! m_pOutputEventStream = (COutputEventStream*)kpNULL; // OTHERWISE, DELETE WOULD CAUSE A SEGMENTATION FAULT. } + */ + m_pOutputEventStream->Close(); + delete m_pOutputEventStream; + m_pOutputEventStream = (COutputEventStream*)kpNULL; // OTHERWISE, DELETE WOULD CAUSE A SEGMENTATION FAULT. + } + m_fEnabled = false; + } + + string CEventFilter::ParseFileName(string& rFileName) { + /* + Not currently implemented in OutputEventStream due to potential conflict with respect to setting the default file name when none is specified. + This should not pose any problems as the user only sets file names with respect to the filter (which then calls the output event stream), and this is taken care of right here. + */ + char* pHomeDir = getenv("HOME"); + string sHomeDir = "", sFileName = ""; + + if(pHomeDir) { + sHomeDir = string(pHomeDir); + } + + if(rFileName == "") { // If empty, + sFileName = sHomeDir + "/filteroutput.txt"; // use default. + } else if(rFileName[0] == '~') { // Else if it begins with a ~, + sFileName = sHomeDir + rFileName.substr(1, (rFileName.length()-1)); + } else { + sFileName = rFileName; } + + return sFileName; + } + + void CEventFilter::setFileName(string& rFileName) { + // Whenever this is called, a call to Enable() must be made for the filter to be used. + Disable(); // Reset output event stream using new file name. (This Disable() call is unnecessary, but I'll leave it just to be explicit.) + m_sFileName = ParseFileName(rFileName); + } + + std::string CEventFilter::getFileName() { + return m_sFileName; } Index: EventFilter.h =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Filter/EventFilter.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EventFilter.h 20 Mar 2003 14:31:13 -0000 1.4 --- EventFilter.h 16 Apr 2003 19:03:28 -0000 1.5 *************** *** 7,10 **** --- 7,15 ---- #define __EVENTFILTER_H + #ifndef __STL_STRING + #include <string> + #define __STL_STRING + #endif + #ifndef __EVENT_H #include <Event.h> *************** *** 32,35 **** --- 37,41 ---- protected: Bool_t m_fEnabled; + string m_sFileName; COutputEventStream* m_pOutputEventStream; *************** *** 37,41 **** // Constructors. CEventFilter(); ! CEventFilter(COutputEventStream&); virtual ~CEventFilter(); --- 43,48 ---- // Constructors. CEventFilter(); ! CEventFilter(string& rFileName); ! //CEventFilter(COutputEventStream&); // I doubt that this will ever be used, even if it at all could be. virtual ~CEventFilter(); *************** *** 48,55 **** void Enable(); void Disable(); ! virtual void FormatOutputEvent(CEvent&); COutputEventStream& AttachOutputEventStream(COutputEventStream&); COutputEventStream& DetachOutputEventStream(); ! //protected: // Commented out for now. Bool_t CheckEnabled(); virtual Bool_t CheckCondition(CEvent&); --- 55,65 ---- void Enable(); void Disable(); ! string ParseFileName(string&); ! void setFileName(string&); ! string getFileName(); COutputEventStream& AttachOutputEventStream(COutputEventStream&); COutputEventStream& DetachOutputEventStream(); ! virtual void FormatOutputEvent(CEvent&); ! //protected: Bool_t CheckEnabled(); virtual Bool_t CheckCondition(CEvent&); Index: GatedEventFilter.cpp =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Filter/GatedEventFilter.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GatedEventFilter.cpp 20 Mar 2003 14:31:13 -0000 1.3 --- GatedEventFilter.cpp 16 Apr 2003 19:03:28 -0000 1.4 *************** *** 21,25 **** CGatedEventFilter::CGatedEventFilter() {} ! CGatedEventFilter::CGatedEventFilter(COutputEventStream& rOutputEventStream) {} /* --- 21,27 ---- CGatedEventFilter::CGatedEventFilter() {} ! CGatedEventFilter::CGatedEventFilter(string& rFileName) {} ! ! //CGatedEventFilter::CGatedEventFilter(COutputEventStream& rOutputEventStream) {} /* *************** *** 34,39 **** // Operators. - // NOTE: There is a !BUG! in CEventList::end(). There may be null events before the end. void CGatedEventFilter::operator()(CEventList& rEventList) { for(CEventListIterator i = rEventList.begin(); i != rEventList.end(); i++) { if((*i) != (CEvent*)kpNULL) { // Check to ensure that the event is valid. --- 36,41 ---- // Operators. void CGatedEventFilter::operator()(CEventList& rEventList) { + // NOTE: There is a !BUG! in CEventList::end(). There may be null events before the end. for(CEventListIterator i = rEventList.begin(); i != rEventList.end(); i++) { if((*i) != (CEvent*)kpNULL) { // Check to ensure that the event is valid. Index: GatedEventFilter.h =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Filter/GatedEventFilter.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GatedEventFilter.h 20 Mar 2003 14:31:13 -0000 1.4 --- GatedEventFilter.h 16 Apr 2003 19:03:28 -0000 1.5 *************** *** 61,65 **** // Constructors. CGatedEventFilter(); ! CGatedEventFilter(COutputEventStream&); virtual ~CGatedEventFilter(); --- 61,66 ---- // Constructors. CGatedEventFilter(); ! CGatedEventFilter(string&); ! //CGatedEventFilter(COutputEventStream&); virtual ~CGatedEventFilter(); Index: FilterDictionary.cpp =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Filter/FilterDictionary.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FilterDictionary.cpp 20 Mar 2003 14:31:13 -0000 1.1 --- FilterDictionary.cpp 16 Apr 2003 19:03:28 -0000 1.2 *************** *** 15,19 **** // Initializations. ! CFilterDictionary* CFilterDictionary::m_pInstance = 0; //kpNULL; // Constructors. --- 15,19 ---- // Initializations. ! CFilterDictionary* CFilterDictionary::m_pInstance = (CFilterDictionary*)kpNULL; // Constructors. *************** *** 23,27 **** // Additional functions. CFilterDictionary* CFilterDictionary::GetInstance() { ! if(m_pInstance==0) { m_pInstance = new CFilterDictionary; } --- 23,27 ---- // Additional functions. CFilterDictionary* CFilterDictionary::GetInstance() { ! if(m_pInstance == (CFilterDictionary*)kpNULL) { m_pInstance = new CFilterDictionary; } |