CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/IOPool/Streamer/src/StreamerFileIO.cc

Go to the documentation of this file.
00001 #include "IOPool/Streamer/interface/StreamerFileIO.h"
00002 #include <fstream>
00003 #include <iostream>
00004 #include "FWCore/Utilities/interface/Adler32Calculator.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 
00007   OutputFile::OutputFile(const std::string& name):
00008     current_offset_(1), 
00009     first_event_offset_(0),
00010     last_event_offset_(0),
00011     events_(0),
00012     run_(0),
00013     do_adler_(0),
00014     adlera_(1),
00015     adlerb_(0),
00016     ost_(new std::ofstream(name.c_str(), std::ios_base::binary | std::ios_base::out)),
00017     filename_(name)
00018   {
00019     if(!ost_->is_open()) {
00020       throw cms::Exception("OutputFile","OutputFile")
00021         << "Error Opening Output File: "<<name<<"\n";
00022     }
00023     ost_->rdbuf()->pubsetbuf(0,0);
00024   }
00025 
00026   OutputFile::~OutputFile() 
00027   {
00028     ost_->close();
00029   }
00030 
00031   bool OutputFile::write(const char *ptr, size_t n) 
00032   {
00033     ost_->write(ptr,n);
00034     if(!ost_->fail()) {
00035       current_offset_ += (uint64)(n);
00036       if (do_adler_)
00037         cms::Adler32(ptr,n,adlera_,adlerb_);
00038       return 0;
00039     }
00040     return 1;
00041   }
00042