Commit c046365e authored by Stezowski Olivier's avatar Stezowski Olivier
Browse files

correct bug to get file properly closed

git-svn-id: svn+ssh://anonsvn.in2p3.fr/agata/gammaware/trunk@1165 c3abf467-7ff2-0310-b516-c5fb849bdde0
parent 11c65a8a
......@@ -25,6 +25,7 @@
#endif
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace ADF;
......@@ -36,7 +37,7 @@ BasicAFC::BasicAFC() :
fBaseForName("AFC_"),
fCurrentFile(0x0),
fCurrentFileNumber(0u),
fMaxSize(kMaxUInt_t)
fMaxSize(kMaxInt_t)
{
Log.GetProcessName() = "BasicAFC"; Log.SetPID(GetPID());
GetFrameIO().SetName("BasicAFC");
......@@ -78,7 +79,9 @@ Bool_t BasicAFC::NewFile()
tmp += '/';
std::ostringstream filename;
filename << tmp << fBaseForName << fCurrentFileNumber++ << ".adf";
filename << tmp << fBaseForName
<< std::setfill('0') << std::setw(4) << fCurrentFileNumber++ << std::setfill(' ')
<< ".adf";
fCurrentFile = ::fopen(filename.str().data(),"wb");
if ( fCurrentFile != 0x0 ) {
......
......@@ -25,6 +25,7 @@
#endif
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace ADF;
......@@ -36,7 +37,7 @@ BasicAFP::BasicAFP():
fBaseForName("AFP_"),
fCurrentFile(0x0),
fCurrentFileNumber(0u),
fMaxSize(kMaxUInt_t)
fMaxSize(kMaxInt_t)
{
Log.GetProcessName() = "BasicAFP"; GetFrameIO().SetName("BasicAFP");
......@@ -68,8 +69,10 @@ Bool_t BasicAFP::NewFile()
tmp += '/';
std::ostringstream filename;
filename << tmp << fBaseForName << fCurrentFileNumber++ << ".adf";
filename << tmp << fBaseForName
<< std::setfill('0') << std::setw(4) << fCurrentFileNumber++ << std::setfill(' ')
<< ".adf";
fCurrentFile = ::fopen(filename.str().data(),"rb");
if ( fCurrentFile != 0x0 ) {
Log << "A new input file has just been open "
......
......@@ -63,7 +63,7 @@ Bool_t OneBlock::SetBlock(Char_t *buf, UInt_t size, char opt, UInt_t /*which*/)
return ok;
}
Bool_t OneBlock::Reserve(UInt_t size)
Bool_t OneBlock::Reserve(UInt_t size, Bool_t switch_eob, UInt_t /*which*/)
{
if ( IsMode(ConfAgent::kRead) || IsEoB() ) {
return false;
......@@ -74,7 +74,9 @@ Bool_t OneBlock::Reserve(UInt_t size)
if ( fBuffer.FreeSize() < size )
add_ok = Expand( fBuffer.Offset() + size );
if ( !add_ok ) {
return false;
if ( switch_eob )
SetEoB(true);
return false;
}
return true;
}
......@@ -190,6 +192,17 @@ Bool_t FileBlock::AddFrame(const Frame &frame, UInt_t)
SetEoB(!ok); return ok;
}
Bool_t FileBlock::Reserve(UInt_t size, Bool_t switch_eob, UInt_t /*which*/)
{
if ( size <= (fMaxSize-fCurrentSize) )
return true;
if ( switch_eob )
SetEoB(true);
return false;
}
class NarvalBlock : public OneBlock
{
protected:
......
......@@ -99,8 +99,10 @@ public:
be sure it is possible.
if it is not possible, return false.
If switch_eob is set to true, it set end of block if Reserve is not possible
*/
virtual Bool_t Reserve(UInt_t)
virtual Bool_t Reserve(UInt_t, Bool_t /*switch_eob*/ = false, UInt_t /*which*/ = 0u)
{ return false; }
virtual UInt_t GetSize(UInt_t = 0u) const
......@@ -203,8 +205,8 @@ public:
virtual BufferIO &GetFrame(UInt_t = 0u)
{ return fFrame; }
//! check if enough place to write something (writing mode)
virtual Bool_t Reserve(UInt_t);
//! check if enough place to write something (writing mode)
virtual Bool_t Reserve(UInt_t, Bool_t /*switch_eob*/ = false, UInt_t /*which*/ = 0u);
//! keep the position
virtual void Snapshot()
......@@ -253,7 +255,7 @@ public:
virtual BufferIO &GetFrame(UInt_t = 0u)
{ fFrame.SetEffectiveSize(0u); return fFrame; }
virtual Bool_t Reserve(UInt_t)
virtual Bool_t Reserve(UInt_t, Bool_t /*switch_eob*/ = false, UInt_t /*which*/ = 0u)
{ return true; }
virtual Bool_t AddFrame(const BufferIO &, UInt_t = 0u)
......@@ -308,8 +310,7 @@ public:
fFile = file;
}
virtual Bool_t Reserve(UInt_t size)
{ if ( size <= (fMaxSize-fCurrentSize) ) return true; return false; }
virtual Bool_t Reserve(UInt_t, Bool_t /*switch_eob*/ = false, UInt_t /*which*/ = 0u);
virtual Bool_t NextFrame(Key *);
......
......@@ -254,7 +254,7 @@ Bool_t FrameIO::DoGlobalReconfiguration()
// First sent the configuration frame on the output data flow
//
if ( fOuFB->Reserve(fInFB->GetFrame().Size()) ) {
if ( fOuFB->Reserve(fInFB->GetFrame().Size(),true) ) {
fOuFB->AddFrame(fInFB->GetFrame());
fWritten++;
fGlobalCounter += fInFB->GetFrame().Size();
......@@ -452,7 +452,8 @@ Bool_t FrameIO::Notify()
case ConfAgent::kSafe:
case ConfAgent::kGrowing:
// able to write the frame on the output data flow
if ( fOuFB->Reserve(fInFB->GetFrame().Size()) ) {
// if not set also eob
if ( fOuFB->Reserve(fInFB->GetFrame().Size(),true) ) {
fOuFB->AddFrame(fInFB->GetFrame());
fWritten++;
fNoTrigCounterOUT +=
......@@ -555,7 +556,7 @@ Bool_t FrameIO::Record(DFTrigger *trig)
// check if the ouput can be written in the output FrameBlock
// cannot put all the frames on the output, so get out
if ( fOuFB->Reserve(needed) == false ) {
if ( fOuFB->Reserve(needed,true) == false ) {
Log.GetProcessMethod() = "Record(DFTrigger *trig)";
Log << error
<< " Cannot write any more in output block " << dolog;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment