/******************************************************************* * * DESCRIPTION: Utilities to parse the simulation log * * AUTHOR: Alejandro Troccoli * AUTHOR: Ezequiel Glinsky * * EMAIL: mailto://atroccol@dc.uba.ar * EMAIL: mailto://eglinsky@sce.carleton.ca * * DATE: 19/04/2001 * *******************************************************************/ #include "logparser.h" /******************************************************************** * parseLine: * Returns True if line pointed by l contains an output message from a cell in modelName. * VTime current will be filled with the message time, posi with the CellPosition and value with the output value ********************************************************************/ bool parseLine( const char *l, VTime ¤t, const string &modelName, CellPosition &posi, Real &value ) { istrstream line( l ) ; istream_iterator cursor( line ) ; string tokens[ 15 ]; register long pos( 0 ) ; while( cursor != istream_iterator() && pos < 15 ) tokens[ pos++ ] = *cursor++ ; // Token 14 can be either the model name (e.g., life) or "ParallelFlatCoordinator" when running in flat mode //if( pos == 15 && tokens[2] == "L" && tokens[4] == "Y" && tokens[8].find( modelName ) == 0 && (tokens[14].find( modelName ) == 0 || tokens[14] == "ParallelFlatCoordinator") ) // Jacky Note: // tokens[8].find( modelName ) == 0 -> The 8th column in a Y message in log files should start with the modelName // Ex: life(2,1)(09) // The modelName in this colume will be in lower case since Ini save all group/def names in lower case. // Because the drawlg.cpp has convert command line option -mModelName to lower case, here we don't need to do the // conversion again. // So no matter users define [life] or [LIFE] in the MA file, and no matter they give -m option to drawlog using // -mlife or -mLIFE, the result will be correct. if( pos == 15 && tokens[2] == "L" && tokens[4] == "Y" && tokens[8].find( modelName ) == 0 ) { // the time of the message current = tokens[ 6 ] ; CellPosition pos( tokens[8] ) ; posi = pos ; value = Real( str2Real(tokens[ 12 ]) ) ; return true ; } return false ; } /******************************************************************** * isMessageLine: * Returns True if line pointed by l contains a valid message * msgTime wil lbe filled with the time of the message, and LP with the number of the LP that receives the message ********************************************************************/ bool isMessageLine( const char* l, int& LP, VTime &msgTime) { istrstream line( l ) ; istream_iterator cursor( line ) ; string tokens[ 15 ]; register long pos( 0 ) ; while( cursor != istream_iterator() && pos < 15 ) tokens[ pos++ ] = *cursor++ ; if( (tokens[4] == "*" && pos == 11 ) || (tokens[4] == "@" && pos == 11) || (tokens[4] == "$" && pos == 11) || (tokens[4] == "Y" && pos == 15 ) || (tokens[4] == "X" && pos == 15) || (tokens[4] == "I" && pos == 11) ||( tokens[4] == "D" && pos == 13)) { // the time of the message msgTime= tokens[ 6 ] ; LP = str2Int( tokens[0]); return true ; } return false ; } /******************************************************************** * isMessageLine: * Returns True if line pointed by l contains a valid message * msgTime will be filled with the time of the message, LP with the number of the LP that receives the message * msgType gets the message type ********************************************************************/ bool isMessageLine( const char* l, int& LP, VTime &msgTime, string& msgType) { istrstream line( l ) ; istream_iterator cursor( line ) ; string tokens[ 15 ]; register long pos( 0 ) ; while( cursor != istream_iterator() && pos < 15 ) tokens[ pos++ ] = *cursor++ ; msgType = tokens[4] ; if( (tokens[4] == "*" && pos == 11 ) || (tokens[4] == "@" && pos == 11) || (tokens[4] == "$" && pos == 11) || (tokens[4] == "Y" && pos == 15 ) || (tokens[4] == "X" && pos == 15) || (tokens[4] == "I" && pos == 11) ||( tokens[4] == "D" && pos == 13)) { // the time of the message msgTime= tokens[ 6 ] ; LP = str2Int( tokens[0]); return true ; } return false ; }