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

DataWriteFits constructor. This is the one that should be used, not the default one (parameter-less)

Parameters
runidThis parameter should probably be removed. I first thought it was the run number, but apparently it is not
ha pointer to the RUN_HEAD structure that contains the informations relative to this run

Implements DataProcessorImp.

Definition at line 39 of file DataWriteFits.cc.

References Error(), RUN_HEAD::FADhead, fTriggerCounter, i, RUN_HEAD::NBoard, NBOARDS, NPIX, RUN_HEAD::NPix, RUN_HEAD::Nroi, RUN_HEAD::NroiTM, RUN_HEAD::NTm, NTMARK, RUN_HEAD::RunTime, RUN_HEAD::RunUsec, str, Converter::ToFormat(), and RUN_HEAD::Version.

Referenced by DataWriteFits().

40 {
41  if (fConv)
42  {
43  Error("DataWriteFits::Open called twice.");
44  return false;
45  }
46 
47  const int16_t realRoiTM = (h.NroiTM >= 2*h.Nroi && h.Nroi<=512) ? h.Nroi : 0;
48 
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);
61 
62  // Write length of physical pipeline (1024)
64 
65  const size_t sz = (h.NPix*h.Nroi + h.NTm*realRoiTM)*2;
66  if (fConv->GetSize()-sz+4!=sizeof(EVENT))
67  {
68  ostringstream str;
69  str << "The EVENT structure size (" << sizeof(EVENT) << ") doesn't match the described FITS row (";
70  str << fConv->GetSize()-sz+4 << ")";
71  Error(str);
72  return false;
73  }
74 
75  //Form filename, based on runid and run-type
76  fFileName = FormFileName("fits");
77 
78  if (!fFile.OpenFile(fFileName))
79  return false;
80 
81  if (!fFile.OpenTable("Events"))
82  return false;
83 
84  if (!fFile.WriteDefaultKeys("fadctrl"))
85  return false;
86 
87  Info("==> TODO: Write sampling frequency...");
88 
89  //write header data
90  //first the "standard" keys
91  try
92  {
93  fFile.WriteKey("BLDVER", h.Version, "Builder version");
94  fFile.WriteKey("RUNID", GetRunId(), "Run number");
95 // fFile.WriteKey("RUNTYPE", h.RunType, "Type of run");
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");
102 
103  const uint16_t realOffset = (h.NroiTM > h.Nroi) ? h.NroiTM - 2*h.Nroi : 0;
104  fFile.WriteKey("TMSHIFT", realOffset, "Shift of the start of the time marker readout wrt to data");
105 
106  //FIXME should we also put the start and stop time of the received data ?
107  //now the events header related variables
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");
113 
114  // Write a single key for:
115  // -----------------------
116  // Start package flag
117  // package length
118  // version number
119  // status
120  // Prescaler
121 
122  // Write 40 kays for (?)
123  // Phaseshift
124  // DAC
125 
126  for (int i=0; i<h.NBoard; i++)
127  {
128  const PEVNT_HEADER &hh = h.FADhead[i];
129 
130  // Header values whihc won't change during the run
131  WriteKey("ID", i, hh.board_id, "Board ID");
132  WriteKey("FWVER", i, hh.version_no, "Firmware Version");
133 
134  ostringstream dna;
135  dna << "0x" << hex << hh.DNA;
136  WriteKey("DNA", i, dna.str(), "Unique FPGA device identifier (DNA)");
137  }
138 
139  // FIXME: Calculate average ref clock frequency
140  for (int i=0; i<h.NBoard; i++)
141  {
142  const PEVNT_HEADER &hh = h.FADhead[i];
143 
144  if (hh.start_package_flag==0)
145  continue;
146 
147  fFile.WriteKey("BOARD", i, "Board number for RUN, PRESC, PHASE and DAC");
148  // fFile.WriteKey("RUN", hh.runnumber, "Run number");
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");
151 
152  for (int j=0; j<8; j++)
153  {
154  ostringstream dac, cmt;
155  dac << "DAC" << j;
156  cmt << "Command value for " << dac.str();
157  fFile.WriteKey(dac.str(), hh.dac[j], cmt.str());
158  }
159 
160  break;
161  }
162 
163  double avg = 0;
164  int cnt = 0;
165  for (int i=0; i<h.NBoard; i++)
166  {
167  const PEVNT_HEADER &hh = h.FADhead[i];
168 
169  if (hh.start_package_flag==0)
170  continue;
171 
172  avg += hh.REFCLK_frequency;
173  cnt ++;
174  }
175 
176  // FIXME: I cannot write a double! WHY?
177  fFile.WriteKey("REFCLK", avg/cnt*2.048, "Average reference clock frequency in Hz");
178 
179  fFile.WriteKey("DRSCALIB", GetDrsStep()>=0, "This file belongs to a DRS calibration");
180  if (GetDrsStep()>=0)
181  fFile.WriteKey("DRSSTEP", GetDrsStep(), "Step of the DRS calibration");
182 
183  }
184  catch (const CCfits::FitsException &e)
185  {
186  Error("CCfits::Table::addKey failed in '"+fFileName+"': "+e.message());
187  return false;
188  }
189 
190  fTstart[0] = h.RunTime;
191  fTstart[1] = h.RunUsec;
192 
193  fTstop[0] = 0;
194  fTstop[1] = 0;
195 
196  fTriggerCounter.fill(0);
197 
198  //Last but not least, add header keys that will be updated when closing the file
199  return WriteFooter();
200 }
uint32_t RunTime
Definition: FAD.h:96
uint16_t NroiTM
Definition: FAD.h:102
uint16_t NTm
Definition: FAD.h:100
int i
Definition: db_dim_client.c:21
char str[80]
Definition: test_client.c:7
uint32_t GetRunId() const
uint32_t fTstop[2]
Definition: DataWriteFits.h:20
virtual int GetDrsStep() const
Definition: DataWriteFits.h:27
const std::vector< std::string > & GetColumnTypes() const
Definition: FitsFile.h:99
void WriteKey(const string &name, const T &value, const string &comment)
Definition: FitsFile.h:55
bool WriteDefaultKeys(const string &prgname, float version=1.0)
Definition: FitsFile.cc:21
void WriteKey(const string &name, const int idx, const T &value, const string &comment)
std::string fFileName
uint32_t Version
Definition: FAD.h:94
FitsFile fFile
Definition: DataWriteFits.h:15
#define NPIX
Definition: BasicGlCamera.h:5
int Error(const std::string &str)
Definition: MessageImp.h:49
bool OpenFile(const string &filename, bool allow_open=false)
Definition: FitsFile.cc:94
Converter * fConv
Definition: DataWriteFits.h:13
bool OpenTable(const string &tablename)
Definition: FitsFile.cc:159
uint16_t Nroi
Definition: FAD.h:101
uint16_t NBoard
Definition: FAD.h:98
#define NTMARK
Definition: BasicGlCamera.h:6
#define NBOARDS
Definition: BasicGlCamera.h:4
void AddColumn(char type, const string &name, int numElems=1, const string &unit="")
uint32_t RunUsec
Definition: FAD.h:97
static std::string ToFormat(const std::vector< std::string > &fits)
Definition: Converter.cc:1004
uint16_t NPix
Definition: FAD.h:99
uint32_t fTstart[2]
Definition: DataWriteFits.h:19
int Info(const std::string &str)
Definition: MessageImp.h:47
A compiler for the DIM data format string.
Definition: Converter.h:16
size_t GetSize() const
Definition: Converter.h:89
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)
std::array< uint32_t, 8 > fTriggerCounter
Definition: DataWriteFits.h:17

+ Here is the call graph for this function:

+ Here is the caller graph for this function: