コード例 #1
0
Compartment_Report_Binary_File_Reader::Compartment_Report_Binary_File_Reader
(const Report_Specification & specs)
    : _sequence_start_frame(0),
      _frame_counter(0),
      _frame_skip(1.0f),
      _current_frame(UNDEFINED_FRAME_NUMBER)
{
    static Report_Specialization_Register<
               Compartment_Report_Binary_File_Reader,
               float
           > register_float_buffer;

    
    namespace fs = boost::filesystem;
    
    Filepath path = uri_to_filename(specs.data_source());
    Filepath filename;
    
    enum Binary_Type
    { 
        Multi_Split, 
        Unknown 
    };
    
    Binary_Type binary_type = Unknown;
    
    // Checking which type of file
    if (fs::is_directory(path))
    {
        if (fs::exists((filename = path / (specs.label() + ".rep"))))
        {
            binary_type = Multi_Split;
        } 
        else if (fs::exists((filename = path / (specs.label() + ".bbp"))))
        {
            binary_type = Multi_Split;
        }
    } 
    else if (fs::exists(path))
    {
        filename = path;
        if (fs::extension(path) == ".rep")
        {
            binary_type = Multi_Split;
        }
        else if (fs::extension(path) == ".bbp")
        {
            binary_type = Multi_Split;
        }
    }
        
    if (binary_type == Multi_Split)
    {
        _parser.open(filename.string());
    }
    else
    {
        throw_exception(Bad_Data("Compartment_Binary_File_Report_Reader: "
                                 "no proper binary file for " + 
                                 specs.data_source() + " found"),
                        FATAL_LEVEL, __FILE__, __LINE__);
    }
}
コード例 #2
0
Compartment_Report_HDF5_File_Reader::Compartment_Report_HDF5_File_Reader
(const Report_Specification & specs) :
    _path(uri_to_filename(specs.data_source())),
    _report_name(specs.label()),
    _sequence_start_frame(0),
    _frame_counter(0),
    _frame_skip(1.0),
    _current_framestamp(UNDEFINED_FRAME_NUMBER)
{
    namespace fs = boost::filesystem;

    static Report_Specialization_Register<
               Compartment_Report_HDF5_File_Reader,
               float
           > register_float_buffer;

    // Finding a suitable cell name from which has a h5 inside the search path.
    bool h5_file_found = false;
    if (!fs::is_directory(_path))
    {
        throw_exception(
            IO_Error("Compartment_Report_HDF5_File_Reader: data source "
                     "is not a directory: " + specs.data_source()),
            FATAL_LEVEL, __FILE__, __LINE__);
    }
    fs::directory_iterator entry(_path), end_entry;
    Cell_GID cell_GID = UNDEFINED_CELL_GID;
    while (cell_GID == UNDEFINED_CELL_GID && entry != end_entry)
    {
        fs::path filename = entry->path();
        std::string cell_name = fs::basename(filename);
        char * endptr;
        if (fs::is_regular(entry->status()) &&
            fs::extension(filename) == ".h5" &&
            // Checking if name matches a[0-9]+ pattern and storing the GID
            cell_name.size() > 1 && cell_name[0] == 'a' &&
            (cell_GID = strtol(&cell_name[1], &endptr, 10)) > 0 &&
            *endptr == '\0')
            h5_file_found = true;
        ++entry;
    }
    if (cell_GID == UNDEFINED_CELL_GID)
    {
        throw_exception(
            Bad_Data("Compartment_Report_HDF5_File_Reader: source path "
                     "doesn't contain any valid .h5 file" + 
                     specs.data_source()), FATAL_LEVEL, __FILE__, __LINE__);
    }
    
    // Not catching any exception here
    H5ID file, dataset;
    open_data_set(cell_GID, "data", file, dataset);
    float start_time, end_time, delta_time;
    if (// Trying to read attributes
        !read_attribute("tstart", dataset, start_time) ||
        !read_attribute("tstop", dataset, end_time) ||
        !read_attribute("Dt", dataset, delta_time) ||
        // And checking them
        start_time != specs.start_time() ||
        end_time != specs.end_time() ||
        delta_time != specs.timestep())
    {
/*!
    \todo Exception commented because the forward_skip is not taken into
    account in the HDF5. SL - 24.07.08
        throw_exception(
            Bad_Data("Compartment_Report_HDF5_File_Reader: inconsistent"
                     " report metadata found for '" + specs.label() +
                     "' in path " + specs.data_source()), 
            FATAL_LEVEL, __FILE__, __LINE__);
*/
    }
}