end of file problem

X

xyz

hi all, i have a small question !! for example
ifstream filein(par("fileName"));

i have 3 clients taking three different input files which are of
different sizes. My 3 clients share the same
function to open the file and reading line by line.. my problem is i
need to ...to finish my simulation after i read the whole 3 files
completely

with filein.eof() , if at certain time my event is at module client
1...it checkes whether the file is at end then if yes simulation is
terminated othewise continues.....if simulation is terminated , i am
loosing remaining lines in client 2 and client 3's input files...

how to resolve this issue
thanks to all
 
M

Mirco Wahab

xyz said:
hi all, i have a small question !! for example
ifstream filein(par("fileName"));

i have 3 clients taking three different input files which are of
different sizes. My 3 clients share the same
function to open the file and reading line by line.. my problem is i
need to ...to finish my simulation after i read the whole 3 files
completely

with filein.eof() , if at certain time my event is at module client
1...it checkes whether the file is at end then if yes simulation is
terminated othewise continues.....if simulation is terminated , i am
loosing remaining lines in client 2 and client 3's input files...

how to resolve this issue

You speak in riddles.

You have three threads, that somehow enter one
function at the same time. OK?

Each of the threads does then simultaneously create
a local std::ifstream file object in this function and each
thread then opens a different physical file for reading
through it, OK?

You came to the conclusion, that the threads and
their corresponding std::eof()'s don't properly
stop to read their files at their end - but rather
mess with the contents of the other files and give
wrong answers, OK?

Can you show the code - where this happens? Can you
copy the declaration of all variables involved - we
need to see *exactly* like it looks in your real code?

Regards

M.
 
F

FAU

You speak in riddles.

You have three threads, that somehow enter one
function at the same time. OK?

Each of the threads does then simultaneously create
a local std::ifstream file object in this function and each
thread then opens a different physical file for reading
through it, OK?

You came to the conclusion, that the threads and
their corresponding std::eof()'s don't properly
stop to read their files at their end - but rather
mess with the contents of the other files and give
wrong answers, OK?

Can you show the code - where this happens? Can you
copy the declaration of all variables involved - we
need to see *exactly* like it looks in your real code?

Regards

M.

The threads dont enter the function at the same time...
I have a time in every trace file such that they enter according to
that time.

void xxx::parsingTheTraceFile()
{
std::string Input;
std::string Time;
std::string name;
ifstream filein(par("fileName")); //fileName is the input file
which i am sending as the parameter

filein.seekg(pos,ios::cur);
getline(filein,Input);
pos = filein.tellg();

std::stringstream Stream( Input );

if ( Stream >> Time >> name)
{
//do the stuff
}
if(filein.eof()) opp_error("STOP\n");

}

so else part checks if it is the end of file then stop the simulation.
this function is used by other clients too using other trace files.
even if one of the trace file is reached then my simulation will be
stopped...
but instead i need to check if all other trace files/ input files
reached till end then stop the simulation....

It does not mess with the other contents of the files...but the
simulation is stopped even if one of the trace file is finished or
reached end of file...but instead i want to check if all other trace
files are reached till end and if it the case then stop the
simulation...hope you all understood...


thanks
 
X

xyz

You speak in riddles.

You have three threads, that somehow enter one
function at the same time. OK?

Each of the threads does then simultaneously create
a local std::ifstream file object in this function and each
thread then opens a different physical file for reading
through it, OK?

You came to the conclusion, that the threads and
their corresponding std::eof()'s don't properly
stop to read their files at their end - but rather
mess with the contents of the other files and give
wrong answers, OK?

Can you show the code - where this happens? Can you
copy the declaration of all variables involved - we
need to see *exactly* like it looks in your real code?

Regards

M.

The threads dont enter the function at the same time...
I have a time in every trace file such that they enter according to
that time.

void xxx::parsingTheTraceFile()
{
std::string Input;
std::string Time;
std::string name;
ifstream filein(par("fileName")); //fileName is the input
file
which i am sending as the parameter

filein.seekg(pos,ios::cur);
getline(filein,Input);
pos = filein.tellg();

std::stringstream Stream( Input );

if ( Stream >> Time >> name)
{
//do the stuff
}
if(filein.eof()) opp_error("STOP\n");

}

so else part checks if it is the end of file then stop the simulation.
this function is used by other clients too using other trace files.
even if one of the trace file is reached then my simulation will be
stopped...
but instead i need to check if all other trace files/ input files
reached till end then stop the simulation....

It does not mess with the other contents of the files...but the
simulation is stopped even if one of the trace file is finished or
reached end of file...but instead i want to check if all other trace
files are reached till end and if it the case then stop the
simulation...hope you all understood...

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top