61 void open(
const std::string& filename, std::ios::openmode mode = std::ios::in);
68 static bool file_exist(
const std::string& filename);
116 template <
typename T>
119 std::shared_ptr<CellMapping> cmap,
121 int nsec, nseg, n_scan;
122 size_t total_lfp_factors;
126 F.getline(line_buf,
sizeof(line_buf));
128 line_buf,
"%s %d %d %zd %d",
name, &nsec, &nseg, &total_lfp_factors, &num_electrodes);
135 auto sec = read_vector<int>(nseg);
136 auto seg = read_vector<int>(nseg);
139 node_permute(seg.data(), seg.size(), nt.
_permute);
142 std::vector<double> lfp_factors;
143 if (total_lfp_factors > 0) {
144 lfp_factors = read_vector<double>(total_lfp_factors);
147 int factor_offset = 0;
148 for (
int i = 0;
i < nseg;
i++) {
151 int factor_offset =
i * num_electrodes;
152 if (total_lfp_factors > 0) {
154 nrn_assert(count_if(lfp_factors.begin(), lfp_factors.end(), [](
double d) {
155 return std::isnan(d);
157 std::vector<double> segment_factors(lfp_factors.begin() + factor_offset,
158 lfp_factors.begin() + factor_offset +
160 cmap->add_segment_lfp_factor(seg[
i], segment_factors);
186 template <
typename T>
188 if (count > 0 && flag !=
seek)
194 F.seekg(count *
sizeof(T), std::ios_base::cur);
197 F.read((
char*)
p, count *
sizeof(T));
208 template <
typename T>
214 template <
typename T>
219 template <
typename T>
221 std::vector<T> vec(count);
230 template <
typename T>
235 F.write((
const char*)
p, nb_elements * (
sizeof(T)));
241 template <
typename T>
246 bool to_transpose =
false) {
250 T* temp_cpy =
new T[nb_elements * nb_lines];
253 for (
size_t i = 0;
i < nb_lines;
i++) {
254 for (
size_t j = 0;
j < nb_elements;
j++) {
255 temp_cpy[
i +
j * nb_lines] =
p[
i * line_width +
j];
259 memcpy(temp_cpy,
p, nb_elements *
sizeof(T) * nb_lines);
263 F.write((
const char*) temp_cpy, nb_elements *
sizeof(T) * nb_lines);
268 template <
typename T>
281 F <<
"chkpnt " <<
chkpnt++ <<
"\n";
T * read_array(size_t count)
Allocate and read an integer array of fixed length.
std::ios_base::openmode current_mode
File open mode (not stored in fstream)
void read_checkpoint_assert()
Read a checkpoint line, bump our chkpnt counter, and assert equality.
void write_array(T *p, size_t nb_elements, size_t line_width, size_t nb_lines, bool to_transpose=false)
Write a padded array.
void write_array(T *p, size_t nb_elements)
Write an 1D array.
parse_action
Defined flag values for parse_array()
T * read_array(T *p, size_t count)
Read an integer array of fixed length.
FileHandler(const FileHandler &)=delete
std::vector< T > read_vector(size_t count)
int stored_chkpnt
last "remembered" checkpoint number state.
void read_mapping_cell_count(int *count)
Reads number of cells in parsing file.
FileHandler & operator=(const FileHandler &)=delete
void record_checkpoint()
Record current chkpnt state.
bool eof()
nothing more to read
void checkpoint(int c)
Explicitly override chkpnt state.
bool fail() const
Is the file not open.
FileHandler & operator<<(const T &scalar)
void open(const std::string &filename, std::ios::openmode mode=std::ios::in)
Preserving chkpnt state, move to a new file.
void read_mapping_count(int *gid, int *nsec, int *nseg, int *nseclist)
Parse a neuron mapping count entries.
void restore_checkpoint()
Restored last recorded chkpnt state.
int read_mapping_info(T mapinfo, NrnThreadMappingInfo *ntmapping, std::shared_ptr< CellMapping > cmap, const NrnThread &nt)
Parse a neuron section segment mapping.
int chkpnt
Current checkpoint number state.
int checkpoint() const
Query chkpnt state.
void close()
Close currently open file.
std::fstream F
File stream associated with reader.
static bool file_exist(const std::string &filename)
T * parse_array(T *p, size_t count, parse_action flag)
Generic parse function for an array of fixed length.
int read_int()
Parse a single integer entry.
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
const int max_line_length
Encapsulate low-level reading of coreneuron input data files.
SectionType section_type_from_string(std::string_view str)
#define nrn_assert(x)
assert()-like macro, independent of NDEBUG status
NrnMappingInfo mapinfo
mapping information
Compartment mapping information for NrnThread.
void add_segment_id(const int segment_id)
add a new segment