Changeset 17231


Ignore:
Timestamp:
10/17/13 15:06:42 (11 years ago)
Author:
tbretz
Message:
Moved the implementation of the output file from a data memember to a shared_ptr. If a DrsCalibration is given in the constructor, a factfits object is created instead of a ofits object to compress the file; Moved WriteDefaultKeys to ofits, to make it usuable in Mars as well
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/DataWriteFits2.cc

    r16585 r17231  
    66#include "FAD.h"
    77
     8#include "externals/factofits.h"
     9#include "externals/DrsCalib.h"
     10
    811using namespace std;
    912
    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)");
     13DataWriteFits2::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
     19DataWriteFits2::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);
    2625}
    2726
     
    3029    const int16_t realRoiTM = (h.NroiTM >= 2*h.Nroi && h.Nroi<=512) ? h.Nroi : 0;
    3130
    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");
    4248
    4349    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))
    4551    {
    4652        ostringstream str;
    4753        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 << ")";
    4955        throw runtime_error(str.str());
    5056    }
    5157
    5258    // =============== Default keys for all files ================
    53     WriteDefaultKeys(fFile);
     59    fFile->SetDefaultKeys();
     60    fFile->SetInt("NIGHT", GetNight(), "Night as int");
    5461
    5562    // ================ 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");
    6471
    6572    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");
    6774
    6875    //FIXME should we also put the start and stop time of the received data ?
    6976    //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");
    7582
    7683    // Write a single key for:
     
    8289    // Prescaler
    8390
    84     // Write 40 kays for (?)
     91    // Write 40 keys for (?)
    8592    // Phaseshift
    8693    // DAC
     
    93100        sout << "Board " << setw(2) << i<< ": ";
    94101
     102        const string num = to_string(i);
     103
    95104        // 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)");
    99108    }
    100109
     
    103112    {
    104113        const PEVNT_HEADER &hh = h.FADhead[i];
    105 
    106114        if (hh.start_package_flag==0)
    107115            continue;
    108116
    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");
    112120
    113121        for (int j=0; j<8; j++)
     
    116124            dac << "DAC" << j;
    117125            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());
    119127        }
    120128
     
    136144
    137145    // 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");
    141149    if (GetDrsStep()>=0)
    142         fFile.SetInt("DRSSTEP", GetDrsStep(), "Step of the DRS calibration");
     150        fFile->SetInt("DRSSTEP", GetDrsStep(), "Step of the DRS calibration");
    143151
    144152    fTstart[0] = h.RunTime;
     
    153161    WriteFooter(NULL);
    154162
    155     fFile.WriteTableHeader("Events");
     163    fFile->WriteTableHeader("Events");
    156164};
    157165
     
    165173{
    166174    //Form filename, based on runid and run-type
    167     fFileName = FormFileName("fits");
     175    fFileName = FormFileName(dynamic_pointer_cast<factofits>(fFile)?"fits.fz":"fits");
    168176
    169177    if (boost::filesystem::exists(fFileName))
     
    175183    try
    176184    {
    177         fFile.open(fFileName.c_str());
     185        fFile->open(fFileName.c_str());
    178186    }
    179187    catch (const exception &e)
     
    183191    }
    184192
    185     if (!fFile)
     193    if (!(*fFile))
    186194    {
    187195        ostringstream str;
     
    201209    }
    202210
    203     if (!fFile)
     211    if (!(*fFile))
    204212    {
    205213        ostringstream str;
     
    244252    try
    245253    {
    246         fFile.WriteRow(reinterpret_cast<const char*>(&e)+4, sz-4);
     254        fFile->WriteRow(reinterpret_cast<const char*>(&e)+4, sz-4);
    247255    }
    248256    catch (const exception &ex)
     
    252260    }
    253261
    254     if (!fFile)
     262    if (!(*fFile))
    255263    {
    256264        ostringstream str;
     
    271279    const Time stop (fTstop[0],  fTstop[1]);
    272280
    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");
    294302}
    295303
     
    301309bool DataWriteFits2::Close(const RUN_TAIL *rt)
    302310{
    303     if (!fFile.is_open())
     311    if (!fFile->is_open())
    304312    {
    305313        Error("DataWriteFits2::Close() called but file '"+fFileName+"' not open.");
     
    319327    try
    320328    {
    321         fFile.close();
     329        fFile->close();
    322330    }
    323331    catch (const exception &e)
     
    327335    }
    328336
    329     if (!fFile)
     337    if (!(*fFile))
    330338    {
    331339        ostringstream str;
  • trunk/FACT++/src/DataWriteFits2.h

    r16055 r17231  
    33
    44#include "DataProcessorImp.h"
    5 #include "externals/ofits.h"
    65
    76#include <array>
    87
     8namespace std
     9{
     10    class ofits;
     11}
     12
     13class DrsCalibration;
     14
    915class DataWriteFits2 : public DataProcessorImp
    1016{
    11     std::ofits fFile;
     17    std::shared_ptr<std::ofits> fFile;
    1218
    1319    std::array<uint32_t, 8> fTriggerCounter;
     
    2228
    2329public:
    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);
    2832
    2933    bool Open(const RUN_HEAD &h, const FAD::RunDescription &d);
     
    3337    Time GetTstart() const { return Time(fTstart[0], fTstart[1]); }
    3438    Time GetTstop() const  { return Time(fTstop[0],  fTstop[1]);  }
    35 
    36     static void WriteDefaultKeys(std::ofits &file);
    3739};
    3840
Note: See TracChangeset for help on using the changeset viewer.