Changeset 17231
- Timestamp:
- 10/17/13 15:06:42 (11 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/DataWriteFits2.cc
r16585 r17231 6 6 #include "FAD.h" 7 7 8 #include "externals/factofits.h" 9 #include "externals/DrsCalib.h" 10 8 11 using namespace std; 9 12 10 void DataWriteFits2::WriteDefaultKeys(ofits &file) 11 { 12 const Time now; 13 file.SetStr( "TELESCOP", "FACT", "Telescope that acquired this data"); 14 file.SetStr( "PACKAGE", PACKAGE_NAME, "Package name"); 15 file.SetStr( "VERSION", PACKAGE_VERSION, "Package description"); 16 file.SetStr( "CREATOR", "fadctrl", "Program that wrote this file"); 17 file.SetFloat("EXTREL", 1.0, "Release Number"); 18 file.SetStr( "COMPILED", __DATE__" "__TIME__, "Compile time"); 19 file.SetStr( "REVISION", REVISION, "SVN revision"); 20 file.SetStr( "ORIGIN", "FACT", "Institution that wrote the file"); 21 file.SetStr( "DATE", now.Iso(), "File creation date"); 22 file.SetInt( "NIGHT", now.NightAsInt(), "Night as int"); 23 file.SetStr( "TIMESYS", "UTC", "Time system"); 24 file.SetStr( "TIMEUNIT", "d", "Time given in days w.r.t. to MJDREF"); 25 file.SetInt( "MJDREF", 40587, "MJD to UNIX time (seconds since 1970/1/1)"); 13 DataWriteFits2::DataWriteFits2(const std::string path, uint64_t night, uint32_t runid, MessageImp &imp) 14 : DataProcessorImp(path, night, runid, imp) 15 { 16 fFile = std::make_shared<std::ofits>(); 17 } 18 19 DataWriteFits2::DataWriteFits2(const std::string path, uint64_t night, uint32_t runid, const DrsCalibration &cal, MessageImp &imp) 20 : DataProcessorImp(path, night, runid, imp) 21 { 22 factofits *file = new factofits; 23 file->SetDrsCalibration(cal); 24 fFile = std::shared_ptr<std::ofits>(file); 26 25 } 27 26 … … 30 29 const int16_t realRoiTM = (h.NroiTM >= 2*h.Nroi && h.Nroi<=512) ? h.Nroi : 0; 31 30 32 fFile.AddColumnInt("EventNum", "uint32", "FAD board event counter"); 33 fFile.AddColumnInt("TriggerNum", "uint32", "FTM board trigger counter"); 34 fFile.AddColumnShort("TriggerType", "uint16", "FTM board trigger type"); 35 fFile.AddColumnInt("NumBoards", "uint32", "Number of connected boards"); 36 fFile.AddColumnInt(2, "UnixTimeUTC", "uint32", "Unix time seconds and microseconds"); 37 fFile.AddColumnInt(NBOARDS, "BoardTime", "uint32", "Board internal time counter"); 38 fFile.AddColumnShort(NPIX, "StartCellData", "uint16", "DRS4 start cell of readout"); 39 fFile.AddColumnShort(NTMARK, "StartCellTimeMarker", "uint16", "DRS4 start cell of readout time marker"); 40 fFile.AddColumnShort(h.NPix*h.Nroi, "Data", "int16", "Digitized data"); 41 fFile.AddColumnShort(h.NTm*realRoiTM, "TimeMarker", "int16", "Digitized time marker - if available"); 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"); 39 40 vector<uint16_t> processing(2); 41 processing[0] = FITS::kFactSmoothing; 42 processing[1] = FITS::kFactHuffman16; 43 44 const Compression comp(processing, FITS::kOrderByRow); 45 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"); 42 48 43 49 const size_t sz = (h.NPix*h.Nroi + h.NTm*realRoiTM)*2; 44 if (fFile .GetBytesPerRow()-sz+4!=sizeof(EVENT))50 if (fFile->GetBytesPerRow()-sz+4!=sizeof(EVENT)) 45 51 { 46 52 ostringstream str; 47 53 str << "The EVENT structure size (" << sizeof(EVENT) << ") doesn't match the described FITS row ("; 48 str << fFile .GetBytesPerRow()-sz+4 << ")";54 str << fFile->GetBytesPerRow()-sz+4 << ")"; 49 55 throw runtime_error(str.str()); 50 56 } 51 57 52 58 // =============== Default keys for all files ================ 53 WriteDefaultKeys(fFile); 59 fFile->SetDefaultKeys(); 60 fFile->SetInt("NIGHT", GetNight(), "Night as int"); 54 61 55 62 // ================ Header keys for raw-data ================= 56 fFile .SetInt("BLDVER", h.Version, "Builder version");57 fFile .SetInt("RUNID", GetRunId(), "Run number");58 fFile .SetInt("NBOARD", h.NBoard, "Number of acquisition boards");59 fFile .SetInt("NPIX", h.NPix, "Number of pixels");60 fFile .SetInt("NTMARK", h.NTm, "Number of time marker channels");61 fFile .SetInt("NCELLS", 1024, "Maximum number of slices per pixels");62 fFile .SetInt("NROI", h.Nroi, "Number of slices per pixels");63 fFile .SetInt("NROITM", realRoiTM, "Number of slices per time-marker");63 fFile->SetInt("BLDVER", h.Version, "Builder version"); 64 fFile->SetInt("RUNID", GetRunId(), "Run number"); 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"); 64 71 65 72 const uint16_t realOffset = (h.NroiTM > h.Nroi) ? h.NroiTM - 2*h.Nroi : 0; 66 fFile .SetInt("TMSHIFT", realOffset, "Shift of marker readout w.r.t. to data");73 fFile->SetInt("TMSHIFT", realOffset, "Shift of marker readout w.r.t. to data"); 67 74 68 75 //FIXME should we also put the start and stop time of the received data ? 69 76 //now the events header related variables 70 fFile .SetStr("CAMERA", "MGeomCamFACT", "MARS camera geometry class");71 fFile .SetStr("DAQ", "DRS4", "Data acquisition type");72 fFile .SetInt("ADCRANGE", 2000, "Dynamic range in mV");73 fFile .SetInt("ADC", 12, "Resolution in bits");74 fFile .SetStr("RUNTYPE", d.name, "File type according to FAD configuration");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"); 75 82 76 83 // Write a single key for: … … 82 89 // Prescaler 83 90 84 // Write 40 k ays for (?)91 // Write 40 keys for (?) 85 92 // Phaseshift 86 93 // DAC … … 93 100 sout << "Board " << setw(2) << i<< ": "; 94 101 102 const string num = to_string(i); 103 95 104 // Header values whihc won't change during the run 96 fFile .SetInt("ID", hh.board_id, sout.str()+"Board ID");97 fFile .SetInt("FWVER", hh.version_no, sout.str()+"Firmware Version");98 fFile .SetHex("DNA", hh.DNA, sout.str()+"Unique FPGA device identifier (DNA)");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)"); 99 108 } 100 109 … … 103 112 { 104 113 const PEVNT_HEADER &hh = h.FADhead[i]; 105 106 114 if (hh.start_package_flag==0) 107 115 continue; 108 116 109 fFile .SetInt("BOARD", i, "Board number for RUN, PRESC, PHASE and DAC");110 fFile .SetInt("PRESC", hh.trigger_generator_prescaler, "Trigger generator prescaler");111 fFile .SetInt("PHASE", (int16_t)hh.adc_clock_phase_shift, "ADC clock phase shift");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"); 112 120 113 121 for (int j=0; j<8; j++) … … 116 124 dac << "DAC" << j; 117 125 cmt << "Command value for " << dac.str(); 118 fFile .SetInt(dac.str(), hh.dac[j], cmt.str());126 fFile->SetInt(dac.str(), hh.dac[j], cmt.str()); 119 127 } 120 128 … … 136 144 137 145 // FIXME: I cannot write a double! WHY? 138 fFile .SetFloat("REFCLK", avg/cnt*2.048, "Average reference clock frequency in Hz");139 140 fFile .SetBool("DRSCALIB", GetDrsStep()>=0, "This file belongs to a DRS calibration");146 fFile->SetFloat("REFCLK", avg/cnt*2.048, "Average reference clock frequency in Hz"); 147 148 fFile->SetBool("DRSCALIB", GetDrsStep()>=0, "This file belongs to a DRS calibration"); 141 149 if (GetDrsStep()>=0) 142 fFile .SetInt("DRSSTEP", GetDrsStep(), "Step of the DRS calibration");150 fFile->SetInt("DRSSTEP", GetDrsStep(), "Step of the DRS calibration"); 143 151 144 152 fTstart[0] = h.RunTime; … … 153 161 WriteFooter(NULL); 154 162 155 fFile .WriteTableHeader("Events");163 fFile->WriteTableHeader("Events"); 156 164 }; 157 165 … … 165 173 { 166 174 //Form filename, based on runid and run-type 167 fFileName = FormFileName( "fits");175 fFileName = FormFileName(dynamic_pointer_cast<factofits>(fFile)?"fits.fz":"fits"); 168 176 169 177 if (boost::filesystem::exists(fFileName)) … … 175 183 try 176 184 { 177 fFile .open(fFileName.c_str());185 fFile->open(fFileName.c_str()); 178 186 } 179 187 catch (const exception &e) … … 183 191 } 184 192 185 if (! fFile)193 if (!(*fFile)) 186 194 { 187 195 ostringstream str; … … 201 209 } 202 210 203 if (! fFile)211 if (!(*fFile)) 204 212 { 205 213 ostringstream str; … … 244 252 try 245 253 { 246 fFile .WriteRow(reinterpret_cast<const char*>(&e)+4, sz-4);254 fFile->WriteRow(reinterpret_cast<const char*>(&e)+4, sz-4); 247 255 } 248 256 catch (const exception &ex) … … 252 260 } 253 261 254 if (! fFile)262 if (!(*fFile)) 255 263 { 256 264 ostringstream str; … … 271 279 const Time stop (fTstop[0], fTstop[1]); 272 280 273 fFile .SetInt("TSTARTI", uint32_t(floor(start.UnixDate())),274 "Time when first evt received (integral part)");275 fFile .SetFloat("TSTARTF", fmod(start.UnixDate(), 1),276 "Time when first evt received (fractional part)");277 fFile .SetInt("TSTOPI", uint32_t(floor(stop.UnixDate())),278 "Time when last evt received (integral part)");279 fFile .SetFloat("TSTOPF", fmod(stop.UnixDate(), 1),280 "Time when last evt received (fractional part)");281 fFile .SetStr("DATE-OBS", start.Iso(),282 "Time when first event received");283 fFile .SetStr("DATE-END", stop.Iso(),284 "Time when last event received");285 286 fFile .SetInt("NTRG", fTriggerCounter[0], "No of physics triggers written");287 fFile .SetInt("NTRGPED", fTriggerCounter[1], "No of pure pedestal triggers written");288 fFile .SetInt("NTRGLPE", fTriggerCounter[2], "No of external light pulser triggers written");289 fFile .SetInt("NTRGTIM", fTriggerCounter[3], "No of time calibration triggers written");290 fFile .SetInt("NTRGLPI", fTriggerCounter[4], "No of internal light pulser triggers written");291 fFile .SetInt("NTRGEXT1", fTriggerCounter[5], "No of triggers from ext1 written");292 fFile .SetInt("NTRGEXT2", fTriggerCounter[6], "No of triggers from ext2 written");293 fFile .SetInt("NTRGMISC", fTriggerCounter[7], "No of all other triggers");281 fFile->SetInt("TSTARTI", uint32_t(floor(start.UnixDate())), 282 "Time when first evt received (integral part)"); 283 fFile->SetFloat("TSTARTF", fmod(start.UnixDate(), 1), 284 "Time when first evt received (fractional part)"); 285 fFile->SetInt("TSTOPI", uint32_t(floor(stop.UnixDate())), 286 "Time when last evt received (integral part)"); 287 fFile->SetFloat("TSTOPF", fmod(stop.UnixDate(), 1), 288 "Time when last evt received (fractional part)"); 289 fFile->SetStr("DATE-OBS", start.Iso(), 290 "Time when first event received"); 291 fFile->SetStr("DATE-END", stop.Iso(), 292 "Time when last event received"); 293 294 fFile->SetInt("NTRG", fTriggerCounter[0], "No of physics triggers written"); 295 fFile->SetInt("NTRGPED", fTriggerCounter[1], "No of pure pedestal triggers written"); 296 fFile->SetInt("NTRGLPE", fTriggerCounter[2], "No of external light pulser triggers written"); 297 fFile->SetInt("NTRGTIM", fTriggerCounter[3], "No of time calibration triggers written"); 298 fFile->SetInt("NTRGLPI", fTriggerCounter[4], "No of internal light pulser triggers written"); 299 fFile->SetInt("NTRGEXT1", fTriggerCounter[5], "No of triggers from ext1 written"); 300 fFile->SetInt("NTRGEXT2", fTriggerCounter[6], "No of triggers from ext2 written"); 301 fFile->SetInt("NTRGMISC", fTriggerCounter[7], "No of all other triggers"); 294 302 } 295 303 … … 301 309 bool DataWriteFits2::Close(const RUN_TAIL *rt) 302 310 { 303 if (!fFile .is_open())311 if (!fFile->is_open()) 304 312 { 305 313 Error("DataWriteFits2::Close() called but file '"+fFileName+"' not open."); … … 319 327 try 320 328 { 321 fFile .close();329 fFile->close(); 322 330 } 323 331 catch (const exception &e) … … 327 335 } 328 336 329 if (! fFile)337 if (!(*fFile)) 330 338 { 331 339 ostringstream str; -
trunk/FACT++/src/DataWriteFits2.h
r16055 r17231 3 3 4 4 #include "DataProcessorImp.h" 5 #include "externals/ofits.h"6 5 7 6 #include <array> 8 7 8 namespace std 9 { 10 class ofits; 11 } 12 13 class DrsCalibration; 14 9 15 class DataWriteFits2 : public DataProcessorImp 10 16 { 11 std:: ofitsfFile;17 std::shared_ptr<std::ofits> fFile; 12 18 13 19 std::array<uint32_t, 8> fTriggerCounter; … … 22 28 23 29 public: 24 DataWriteFits2(const std::string path, uint64_t night, uint32_t runid, MessageImp &imp) : 25 DataProcessorImp(path, night, runid, imp) 26 { 27 } 30 DataWriteFits2(const std::string path, uint64_t night, uint32_t runid, MessageImp &imp); 31 DataWriteFits2(const std::string path, uint64_t night, uint32_t runid, const DrsCalibration &cal, MessageImp &imp); 28 32 29 33 bool Open(const RUN_HEAD &h, const FAD::RunDescription &d); … … 33 37 Time GetTstart() const { return Time(fTstart[0], fTstart[1]); } 34 38 Time GetTstop() const { return Time(fTstop[0], fTstop[1]); } 35 36 static void WriteDefaultKeys(std::ofits &file);37 39 }; 38 40
Note:
See TracChangeset
for help on using the changeset viewer.