// ESAF : Euso Simulation and Analysis Framework // $Id: NumbersFileParser.hh,v 1.4 2004/12/26 00:43:51 thea Exp $ // Author: Daniel De Marco Jan, 28 2002 /***************************************************************************** * ESAF: Euso Simulation and Analysis Framework * * * * Id: NumbersFileParser * * Package: Base * * Coordinator: Marco.Pallavicini * * * *****************************************************************************/ #ifndef __NUMBERSFILEPARSER_HH__ #define __NUMBERSFILEPARSER_HH__ #include #include #include #include #include #include #include #include "euso.hh" #include "EsafMsgSource.hh" //////////////////////////////////////////////////////////////////////////////// // // // NumbersFileParser // // // // Parser of numbers data files // // // //////////////////////////////////////////////////////////////////////////////// class NumbersFileParser : public EsafMsgSource { public: enum Coding {ascii, gzip}; // types of file coding that NumberFileParser can handle NumbersFileParser(const string &fn, size_t ncol, Coding = ascii); // constructor virtual ~NumbersFileParser(); // destructor vector &GetCol(size_t col); // columns vector GetRow(size_t row); // rows Double_t GetNum(size_t row, size_t col); // get element inline void SetUnit(Double_t unit, size_t col); // set colum unit of measure inline Double_t GetUnit(size_t col) const; // get colum unit of measure protected: // access to number of lines and columns for child class inline Int_t GetNumLines() { return fNumbers[0].size(); } inline size_t GetNumColumns() const { return fNumCol; } private: void ProcessLine( string ); // Helper function: gets numbers from a line vector *fNumbers; // a single vector for the whole matrix Double_t *fUnits; string fFileName; Coding fFileType; size_t fNumCol; ClassDef(NumbersFileParser,0) }; // // inline functions // // Get a column inline vector &NumbersFileParser::GetCol(size_t col) { if ( col >= fNumCol ) Msg(EsafMsg::Panic) << "Invalid column number reqeusted to "+fFileName << MsgDispatch; return fNumbers[col]; } // Get an element inline Double_t NumbersFileParser::GetNum(size_t row, size_t col) { if ( col > fNumCol ) Msg(EsafMsg::Panic) << "Invalid column requested to "+fFileName << MsgDispatch; if ( row>fNumbers[col].size() ) { Msg(EsafMsg::Panic) << "Invalid row requsted to "+fFileName << MsgDispatch; } return (fNumbers[col])[row]; } // Set colum unit of measure inline void NumbersFileParser::SetUnit(Double_t unit, size_t col) { if ( col >= fNumCol ) Msg(EsafMsg::Panic) << "SetUnit: Column number out of range "<< MsgDispatch; Double_t ratio = unit/fUnits[col]; vector::iterator it; for (it=fNumbers[col].begin(); it != fNumbers[col].end(); it++) (*it) *= ratio; fUnits[col] = unit; } // Get colum unit of measure inline Double_t NumbersFileParser::GetUnit(size_t col) const { if ( col >= fNumCol ) Msg(EsafMsg::Panic) << "GetUnit: Column number out of range "<< MsgDispatch; return fUnits[col]; } #endif /* __NUMBERSFILEPARSER_HH__ */