bool Foam::fileOperations::masterFileOperation::writeObject
(
    const regIOobject& io,
    IOstream::streamFormat fmt,
    IOstream::versionNumber ver,
    IOstream::compressionType cmp
) const
{
    mkDir(io.path());
    fileName pathName(io.objectPath());

    autoPtr<Ostream> osPtr
    (
        NewOFstream
        (
            pathName,
            fmt,
            ver,
            cmp
        )
    );
    Ostream& os = osPtr();

    // If any of these fail, return (leave error handling to Ostream class)
    if (!os.good())
    {
        return false;
    }

    if (!io.writeHeader(os))
    {
        return false;
    }

    // Write the data to the Ostream
    if (!io.writeData(os))
    {
        return false;
    }

    IOobject::writeEndDivider(os);

    return true;
}
Foam::masterCollatingOFstream::~masterCollatingOFstream()
{
    autoPtr<OSstream> osPtr;
    if (UPstream::master())
    {
        // Note: always write binary. These are strings so readable
        //       anyway. They have already be tokenised on the sending side.
        osPtr.reset
        (
            new OFstream
            (
                pathName_,
                IOstream::BINARY,
                version(),
                IOstream::UNCOMPRESSED  //compression_
            )
        );

        //writeHeader(osPtr());
        // We don't have IOobject so cannot use writeHeader
        OSstream& os = osPtr();
        IOobject::writeBanner(os)
            << "FoamFile\n{\n"
            << "    version     " << version() << ";\n"
            << "    format      " << os.format() << ";\n"
            << "    class       " << decomposedBlockData::typeName << ";\n"
            << "    location    " << pathName_ << ";\n"
            << "    object      " << pathName_.name() << ";\n"
            << "}" << nl;
        IOobject::writeDivider(os) << nl;
    }


    string s(str());
    UList<char> slice(const_cast<char*>(s.data()), label(s.size()));

    List<std::streamoff> start;
    decomposedBlockData::writeBlocks(osPtr, start, slice, commsType_);
    if (osPtr.valid() && !osPtr().good())
    {
        FatalIOErrorInFunction(osPtr())
            << "Failed writing to " << pathName_ << exit(FatalIOError);
    }
}
예제 #3
0
    void ObjectPool::putOstrStream(std::ostrstream * pOs)
    {
        std::auto_ptr<std::ostrstream> osPtr(pOs);

        pOs->clear(); // freezing may have set error state
        pOs->rdbuf()->freeze(false);
        pOs->rdbuf()->pubseekoff(0, std::ios::beg, std::ios::out);

        Lock lock(mOsPoolMutex);
        if (mOsPool.size() < mBufferCountLimit)
        {
            mOsPool.push_back(osPtr.release());
        }
    }
예제 #4
0
    void ObjectPool::putMemOstream(MemOstream * pOs)
    {
        std::auto_ptr<MemOstream> osPtr(pOs);
        std::size_t bufferSize = osPtr->capacity();
        pOs->clear(); // freezing may have set error state
        pOs->rewind();

        // Check buffer count limit and buffer size limit.
        Lock lock(mOsPoolMutex);
        if (mOsPool.size() < mBufferCountLimit && bufferSize <= mBufferSizeLimit)
        {
            mOsPool.push_back(osPtr.release());
        }
    }
bool Foam::fileOperations::autoParallelFileOperation::writeObject
(
    const regIOobject& io,
    IOstream::streamFormat fmt,
    IOstream::versionNumber ver,
    IOstream::compressionType cmp,
    const bool valid
) const
{
    bool ok = true;

    if (Pstream::parRun())
    {
        if (debug)
        {
            Pout<< indent
                << "autoParallelFileOperation::writeObject :"
                << " Searching for handler for type:" << io.type()
                << " of object: " << io.objectPath() << endl;
        }

        autoPtr<streamReconstructor> typeReconstructor
        (
            streamReconstructor::New(io.type())
        );

        if (typeReconstructor.valid())
        {
            const Time& runTime = io.time();

            Pout<< incrIndent;

            // Install basic file handler
            storeFileHandler defaultOp(basicFileHandler_);

            // Mapping engine from mesh to baseMesh (demand loads various)
            const parUnallocatedFvFieldReconstructor& mapper
                 = reconstructor(runTime);

            if (debug)
            {
                Pout<< indent
                    << "autoParallelFileOperation::writeObject :"
                    << " reconstructing and writing:" << io.name()
                    << " with handler for type:" << io.type()
                    << endl;
            }

            Pout<< decrIndent;

            typeReconstructor().reconstruct
            (
                mapper,
                io,
                false,          // no face flips. Tbd.
                fmt,
                ver,
                cmp
            );
        }
        else if
        (
            io.instance() == io.time().timeName()
         && io.local() == "uniform"
        )
        {
            if (valid)
            {
                // Copy of fileOperation::writeObject but with parent path

                fileName pathName
                (
                    io.rootPath()
                   /io.time().globalCaseName()
                   /io.instance()
                   /io.db().dbDir()
                   /io.local()
                   /io.name()
                );

                mkDir(pathName.path());

                autoPtr<Ostream> osPtr
                (
                    NewOFstream
                    (
                        pathName,
                        fmt,
                        ver,
                        cmp
                    )
                );

                if (!osPtr.valid())
                {
                    return false;
                }

                Ostream& os = osPtr();

                // If any of these fail, return (leave error handling to
                // Ostream class)
                if (!os.good())
                {
                    return false;
                }

                if (!io.writeHeader(os))
                {
                    return false;
                }

                // Write the data to the Ostream
                if (!io.writeData(os))
                {
                    return false;
                }

                IOobject::writeEndDivider(os);
            }
            return true;
        }
        else
        {
            ok = uncollatedFileOperation::writeObject
            (
                io,
                fmt,
                ver,
                cmp,
                valid
            );
        }
    }
    else
    {
        ok = uncollatedFileOperation::writeObject
        (
            io,
            fmt,
            ver,
            cmp,
            valid
        );
    }
    return ok;
}