Skip to main content

FiffDirNode

Namespace: FIFFLIB  ·  Library: FIFF Library

#include <fiff/fiff_dir_node.h>

class FIFFLIB::FiffDirNode

Recursive FIFF block-tree node: block kind, block ID, directly contained directory entries and child sub-blocks.

Each node corresponds to one FIFFB_BLOCK_START ... FIFFB_BLOCK_END pair in the on-disk tag stream. The full tree is built once by FiffStream::make_dir_tree after the directory tag is parsed, and is then traversed by every higher-level reader (FiffInfo, FiffRawData, FiffEvoked, FiffCov, ...) via dir_tree_find. The static copy_tree helper streams an entire sub-tree from one FiffStream to another preserving block IDs, which is how MNE-CPP writes derived files that keep provenance back to the source recording.

src/examples/ex_fiff_api/main.cpp
QFile structureFile(dir + "/sample_audvis-ave.fif");
FiffStream::SPtr stream(new FiffStream(&structureFile));
const bool opened = stream->open();
const QList<FiffDirNode::SPtr> measNodes = stream->dirtree()->dir_tree_find(FIFFB_MEAS_INFO);
std::unique_ptr<FiffTag> tag;
const bool hasNchan = measNodes.first()->find_tag(stream, FIFF_NCHAN, tag); // raw tag access
const int nchanTag = *tag->toInt();
const FiffId fileId = stream->id();
stream->close();
src/examples/ex_fiff_api/main.cpp
// The block tree of a transform file, as MNE-C fiff_dir_tree prints it, with the names of tags and units
QFile transFile(dir + "/all-trans.fif");
FiffStream transStream(&transFile);
transStream.open();
QString tree;
QTextStream treeOut(&tree);
transStream.dirtree()->print(treeOut);
transStream.close();
const QString transformTag = FiffExplain::tag(FIFF_COORD_TRANS); // "transform"
const QString gradiometerUnit = FiffExplain::unitMultiplier(FIFF_UNITM_F) + FiffExplain::unit(FIFF_UNIT_T_M); // "fT/m"

Public Methods​

FiffDirNode()​

Constructors the directory tree structure.


FiffDirNode(p_FiffDirTree)​

Copy constructor.

Parameters:

  • p_FiffDirTree : *const FiffDirNode ** Directory tree structure which should be copied.

~FiffDirNode()​

Destroys the fiffDirTree.


isEmpty()​

Returns true if directory tree structure contains no data.

Returns:

  • bool — true if directory tree structure is empty.

dir_tree_find(p_kind)​

Find nodes of the given kind from a directory tree structure.

Parameters:

  • p_kind : fiff_int_t the given kind.

Returns:

  • QList< FiffDirNode::SPtr > — list of the found nodes.

find_tag(p_pStream, findkind, p_pTag)​

Definition of the find_tag function in various files e.g.

fiff_read_named_matrix.m,

Founds a tag of a given kind within a tree, and reeds it from file. Note: In difference to mne-matlab this is not a static function. This is a method of the FiffDirNode class, that's why a tree object doesn't need to be handed to the function.

Parameters:

  • p_pStream : QSharedPointer<FiffStream> & the opened fif file.

  • findkind : fiff_int_t the kind which should be found.

  • p_pTag : std::unique_ptr< FiffTag > & the found tag.

Returns:

  • bool — true if found, false otherwise.

find_tag(p_pStream, findkind, p_pTag)​

Definition of the find_tag function in various files e.g.

fiff_read_named_matrix.m,

Founds a tag of a given kind within a tree, and reeds it from file. Note: In difference to mne-matlab this is not a static function. This is a method of the FiffDirNode class, that's why a tree object doesn't need to be handed to the function.

Parameters:

  • p_pStream : *FiffStream ** the opened fif file.

  • findkind : fiff_int_t the kind which should be found.

  • p_pTag : std::unique_ptr< FiffTag > & the found tag.

Returns:

  • bool — true if found, false otherwise.

has_tag(findkind)​

Definition of the has_tag function in fiff_read_named_matrix.m.

Parameters:

  • findkind : fiff_int_t kind to find.

Returns:

  • bool — true when fiff_dir_node contains kind.

has_kind(p_kind)​

Checks whether a FiffDirNode has a specific kind.

Parameters:

  • p_kind : fiff_int_t kind to find.

Returns:

  • bool — true when fiff_dir_node contains kind.

print(out, indent)​

Prints this block and its sub-blocks like MNE-C's fiff_dir_tree: one line per block with its id, one line per run of equal tag kinds with the run length in brackets, sub-blocks indented by five.

Parameters:

  • out : QTextStream & Stream to print to.

  • indent : int Indentation of this block.


nent()​

Returns the number of entries in this node.

Returns:

  • fiff_int_t — Number of entries in this node.

nchild()​

Returns the number of child nodes.

Returns:

  • fiff_int_t — Number of child nodes.

Static Methods​

copy_tree(p_pStreamIn, in_id, p_Nodes, p_pStreamOut)​

Copies directory subtrees from fidin to fidout.

Parameters:

  • p_pStreamIn : QSharedPointer<FiffStream> & fiff file to copy from.

  • in_id : const FiffId & file id description.

  • p_Nodes : const QList< QSharedPointer<FiffDirNode> > & subtree directories to be copied.

  • p_pStreamOut : QSharedPointer<FiffStream> & fiff file to write to.

Returns:

  • bool — true if succeeded, false otherwise.

Example​

Used in examples​

ex_fiff_api​

FIFF library: measurement info, channels, digitizer, transforms, projectors, covariance, events,.

src/examples/ex_fiff_api/main.cpp, line 208
QFile structureFile(dir + "/sample_audvis-ave.fif");
FiffStream::SPtr stream(new FiffStream(&structureFile));
const bool opened = stream->open();
const QList<FiffDirNode::SPtr> measNodes = stream->dirtree()->dir_tree_find(FIFFB_MEAS_INFO);
std::unique_ptr<FiffTag> tag;
const bool hasNchan = measNodes.first()->find_tag(stream, FIFF_NCHAN, tag); // raw tag access
const int nchanTag = *tag->toInt();
const FiffId fileId = stream->id();
stream->close();
ok &= expect(opened && measNodes.size() == 1 && hasNchan && nchanTag == 376 && !fileId.isEmpty() && fileId.version > 0,
"FiffStream/FiffDirNode/FiffTag/FiffId: the FIFF_NCHAN tag of the measurement block reads 376");

ex_fiff_sniffer​

Read a FIFF file from a memory buffer with a chosen byte order and summarise its contents.

src/examples/ex_fiff_sniffer/main.cpp, line 133
FIFFLIB::FiffInfo FifInfo;
FIFFLIB::FiffDirNode::SPtr DirNode;

Authors of this file​