62 void open(
const std::string& filename, std::ios::openmode mode = std::ios::in);
69 static bool file_exist(
const std::string& filename);
117 template <
typename T>
120 std::shared_ptr<CellMapping> cmap,
123 std::getline(
F, line);
125 std::istringstream iss(line);
126 std::string name_str;
129 size_t total_lfp_factors = 0;
130 int offset_count = 0;
131 iss >> name_str >> nsec >> nseg >> total_lfp_factors >> offset_count;
134 if (offset_count > 0) {
135 cmap->electrode_offsets.resize(offset_count);
136 for (
int k = 0;
k < offset_count;
k++) {
137 iss >> cmap->electrode_offsets[
k];
145 auto sec = read_vector<int>(nseg);
146 auto seg = read_vector<int>(nseg);
149 node_permute(seg.data(), seg.size(), nt.
_permute);
152 std::vector<double> lfp_factors;
153 if (total_lfp_factors > 0) {
154 lfp_factors = read_vector<double>(total_lfp_factors);
157 for (
int i = 0;
i < nseg;
i++) {
160 if (total_lfp_factors > 0) {
161 const auto num_electrodes = cmap->num_electrodes();
162 nrn_assert(count_if(lfp_factors.begin(), lfp_factors.end(), [](
double d) {
163 return std::isnan(d);
165 auto begin = lfp_factors.begin() +
i * num_electrodes;
166 cmap->add_segment_lfp_factor(seg[
i], begin, begin + num_electrodes);
192 template <
typename T>
194 if (count > 0 && flag !=
seek)
200 F.seekg(count *
sizeof(T), std::ios_base::cur);
203 F.read((
char*)
p, count *
sizeof(T));
214 template <
typename T>
220 template <
typename T>
225 template <
typename T>
227 std::vector<T> vec(count);
236 template <
typename T>
241 F.write((
const char*)
p, nb_elements * (
sizeof(T)));
247 template <
typename T>
252 bool to_transpose =
false) {
256 T* temp_cpy =
new T[nb_elements * nb_lines];
259 for (
size_t i = 0;
i < nb_lines;
i++) {
260 for (
size_t j = 0;
j < nb_elements;
j++) {
261 temp_cpy[
i +
j * nb_lines] =
p[
i * line_width +
j];
265 memcpy(temp_cpy,
p, nb_elements *
sizeof(T) * nb_lines);
269 F.write((
const char*) temp_cpy, nb_elements *
sizeof(T) * nb_lines);
274 template <
typename T>
287 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, const std::string_view file_path="")
#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