59 void open(
const std::string& filename, std::ios::openmode mode = std::ios::in);
66 static bool file_exist(
const std::string& filename);
114 template <
typename T>
116 int nsec, nseg, n_scan;
117 size_t total_lfp_factors;
121 F.getline(line_buf,
sizeof(line_buf));
123 line_buf,
"%s %d %d %zd %d",
name, &nsec, &nseg, &total_lfp_factors, &num_electrodes);
130 auto sec = read_vector<int>(nseg);
131 auto seg = read_vector<int>(nseg);
133 std::vector<double> lfp_factors;
134 if (total_lfp_factors > 0) {
135 lfp_factors = read_vector<double>(total_lfp_factors);
138 int factor_offset = 0;
139 for (
int i = 0;
i < nseg;
i++) {
142 int factor_offset =
i * num_electrodes;
143 if (total_lfp_factors > 0) {
145 nrn_assert(count_if(lfp_factors.begin(), lfp_factors.end(), [](
double d) {
146 return std::isnan(d);
148 std::vector<double> segment_factors(lfp_factors.begin() + factor_offset,
149 lfp_factors.begin() + factor_offset +
177 template <
typename T>
179 if (count > 0 && flag !=
seek)
185 F.seekg(count *
sizeof(T), std::ios_base::cur);
188 F.read((
char*)
p, count *
sizeof(T));
199 template <
typename T>
205 template <
typename T>
210 template <
typename T>
212 std::vector<T> vec(count);
221 template <
typename T>
226 F.write((
const char*)
p, nb_elements * (
sizeof(T)));
232 template <
typename T>
237 bool to_transpose =
false) {
241 T* temp_cpy =
new T[nb_elements * nb_lines];
244 for (
size_t i = 0;
i < nb_lines;
i++) {
245 for (
size_t j = 0;
j < nb_elements;
j++) {
246 temp_cpy[
i +
j * nb_lines] =
p[
i * line_width +
j];
250 memcpy(temp_cpy,
p, nb_elements *
sizeof(T) * nb_lines);
254 F.write((
const char*) temp_cpy, nb_elements *
sizeof(T) * nb_lines);
259 template <
typename T>
272 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.
int read_mapping_info(T *mapinfo, NrnThreadMappingInfo *ntmapping, CellMapping *cmap)
Parse a neuron section segment mapping.
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 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.
#define nrn_assert(x)
assert()-like macro, independent of NDEBUG status
NrnMappingInfo mapinfo
mapping information
Compartment mapping information for a cell.
void add_segment_lfp_factor(const int segment_id, std::vector< double > &factors)
add the lfp electrode factors of a segment_id
Compartment mapping information for NrnThread.
void add_segment_id(const int segment_id)
add a new segment