CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FRDEventFileWriter.cc
Go to the documentation of this file.
1 // $Id: FRDEventFileWriter.cc,v 1.3 2010/02/18 09:19:02 mommsen Exp $
2 
6 #include <iostream>
7 
9 {
10  initialize(ps.getUntrackedParameter<std::string>("fileName", "testFRDfile.dat"));
11 }
12 
14 {
15  initialize(fileName);
16 }
17 
19 {
20  ost_->close();
21 }
22 
24 {
25  ost_->write((const char*) msg.startAddress(), msg.size());
26  if (ost_->fail()) {
27  throw cms::Exception("FRDEventFileWriter", "doOutputEvent")
28  << "Error writing FED Raw Data event data to "
29  << fileName_ << ". Possibly the output disk "
30  << "is full?" << std::endl;
31  }
32 
33  ost_->flush();
34  if (ost_->fail()) {
35  throw cms::Exception("FRDEventFileWriter", "doOutputEvent")
36  << "Error writing FED Raw Data event data to "
37  << fileName_ << ". Possibly the output disk "
38  << "is full?" << std::endl;
39  }
40 
41  cms::Adler32((const char*) msg.startAddress(), msg.size(), adlera_, adlerb_);
42 }
43 
44 void FRDEventFileWriter::doOutputEventFragment(unsigned char* dataPtr,
45  unsigned long dataSize)
46 {
47  ost_->write((const char*) dataPtr, dataSize);
48  if (ost_->fail()) {
49  throw cms::Exception("FRDEventFileWriter", "doOutputEventFragment")
50  << "Error writing FED Raw Data event data to "
51  << fileName_ << ". Possibly the output disk "
52  << "is full?" << std::endl;
53  }
54 
55  ost_->flush();
56  if (ost_->fail()) {
57  throw cms::Exception("FRDEventFileWriter", "doOutputEventFragment")
58  << "Error writing FED Raw Data event data to "
59  << fileName_ << ". Possibly the output disk "
60  << "is full?" << std::endl;
61  }
62 
63  cms::Adler32((const char*) dataPtr, dataSize, adlera_, adlerb_);
64 }
65 
66 void FRDEventFileWriter::initialize(std::string const& name)
67 {
68  fileName_ = name;
69  ost_.reset(new std::ofstream(name.c_str(), std::ios_base::binary | std::ios_base::out));
70 
71  if (!ost_->is_open()) {
72  throw cms::Exception("FRDEventFileWriter","initialize")
73  << "Error opening FED Raw Data event output file: " << name << "\n";
74  }
75 
76  adlera_ = 1;
77  adlerb_ = 0;
78 }
T getUntrackedParameter(std::string const &, T const &) const
FRDEventFileWriter(edm::ParameterSet const &ps)
std::auto_ptr< std::ofstream > ost_
uint32 size() const
void doOutputEventFragment(unsigned char *dataPtr, unsigned long dataSize)
uint8 * startAddress() const
void initialize(std::string const &name)
tuple out
Definition: dbtoconf.py:99
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
void doOutputEvent(FRDEventMsgView const &msg)