3 #include <boost/filesystem.hpp> 16 fFile = std::make_shared<ofits>();
24 fFile = std::shared_ptr<ofits>(file);
31 fFile->AddColumnInt(
"EventNum",
"uint32",
"FAD board event counter");
32 fFile->AddColumnInt(
"TriggerNum",
"uint32",
"FTM board trigger counter");
33 fFile->AddColumnShort(
"TriggerType",
"uint16",
"FTM board trigger type");
34 fFile->AddColumnInt(
"NumBoards",
"uint32",
"Number of connected boards");
35 fFile->AddColumnInt(2,
"UnixTimeUTC",
"uint32",
"Unix time seconds and microseconds");
36 fFile->AddColumnInt(
NBOARDS,
"BoardTime",
"uint32",
"Board internal time counter");
37 fFile->AddColumnShort(
NPIX,
"StartCellData",
"uint16",
"DRS4 start cell of readout");
38 fFile->AddColumnShort(
NTMARK,
"StartCellTimeMarker",
"uint16",
"DRS4 start cell of readout time marker");
40 vector<uint16_t> processing(2);
46 fFile->AddColumnShort(comp, h.
NPix*h.
Nroi,
"Data",
"int16",
"Digitized data");
47 fFile->AddColumnShort(comp, h.
NTm*realRoiTM,
"TimeMarker",
"int16",
"Digitized time marker - if available");
49 const size_t sz = (h.
NPix*h.
Nroi + h.
NTm*realRoiTM)*2;
50 if (
fFile->GetBytesPerRow()-sz+4!=
sizeof(EVENT))
53 str <<
"The EVENT structure size (" <<
sizeof(EVENT) <<
") doesn't match the described FITS row (";
54 str <<
fFile->GetBytesPerRow()-sz+4 <<
")";
55 throw runtime_error(str.str());
59 fFile->SetDefaultKeys();
65 fFile->SetInt(
"NBOARD", h.
NBoard,
"Number of acquisition boards");
66 fFile->SetInt(
"NPIX", h.
NPix,
"Number of pixels");
67 fFile->SetInt(
"NTMARK", h.
NTm,
"Number of time marker channels");
68 fFile->SetInt(
"NCELLS", 1024,
"Maximum number of slices per pixels");
69 fFile->SetInt(
"NROI", h.
Nroi,
"Number of slices per pixels");
70 fFile->SetInt(
"NROITM", realRoiTM,
"Number of slices per time-marker");
73 fFile->SetInt(
"TMSHIFT", realOffset,
"Shift of marker readout w.r.t. to data");
77 fFile->SetStr(
"CAMERA",
"MGeomCamFACT",
"MARS camera geometry class");
78 fFile->SetStr(
"DAQ",
"DRS4",
"Data acquisition type");
79 fFile->SetInt(
"ADCRANGE", 2000,
"Dynamic range in mV");
80 fFile->SetInt(
"ADC", 12,
"Resolution in bits");
81 fFile->SetStr(
"RUNTYPE", d.name,
"File type according to FAD configuration");
97 const PEVNT_HEADER &hh = h.
FADhead[
i];
100 sout <<
"Board " << setw(2) <<
i<<
": ";
102 const string num = to_string(i);
105 fFile->SetInt(
"ID"+num, hh.board_id, sout.str()+
"Board ID");
106 fFile->SetInt(
"FWVER"+num, hh.version_no, sout.str()+
"Firmware Version");
107 fFile->SetHex(
"DNA"+num, hh.DNA, sout.str()+
"Unique FPGA device identifier (DNA)");
113 const PEVNT_HEADER &hh = h.
FADhead[
i];
114 if (hh.start_package_flag==0)
117 fFile->SetInt(
"BOARD",
i,
"Board number for RUN, PRESC, PHASE and DAC");
118 fFile->SetInt(
"PRESC", hh.trigger_generator_prescaler,
"Trigger generator prescaler");
119 fFile->SetInt(
"PHASE", (int16_t)hh.adc_clock_phase_shift,
"ADC clock phase shift");
121 for (
int j=0; j<8; j++)
123 ostringstream dac, cmt;
125 cmt <<
"Command value for " << dac.str();
126 fFile->SetInt(dac.str(), hh.dac[j], cmt.str());
136 const PEVNT_HEADER &hh = h.
FADhead[
i];
138 if (hh.start_package_flag==0)
141 avg += hh.REFCLK_frequency;
146 fFile->SetFloat(
"REFCLK", avg/cnt*2.048,
"Average reference clock frequency in Hz");
148 fFile->SetBool(
"DRSCALIB",
GetDrsStep()>=0,
"This file belongs to a DRS calibration");
162 fFile->WriteTableHeader(
"Events");
176 if (boost::filesystem::exists(
fFileName))
189 const uint32_t ntime = d.maxtime*100/nrpt;
193 const uint32_t nevts = d.maxevt/nrpt+1;
209 catch (
const exception &e)
218 str <<
"ofstream::open() failed for '" <<
fFileName <<
"': " << strerror(errno) <<
" [errno=" << errno <<
"]";
227 catch (
const exception &e)
229 Error(
"ofits - Writing header failed for '"+
fFileName+
"': "+e.what());
236 str <<
"ofstream::write() failed for '" <<
fFileName <<
"': " << strerror(errno) <<
" [errno=" << errno <<
"]";
258 const EVENT &e = *evt.
fEvent;
260 const int realRoiTM = (e.RoiTM > e.Roi) ? e.Roi : 0;
261 const size_t sz =
sizeof(EVENT) +
sizeof(e.StartPix)*e.Roi+
sizeof(e.StartTM)*realRoiTM;
265 fFile->WriteRow(reinterpret_cast<const char*>(&e)+4, sz-4);
267 catch (
const exception &ex)
276 str <<
"fstream::write() failed for '" <<
fFileName <<
"': " << strerror(errno) <<
" [errno=" << errno <<
"]";
293 "Time when first evt received (integral part)");
295 "Time when first evt received (fractional part)");
297 "Time when last evt received (integral part)");
299 "Time when last evt received (fractional part)");
300 fFile->SetStr(
"DATE-OBS", start.
Iso(),
301 "Time when first event received");
302 fFile->SetStr(
"DATE-END", stop.
Iso(),
303 "Time when last event received");
322 if (!
fFile->is_open())
324 Error(
"DataWriteFits2::Close() called but file '"+
fFileName+
"' not open.");
332 catch (
const exception &e)
334 Error(
"ofits - Setting footer key values failed for '"+
fFileName+
"': "+e.what());
342 catch (
const exception &e)
351 str <<
"ofstream::close() failed for '" <<
fFileName <<
"': " << strerror(errno) <<
" [errno=" << errno <<
"]";
The base implementation of a distributed messaging system.
Adds some functionality to boost::posix_time::ptime for our needs.
uint32_t GetRunId() const
std::shared_ptr< ofits > fFile
bool WriteEvt(const EVT_CTRL2 &e)
static uint32_t DefaultMaxNumTiles(const uint32_t &_n=0)
void WriteHeader(const RUN_HEAD &h, const FAD::RunDescription &d)
void SetDrsCalibration(const std::vector< float > &calib)
assign a given drs offset calibration
bool Open(const RUN_HEAD &h, const FAD::RunDescription &d)
std::array< uint32_t, 8 > fTriggerCounter
int Error(const std::string &str)
uint32_t GetNight() const
virtual int GetDrsStep() const
void SetNumTiles(uint32_t num)
static uint32_t DefaultNumRowsPerTile(const uint32_t &_n=0)
std::array< uint32_t, 8 > triggerCounter
DataWriteFits2(const std::string path, uint64_t night, uint32_t runid, MessageImp &imp)
PEVNT_HEADER FADhead[NBOARDS]
bool Close(const EVT_CTRL2 &)
static std::string FormFileName(const std::string &path, uint64_t night, uint32_t runid, const std::string &extension)