28 com <<
"Board " << setw(2) << idx <<
": " << comment;
30 fFile.WriteKey(str.str(), value, com.str());
43 Error(
"DataWriteFits::Open called twice.");
49 fFile.AddColumn(
'I',
"EventNum");
50 fFile.AddColumn(
'I',
"TriggerNum");
51 fFile.AddColumn(
'S',
"TriggerType");
52 fFile.AddColumn(
'I',
"NumBoards");
53 fFile.AddColumn(
'C',
"Errors", 4);
54 fFile.AddColumn(
'I',
"SoftTrig");
55 fFile.AddColumn(
'I',
"UnixTimeUTC", 2);
56 fFile.AddColumn(
'I',
"BoardTime",
NBOARDS);
57 fFile.AddColumn(
'S',
"StartCellData",
NPIX);
58 fFile.AddColumn(
'S',
"StartCellTimeMarker",
NTMARK);
59 fFile.AddColumn(
'S',
"Data", h.
NPix*h.
Nroi);
60 fFile.AddColumn(
'S',
"TimeMarker", h.
NTm*realRoiTM);
65 const size_t sz = (h.
NPix*h.
Nroi + h.
NTm*realRoiTM)*2;
66 if (fConv->GetSize()-sz+4!=
sizeof(EVENT))
69 str <<
"The EVENT structure size (" <<
sizeof(EVENT) <<
") doesn't match the described FITS row (";
70 str << fConv->GetSize()-sz+4 <<
")";
76 fFileName = FormFileName(
"fits");
78 if (!fFile.OpenFile(fFileName))
81 if (!fFile.OpenTable(
"Events"))
84 if (!fFile.WriteDefaultKeys(
"fadctrl"))
87 Info(
"==> TODO: Write sampling frequency...");
93 fFile.WriteKey(
"BLDVER", h.
Version,
"Builder version");
94 fFile.WriteKey(
"RUNID", GetRunId(),
"Run number");
96 fFile.WriteKey(
"NBOARD", h.
NBoard,
"Number of acquisition boards");
97 fFile.WriteKey(
"NPIX", h.
NPix,
"Number of pixels");
98 fFile.WriteKey(
"NTMARK", h.
NTm,
"Number of time marker channels");
99 fFile.WriteKey(
"NCELLS", 1024,
"Maximum number of slices per pixels");
100 fFile.WriteKey(
"NROI", h.
Nroi,
"Number of slices per pixels");
101 fFile.WriteKey(
"NROITM", realRoiTM,
"Number of slices per time-marker");
104 fFile.WriteKey(
"TMSHIFT", realOffset,
"Shift of the start of the time marker readout wrt to data");
108 fFile.WriteKey(
"CAMERA",
"MGeomCamFACT",
"");
109 fFile.WriteKey(
"DAQ",
"DRS4",
"");
110 fFile.WriteKey(
"ADCRANGE", 2000,
"Dynamic range in mV");
111 fFile.WriteKey(
"ADC", 12,
"Resolution in bits");
112 fFile.WriteKey(
"RUNTYPE", d.name,
"File type according to FAD configuration");
128 const PEVNT_HEADER &hh = h.
FADhead[
i];
131 WriteKey(
"ID",
i, hh.board_id,
"Board ID");
132 WriteKey(
"FWVER",
i, hh.version_no,
"Firmware Version");
135 dna <<
"0x" << hex << hh.DNA;
136 WriteKey(
"DNA",
i, dna.str(),
"Unique FPGA device identifier (DNA)");
142 const PEVNT_HEADER &hh = h.
FADhead[
i];
144 if (hh.start_package_flag==0)
147 fFile.WriteKey(
"BOARD",
i,
"Board number for RUN, PRESC, PHASE and DAC");
149 fFile.WriteKey(
"PRESC", hh.trigger_generator_prescaler,
"Trigger generator prescaler");
150 fFile.WriteKey(
"PHASE", (int16_t)hh.adc_clock_phase_shift,
"ADC clock phase shift");
152 for (
int j=0; j<8; j++)
154 ostringstream dac, cmt;
156 cmt <<
"Command value for " << dac.str();
157 fFile.WriteKey(dac.str(), hh.dac[j], cmt.str());
167 const PEVNT_HEADER &hh = h.
FADhead[
i];
169 if (hh.start_package_flag==0)
172 avg += hh.REFCLK_frequency;
177 fFile.WriteKey(
"REFCLK", avg/cnt*2.048,
"Average reference clock frequency in Hz");
179 fFile.WriteKey(
"DRSCALIB", GetDrsStep()>=0,
"This file belongs to a DRS calibration");
181 fFile.WriteKey(
"DRSSTEP", GetDrsStep(),
"Step of the DRS calibration");
184 catch (
const CCfits::FitsException &e)
186 Error(
"CCfits::Table::addKey failed in '"+fFileName+
"': "+e.message());
199 return WriteFooter();
216 fTstop[0] = evt.
time.tv_sec;
217 fTstop[1] = evt.
time.tv_usec;
219 const EVENT &e = *evt.
fEvent;
221 const int realRoiTM = (e.RoiTM > e.Roi) ? e.Roi : 0;
222 const size_t sz =
sizeof(EVENT) +
sizeof(e.StartPix)*e.Roi+
sizeof(e.StartTM)*realRoiTM;
224 const vector<char>
data = fConv->ToFits(reinterpret_cast<const char*>(&e)+4, sz-4);
226 return fFile.WriteData(data.data(), data.size());
247 const Time start(fTstart[0], fTstart[1]);
248 const Time stop (fTstop[0], fTstop[1]);
250 fFile.WriteKey(
"TSTARTI", uint32_t(floor(start.
UnixDate())),
251 "Time when first event received (integral part)");
252 fFile.WriteKey(
"TSTARTF", fmod(start.
UnixDate(), 1),
253 "Time when first event received (fractional part)");
254 fFile.WriteKey(
"TSTOPI", uint32_t(floor(stop.
UnixDate())),
255 "Time when last event received (integral part)");
256 fFile.WriteKey(
"TSTOPF", fmod(stop.
UnixDate(), 1),
257 "Time when last event received (fractional part)");
258 fFile.WriteKey(
"DATE-OBS", start.
Iso(),
259 "Time when first event received");
260 fFile.WriteKey(
"DATE-END", stop.
Iso(),
261 "Time when last event received");
263 fFile.WriteKey(
"NTRG",
fTriggerCounter[0],
"No of physics triggered events");
264 fFile.WriteKey(
"NTRGPED",
fTriggerCounter[1],
"No of pure pedestal triggered events");
265 fFile.WriteKey(
"NTRGLPE",
fTriggerCounter[2],
"No of external light pulser triggered events");
266 fFile.WriteKey(
"NTRGTIM",
fTriggerCounter[3],
"No of time calibration triggered events");
267 fFile.WriteKey(
"NTRGLPI",
fTriggerCounter[4],
"No of internal light pulser triggered events");
268 fFile.WriteKey(
"NTRGEXT1",
fTriggerCounter[5],
"No of triggers from ext1 triggered events");
269 fFile.WriteKey(
"NTRGEXT2",
fTriggerCounter[6],
"No of triggers from ext2 triggered events");
270 fFile.WriteKey(
"NTRGMISC",
fTriggerCounter[7],
"No of all other triggered events");
272 catch (
const CCfits::FitsException &e)
274 Error(
"CCfits::Table::addKey failed in '"+fFile.GetName()+
"': "+e.message());
Adds some functionality to boost::posix_time::ptime for our needs.
bool Close(const EVT_CTRL2 &)
void WriteKey(const string &name, const int idx, const T &value, const string &comment)
bool Open(const RUN_HEAD &h, const FAD::RunDescription &d)
static std::string ToFormat(const std::vector< std::string > &fits)
std::array< uint32_t, 8 > triggerCounter
bool WriteEvt(const EVT_CTRL2 &)
A compiler for the DIM data format string.
PEVNT_HEADER FADhead[NBOARDS]