Xmipp
v3.23.11-Nereus
|
#include <metadata_base.h>
Classes | |
struct | idIterator |
struct | IdIteratorProxy |
struct | rowIterator |
Public Member Functions | |
virtual void | fillConstant (MDLabel label, const String &value)=0 |
virtual void | fillRandom (MDLabel label, const String &mode, double op1, double op2, double op3=0.)=0 |
virtual void | fillLinear (MDLabel label, double initial, double step)=0 |
virtual void | copyColumn (MDLabel labelDest, MDLabel labelSrc)=0 |
virtual void | copyColumnTo (MetaData &md, MDLabel labelDest, MDLabel labelSrc)=0 |
virtual void | renameColumn (MDLabel oldLabel, MDLabel newLabel)=0 |
virtual void | renameColumn (const std::vector< MDLabel > &oldLabel, const std::vector< MDLabel > &newLabel)=0 |
virtual bool | nextBlock (mdBuffer &buffer, mdBlock &block) |
Constructors | |
MetaData ()=default | |
virtual | ~MetaData () |
virtual void | clear () |
Getters and setters | |
virtual bool | isColumnFormat () const |
virtual void | setMaxRows (size_t maxRows=0) |
virtual size_t | getParsedLines () |
virtual void | setPrecission (int _precision) |
virtual void | setColumnFormat (bool column) |
virtual void | writeXML (const FileName fn, const FileName blockname, WriteModeMetaData mode) const =0 |
virtual void | writeText (const FileName fn, const std::vector< MDLabel > *desiredLabels) const =0 |
virtual void | writeStar (const FileName &outFile, const String &blockName, WriteModeMetaData mode) const |
virtual String | getComment () const |
virtual void | setComment (const String &newComment="No comment") |
virtual FileName | getFilename () const |
virtual void | setFilename (const FileName &_filename) |
virtual std::vector< MDLabel > | getActiveLabels () const =0 |
virtual int | getMaxStringLength (const MDLabel thisLabel) const =0 |
MetaData Manipulation | |
virtual bool | setValueCol (const MDObject &mdValueIn)=0 |
template<class T > | |
bool | setValueCol (const MDLabel label, const T &valueIn) |
template<class T > | |
bool | setValue (const MDLabel label, const T &valueIn, size_t id) |
virtual size_t | addRow (const MDRow &row)=0 |
MetaData & | operator= (const MetaData &md) |
virtual bool | setValue (const MDObject &mdValueIn, size_t id)=0 |
virtual bool | getValue (MDObject &mdValueOut, size_t id) const =0 |
template<class T > | |
T | getValue (const MDLabel label, size_t id) const |
template<class T > | |
bool | getValue (const MDLabel label, T &valueOut, size_t id) const |
template<class T > | |
const T & | getValueOrAbort (const MDLabel label, size_t id) const |
template<class T > | |
T & | getValueOrAbort (const MDLabel label, size_t id) |
template<class T > | |
void | getValueOrAbort (const MDLabel label, T &valueOut, size_t id) const |
template<typename T > | |
const T | getValueOrDefault (const MDLabel label, size_t id, const T &_default) const |
template<typename T > | |
T | getValueOrDefault (const MDLabel label, size_t id, T &_default) |
template<typename T , typename T1 > | |
void | getValueOrDefault (const MDLabel label, T &valueOut, size_t id, const T1 &_default) const |
template<class T > | |
std::vector< T > | getColumnValues (const MDLabel label) const |
template<class T > | |
void | getColumnValues (const MDLabel label, std::vector< T > &out) const |
virtual bool | getRowValues (size_t id, std::vector< MDObject > &values) const =0 |
virtual void | getColumnValues (const MDLabel label, std::vector< MDObject > &valuesOut) const =0 |
template<class T > | |
void | setColumnValues (const MDLabel label, const std::vector< T > &valuesIn) |
virtual void | setColumnValues (const std::vector< MDObject > &valuesIn)=0 |
virtual std::unique_ptr< MDRow > | getRow (size_t id)=0 |
virtual std::unique_ptr< const MDRow > | getRow (size_t id) const =0 |
virtual bool | setValueFromStr (const MDLabel label, const String &value, size_t id) |
virtual bool | getStrFromValue (const MDLabel label, String &strOut, size_t id) const |
virtual bool | isEmpty () const |
virtual size_t | size () const =0 |
virtual bool | containsLabel (const MDLabel label) const =0 |
virtual bool | addLabel (const MDLabel label, int pos=-1)=0 |
virtual bool | removeLabel (const MDLabel label)=0 |
void | keepLabels (const std::vector< MDLabel > &labels) |
virtual size_t | addObject ()=0 |
virtual void | importObject (const MetaData &md, const size_t id, bool doClear=true)=0 |
virtual void | importObjects (const MetaData &md, const std::vector< size_t > &objectsToAdd, bool doClear=true)=0 |
virtual void | importObjects (const MetaData &md, const MDQuery &query, bool doClear=true)=0 |
virtual bool | removeObject (size_t id)=0 |
virtual void | removeObjects (const std::vector< size_t > &toRemove)=0 |
virtual int | removeObjects (const MDQuery &)=0 |
virtual int | removeObjects ()=0 |
Iteration functions | |
virtual size_t | firstRowId () const =0 |
virtual size_t | firstObject (const MDQuery &) const =0 |
virtual size_t | lastRowId () const =0 |
Search operations | |
virtual void | findObjects (std::vector< size_t > &objectsOut, const MDQuery &query) const =0 |
virtual void | findObjects (std::vector< size_t > &objectsOut, int limit=-1) const =0 |
virtual size_t | countObjects (const MDQuery &) const =0 |
virtual bool | containsObject (size_t objectId) const =0 |
virtual bool | containsObject (const MDQuery &) const =0 |
I/O functions | |
virtual void | _writeRows (std::ostream &os) const =0 |
virtual void | write (const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const =0 |
virtual void | write (std::ostream &os, const String &blockName="", WriteModeMetaData mode=MD_OVERWRITE) const =0 |
virtual void | print () const |
void | append (const FileName &outFile) const |
virtual void | read (const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true)=0 |
Set Operations | |
virtual void | removeDisabled () |
virtual void | selectRandomSubset (const MetaData &mdIn, size_t numberOfObjects, const MDLabel sortLabel=MDL_OBJID)=0 |
virtual void | selectPart (const MetaData &mdIn, size_t startPosition, size_t numberOfObjects, const MDLabel sortLabel=MDL_OBJID)=0 |
Public Attributes | |
bool | isMetadataFile |
Protected Member Functions | |
void | copyInfo (const MetaData &md) |
double | precision () const |
virtual void | readStar (const FileName &filename, const std::vector< MDLabel > *desiredLabels, const String &blockRegExp, bool decomposeStack) |
virtual void | _readColumns (std::istream &is, std::vector< MDObject *> &columnValues, const std::vector< MDLabel > *desiredLabels=nullptr) |
virtual void | _readColumnsStar (mdBlock &block, std::vector< MDObject *> &columnValues, const std::vector< MDLabel > *desiredLabels, bool addColumns=true, size_t id=BAD_OBJID) |
virtual void | _parseObject (std::istream &is, MDObject &object, size_t id=BAD_OBJID) |
virtual void | _parseObjects (std::istream &is, std::vector< MDObject *> &columnValues, const std::vector< MDLabel > *desiredLabels, bool firstTime)=0 |
virtual void | _readRows (std::istream &is, std::vector< MDObject *> &columnValues, bool useCommentAsImage) |
virtual void | _readRowsStar (mdBlock &block, std::vector< MDObject *> &columnValues, const std::vector< MDLabel > *desiredLabels) |
Protected Attributes | |
std::map< String, size_t > | _fastStringSearch |
MDLabel | _fastStringSearchLabel |
String | _comment |
int | _precision = 1000 |
FileName | _inFile |
size_t | _maxRows = 0 |
size_t | _parsedLines = 0 |
Iterators | |
using | iterator = rowIterator< false > |
using | const_iterator = rowIterator< true > |
using | id_iterator = idIterator< false > |
using | id_const_iterator = idIterator< true > |
struct | MDBaseRowIterator< false > |
struct | MDBaseRowIterator< true > |
virtual iterator | begin ()=0 |
virtual iterator | end ()=0 |
virtual const_iterator | begin () const =0 |
virtual const_iterator | end () const =0 |
virtual id_iterator | id_begin ()=0 |
virtual id_iterator | id_end ()=0 |
virtual id_const_iterator | id_begin () const =0 |
virtual id_const_iterator | id_end () const =0 |
virtual IdIteratorProxy< false > | ids () |
virtual IdIteratorProxy< true > | ids () const |
Definition of API of all MetaDatas.
MetaData* class(es) implement a way to store metadata in xmipp programs.
There was a single original database (MetaDataDb) implementation of MetaData till 2021, when MetaData were split into MetaDataDb & MetaDataVec with aim to achive higner speeds via saving metadata in std::vectors instead of sql database.
Current MetaData implementation:
MetaData class cannot be instantiated however it could be passed to functions as reference or pointer where only common MetaData functions are required:
void foo(MetaData&);
void boo(MetaData*);
This code doesn't compile: void roo(MetaData& md) { md.someDbSpeficicOperation(); }
This code compiles: void roo(MetaDataDb& md) { md.someDbSpeficicOperation(); }
You can iterate directly over abstract MetaData as well as over specific MetaData*. You can iterate over:
for (size_t id : md.ids())
for (const MDRow& row : md)
for (const MDRow& row : md) { const MDRowVec& rowv = dynamic_cast<MDRowVec&>(row); }
You need to make sure type of md is MetaDataVec (otherwise exception is thrown). Definition at line 176 of file metadata_base.h.
using MetaData::const_iterator = rowIterator<true> |
Definition at line 706 of file metadata_base.h.
using MetaData::id_const_iterator = idIterator<true> |
Definition at line 736 of file metadata_base.h.
using MetaData::id_iterator = idIterator<false> |
Definition at line 735 of file metadata_base.h.
using MetaData::iterator = rowIterator<false> |
Definition at line 705 of file metadata_base.h.
|
default |
|
virtual |
Definition at line 105 of file metadata_base.cpp.
|
protectedvirtual |
Definition at line 325 of file metadata_base.cpp.
|
protectedpure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
protectedvirtual |
Definition at line 223 of file metadata_base.cpp.
|
protectedvirtual |
Definition at line 253 of file metadata_base.cpp.
|
protectedvirtual |
Definition at line 379 of file metadata_base.cpp.
|
protectedvirtual |
This function will be used to parse the rows data in START format
[out] | columnValues | MDRow with values to fill in |
pchStart | pointer to the position of '_loop' in memory | |
pEnd | pointer to the position of the next '_data' in memory | |
maxRows | if this number if greater than 0, only this number of rows will be parsed. |
Reimplemented in MetaDataDb.
Definition at line 340 of file metadata_base.cpp.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Add a new label to the metadata. By default the label is added at the end, if the position is specified and is between 0 and n-1 the new label is inserted at that position.
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Adds a new, empty object to the objects map. If objectId == -1 the new ID will be that for the last object inserted + 1, else the given objectId is used. If there is already an object whose objectId == input objectId, just removes it and creates an empty one
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
void MetaData::append | ( | const FileName & | outFile | ) | const |
Append data lines to file. This function can be used to add new data to an existing metadata. Now should be used with files with only one metadata, maybe can be extended later. For now it will not check any compatibility beetween the existent metadata and the new data to append.
Definition at line 647 of file metadata_base.cpp.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
virtual |
Clear all data
Reimplemented in MetaDataDb, and MetaDataVec.
Definition at line 152 of file metadata_base.cpp.
|
pure virtual |
Check whether a label is contained in metadata.
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
Copy all values from one column to another. Source column should exist
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Same as previous, but copy to another metadata
Implemented in MetaDataDb, and MetaDataVec.
|
protected |
Definition at line 163 of file metadata_base.cpp.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
Fill column with constant value
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Fill lineal, starting at some value and with some step
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Fill column with random value mode should be: uniform, gaussian or student op1, op2 and op2 are interpreted for each mode: uniform: op1 and op2 are the limits of the interval gaussian: op1 and op2 are mean and std student: same as gaussian and use op3
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Find all objects that match a query. if called without query, all objects are returned if limit is provided only return a maximun of 'limit'
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Return the object id of the first element in metadata.
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Get safe access to active labels.
Implemented in MetaDataDb, and MetaDataVec.
|
inline |
Get all values of a column as a vector.
Definition at line 466 of file metadata_base.h.
|
inline |
Definition at line 483 of file metadata_base.h.
|
pure virtual |
Get all values of a column as a vector.
Implemented in MetaDataDb, and MetaDataVec.
|
inlinevirtual |
Get Header Comment. the comment will appear in second line.
Definition at line 310 of file metadata_base.h.
|
inlinevirtual |
|
pure virtual |
Get maximum string length of column values.
Implemented in MetaDataDb, and MetaDataVec.
|
inlinevirtual |
Return the number of lines in the metadata file. Serves to know the number of items even is read with maxRows != 0
Definition at line 283 of file metadata_base.h.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
Get string representation from label value.
Definition at line 115 of file metadata_base.cpp.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
inline |
Get the value of some label. from the object that has id 'objectId' or from 'activeObject' if objectId=-1.
Definition at line 409 of file metadata_base.h.
|
inline |
Definition at line 417 of file metadata_base.h.
|
inline |
Definition at line 426 of file metadata_base.h.
|
inline |
Definition at line 431 of file metadata_base.h.
|
inline |
Definition at line 436 of file metadata_base.h.
|
inline |
Definition at line 442 of file metadata_base.h.
|
inline |
Definition at line 450 of file metadata_base.h.
|
inline |
Definition at line 458 of file metadata_base.h.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
inlinevirtual |
Definition at line 754 of file metadata_base.h.
|
inlinevirtual |
Definition at line 755 of file metadata_base.h.
|
pure virtual |
Import objects from another metadata.
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
inlinevirtual |
Return true if the metadata is in column format.
Definition at line 272 of file metadata_base.h.
|
inlinevirtual |
Check whether the metadata is empty.
Reimplemented in MetaDataVec.
Definition at line 522 of file metadata_base.h.
void MetaData::keepLabels | ( | const std::vector< MDLabel > & | labels | ) |
Remove all the labels from the metadata but the ones given in labels vector.
Definition at line 143 of file metadata_base.cpp.
|
pure virtual |
Goto last metadata object.
Implemented in MetaDataDb, and MetaDataVec.
Definition at line 176 of file metadata_base.cpp.
Definition at line 373 of file metadata_base.h.
|
protected |
Definition at line 172 of file metadata_base.cpp.
|
inlinevirtual |
Definition at line 631 of file metadata_base.h.
|
pure virtual |
Read data from file. Guess the blockname from the filename
Implemented in MetaDataDb, and MetaDataVec.
|
protectedvirtual |
Definition at line 406 of file metadata_base.cpp.
|
virtual |
Remove rows with MDL_ENABLED = -1 if this label is present
Definition at line 123 of file metadata_base.cpp.
|
pure virtual |
Remove a label from the metadata. The data is still in the table. If you want to remove the data, make a copy of the MetaData.
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Remove the object with this id. Returns true if the object was removed or false if the object did not exist
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Removes the collection of objects of given vector id's NOTE: The iterator will point to the first object after any of these operations
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Removes objects from metadata. return the number of deleted rows if not query, all objectes are removed Queries can be used in the same way as in the importObjects function
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
Rename column.
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Rename several columns. This is an expensive operations so if several columns need to be changed do it using this function instead one by one
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Select some part from Metadata. Select elements from input Metadata at some starting position if the numberOfObjects is -1, all objects will be returned from startPosition to the end.
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Select random subset
Implemented in MetaDataDb, and MetaDataVec.
|
inlinevirtual |
Set to false for row format (parameter files). set to true for column format (this is the default) (docfiles)
Definition at line 293 of file metadata_base.h.
|
inline |
Set all values of a column as a vector. The input vector must have the same size as the Metadata.
Definition at line 499 of file metadata_base.h.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
inlinevirtual |
Set Header Comment. the comment will appear in second line
Definition at line 315 of file metadata_base.h.
|
inlinevirtual |
|
inlinevirtual |
Prevent from parsing all rows from the metadata. When reading from file, only maxRows will be read.
Definition at line 277 of file metadata_base.h.
|
inlinevirtual |
Set precision (number of decimal digits) use by operator == when comparing metadatas with double data. "2" is a good value for angles
Definition at line 288 of file metadata_base.h.
|
inline |
Set the value for some label. to the object that has id 'objectId' or to 'activeObject' if is objectId=-1. This is one of the most used functions to programatically fill a metadata.
Definition at line 367 of file metadata_base.h.
|
pure virtual |
This functions are using MDObject for set real values there is an explicit function signature foreach type supported in Metadata. This is done for some type checking of Metadata labels and values
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Set the value of all objects in an specified column (both value and column are specified in mdValueIn)
Implemented in MetaDataDb, and MetaDataVec.
|
inline |
Set the value of all objects in an specified column.
Definition at line 350 of file metadata_base.h.
Set label values from string representation.
Definition at line 107 of file metadata_base.cpp.
|
pure virtual |
Number of objects contained in the metadata.
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Implemented in MetaDataDb, and MetaDataVec.
|
virtual |
Definition at line 557 of file metadata_base.cpp.
|
pure virtual |
Write metadata in text file as plain data without header.
Implemented in MetaDataDb, and MetaDataVec.
|
pure virtual |
Export medatada to xml file.
Implemented in MetaDataDb, and MetaDataVec.
|
friend |
Definition at line 676 of file metadata_base.h.
|
friend |
Definition at line 677 of file metadata_base.h.
|
protected |
A general comment for the MetaData file
Definition at line 185 of file metadata_base.h.
|
protected |
Definition at line 183 of file metadata_base.h.
|
protected |
Definition at line 184 of file metadata_base.h.
|
protected |
Input file name Where does this MetaData come from/go to be stored?
Definition at line 195 of file metadata_base.h.
|
protected |
This two variables will be used to read the metadata information (labels and size) or maybe a few rows only
Definition at line 200 of file metadata_base.h.
|
protected |
Definition at line 200 of file metadata_base.h.
|
protected |
Definition at line 190 of file metadata_base.h.
bool MetaData::isMetadataFile |
Filename used in the read command, useful to write Error messages
Definition at line 246 of file metadata_base.h.