1 //--------------------------------------------------------------------------
4 // This software is part of the EvtGen package developed jointly
5 // for the BaBar and CLEO collaborations. If you use all or part
6 // of it, please give an appropriate acknowledgement.
8 // Copyright Information: See EvtGen/COPYRIGHT
9 // Copyright (C) 1998 Caltech, UCSB
11 // Module: EvtParser.cc
13 // Description: Reading the decay table and produce a list of tokens.
15 // Modification history:
17 // RYD Febuary 11, 1998 Module created
19 //------------------------------------------------------------------------
21 #include "EvtGenBase/EvtPatches.hh"
22 #include "EvtGenBase/EvtPatches.hh"
26 #include "EvtGenBase/EvtParser.hh"
27 #include "EvtGenBase/EvtReport.hh"
32 EvtParser::EvtParser(){
39 EvtParser::~EvtParser(){
47 int EvtParser::getNToken(){
53 const std::string& EvtParser::getToken(int i){
59 int EvtParser::getLineofToken(int i){
65 int EvtParser::read(const std::string filename){
68 fin.open(filename.c_str());
70 report(ERROR,"EvtGen") << "Could not open file '"<<filename.c_str()<<"'"<<endl;
81 while(fin.peek() != EOF){
85 while((c=fin.get()) != '\n' && i<MAXBUF) {
90 report(ERROR,"EvtGen") << "Error in EvtParser: line:"
91 <<line<<" to long"<<endl;
97 //search for '#' which indicates comment for rest of line!
100 if (buf[i]=='#') buf[i]=0;
104 string tmp(buf,strlen(buf));
107 istringstream ist(tmp);
116 }while(buf2[i++]!=0);
120 if (semicolon) addToken(line,";");
132 void EvtParser::addToken(int line,const std::string& string){
134 //report(INFO,"EvtGen") <<_ntoken<<" "<<line<<" "<<string<<endl;
136 if (_ntoken==_lengthoftokenlist) {
138 int new_length=1000+4*_lengthoftokenlist;
142 int* newlinelist= new int[new_length];
143 std::string* newtokenlist= new std::string[new_length];
147 for(i=0;i<_ntoken;i++){
148 newlinelist[i]=_linelist[i];
149 newtokenlist[i]=_tokenlist[i];
152 delete [] _tokenlist;
155 _tokenlist=newtokenlist;
156 _linelist=newlinelist;
158 _lengthoftokenlist=new_length;
163 _tokenlist[_ntoken]=string;
165 _linelist[_ntoken]=line;
169 //report(INFO,"EvtGen") << "First:"<<_tokenlist[0]<<" last:"<<_tokenlist[_ntoken-1]<<endl;