FACT++  1.0
bool DataWriteRaw::Open ( const RUN_HEAD h,
const FAD::RunDescription &  d 
)
virtual

Implements DataProcessorImp.

Definition at line 21 of file DataWriteRaw.cc.

References Error(), RUN_HEAD::FADhead, i, and str.

22 {
23  const string name = FormFileName("bin");
24  if (access(name.c_str(), F_OK)==0)
25  {
26  Error("File '"+name+"' already exists.");
27  return false;
28  }
29 
30  fFileName = name;
31 
32  errno = 0;
33  fOut.open(name.c_str(), ios_base::out);
34  if (!fOut)
35  {
36  ostringstream str;
37  str << "ofstream::open() failed for '" << name << "': " << strerror(errno) << " [errno=" << errno << "]";
38  Error(str);
39 
40  return false;
41  }
42 
43  fCounter = 0;
44 
45  static uint32_t FACT = 0xFAC77e1e;
46 
47  fOut.write(reinterpret_cast<char*>(&FACT), 4);
48 
49  WriteBlockHeader(kIdentifier, 1, 0, 8);
50  WriteValue(uint32_t(0));
52 
53  WriteBlockHeader(kRunHeader, 1, 0, sizeof(RUN_HEAD)-sizeof(PEVNT_HEADER*));
54  fOut.write(reinterpret_cast<const char*>(&h), sizeof(RUN_HEAD)-sizeof(PEVNT_HEADER*));
55 
56  for (int i=0; i<40; i++)
57  {
58  WriteBlockHeader(kBoardHeader, 1, i, sizeof(PEVNT_HEADER));
59  fOut.write(reinterpret_cast<const char*>(h.FADhead+i), sizeof(PEVNT_HEADER));
60  }
61 
62  // FIXME: Split this
63  const vector<char> block(sizeof(uint32_t)/*+sizeof(RUN_TAIL)*/);
64  WriteBlockHeader(kRunSummary, 1, 0, block.size());
65 
66  fPosTail = fOut.tellp();
67  fOut.write(block.data(), block.size());
68 
69  if (!fOut)
70  {
71  ostringstream str;
72  str << "ofstream::write() failed for '" << name << "': " << strerror(errno) << " [errno=" << errno << "]";
73  Error(str);
74 
75  return false;
76  }
77 
78  return true;
79 }
std::ofstream fOut
Definition: DataWriteRaw.h:8
Namespace to help with some general things in the program initialization.
Definition: Prediction.h:8
int i
Definition: db_dim_client.c:21
char str[80]
Definition: test_client.c:7
uint32_t GetRunId() const
void WriteBlockHeader(uint32_t type, uint32_t ver, uint32_t cnt, uint32_t len)
Definition: DataWriteRaw.cc:8
off_t fPosTail
Definition: DataWriteRaw.h:10
std::string fFileName
Definition: FAD.h:92
int Error(const std::string &str)
Definition: MessageImp.h:49
void WriteValue(const T &t)
Definition: DataWriteRaw.cc:16
uint32_t fCounter
Definition: DataWriteRaw.h:12
PEVNT_HEADER FADhead[NBOARDS]
Definition: FAD.h:105
static std::string FormFileName(const std::string &path, uint64_t night, uint32_t runid, const std::string &extension)

+ Here is the call graph for this function: