MUSIC unknown
Analysis for the MUSIC active-target ionization chamber
Loading...
Searching...
No Matches
BinaryToRoot.cpp
Go to the documentation of this file.
1#include "BinaryToRoot.hpp"
2
3TString BinaryToRoot::HeaderFileName(Int_t run) {
4 return Form("DataR_run_%d.header", run);
5}
6
7void BinaryToRoot::WriteHeaderFile(Int_t run, UShort_t header) {
8 TString path = IO::GetRootFilesBaseDir() + "/" + HeaderFileName(run);
9 gSystem->mkdir(gSystem->DirName(path), kTRUE);
10 std::ofstream f(path.Data());
11 f << "0x" << std::hex << header << std::endl;
12}
13
14Bool_t BinaryToRoot::ReadHeaderFile(Int_t run, UShort_t &header) {
15 TString path = IO::GetRootFilesBaseDir() + "/" + HeaderFileName(run);
16 if (gSystem->AccessPathName(path))
17 return kFALSE;
18 std::ifstream f(path.Data());
19 std::string s;
20 f >> s;
21 if (s.empty())
22 return kFALSE;
23 header = static_cast<UShort_t>(std::stoul(s, nullptr, 0));
24 return kTRUE;
25}
static void WriteHeaderFile(Int_t run, UShort_t header)
Write a run's global header to its file.
static Bool_t ReadHeaderFile(Int_t run, UShort_t &header)
Read a run's global header back from its file.
static TString HeaderFileName(Int_t run)
Header filename for a run.