CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/IOPool/Streamer/src/FRDEventFileWriter.cc

Go to the documentation of this file.
00001 // $Id: FRDEventFileWriter.cc,v 1.3 2010/02/18 09:19:02 mommsen Exp $
00002 
00003 #include "IOPool/Streamer/interface/FRDEventFileWriter.h"
00004 #include "FWCore/Utilities/interface/Adler32Calculator.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 #include <iostream>
00007 
00008 FRDEventFileWriter::FRDEventFileWriter(edm::ParameterSet const& ps)
00009 {
00010   initialize(ps.getUntrackedParameter<std::string>("fileName", "testFRDfile.dat"));
00011 }
00012 
00013 FRDEventFileWriter::FRDEventFileWriter(std::string const& fileName)
00014 {
00015   initialize(fileName);
00016 }
00017 
00018 FRDEventFileWriter::~FRDEventFileWriter()
00019 {
00020   ost_->close();
00021 }
00022 
00023 void FRDEventFileWriter::doOutputEvent(FRDEventMsgView const& msg)
00024 {
00025   ost_->write((const char*) msg.startAddress(), msg.size());
00026   if (ost_->fail()) {
00027     throw cms::Exception("FRDEventFileWriter", "doOutputEvent")
00028       << "Error writing FED Raw Data event data to "
00029       << fileName_ << ".  Possibly the output disk "
00030       << "is full?" << std::endl;
00031   }
00032 
00033   ost_->flush();
00034   if (ost_->fail()) {
00035     throw cms::Exception("FRDEventFileWriter", "doOutputEvent")
00036       << "Error writing FED Raw Data event data to "
00037       << fileName_ << ".  Possibly the output disk "
00038       << "is full?" << std::endl;
00039   }
00040   
00041   cms::Adler32((const char*) msg.startAddress(), msg.size(), adlera_, adlerb_);
00042 }
00043 
00044 void FRDEventFileWriter::doOutputEventFragment(unsigned char* dataPtr,
00045                                                unsigned long dataSize)
00046 {
00047   ost_->write((const char*) dataPtr, dataSize);
00048   if (ost_->fail()) {
00049     throw cms::Exception("FRDEventFileWriter", "doOutputEventFragment")
00050       << "Error writing FED Raw Data event data to "
00051       << fileName_ << ".  Possibly the output disk "
00052       << "is full?" << std::endl;
00053   }
00054 
00055   ost_->flush();
00056   if (ost_->fail()) {
00057     throw cms::Exception("FRDEventFileWriter", "doOutputEventFragment")
00058       << "Error writing FED Raw Data event data to "
00059       << fileName_ << ".  Possibly the output disk "
00060       << "is full?" << std::endl;
00061   }
00062 
00063   cms::Adler32((const char*) dataPtr, dataSize, adlera_, adlerb_);
00064 }
00065 
00066 void FRDEventFileWriter::initialize(std::string const& name)
00067 {
00068   fileName_ = name;
00069   ost_.reset(new std::ofstream(name.c_str(), std::ios_base::binary | std::ios_base::out));
00070 
00071   if (!ost_->is_open()) {
00072     throw cms::Exception("FRDEventFileWriter","initialize")
00073       << "Error opening FED Raw Data event output file: " << name << "\n";
00074   }
00075 
00076   adlera_ = 1;
00077   adlerb_ = 0;
00078 }