00001 // $Id: FRDEventFileWriter.cc,v 1.1 2008/08/13 18:35:21 biery Exp $ 00002 00003 #include "IOPool/Streamer/interface/FRDEventFileWriter.h" 00004 #include "FWCore/Utilities/interface/Exception.h" 00005 #include <iostream> 00006 00007 FRDEventFileWriter::FRDEventFileWriter(edm::ParameterSet const& ps) 00008 { 00009 initialize(ps.getUntrackedParameter<std::string>("fileName", "testFRDfile.dat")); 00010 } 00011 00012 FRDEventFileWriter::FRDEventFileWriter(std::string const& fileName) 00013 { 00014 initialize(fileName); 00015 } 00016 00017 FRDEventFileWriter::~FRDEventFileWriter() 00018 { 00019 ost_->close(); 00020 } 00021 00022 void FRDEventFileWriter::doOutputEvent(FRDEventMsgView const& msg) 00023 { 00024 ost_->write((const char*) msg.startAddress(), msg.size()); 00025 if (ost_->fail()) { 00026 throw cms::Exception("FRDEventFileWriter", "doOutputEvent") 00027 << "Error writing FED Raw Data event data to " 00028 << fileName_ << ". Possibly the output disk " 00029 << "is full?" << std::endl; 00030 } 00031 00032 ost_->flush(); 00033 if (ost_->fail()) { 00034 throw cms::Exception("FRDEventFileWriter", "doOutputEvent") 00035 << "Error writing FED Raw Data event data to " 00036 << fileName_ << ". Possibly the output disk " 00037 << "is full?" << std::endl; 00038 } 00039 } 00040 00041 void FRDEventFileWriter::initialize(std::string const& name) 00042 { 00043 fileName_ = name; 00044 ost_.reset(new std::ofstream(name.c_str(), std::ios_base::binary | std::ios_base::out)); 00045 00046 if (!ost_->is_open()) { 00047 throw cms::Exception("FRDEventFileWriter","initialize") 00048 << "Error opening FED Raw Data event output file: " << name << "\n"; 00049 } 00050 }