Xmipp  v3.23.11-Nereus
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
MetaDataDb Class Reference

#include <metadata_db.h>

Inheritance diagram for MetaDataDb:
Inheritance graph
[legend]
Collaboration diagram for MetaDataDb:
Collaboration graph
[legend]

Classes

struct  MDDbIdIterator
 
struct  MDDbRowIterator
 

Public Member Functions

void readPlain (const FileName &inFile, const String &labelsString, const String &separator=" ")
 
void addPlain (const FileName &inFile, const String &labelsString, const String &separator=" ")
 
iterator begin () override
 
iterator end () override
 
const_iterator begin () const override
 
const_iterator end () const override
 
id_iterator id_begin () override
 
id_iterator id_end () override
 
id_const_iterator id_begin () const override
 
id_const_iterator id_end () const override
 
void fillExpand (MDLabel label)
 
void fillConstant (MDLabel label, const String &value) override
 
void fillRandom (MDLabel label, const String &mode, double op1, double op2, double op3=0.) override
 
void fillLinear (MDLabel label, double initial, double step) override
 
void copyColumn (MDLabel labelDest, MDLabel labelSrc) override
 
void copyColumnTo (MetaData &md, MDLabel labelDest, MDLabel labelSrc) override
 
void renameColumn (MDLabel oldLabel, MDLabel newLabel) override
 
void renameColumn (const std::vector< MDLabel > &oldLabel, const std::vector< MDLabel > &newLabel) override
 
void metadataToVec (std::vector< MDRowSql > &vd)
 
void vecToMetadata (const std::vector< MDRow > &rowMetadata)
 
bool operator== (const MetaDataDb &op) const
 
Constructors
 MetaDataDb ()
 
 MetaDataDb (const std::vector< MDLabel > &labelsVector)
 
 MetaDataDb (const MetaData &md)
 
 MetaDataDb (const FileName &fileName, const std::vector< MDLabel > &desiredLabels={})
 
 MetaDataDb (const MetaDataDb &md)
 
MetaDataDboperator= (const MetaDataDb &md)
 
virtual ~MetaDataDb ()
 
void clear () override
 
Getters and setters
MDSqlgetDatabase ()
 
void writeXML (const FileName fn, const FileName blockname, WriteModeMetaData mode) const override
 
void writeDB (const FileName fn, const FileName blockname, WriteModeMetaData mode) const
 
void writeText (const FileName fn, const std::vector< MDLabel > *desiredLabels) const override
 
int getMaxStringLength (const MDLabel thisLabel) const override
 
MetaData Manipulation
bool setValueCol (const MDObject &mdValueIn) override
 
template<class T >
bool setValueCol (const MDLabel label, const T &valueIn)
 
bool setValue (const MDObject &mdValueIn, size_t id) override
 
template<class T >
bool setValue (const MDLabel label, const T &valueIn, size_t id)
 
bool getValue (MDObject &mdValueOut, size_t id) const override
 
bool getRowValues (size_t id, std::vector< MDObject > &values) const override
 
template<class T >
bool getValue (const MDLabel label, T &valueOut, size_t id) const
 
void getColumnValues (const MDLabel label, std::vector< MDObject > &valuesOut) const override
 
template<class T >
std::vector< T > getColumnValues (const MDLabel label) const
 
template<class T >
void getColumnValues (const MDLabel label, std::vector< T > &valuesOut) const
 
template<typename T >
bool getColumnValuesOpt (const MDLabel label, std::vector< T > &values) const
 
void setColumnValues (const std::vector< MDObject > &valuesIn) override
 
template<class T >
void setColumnValues (const MDLabel label, const std::vector< T > &valuesIn)
 
bool bindValue (size_t id) const
 
bool initGetRow (bool addWhereClause) const
 
bool execGetRow (MDRow &row) const
 
void finalizeGetRow (void) const
 
std::unique_ptr< MDRowgetRow (size_t id) override
 
std::unique_ptr< const MDRowgetRow (size_t id) const override
 
MDRowSql getRowSql (size_t id)
 
const MDRowSql getRowSql (size_t id) const
 
bool getRow (MDRowSql &row, size_t id) const
 
bool getAllRows (std::vector< MDRowSql > &rows) const
 
bool getRow2 (MDRow &row, size_t id) const
 
bool setRow (const MDRow &row, size_t id)
 
bool initAddRow (const MDRow &row)
 
bool execAddRow (const MDRow &row)
 
void finalizeAddRow (void)
 
size_t addRow (const MDRow &row) override
 
void addRowOpt (const MDRowSql &row)
 
void addRows (const std::vector< MDRowSql > &rows)
 
void addMissingLabels (const MDRow &row)
 
size_t addRow2 (const MDRow &row)
 
size_t size () const override
 
bool containsLabel (const MDLabel label) const override
 
std::vector< MDLabelgetActiveLabels () const override
 
bool addLabel (const MDLabel label, int pos=-1) override
 
bool removeLabel (const MDLabel label) override
 
size_t addObject () override
 
void importObject (const MetaData &md, const size_t id, bool doClear=true) override
 
void importObjects (const MetaData &md, const std::vector< size_t > &objectsToAdd, bool doClear=true) override
 
void importObjects (const MetaData &md, const MDQuery &query, bool doClear=true) override
 
bool removeObject (size_t id) override
 
void removeObjects (const std::vector< size_t > &toRemove) override
 
int removeObjects (const MDQuery &query) override
 
int removeObjects () override
 
void addIndex (MDLabel label) const
 
void addIndex (const std::vector< MDLabel > &desiredLabels) const
 
void removeIndex (MDLabel label)
 
void removeIndex (const std::vector< MDLabel > &desiredLabels)
 
void addItemId ()
 
void removeItemId ()
 
Iteration functions
size_t firstRowId () const override
 
size_t firstObject (const MDQuery &) const override
 
size_t lastRowId () const override
 
Search operations
void findObjects (std::vector< size_t > &objectsOut, const MDQuery &query) const override
 
void findObjects (std::vector< size_t > &objectsOut, int limit=-1) const override
 
size_t countObjects (const MDQuery &query) const override
 
bool containsObject (size_t objectId) const override
 
bool containsObject (const MDQuery &query) const override
 
I/O functions
void _writeRows (std::ostream &os) const override
 
void write (const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const override
 
void write (std::ostream &os, const String &blockName="", WriteModeMetaData mode=MD_OVERWRITE) const override
 
bool existsBlock (const FileName &_inFile)
 
void readXML (const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, const String &blockRegExp=DEFAULT_BLOCK_NAME, bool decomposeStack=true)
 
void readDB (const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, const String &blockRegExp=DEFAULT_BLOCK_NAME, bool decomposeStack=true)
 
void read (const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, bool decomposeStack=true) override
 
Set Operations
void aggregate (const MetaDataDb &mdIn, AggregateOperation op, MDLabel aggregateLabel, MDLabel operateLabel, MDLabel resultLabel)
 
void aggregate (const MetaDataDb &mdIn, const std::vector< AggregateOperation > &ops, const std::vector< MDLabel > &operateLabels, const std::vector< MDLabel > &resultLabels)
 
void aggregateGroupBy (const MetaDataDb &mdIn, AggregateOperation op, const std::vector< MDLabel > &groupByLabels, MDLabel operateLabel, MDLabel resultLabel)
 
void aggregateSingle (MDObject &mdValueOut, AggregateOperation op, MDLabel aggregateLabel)
 
void aggregateSingleInt (MDObject &mdValueOut, AggregateOperation op, MDLabel aggregateLabel)
 
void aggregateSingleSizeT (MDObject &mdValueOut, AggregateOperation op, MDLabel aggregateLabel)
 
double getColumnMax (MDLabel column)
 
double getColumnMin (MDLabel column)
 
void unionDistinct (const MetaDataDb &mdIn, const MDLabel label=MDL_OBJID)
 
void unionAll (const MetaDataDb &mdIn)
 
void merge (const MetaData &md2)
 
void intersection (const MetaDataDb &mdIn, const MDLabel label)
 
void subtraction (const MetaDataDb &mdIn, const MDLabel label)
 
void distinct (MetaDataDb &MDin, MDLabel label)
 
void join1 (const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight, const MDLabel label, JoinType type=LEFT)
 
void join2 (const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight, const MDLabel labelLeft, const MDLabel labelRight, JoinType type=LEFT)
 
void join1 (const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight, const std::vector< MDLabel > &labels, JoinType type=LEFT)
 
void join2 (const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight, const std::vector< MDLabel > &labelsLeft, const std::vector< MDLabel > &labelsRight, JoinType type=LEFT)
 
void joinNatural (const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight)
 
void operate (const String &expression)
 
void replace (const MDLabel label, const String &oldStr, const String &newStr)
 
void randomize (const MetaDataDb &MDin)
 
void removeDuplicates (MetaDataDb &MDin, MDLabel label=MDL_UNDEFINED)
 
void sort (MetaDataDb &MDin, const MDLabel sortLabel, bool asc=true, int limit=-1, int offset=0)
 
void sort (MetaDataDb &MDin, const String &sortLabel, bool asc=true, int limit=-1, int offset=0)
 
void split (size_t n, std::vector< MetaDataDb > &results, const MDLabel sortLabel=MDL_OBJID)
 
void selectSplitPart (const MetaData &mdIn, size_t n, size_t part, const MDLabel sortLabel=MDL_OBJID)
 
void selectRandomSubset (const MetaData &mdIn, size_t numberOfObjects, const MDLabel sortLabel=MDL_OBJID) override
 
void selectPart (const MetaData &mdIn, size_t startPosition, size_t numberOfObjects, const MDLabel sortLabel=MDL_OBJID) override
 
void makeAbsPath (const MDLabel label=MDL_IMAGE)
 

Protected Member Functions

void init (const std::vector< MDLabel > &labelsVector)
 
void copyMetadata (const MetaDataDb &md, bool copyObjects=true)
 
void _selectSplitPart (const MetaDataDb &mdIn, int n, int part, size_t mdSize, const MDLabel sortLabel)
 
void _selectSplitPart (const MetaDataDb &mdIn, size_t n, size_t part, const MDLabel sortLabel=MDL_OBJID)
 
void _selectRandomSubset (const MetaDataDb &mdIn, size_t numberOfObjects, const MDLabel sortLabel=MDL_OBJID)
 
void _selectPart (const MetaDataDb &mdIn, size_t startPosition, size_t numberOfObjects, const MDLabel sortLabel=MDL_OBJID)
 
void _setOperates (const MetaDataDb &mdIn, const MDLabel label, SetOperation operation)
 
void _setOperates (const MetaDataDb &mdIn, const std::vector< MDLabel > &labels, SetOperation operation)
 
void _setOperates (const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight, const std::vector< MDLabel > &labelsLeft, const std::vector< MDLabel > &labelsRight, SetOperation operation)
 
void _setOperatesLabel (const MetaDataDb &mdIn, const MDLabel label, SetOperation operation)
 
void _clear (bool onlyData=false)
 
void _readRowsStar (mdBlock &block, std::vector< MDObject *> &columnValues, const std::vector< MDLabel > *desiredLabels) override
 
void _readRowFormat (std::istream &is)
 
void _parseObjects (std::istream &is, std::vector< MDObject *> &columnValues, const std::vector< MDLabel > *desiredLabels, bool firstTime) override
 
std::vector< MDObjectgetObjectsForActiveLabels () const
 
void _importObjectsDb (const MetaDataDb &md, const MDQuery &query, bool doClear=true)
 
void _importObjectsGeneral (const MetaData &md, const MDQuery &query, bool doClear=true)
 

Protected Attributes

MDSqlmyMDSql
 
std::vector< MDLabel_activeLabels
 

Friends

class MDSql
 

Additional Inherited Members

Detailed Description

Original database implementation of MetaData. MetaData are stored in SQL database. Some database-specific commands are available in this implementation only.

Notes

  1. It's quite fast to iterate over ids.
  2. It's slow to iterate over rows.
  3. Best practices: https://github.com/I2PC/xmipp-portal/wiki/MetaData&mdash;SQL-best-practices

Definition at line 55 of file metadata_db.h.

Constructor & Destructor Documentation

◆ MetaDataDb() [1/5]

MetaDataDb::MetaDataDb ( )

Empty Constructor.

The MetaDataDb is created with no data stored on it. You can fill in it programmatically or by a later reading from a MetaDataDb file or old Xmipp formatted type. if labels vectors is passed this labels are created on metadata

Definition at line 496 of file metadata_db.cpp.

497 {
498  myMDSql = new MDSql(this);
499  init({});
500 }//close MetaData default Constructor
MDSql * myMDSql
Definition: metadata_db.h:62
friend class MDSql
Definition: metadata_db.h:61
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59

◆ MetaDataDb() [2/5]

MetaDataDb::MetaDataDb ( const std::vector< MDLabel > &  labelsVector)

Definition at line 508 of file metadata_db.cpp.

509 {
510  myMDSql = new MDSql(this);
511  init(labelsVector);
512 }//close MetaData default Constructor
MDSql * myMDSql
Definition: metadata_db.h:62
friend class MDSql
Definition: metadata_db.h:61
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59

◆ MetaDataDb() [3/5]

MetaDataDb::MetaDataDb ( const MetaData md)

Definition at line 502 of file metadata_db.cpp.

502  {
503  myMDSql = new MDSql(this);
504  init({});
506 }
MDSql * myMDSql
Definition: metadata_db.h:62
friend class MDSql
Definition: metadata_db.h:61
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59
MetaData & operator=(const MetaData &md)

◆ MetaDataDb() [4/5]

MetaDataDb::MetaDataDb ( const FileName fileName,
const std::vector< MDLabel > &  desiredLabels = {} 
)

From File Constructor.

The MetaData is created and data is read from provided FileName. Optionally, a vector of labels can be provided to read just those required labels

Definition at line 514 of file metadata_db.cpp.

515 {
516  myMDSql = new MDSql(this);
517  init(desiredLabels);
518  read(fileName, desiredLabels.empty() ? nullptr : &desiredLabels);
519 }//close MetaData from file Constructor
MDSql * myMDSql
Definition: metadata_db.h:62
friend class MDSql
Definition: metadata_db.h:61
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, bool decomposeStack=true) override

◆ MetaDataDb() [5/5]

MetaDataDb::MetaDataDb ( const MetaDataDb md)

Copy constructor

Created a new metadata by copying all data from an existing MetaData object.

Definition at line 521 of file metadata_db.cpp.

522 {
523  myMDSql = new MDSql(this);
524  copyMetadata(md);
525 }//close MetaData copy Constructor
void copyMetadata(const MetaDataDb &md, bool copyObjects=true)
Definition: metadata_db.cpp:71
MDSql * myMDSql
Definition: metadata_db.h:62
friend class MDSql
Definition: metadata_db.h:61

◆ ~MetaDataDb()

MetaDataDb::~MetaDataDb ( )
virtual

Destructor

Frees all used memory and destroys object.

Definition at line 533 of file metadata_db.cpp.

534 {
535  _clear();
536  delete myMDSql;
537 }//close MetaData Destructor
MDSql * myMDSql
Definition: metadata_db.h:62
void _clear(bool onlyData=false)
Definition: metadata_db.cpp:40

Member Function Documentation

◆ _clear()

void MetaDataDb::_clear ( bool  onlyData = false)
protected

clear data and table structure

Definition at line 40 of file metadata_db.cpp.

41 {
42  if (onlyData)
43  {
44  myMDSql->deleteObjects();
45  }
46  else
47  {
49  _activeLabels.clear();
50  myMDSql->clearMd();
51  }
52 }//close clear
virtual void clear()
MDSql * myMDSql
Definition: metadata_db.h:62
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68

◆ _importObjectsDb()

void MetaDataDb::_importObjectsDb ( const MetaDataDb md,
const MDQuery query,
bool  doClear = true 
)
protected

Definition at line 612 of file metadata_db.cpp.

613 {
614  if (doClear)
615  {
616  //Copy all structure and info from the other metadata
617  init(md._activeLabels);
618  copyInfo(md);
619  }
620  else
621  {
622  //If not clear, ensure that the have the same labels
623  for (size_t i = 0; i < md._activeLabels.size(); i++)
624  addLabel(md._activeLabels[i]);
625  }
626  md.myMDSql->copyObjects(this, &query);
627 }
MDSql * myMDSql
Definition: metadata_db.h:62
#define i
void copyInfo(const MetaData &md)
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
bool addLabel(const MDLabel label, int pos=-1) override

◆ _importObjectsGeneral()

void MetaDataDb::_importObjectsGeneral ( const MetaData md,
const MDQuery query,
bool  doClear = true 
)
protected

◆ _parseObjects()

void MetaDataDb::_parseObjects ( std::istream &  is,
std::vector< MDObject *> &  columnValues,
const std::vector< MDLabel > *  desiredLabels,
bool  firstTime 
)
overrideprotectedvirtual

Implements MetaData.

Definition at line 853 of file metadata_db.cpp.

854 {
855  size_t i=0; // Loop counter.
856  size_t size=0; // Column values vector size.
857 
858  // Columns loop.
859  size = columnValues.size();
860  for (i=0; i<size ;i++)
861  {
862  columnValues[i]->fromStream(is);
863  if (is.fail())
864  {
865  String errorMsg = formatString("MetaData: Error parsing column '%s' value.", MDL::label2Str(columnValues[i]->label).c_str());
866  columnValues[i]->failed = true;
867  std::cerr << "WARNING: " << errorMsg << std::endl;
868  //REPORT_ERROR(ERR_MD_BADLABEL, (String)"read: Error parsing data column, expecting " + MDL::label2Str(object.label));
869  }
870  else
871  {
872  if (firstTime)
873  {
874  // Check if current column label exists.
875  if (columnValues[i]->label != MDL_UNDEFINED)
876  {
877  // If there are no desired labels then add all.
878  bool reallyAdd=false;
879  if (desiredLabels==NULL)
880  {
881  reallyAdd=true;
882  }
883  else
884  {
885  // Check if current column belongs to desired labels.
886  for (size_t j=0; j<desiredLabels->size(); ++j)
887  {
888  if ((*desiredLabels)[j]==columnValues[i]->label)
889  {
890  reallyAdd=true;
891  break;
892  }
893  }
894  }
895 
896  // Add label if not exists.
897  if (reallyAdd)
898  {
899  addLabel(columnValues[i]->label);
900  }
901  }
902  }
903  }
904  }
905 
906  // Insert elements in DB.
907  myMDSql->setObjectValues( -1, columnValues, desiredLabels);
908 }
MDSql * myMDSql
Definition: metadata_db.h:62
#define i
size_t size() const override
#define j
bool addLabel(const MDLabel label, int pos=-1) override
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
static String label2Str(const MDLabel &label)

◆ _readRowFormat()

void MetaDataDb::_readRowFormat ( std::istream &  is)
protected

Some private reading functions

Definition at line 1096 of file metadata_db.cpp.

1096  {
1097  String line, token;
1098  MDLabel label;
1099 
1100  size_t objectID = addObject();
1101 
1102  // Read data and fill structures accordingly
1103  while (getline(is, line, '\n'))
1104  {
1105  if (line[0] == '#' || line[0] == '\0' || line[0] == ';')
1106  continue;
1107 
1108  // Parse labels
1109  std::stringstream os(line);
1110 
1111  os >> token;
1112  label = MDL::str2Label(token);
1113  MDObject value(label);
1114  os >> value;
1115  if (label != MDL_UNDEFINED)
1116  setValue(value, objectID);
1117  }
1118 }
static MDLabel str2Label(const String &labelName)
size_t addObject() override
bool setValue(const MDObject &mdValueIn, size_t id) override
Definition: metadata_db.cpp:90
std::string String
Definition: xmipp_strings.h:34
MDLabel

◆ _readRowsStar()

void MetaDataDb::_readRowsStar ( mdBlock block,
std::vector< MDObject *> &  columnValues,
const std::vector< MDLabel > *  desiredLabels 
)
overrideprotectedvirtual

This function will be used to parse the rows data in START format

Parameters
[out]columnValuesMDRow with values to fill in
pchStartpointer to the position of '_loop' in memory
pEndpointer to the position of the next '_data' in memory
maxRowsif this number if greater than 0, only this number of rows will be parsed.

Reimplemented from MetaData.

Definition at line 1051 of file metadata_db.cpp.

1052  {
1053  String line;
1054  std::stringstream ss;
1055  size_t n = block.end - block.loop;
1056  bool firstTime = true;
1057 
1058  if (n == 0)
1059  return;
1060 
1061  char * buffer = new char[n];
1062  memcpy(buffer, block.loop, n);
1063  char *iter = buffer, *end = iter + n, * newline = NULL;
1064  _parsedLines = 0; //Check how many lines the md have
1065 
1066  if (myMDSql->initializeInsert( desiredLabels, columnValues))
1067  {
1068  while (iter < end) { //while there are data lines
1069  //Adding \n position and check if NULL at the same time
1070  if (!(newline = END_OF_LINE()))
1071  newline = end;
1072  line.assign(iter, newline - iter);
1073  trim(line);
1074 
1075  if (!line.empty() && line[0] != '#') {
1076  //_maxRows would be > 0 if we only want to read some
1077  // rows from the md for performance reasons...
1078  // anyway the number of lines will be counted in _parsedLines
1079  if (_maxRows == 0 || _parsedLines < _maxRows) {
1080  std::stringstream ss(line);
1081  this->_parseObjects(ss, columnValues, desiredLabels, firstTime);
1082  firstTime = false;
1083  }
1084  _parsedLines++;
1085  }
1086  iter = newline + 1; //go to next line
1087  }
1088 
1089  myMDSql->finalizePreparedStmt();
1090  }
1091 
1092  delete[] buffer;
1093 }
#define END_OF_LINE()
Definition: metadata_base.h:69
size_t _parsedLines
char * end
Definition: metadata_base.h:96
HBITMAP buffer
Definition: svm-toy.cpp:37
void trim(std::string &s)
Definition: text.cpp:205
MDSql * myMDSql
Definition: metadata_db.h:62
glob_prnt iter
iterator end() override
Definition: metadata_db.h:749
size_t _maxRows
void _parseObjects(std::istream &is, std::vector< MDObject *> &columnValues, const std::vector< MDLabel > *desiredLabels, bool firstTime) override
char * loop
Definition: metadata_base.h:97
std::string String
Definition: xmipp_strings.h:34
int * n

◆ _selectPart()

void MetaDataDb::_selectPart ( const MetaDataDb mdIn,
size_t  startPosition,
size_t  numberOfObjects,
const MDLabel  sortLabel = MDL_OBJID 
)
protected

Definition at line 1609 of file metadata_db.cpp.

1611 {
1612  size_t mdSize = mdIn.size();
1613  if (startPosition < 0 || startPosition >= mdSize)
1614  REPORT_ERROR(ERR_MD, "selectPart: 'startPosition' should be between 0 and size()-1");
1615  init(mdIn._activeLabels);
1616  copyInfo(mdIn);
1617  mdIn.myMDSql->copyObjects(this, new MDQuery(numberOfObjects, startPosition, sortLabel));
1618 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MDSql * myMDSql
Definition: metadata_db.h:62
MetaData error.
Definition: xmipp_error.h:154
void copyInfo(const MetaData &md)
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59
size_t size() const override
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68

◆ _selectRandomSubset()

void MetaDataDb::_selectRandomSubset ( const MetaDataDb mdIn,
size_t  numberOfObjects,
const MDLabel  sortLabel = MDL_OBJID 
)
protected

Definition at line 1591 of file metadata_db.cpp.

1592 {
1593  clear();
1594 
1595  MetaDataDb mdAux, mdAux2;
1596  mdAux.randomize(mdIn);
1597  mdAux2.selectPart(mdAux, 0, numberOfObjects);
1598  sort(mdAux2,sortLabel);
1599 }
void randomize(const MetaDataDb &MDin)
void clear() override
Definition: metadata_db.cpp:54
void selectPart(const MetaData &mdIn, size_t startPosition, size_t numberOfObjects, const MDLabel sortLabel=MDL_OBJID) override
void sort(MetaDataDb &MDin, const MDLabel sortLabel, bool asc=true, int limit=-1, int offset=0)

◆ _selectSplitPart() [1/2]

void MetaDataDb::_selectSplitPart ( const MetaDataDb mdIn,
int  n,
int  part,
size_t  mdSize,
const MDLabel  sortLabel 
)
protected

This have the same logic of the public one, but doesn't perform any range(which implies do a size()) checks.

Definition at line 1555 of file metadata_db.cpp.

1558 {
1559  size_t first, last, n_images;
1560  n_images = divide_equally(mdSize, n, part, first, last);
1561  init(mdIn._activeLabels);
1562  copyInfo(mdIn);
1563  mdIn.myMDSql->copyObjects(this, new MDQuery(n_images, first, sortLabel));
1564 }
size_t divide_equally(size_t N, size_t size, size_t rank, size_t &first, size_t &last)
MDSql * myMDSql
Definition: metadata_db.h:62
glob_log first
void copyInfo(const MetaData &md)
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
int * n

◆ _selectSplitPart() [2/2]

void MetaDataDb::_selectSplitPart ( const MetaDataDb mdIn,
size_t  n,
size_t  part,
const MDLabel  sortLabel = MDL_OBJID 
)
protected

Definition at line 1573 of file metadata_db.cpp.

1574 {
1575  size_t mdSize = mdIn.size();
1576  if (n > mdSize)
1577  REPORT_ERROR(ERR_MD, "selectSplitPart: Couldn't split a metadata in more parts than its size");
1578  if (part < 0 || part >= n)
1579  REPORT_ERROR(ERR_MD, "selectSplitPart: 'part' should be between 0 and n-1");
1580  _selectSplitPart(mdIn, n, part, mdSize, sortLabel);
1581 
1582 }
void _selectSplitPart(const MetaDataDb &mdIn, int n, int part, size_t mdSize, const MDLabel sortLabel)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MetaData error.
Definition: xmipp_error.h:154
size_t size() const override
int * n

◆ _setOperates() [1/3]

void MetaDataDb::_setOperates ( const MetaDataDb mdIn,
const MDLabel  label,
SetOperation  operation 
)
protected

This function is for generalize the sets operations of unionDistinct, intersection, subtraction which can be expressed in terms of ADD, SUBSTRACT of intersection part

Definition at line 1293 of file metadata_db.cpp.

1296 {
1297  std::vector<MDLabel> labels;
1298  labels.emplace_back(label);
1299  _setOperates(mdIn,labels,operation);
1300 }
void _setOperates(const MetaDataDb &mdIn, const MDLabel label, SetOperation operation)

◆ _setOperates() [2/3]

void MetaDataDb::_setOperates ( const MetaDataDb mdIn,
const std::vector< MDLabel > &  labels,
SetOperation  operation 
)
protected

Definition at line 1302 of file metadata_db.cpp.

1305 {
1306  if (this == &mdIn) //not sense to operate on same metadata
1307  REPORT_ERROR(ERR_MD, "Couldn't perform this operation on input metadata");
1308  if (size() == 0 && mdIn.size() == 0)
1309  REPORT_ERROR(ERR_MD, "Couldn't perform this operation if both metadata are empty");
1310  //Add labels to be sure are present
1311  for (size_t i = 0; i < mdIn._activeLabels.size(); i++)
1312  addLabel(mdIn._activeLabels[i]);
1313 
1314  mdIn.myMDSql->setOperate(this, labels, operation);
1315 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MDSql * myMDSql
Definition: metadata_db.h:62
#define i
MetaData error.
Definition: xmipp_error.h:154
size_t size() const override
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
bool addLabel(const MDLabel label, int pos=-1) override

◆ _setOperates() [3/3]

void MetaDataDb::_setOperates ( const MetaDataDb mdInLeft,
const MetaDataDb mdInRight,
const std::vector< MDLabel > &  labelsLeft,
const std::vector< MDLabel > &  labelsRight,
SetOperation  operation 
)
protected

Definition at line 1332 of file metadata_db.cpp.

1337 {
1338  if (this == &mdInLeft || this == &mdInRight) //not sense to operate on same metadata
1339  REPORT_ERROR(ERR_MD, "Couldn't perform this operation on input metadata");
1340  //Add labels to be sure are present
1341  for (size_t i = 0; i < mdInLeft._activeLabels.size(); i++)
1342  addLabel(mdInLeft._activeLabels[i]);
1343  for (size_t i = 0; i < mdInRight._activeLabels.size(); i++)
1344  {
1345  bool found=false;
1346  for (size_t j=0; j<labelsRight.size(); ++j)
1347  if (mdInRight._activeLabels[i]==labelsRight[j])
1348  {
1349  found=true;
1350  break;
1351  }
1352  if (!found)
1353  addLabel(mdInRight._activeLabels[i]);
1354  }
1355 
1356  myMDSql->setOperate(&mdInLeft, &mdInRight, labelsLeft,labelsRight, operation);
1357 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MDSql * myMDSql
Definition: metadata_db.h:62
#define i
MetaData error.
Definition: xmipp_error.h:154
#define j
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
bool addLabel(const MDLabel label, int pos=-1) override

◆ _setOperatesLabel()

void MetaDataDb::_setOperatesLabel ( const MetaDataDb mdIn,
const MDLabel  label,
SetOperation  operation 
)
protected

This function is for generalize the sets operations in which the output has a single label a vector of labels instead of a single label may be implemented in the future

Definition at line 1317 of file metadata_db.cpp.

1320 {
1321  if (this == &mdIn) //not sense to operate on same metadata
1322  REPORT_ERROR(ERR_MD, "Couldn't perform this operation on input metadata");
1323  if (mdIn.size() == 0)
1324  REPORT_ERROR(ERR_MD, "Couldn't perform this operation if both metadata are empty");
1325  //Add label to be sure is present in output
1326  addLabel(label);
1327  std::vector<MDLabel> labels;
1328  labels.emplace_back(label);
1329  mdIn.myMDSql->setOperate(this, labels, operation);
1330 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MDSql * myMDSql
Definition: metadata_db.h:62
MetaData error.
Definition: xmipp_error.h:154
size_t size() const override
bool addLabel(const MDLabel label, int pos=-1) override

◆ _writeRows()

void MetaDataDb::_writeRows ( std::ostream &  os) const
overridevirtual

Write rows data to disk.

Implements MetaData.

Definition at line 774 of file metadata_db.cpp.

775 {
776 
777  auto sortedLabels = this->_activeLabels;
778  std::sort(sortedLabels.begin(), sortedLabels.end());
779  for (const auto& row : *this)
780  {
781  for (size_t i = 0; i < sortedLabels.size(); i++)
782  {
783  if (sortedLabels[i] != MDL_STAR_COMMENT)
784  {
785  os.width(1);
786  row.getObject(sortedLabels[i])->toStream(os, true);
787  os << " ";
788  }
789  }
790 
791  os << '\n';
792  }
793 }
#define i
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
A comment for this object /*** NOTE THIS IS A SPECIAL CASE AND SO IS TREATED ***/.

◆ addIndex() [1/2]

void MetaDataDb::addIndex ( MDLabel  label) const

Add and remove indexes for fast search in other labels, but insert are more expensive

Definition at line 653 of file metadata_db.cpp.

654 {
655  std::vector<MDLabel> labels(1);
656  labels[0]=label;
657  addIndex(labels);
658 }
void addIndex(MDLabel label) const

◆ addIndex() [2/2]

void MetaDataDb::addIndex ( const std::vector< MDLabel > &  desiredLabels) const

Definition at line 659 of file metadata_db.cpp.

660 {
661 
662  myMDSql->indexModify(desiredLabels, true);
663 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ addItemId()

void MetaDataDb::addItemId ( )

Add item id. From 1 to last.

Definition at line 677 of file metadata_db.cpp.

678 {
680  fillLinear(MDL_ITEM_ID,1,1);
681 }
Unique identifier for items inside a list or set (std::size_t)
void fillLinear(MDLabel label, double initial, double step) override
bool addLabel(const MDLabel label, int pos=-1) override

◆ addLabel()

bool MetaDataDb::addLabel ( const MDLabel  label,
int  pos = -1 
)
overridevirtual

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.

Implements MetaData.

Definition at line 554 of file metadata_db.cpp.

555 {
556  if (containsLabel(label))
557  return false;
558  if (pos < 0 || pos >= (int)this->_activeLabels.size())
559  this->_activeLabels.emplace_back(label);
560  else
561  this->_activeLabels.insert(this->_activeLabels.begin() + pos, label);
562  myMDSql->addColumn(label);
563  return true;
564 }
MDSql * myMDSql
Definition: metadata_db.h:62
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305

◆ addMissingLabels()

void MetaDataDb::addMissingLabels ( const MDRow row)

Definition at line 422 of file metadata_db.cpp.

422  {
423  // find missing labels
424  std::vector<MDLabel> missingLabels;
425  auto definedLabels = row.labels();
426  for (const auto &l : definedLabels){
427  if ( ! containsLabel(l)) {
428  missingLabels.emplace_back(l);
429  }
430  }
431  // add missing labels
432  if ( ! missingLabels.empty()) {
433  sqlUtils::addColumns(missingLabels,
434  myMDSql->db,
435  myMDSql->tableName(myMDSql->tableId));
436  this->_activeLabels.insert(this->_activeLabels.end(), missingLabels.begin(), missingLabels.end());
437  }
438 }
virtual std::vector< MDLabel > labels() const =0
MDSql * myMDSql
Definition: metadata_db.h:62
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
static bool addColumns(const std::vector< MDLabel > &columns, sqlite3 *db, const std::string &table)
Definition: sql_utils.cpp:31
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305

◆ addObject()

size_t MetaDataDb::addObject ( )
overridevirtual

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

Implements MetaData.

Definition at line 578 of file metadata_db.cpp.

579 {
580  return (size_t)myMDSql->addRow();
581 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ addPlain()

void MetaDataDb::addPlain ( const FileName inFile,
const String labelsString,
const String separator = " " 
)

Same as readPlain, but instead of cleanning data, the readed values will be added. If there are common columns in metadata and the plain text, the lattest will be setted

Definition at line 975 of file metadata_db.cpp.

976 {
977  MetaDataDb md2;
978  md2.readPlain(inFile, labelsString);
979  merge(md2);
980 }
void readPlain(const FileName &inFile, const String &labelsString, const String &separator=" ")
void merge(const MetaData &md2)

◆ addRow()

size_t MetaDataDb::addRow ( const MDRow row)
overridevirtual

Implements MetaData.

Definition at line 394 of file metadata_db.cpp.

395 {
396  size_t id = addObject();
397  for (auto obj : row)
398  if (obj->label != MDL_FIRST_LABEL)
399  setValue(*obj, id);
400 
401  return id;
402 }
The label MDL_OBJID is special and should not be used.
size_t addObject() override
bool setValue(const MDObject &mdValueIn, size_t id) override
Definition: metadata_db.cpp:90
void(* obj)()

◆ addRow2()

size_t MetaDataDb::addRow2 ( const MDRow row)

Definition at line 475 of file metadata_db.cpp.

476 {
477  size_t id = BAD_OBJID;
478 
479  // Initialize INSERT.
480  if (initAddRow( row))
481  {
482  // Execute INSERT.
483  if (execAddRow( row))
484  {
485  // Get last inserted row id.
486  id = myMDSql->getObjId();
487  }
488 
489  // Finalize INSERT.
490  finalizeAddRow();
491  }
492 
493  return(id);
494 }
void finalizeAddRow(void)
MDSql * myMDSql
Definition: metadata_db.h:62
bool initAddRow(const MDRow &row)
bool execAddRow(const MDRow &row)
#define BAD_OBJID
Definition: metadata_base.h:55

◆ addRowOpt()

void MetaDataDb::addRowOpt ( const MDRowSql row)

Definition at line 417 of file metadata_db.cpp.

418 {
419  addRows({row});
420 }
void addRows(const std::vector< MDRowSql > &rows)

◆ addRows()

void MetaDataDb::addRows ( const std::vector< MDRowSql > &  rows)

Definition at line 440 of file metadata_db.cpp.

441 {
442  const auto noOfRows = rows.size();
443  if (0 == noOfRows) {
444  return;
445  }
446  const auto &firstRow = rows.at(0);
447 
448  // assuming all rows are using the same labels
450 
451  // create mask of valid labels
452  std::vector<MDLabel> labels;
453  labels.reserve(firstRow.size());
454  for (const MDObject* obj : firstRow)
455  labels.emplace_back(obj->label);
456  const auto noOfLabels = labels.size();
457 
458  // extract values to be added
459  std::vector<std::vector<const MDObject*>> records;
460  records.reserve(noOfRows);
461  for (const auto &r : rows) {
462  records.emplace_back(std::vector<const MDObject*>());
463  auto &vals = records.back();
464  vals.reserve(noOfLabels);
465  for (const auto &l : labels) {
466  vals.emplace_back(r.getObject(l));
467  }
468  }
469  // insert values to db
470  sqlUtils::insert(records, myMDSql->db,
471  myMDSql->tableName(myMDSql->tableId));
472 }
static bool insert(const std::vector< std::vector< const MDObject *>> &records, sqlite3 *db, const std::string &table)
Definition: sql_utils.cpp:258
int size() const override
MDSql * myMDSql
Definition: metadata_db.h:62
void addMissingLabels(const MDRow &row)
void(* obj)()
MDRowVec firstRow(const FileName &fnMetadata)

◆ aggregate() [1/2]

void MetaDataDb::aggregate ( const MetaDataDb mdIn,
AggregateOperation  op,
MDLabel  aggregateLabel,
MDLabel  operateLabel,
MDLabel  resultLabel 
)

Aggregate metadata objects, result in calling metadata object (except for aggregateSingle) thisLabel label is used for aggregation, second. Valid operations are:

MDL_AVG: The avg function returns the average value of all operationLabel within a group. The result of avg is always a floating point value as long as at there is at least one non-NULL input even if all inputs are integers. The result of avg is NULL if and only if there are no non-NULL inputs.

AGGR_COUNT: The count function returns a count of the number of times that operationLabel is in a group.

AGGR_MAX The max aggregate function returns the maximum value of all values in the group.

AGGR_MIN The min aggregate function returns the minimum value of all values in the group.

AGGRL_SUM The total aggregate functions return sum of all values in the group. If there are no non-NULL input rows then returns 0.0.

Definition at line 1255 of file metadata_db.cpp.

1257 {
1258  std::vector<MDLabel> labels(2);
1259  std::vector<MDLabel> operateLabels(1);
1260  labels[0] = aggregateLabel;
1261  labels[1] = resultLabel;
1262  operateLabels[0]=operateLabel;
1263  init(labels);
1264  std::vector<AggregateOperation> ops(1);
1265  ops[0] = op;
1266  mdIn.myMDSql->aggregateMd(this, ops, operateLabels);
1267 }
MDSql * myMDSql
Definition: metadata_db.h:62
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59

◆ aggregate() [2/2]

void MetaDataDb::aggregate ( const MetaDataDb mdIn,
const std::vector< AggregateOperation > &  ops,
const std::vector< MDLabel > &  operateLabels,
const std::vector< MDLabel > &  resultLabels 
)

Definition at line 1269 of file metadata_db.cpp.

1272 {
1273  if (resultLabels.size() - ops.size() != 1)
1274  REPORT_ERROR(ERR_MD, "Labels vectors should contain one element more than operations");
1275  init(resultLabels);
1276  mdIn.myMDSql->aggregateMd(this, ops, operateLabels);
1277 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MDSql * myMDSql
Definition: metadata_db.h:62
MetaData error.
Definition: xmipp_error.h:154
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59

◆ aggregateGroupBy()

void MetaDataDb::aggregateGroupBy ( const MetaDataDb mdIn,
AggregateOperation  op,
const std::vector< MDLabel > &  groupByLabels,
MDLabel  operateLabel,
MDLabel  resultLabel 
)

Definition at line 1279 of file metadata_db.cpp.

1284 {
1285  std::vector<MDLabel> labels;
1286  labels = groupByLabels;
1287  labels.emplace_back(resultLabel);
1288  init(labels);
1289  mdIn.myMDSql->aggregateMdGroupBy(this, op, groupByLabels, operateLabel, resultLabel);
1290 }
MDSql * myMDSql
Definition: metadata_db.h:62
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59

◆ aggregateSingle()

void MetaDataDb::aggregateSingle ( MDObject mdValueOut,
AggregateOperation  op,
MDLabel  aggregateLabel 
)

This function performs aggregation operations. without grouping. (i.e. absolute maximum of a metadata column) for double

Definition at line 1216 of file metadata_db.cpp.

1219 {
1220  mdValueOut.setValue(myMDSql->aggregateSingleDouble(op,aggregateLabel));
1221 }
MDSql * myMDSql
Definition: metadata_db.h:62
void setValue(const int &iv)

◆ aggregateSingleInt()

void MetaDataDb::aggregateSingleInt ( MDObject mdValueOut,
AggregateOperation  op,
MDLabel  aggregateLabel 
)

This function performs aggregation operations. without grouping. (i.e. absolute maximum of a metadata column) for int

Definition at line 1246 of file metadata_db.cpp.

1249 {
1250  size_t aux = myMDSql->aggregateSingleSizeT(op,aggregateLabel);
1251  int aux2 = (int) aux;
1252  mdValueOut.setValue(aux2);
1253 }
MDSql * myMDSql
Definition: metadata_db.h:62
void setValue(const int &iv)

◆ aggregateSingleSizeT()

void MetaDataDb::aggregateSingleSizeT ( MDObject mdValueOut,
AggregateOperation  op,
MDLabel  aggregateLabel 
)

This function performs aggregation operations. without grouping. (i.e. absolute maximum of a metadata column) for size_t

Definition at line 1223 of file metadata_db.cpp.

1226 {
1227  mdValueOut.setValue(myMDSql->aggregateSingleSizeT(op,aggregateLabel));
1228 }
MDSql * myMDSql
Definition: metadata_db.h:62
void setValue(const int &iv)

◆ begin() [1/2]

iterator MetaDataDb::begin ( )
inlineoverridevirtual

Implements MetaData.

Definition at line 746 of file metadata_db.h.

746  {
747  return {memoryUtils::make_unique<MDDbRowIterator<false>>(*this, 0)};
748  }

◆ begin() [2/2]

const_iterator MetaDataDb::begin ( ) const
inlineoverridevirtual

Implements MetaData.

Definition at line 753 of file metadata_db.h.

753  {
754  return {memoryUtils::make_unique<MDDbRowIterator<true>>(*this, 0)};
755  }

◆ bindValue()

bool MetaDataDb::bindValue ( size_t  id) const

Get all values of an MetaData row of an specified objId

Definition at line 155 of file metadata_db.cpp.

156 {
157  bool success=true;
158 
159  // Prepare statement.
160  if (!myMDSql->bindStatement( id))
161  {
162  success = false;
163  }
164 
165  return success;
166 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ clear()

void MetaDataDb::clear ( )
overridevirtual

Clear all data

Reimplemented from MetaData.

Definition at line 54 of file metadata_db.cpp.

55 {
56  init({});
57 }
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59

◆ containsLabel()

bool MetaDataDb::containsLabel ( const MDLabel  label) const
inlineoverridevirtual

Check whether a label is contained in metadata.

Implements MetaData.

Definition at line 305 of file metadata_db.h.

305  {
306  return vectorContainsLabel(this->_activeLabels, label);
307  }
bool vectorContainsLabel(const std::vector< MDLabel > &labelsVector, const MDLabel label)
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68

◆ containsObject() [1/2]

bool MetaDataDb::containsObject ( size_t  objectId) const
overridevirtual

Implements MetaData.

Definition at line 729 of file metadata_db.cpp.

730 {
731  return containsObject(MDValueEQ(MDL_OBJID, objectId));
732 }
object id (int), NOTE: This label is special and shouldn&#39;t be used
bool containsObject(size_t objectId) const override

◆ containsObject() [2/2]

bool MetaDataDb::containsObject ( const MDQuery query) const
overridevirtual

Implements MetaData.

Definition at line 734 of file metadata_db.cpp.

735 {
736  std::vector<size_t> objects;
737  findObjects(objects, query);
738  return objects.size() > 0;
739 }
void findObjects(std::vector< size_t > &objectsOut, const MDQuery &query) const override

◆ copyColumn()

void MetaDataDb::copyColumn ( MDLabel  labelDest,
MDLabel  labelSrc 
)
overridevirtual

Copy all values from one column to another. Source column should exist

Implements MetaData.

Definition at line 1175 of file metadata_db.cpp.

1176 {
1177  String srcName = MDL::label2Str(labelSrc);
1178  if (!containsLabel(labelSrc))
1179  REPORT_ERROR(ERR_ARG_MISSING, formatString("Source label: '%s' doesn't exist on metadata", srcName.c_str()));
1180  addLabel(labelDest);
1181 
1182  String destName = MDL::label2Str(labelDest);
1183  String cmd = formatString("%s=%s", destName.c_str(), srcName.c_str());
1184  operate(cmd);
1185 }
Argument missing.
Definition: xmipp_error.h:114
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void operate(const String &expression)
bool addLabel(const MDLabel label, int pos=-1) override
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
static String label2Str(const MDLabel &label)
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305

◆ copyColumnTo()

void MetaDataDb::copyColumnTo ( MetaData md,
MDLabel  labelDest,
MDLabel  labelSrc 
)
overridevirtual

Same as previous, but copy to another metadata

Implements MetaData.

Definition at line 1187 of file metadata_db.cpp.

1188 {
1189  if (!containsLabel(labelSrc))
1190  REPORT_ERROR(ERR_ARG_MISSING, formatString("Source label: '%s' doesn't exist on metadata",
1191  (MDL::label2Str(labelSrc)).c_str()));
1192  md.addLabel(labelDest);
1193  std::vector<MDObject> values;
1194  getColumnValues(labelSrc, values);
1195  md.setColumnValues(values);
1196 }
Argument missing.
Definition: xmipp_error.h:114
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void getColumnValues(const MDLabel label, std::vector< MDObject > &valuesOut) const override
virtual bool addLabel(const MDLabel label, int pos=-1)=0
String formatString(const char *format,...)
void setColumnValues(const MDLabel label, const std::vector< T > &valuesIn)
static String label2Str(const MDLabel &label)
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305

◆ copyMetadata()

void MetaDataDb::copyMetadata ( const MetaDataDb md,
bool  copyObjects = true 
)
protected

Copy all data from another metadata

Definition at line 71 of file metadata_db.cpp.

72 {
73  if (this == &md) //not sense to copy same metadata
74  return;
75  init(md._activeLabels);
76  copyInfo(md);
77  if (!md._activeLabels.empty())
78  {
79  if (copyObjects)
80  md.myMDSql->copyObjects(this);
81  }
82  else
83  {
84  int n = md.size();
85  for (int i = 0; i < n; i++)
86  addObject();
87  }
88 }
MDSql * myMDSql
Definition: metadata_db.h:62
#define i
size_t addObject() override
void copyInfo(const MetaData &md)
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59
size_t size() const override
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
int * n

◆ countObjects()

size_t MetaDataDb::countObjects ( const MDQuery query) const
overridevirtual

Implements MetaData.

Definition at line 722 of file metadata_db.cpp.

723 {
724  std::vector<size_t> objects;
725  findObjects(objects, query);
726  return objects.size();
727 }
void findObjects(std::vector< size_t > &objectsOut, const MDQuery &query) const override

◆ distinct()

void MetaDataDb::distinct ( MetaDataDb MDin,
MDLabel  label 
)

Return only distinct (different) values of column label. Result in "calling" metadata with a single column

Definition at line 1389 of file metadata_db.cpp.

1390 {
1391  if(MDin.isEmpty())
1392  return;
1393  _setOperatesLabel(MDin, label, DISTINCT);
1394 }
void _setOperatesLabel(const MetaDataDb &mdIn, const MDLabel label, SetOperation operation)
virtual bool isEmpty() const

◆ end() [1/2]

iterator MetaDataDb::end ( )
inlineoverridevirtual

Implements MetaData.

Definition at line 749 of file metadata_db.h.

749  {
750  return {memoryUtils::make_unique<MDDbRowIterator<false>>(*this, this->size())};
751  }
size_t size() const override

◆ end() [2/2]

const_iterator MetaDataDb::end ( ) const
inlineoverridevirtual

Implements MetaData.

Definition at line 756 of file metadata_db.h.

756  {
757  return {memoryUtils::make_unique<MDDbRowIterator<true>>(*this, this->size())};
758  }
size_t size() const override

◆ execAddRow()

bool MetaDataDb::execAddRow ( const MDRow row)

Definition at line 361 of file metadata_db.cpp.

362 {
363  int j = 0;
364  bool success = true;
365  std::vector<const MDObject*> mdValues;
366 
367  // Set values vector size.
368  mdValues.resize(row.size());
369 
370  // Get values to insert.
371  j = 0;
372  for (const MDObject* obj : row) {
373  addLabel(obj->label);
374  mdValues[j] = row.getObject(obj->label);
375  j++;
376  }
377  mdValues.resize(j);
378 
379  // Execute statement.
380  if (!myMDSql->setObjectValues( -1, mdValues))
381  {
382  std::cerr << "execAddRow: error executing myMDSql->setObjectValues" << std::endl;
383  success = false;
384  }
385 
386  return(success);
387 }
MDSql * myMDSql
Definition: metadata_db.h:62
#define j
virtual int size() const =0
bool addLabel(const MDLabel label, int pos=-1) override
void(* obj)()

◆ execGetRow()

bool MetaDataDb::execGetRow ( MDRow row) const

Definition at line 181 of file metadata_db.cpp.

182 {
183  std::vector<MDObject> mdValues;
184  mdValues.reserve(this->_activeLabels.size());
185 
186  row.clear();
187 
188  bool success = myMDSql->getObjectsValues(this->_activeLabels, mdValues);
189  if (success)
190  for (const auto &obj : mdValues)
191  row.setValue(obj);
192 
193  return success;
194 }
MDSql * myMDSql
Definition: metadata_db.h:62
virtual void clear()=0
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
void setValue(MDLabel label, const T &d, bool addLabel=true)
void(* obj)()

◆ existsBlock()

bool MetaDataDb::existsBlock ( const FileName _inFile)

Check if block exists in metadata file input full parh block return false if metadata block does not exits

Definition at line 982 of file metadata_db.cpp.

983 {
984 #ifdef XMIPP_MMAP
985  String blockName;
986  FileName outFile;
987 
988  blockName=_inFile.getBlockName();
989  outFile = _inFile.removeBlockName();
990 
991  struct stat file_status;
992  int fd;
993  char *map;
994 
995  //check if file exists or not block name has been given
996  //in our format no two identical data_xxx strings may exists
997 
998  if (blockName.empty() || !outFile.exists())
999  return false;
1000  else
1001  {
1002  //does blockname exists?
1003  //remove it from file in this case
1004  // get length of file:
1005  if(stat(outFile.c_str(), &file_status) != 0)
1006  REPORT_ERROR(ERR_IO_NOPATH,"Metadata:existsBlock can not get filesize for file "+outFile);
1007  size_t size = file_status.st_size;
1008  if(size!=0)//size=0 for /dev/stderr
1009  {
1010  fd = open(outFile.c_str(), O_RDWR, S_IREAD | S_IWRITE);
1011  if (fd == -1)
1012  REPORT_ERROR(ERR_IO_NOPATH,"Metadata:existsBlock can not read file named "+outFile);
1013 
1014  map = (char *) mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
1015  if (map == MAP_FAILED)
1016  REPORT_ERROR(ERR_MEM_BADREQUEST,"Metadata:existsBlock can not map memory ");
1017 
1018  // Is this a START formatted FILE
1019  String _szBlockName = (String)("\ndata_") + blockName;
1020  size_t blockNameSize = _szBlockName.size();
1021  close(fd);
1022  bool found=_memmem(map, size, _szBlockName.data(), blockNameSize) != NULL;
1023  if (munmap(map, size) == -1)
1024  REPORT_ERROR(ERR_MEM_NOTDEALLOC,"metadata:write, Can not unmap memory");
1025  return found;
1026  }
1027  return false;
1028  }
1029 #else
1030  REPORT_ERROR(ERR_MMAP,"Mapping not supported in Windows");
1031 #endif
1032 }
String getBlockName() const
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Global mmap error.
Definition: xmipp_error.h:170
Memory has not been deallocated.
Definition: xmipp_error.h:167
Bad amount of memory requested.
Definition: xmipp_error.h:165
void * _memmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len)
bool exists() const
size_t size() const override
FileName removeBlockName() const
std::string String
Definition: xmipp_strings.h:34
Environment PATH cannot be read.
Definition: xmipp_error.h:143

◆ fillConstant()

void MetaDataDb::fillConstant ( MDLabel  label,
const String value 
)
overridevirtual

Fill column with constant value

Implements MetaData.

Definition at line 1157 of file metadata_db.cpp.

1158 {
1159  MDConstGenerator generator(value);
1160  SET_AND_FILL();
1161 }
#define SET_AND_FILL()

◆ fillExpand()

void MetaDataDb::fillExpand ( MDLabel  label)

Expand Metadata with metadata pointed by label Given a metadata md1, with a column containing the name of another column metdata file mdxx add the columns in mdxx to md1

Definition at line 1131 of file metadata_db.cpp.

1132 {
1133  //aggregate metadata by label (that is, avoid repetitions
1134  MetaDataDb mdCTFs;
1135  mdCTFs.distinct(*this,label);
1136  //read file-metadatas in new metadata
1137  MetaDataDb ctfModel;
1138  FileName fn;
1139  MDRowSql row;
1140 
1141  for (size_t id : mdCTFs.ids())
1142  {
1143  if (mdCTFs.getValue(label, fn, id))
1144  {
1145  ctfModel.read(fn);
1146  if (ctfModel.isEmpty())
1147  REPORT_ERROR(ERR_VALUE_INCORRECT, "Only can expand non empty metadatas");
1148  ctfModel.getRow(row, ctfModel.firstRowId());
1149  mdCTFs.setRow(row, id);
1150  }
1151  }
1152  //join
1153  MetaDataDb md(*this);
1154  join1(md, mdCTFs, label);
1155 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void distinct(MetaDataDb &MDin, MDLabel label)
bool getValue(MDObject &mdValueOut, size_t id) const override
virtual IdIteratorProxy< false > ids()
std::unique_ptr< MDRow > getRow(size_t id) override
virtual bool isEmpty() const
bool setRow(const MDRow &row, size_t id)
size_t firstRowId() const override
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, bool decomposeStack=true) override
void join1(const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight, const MDLabel label, JoinType type=LEFT)
Incorrect value received.
Definition: xmipp_error.h:195

◆ fillLinear()

void MetaDataDb::fillLinear ( MDLabel  label,
double  initial,
double  step 
)
overridevirtual

Fill lineal, starting at some value and with some step

Implements MetaData.

Definition at line 1169 of file metadata_db.cpp.

1170 {
1171  MDLinealGenerator generator(initial, step);
1172  SET_AND_FILL();
1173 }
#define SET_AND_FILL()

◆ fillRandom()

void MetaDataDb::fillRandom ( MDLabel  label,
const String mode,
double  op1,
double  op2,
double  op3 = 0. 
)
overridevirtual

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

Implements MetaData.

Definition at line 1163 of file metadata_db.cpp.

1164 {
1165  MDRandGenerator generator(op1, op2, mode, op3);
1166  SET_AND_FILL();
1167 }
#define SET_AND_FILL()
void mode

◆ finalizeAddRow()

void MetaDataDb::finalizeAddRow ( void  )

Definition at line 389 of file metadata_db.cpp.

390 {
391  myMDSql->finalizePreparedStmt();
392 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ finalizeGetRow()

void MetaDataDb::finalizeGetRow ( void  ) const

Definition at line 196 of file metadata_db.cpp.

197 {
198  myMDSql->finalizePreparedStmt();
199 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ findObjects() [1/2]

void MetaDataDb::findObjects ( std::vector< size_t > &  objectsOut,
const MDQuery query 
) const
overridevirtual

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'

Implements MetaData.

Definition at line 709 of file metadata_db.cpp.

710 {
711  objectsOut.clear();
712  myMDSql->selectObjects(objectsOut, &query);
713 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ findObjects() [2/2]

void MetaDataDb::findObjects ( std::vector< size_t > &  objectsOut,
int  limit = -1 
) const
overridevirtual

Implements MetaData.

Definition at line 715 of file metadata_db.cpp.

716 {
717  objectsOut.clear();
718  MDQuery query(limit);
719  myMDSql->selectObjects(objectsOut, &query);
720 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ firstObject()

size_t MetaDataDb::firstObject ( const MDQuery query) const
overridevirtual

Implements MetaData.

Definition at line 695 of file metadata_db.cpp.

696 {
697  std::vector<size_t> ids;
698  findObjects(ids, query);
699  size_t id = ids.size() == 1 ? ids[0] : BAD_OBJID;
700  return id;
701 }
void findObjects(std::vector< size_t > &objectsOut, const MDQuery &query) const override
virtual IdIteratorProxy< false > ids()
#define BAD_OBJID
Definition: metadata_base.h:55

◆ firstRowId()

size_t MetaDataDb::firstRowId ( ) const
overridevirtual

Return the object id of the first element in metadata.

Implements MetaData.

Definition at line 690 of file metadata_db.cpp.

691 {
692  return myMDSql->firstRow();
693 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ getActiveLabels()

std::vector<MDLabel> MetaDataDb::getActiveLabels ( ) const
inlineoverridevirtual

Get safe access to active labels.

Implements MetaData.

Definition at line 309 of file metadata_db.h.

309  {
310  return this->_activeLabels;
311  }
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68

◆ getAllRows()

bool MetaDataDb::getAllRows ( std::vector< MDRowSql > &  rows) const

Definition at line 212 of file metadata_db.cpp.

213 {
214  std::vector<std::vector<MDObject>> rawRows;
215  rawRows.reserve(this->size());
216  auto columns = getObjectsForActiveLabels();
217  if ( ! sqlUtils::select(myMDSql->db,
218  myMDSql->tableName(myMDSql->tableId),
219  columns,
220  rawRows)) return false;
221 
222  rows.clear();
223  const auto noOfRows = rawRows.size();
224  rows.resize(noOfRows);
225  for (size_t i = 0; i < noOfRows; ++i) {
226  auto &row = rows.at(i);
227  const auto &vals = rawRows.at(i);
228  // fill the row
229  for (auto &v : vals) {
230  row.setValue(v);
231  }
232  }
233  return true;
234 }
MDSql * myMDSql
Definition: metadata_db.h:62
#define i
std::vector< MDObject > getObjectsForActiveLabels() const
size_t size() const override
static bool select(size_t rowId, sqlite3 *db, const std::string &table, std::vector< MDObject > &values)
Definition: sql_utils.cpp:87

◆ getColumnMax()

double MetaDataDb::getColumnMax ( MDLabel  column)

Returns Max and Min values from a column in metadata These functions can only be used for labels of type double

Definition at line 1231 of file metadata_db.cpp.

1232 {
1233  MDObject result(column);
1234  aggregateSingle(result, AGGR_MAX, column);
1235  return result.getValue2(double());
1236 }
void aggregateSingle(MDObject &mdValueOut, AggregateOperation op, MDLabel aggregateLabel)

◆ getColumnMin()

double MetaDataDb::getColumnMin ( MDLabel  column)

Definition at line 1238 of file metadata_db.cpp.

1239 {
1240  MDObject result(column);
1241  aggregateSingle(result, AGGR_MIN, column);
1242  return result.getValue2(double());
1243 }
void aggregateSingle(MDObject &mdValueOut, AggregateOperation op, MDLabel aggregateLabel)

◆ getColumnValues() [1/3]

void MetaDataDb::getColumnValues ( const MDLabel  label,
std::vector< MDObject > &  valuesOut 
) const
overridevirtual

Get all values of a column as a vector.

Implements MetaData.

Definition at line 120 of file metadata_db.cpp.

121 {
122  MDObject mdValueOut(label);
123  std::vector<size_t> objectsId;
124  findObjects(objectsId);
125  size_t n = objectsId.size();
126  valuesOut.resize(n,mdValueOut);
127  for (size_t i = 0; i < n; ++i)
128  {
129  getValue(mdValueOut, objectsId[i]);
130  valuesOut[i] = mdValueOut;
131  }
132 }
void findObjects(std::vector< size_t > &objectsOut, const MDQuery &query) const override
bool getValue(MDObject &mdValueOut, size_t id) const override
#define i
int * n

◆ getColumnValues() [2/3]

template<class T >
std::vector<T> MetaDataDb::getColumnValues ( const MDLabel  label) const
inline

Definition at line 247 of file metadata_db.h.

247  {
248  return MetaData::getColumnValues<T>(label);
249  }

◆ getColumnValues() [3/3]

template<class T >
void MetaDataDb::getColumnValues ( const MDLabel  label,
std::vector< T > &  valuesOut 
) const
inline

Definition at line 252 of file metadata_db.h.

252  {
253  return MetaData::getColumnValues(label, valuesOut);
254  }
std::vector< T > getColumnValues(const MDLabel label) const

◆ getColumnValuesOpt()

template<typename T >
bool MetaDataDb::getColumnValuesOpt ( const MDLabel  label,
std::vector< T > &  values 
) const

Get all values of a column as a vector.

Definition at line 845 of file metadata_db.h.

845  {
846  if (!containsLabel(label))
847  return false;
848  return sqlUtils::select(label,
849  myMDSql->db,
850  myMDSql->tableName(myMDSql->tableId),
851  values);
852 }
MDSql * myMDSql
Definition: metadata_db.h:62
static bool select(size_t rowId, sqlite3 *db, const std::string &table, std::vector< MDObject > &values)
Definition: sql_utils.cpp:87
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305

◆ getDatabase()

MDSql* MetaDataDb::getDatabase ( )
inline

Definition at line 182 of file metadata_db.h.

182 { return myMDSql; }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ getMaxStringLength()

int MetaDataDb::getMaxStringLength ( const MDLabel  thisLabel) const
overridevirtual

Get maximum string length of column values.

Implements MetaData.

Definition at line 541 of file metadata_db.cpp.

542 {
543  if (!containsLabel(thisLabel))
544  return -1;
545 
546  return myMDSql->columnMaxLength(thisLabel);
547 }
MDSql * myMDSql
Definition: metadata_db.h:62
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305

◆ getObjectsForActiveLabels()

std::vector< MDObject > MetaDataDb::getObjectsForActiveLabels ( ) const
protected

Get a vector of (empty) objects for each active label

Definition at line 201 of file metadata_db.cpp.

201  {
202  // get active labels
203  std::vector<MDObject> values;
204  const auto &labels = this->_activeLabels;
205  values.reserve(labels.size());
206  for (auto &l : labels) {
207  values.emplace_back(l);
208  }
209  return values;
210 }
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68

◆ getRow() [1/3]

std::unique_ptr< MDRow > MetaDataDb::getRow ( size_t  id)
overridevirtual

Implements MetaData.

Definition at line 236 of file metadata_db.cpp.

236  {
237  std::unique_ptr<MDRowSql> row(new MDRowSql());
238  if (!getRow(*row, id))
239  return nullptr;
240  return std::move(row);
241 }
std::unique_ptr< MDRow > getRow(size_t id) override

◆ getRow() [2/3]

std::unique_ptr< const MDRow > MetaDataDb::getRow ( size_t  id) const
overridevirtual

Implements MetaData.

Definition at line 243 of file metadata_db.cpp.

243  {
244  std::unique_ptr<MDRowSql> row(new MDRowSql());
245  if (!getRow(*row, id))
246  return nullptr;
247  return std::move(row);
248 }
std::unique_ptr< MDRow > getRow(size_t id) override

◆ getRow() [3/3]

bool MetaDataDb::getRow ( MDRowSql row,
size_t  id 
) const

Definition at line 264 of file metadata_db.cpp.

265 {
266  if (id == BAD_OBJID)
267  REPORT_ERROR(ERR_MD_NOACTIVE, "getValue: please provide objId other than -1");
268  // clear whatever is there now
269  row.clear();
270  // get active labels
271  auto values = getObjectsForActiveLabels();
272  // get values from the row
273  if ( ! sqlUtils::select(id,
274  myMDSql->db,
275  myMDSql->tableName(myMDSql->tableId),
276  values)) return false;
277  // fill them
278  for (auto &v : values)
279  row.setValue(v);
280  return true;
281 }
No active object in MetaData.
Definition: xmipp_error.h:155
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void clear() override
MDSql * myMDSql
Definition: metadata_db.h:62
void setValue(const MDObject &object) override
std::vector< MDObject > getObjectsForActiveLabels() const
static bool select(size_t rowId, sqlite3 *db, const std::string &table, std::vector< MDObject > &values)
Definition: sql_utils.cpp:87
#define BAD_OBJID
Definition: metadata_base.h:55

◆ getRow2()

bool MetaDataDb::getRow2 ( MDRow row,
size_t  id 
) const

Definition at line 283 of file metadata_db.cpp.

284 {
285  bool success=true;
286 
287  // Clear row.
288  row.clear();
289 
290  // Initialize SELECT.
291  success = this->initGetRow( true);
292  if (success)
293  {
294  bindValue( id);
295 
296  // Execute SELECT.
297  success = execGetRow( row);
298 
299  // Finalize SELECT.
300  finalizeGetRow();
301  }
302 
303  return(success);
304 }
bool bindValue(size_t id) const
bool initGetRow(bool addWhereClause) const
bool execGetRow(MDRow &row) const
virtual void clear()=0
void finalizeGetRow(void) const

◆ getRowSql() [1/2]

MDRowSql MetaDataDb::getRowSql ( size_t  id)

Definition at line 250 of file metadata_db.cpp.

250  {
251  MDRowSql row;
252  if (!getRow(row, id))
253  throw ObjectDoesNotExist(id, getFilename());
254  return row;
255 }
std::unique_ptr< MDRow > getRow(size_t id) override
virtual FileName getFilename() const

◆ getRowSql() [2/2]

const MDRowSql MetaDataDb::getRowSql ( size_t  id) const

Definition at line 257 of file metadata_db.cpp.

257  {
258  MDRowSql row;
259  if (!getRow(row, id))
260  throw ObjectDoesNotExist(id, getFilename());
261  return row;
262 }
std::unique_ptr< MDRow > getRow(size_t id) override
virtual FileName getFilename() const

◆ getRowValues()

bool MetaDataDb::getRowValues ( size_t  id,
std::vector< MDObject > &  values 
) const
overridevirtual

Implements MetaData.

Definition at line 404 of file metadata_db.cpp.

404  {
405  for (auto &v : values) {
406  if (!containsLabel(v.label))
407  return false;
408  }
409  if (id == BAD_OBJID)
410  REPORT_ERROR(ERR_MD_NOACTIVE, "getValue: please provide objId other than -1");
411  return sqlUtils::select(id,
412  myMDSql->db,
413  myMDSql->tableName(myMDSql->tableId),
414  values);
415 }
No active object in MetaData.
Definition: xmipp_error.h:155
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MDSql * myMDSql
Definition: metadata_db.h:62
static bool select(size_t rowId, sqlite3 *db, const std::string &table, std::vector< MDObject > &values)
Definition: sql_utils.cpp:87
#define BAD_OBJID
Definition: metadata_base.h:55
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305

◆ getValue() [1/2]

bool MetaDataDb::getValue ( MDObject mdValueOut,
size_t  id 
) const
overridevirtual

Implements MetaData.

Definition at line 109 of file metadata_db.cpp.

110 {
111  if (!containsLabel(mdValueOut.label))
112  return false;
113 
114  if (id == BAD_OBJID)
115  REPORT_ERROR(ERR_MD_NOACTIVE, "getValue: please provide objId other than -1");
116 
117  return myMDSql->getObjectValue(id, mdValueOut);
118 }
No active object in MetaData.
Definition: xmipp_error.h:155
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MDSql * myMDSql
Definition: metadata_db.h:62
MDLabel label
#define BAD_OBJID
Definition: metadata_base.h:55
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305

◆ getValue() [2/2]

template<class T >
bool MetaDataDb::getValue ( const MDLabel  label,
T &  valueOut,
size_t  id 
) const
inline

Definition at line 238 of file metadata_db.h.

238  {
239  return MetaData::getValue(label, valueOut, id);
240  }
virtual bool getValue(MDObject &mdValueOut, size_t id) const =0

◆ id_begin() [1/2]

id_iterator MetaDataDb::id_begin ( )
inlineoverridevirtual

Implements MetaData.

Definition at line 793 of file metadata_db.h.

793  {
794  return {memoryUtils::make_unique<MDDbIdIterator<false>>(*this)};
795  }

◆ id_begin() [2/2]

id_const_iterator MetaDataDb::id_begin ( ) const
inlineoverridevirtual

Implements MetaData.

Definition at line 801 of file metadata_db.h.

801  {
802  return {memoryUtils::make_unique<MDDbIdIterator<true>>(*this)};
803  }

◆ id_end() [1/2]

id_iterator MetaDataDb::id_end ( )
inlineoverridevirtual

Implements MetaData.

Definition at line 797 of file metadata_db.h.

797  {
798  return {memoryUtils::make_unique<MDDbIdIterator<false>>(*this, true)};
799  }

◆ id_end() [2/2]

id_const_iterator MetaDataDb::id_end ( ) const
inlineoverridevirtual

Implements MetaData.

Definition at line 805 of file metadata_db.h.

805  {
806  return {memoryUtils::make_unique<MDDbIdIterator<true>>(*this, true)};
807  }

◆ importObject()

void MetaDataDb::importObject ( const MetaData md,
const size_t  id,
bool  doClear = true 
)
overridevirtual

Import objects from another metadata.

//Import object 1000 from metadata B into metadata A
A.importObject(B, 1000);
//Import all objects with rotational angle greater that 60
A.importObjects(B, MDValuesGT(MDL_ANGLE_ROT, 60));
//Import all objects
A.importObjects(B); *

Implements MetaData.

Definition at line 583 of file metadata_db.cpp.

584 {
585  // Currently supports importing only from MetaDataDb
586  assert(dynamic_cast<const MetaDataDb*>(&md) != nullptr);
587 
588  const MetaDataDb& mdd = dynamic_cast<const MetaDataDb&>(md);
589  MDValueEQ query(MDL_OBJID, id);
590  mdd.myMDSql->copyObjects(this, &query);
591 }
object id (int), NOTE: This label is special and shouldn&#39;t be used
MDSql * myMDSql
Definition: metadata_db.h:62

◆ importObjects() [1/2]

void MetaDataDb::importObjects ( const MetaData md,
const std::vector< size_t > &  objectsToAdd,
bool  doClear = true 
)
overridevirtual

Implements MetaData.

Definition at line 593 of file metadata_db.cpp.

594 {
595  const std::vector<MDLabel>& labels = md.getActiveLabels();
596  init(labels);
597  copyInfo(md);
598  int size = objectsToAdd.size();
599  for (int i = 0; i < size; i++)
600  importObject(md, objectsToAdd[i]);
601 }
#define i
void importObject(const MetaData &md, const size_t id, bool doClear=true) override
void copyInfo(const MetaData &md)
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59
size_t size() const override
virtual std::vector< MDLabel > getActiveLabels() const =0

◆ importObjects() [2/2]

void MetaDataDb::importObjects ( const MetaData md,
const MDQuery query,
bool  doClear = true 
)
overridevirtual

Implements MetaData.

Definition at line 603 of file metadata_db.cpp.

604 {
605  // Currently supports importing only from MetaDataDb
606  assert(dynamic_cast<const MetaDataDb*>(&md) != nullptr);
607 
608  const MetaDataDb& mdd = dynamic_cast<const MetaDataDb&>(md);
609  this->_importObjectsDb(mdd, query, doClear);
610 }
void _importObjectsDb(const MetaDataDb &md, const MDQuery &query, bool doClear=true)

◆ init()

void MetaDataDb::init ( const std::vector< MDLabel > &  labelsVector)
protected

Init, do some initializations tasks, used in constructors

Definition at line 59 of file metadata_db.cpp.

60 {
61  _clear();
62  _maxRows = 0; //by default read all rows
63  _parsedLines = 0; //no parsed line;
64  _activeLabels = labelsVector;
65  //Create table in database
66  myMDSql->createMd();
67  _precision = 100;
68  isMetadataFile = false;
69 }//close init
size_t _parsedLines
MDSql * myMDSql
Definition: metadata_db.h:62
bool isMetadataFile
void _clear(bool onlyData=false)
Definition: metadata_db.cpp:40
size_t _maxRows
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
int _precision

◆ initAddRow()

bool MetaDataDb::initAddRow ( const MDRow row)

Add a new Row and set values, return the objId of newly added object

Definition at line 331 of file metadata_db.cpp.

332 {
333  int j=0; // Loop counter.
334  bool success=true; // Return value.
335  std::vector<MDLabel> labels; // Columns labels.
336  std::vector<MDObject*> mdValues; // Vector to store values.
337 
338  // Set vector size.
339  labels.resize(row.size());
340 
341  // Get labels.
342  j=0;
343  for (const MDObject* obj : row) {
344  addLabel(obj->label);
345  labels[j] = obj->label;
346  j++;
347  }
348  labels.resize(j);
349 
350  // Prepare statement (mdValues is not used).
351  if (!myMDSql->initializeInsert( &labels, mdValues))
352  {
353  std::cerr << "initAddRow: error executing myMDSql->initializeInsert" << std::endl;
354  success = false;
355  }
356 
357  return success;
358 }
MDSql * myMDSql
Definition: metadata_db.h:62
#define j
virtual int size() const =0
bool addLabel(const MDLabel label, int pos=-1) override
void(* obj)()

◆ initGetRow()

bool MetaDataDb::initGetRow ( bool  addWhereClause) const

Definition at line 168 of file metadata_db.cpp.

169 {
170  bool success=true;
171 
172  // Prepare statement.
173  if (!myMDSql->initializeSelect( addWhereClause, this->_activeLabels))
174  {
175  success = false;
176  }
177 
178  return success;
179 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ intersection()

void MetaDataDb::intersection ( const MetaDataDb mdIn,
const MDLabel  label 
)

Intersects two Metadatas. Result in "calling" Metadata

Definition at line 1374 of file metadata_db.cpp.

1375 {
1376  if(mdIn.isEmpty())
1377  clear();
1378  else
1379  _setOperates(mdIn, label, INTERSECTION);
1380 }
virtual bool isEmpty() const
void _setOperates(const MetaDataDb &mdIn, const MDLabel label, SetOperation operation)
void clear() override
Definition: metadata_db.cpp:54

◆ join1() [1/2]

void MetaDataDb::join1 ( const MetaDataDb mdInLeft,
const MetaDataDb mdInRight,
const MDLabel  label,
JoinType  type = LEFT 
)

Join two Metadatas Result in "calling" metadata

Definition at line 1403 of file metadata_db.cpp.

1404 {
1405  join2(mdInLeft, mdInRight, label, label, type);
1406 }
void join2(const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight, const MDLabel labelLeft, const MDLabel labelRight, JoinType type=LEFT)
viol type

◆ join1() [2/2]

void MetaDataDb::join1 ( const MetaDataDb mdInLeft,
const MetaDataDb mdInRight,
const std::vector< MDLabel > &  labels,
JoinType  type = LEFT 
)

Join two Metadatas Result in "calling" metadata

Definition at line 1418 of file metadata_db.cpp.

1419 {
1420  join2(mdInLeft, mdInRight, labels, labels, type);
1421 }
void join2(const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight, const MDLabel labelLeft, const MDLabel labelRight, JoinType type=LEFT)
viol type

◆ join2() [1/2]

void MetaDataDb::join2 ( const MetaDataDb mdInLeft,
const MetaDataDb mdInRight,
const MDLabel  labelLeft,
const MDLabel  labelRight,
JoinType  type = LEFT 
)

Join two Metadatas Result in "calling" metadata. join may be done using different labels in each metadata

Definition at line 1408 of file metadata_db.cpp.

1410 {
1411  clear();
1412  std::vector<MDLabel> labelsLeft, labelsRight;
1413  labelsLeft.emplace_back(labelLeft);
1414  labelsRight.emplace_back(labelRight);
1415  _setOperates(mdInLeft, mdInRight, labelsLeft,labelsRight, (SetOperation)type);
1416 }
viol type
void _setOperates(const MetaDataDb &mdIn, const MDLabel label, SetOperation operation)
void clear() override
Definition: metadata_db.cpp:54

◆ join2() [2/2]

void MetaDataDb::join2 ( const MetaDataDb mdInLeft,
const MetaDataDb mdInRight,
const std::vector< MDLabel > &  labelsLeft,
const std::vector< MDLabel > &  labelsRight,
JoinType  type = LEFT 
)

Join two Metadatas Result in "calling" metadata. join may be done using different labels in each metadata

Definition at line 1423 of file metadata_db.cpp.

1425 {
1426  clear();
1427  _setOperates(mdInLeft, mdInRight, labelsLeft,labelsRight, (SetOperation)type);
1428 }
viol type
void _setOperates(const MetaDataDb &mdIn, const MDLabel label, SetOperation operation)
void clear() override
Definition: metadata_db.cpp:54

◆ joinNatural()

void MetaDataDb::joinNatural ( const MetaDataDb mdInLeft,
const MetaDataDb mdInRight 
)

Join two Metadatas using all common labels (NATURAL_JOIN)

Definition at line 1430 of file metadata_db.cpp.

1431 {
1432  join2(mdInLeft, mdInRight, MDL_UNDEFINED, MDL_UNDEFINED, NATURAL);
1433 }
void join2(const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight, const MDLabel labelLeft, const MDLabel labelRight, JoinType type=LEFT)

◆ lastRowId()

size_t MetaDataDb::lastRowId ( ) const
overridevirtual

Goto last metadata object.

Implements MetaData.

Definition at line 703 of file metadata_db.cpp.

704 {
705  return myMDSql->lastRow();
706 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ makeAbsPath()

void MetaDataDb::makeAbsPath ( const MDLabel  label = MDL_IMAGE)

Makes filenames with absolute paths

Definition at line 1620 of file metadata_db.cpp.

1621 {
1622 
1623  String aux_string;
1624  String aux_string_path;
1625  char buffer[1024];
1626 
1627  if (!getcwd(buffer, 1023))
1628  REPORT_ERROR(ERR_UNCLASSIFIED,"Cannot get the current directory");
1629  String path_str(buffer);
1630  path_str += "/";
1631  getValue(label, aux_string, firstRowId());
1632 
1633  if (aux_string[0] == '/')
1634  return;
1635 
1636  FileName auxFile;
1637  for (size_t id : this->ids())
1638  {
1639  aux_string_path = path_str;
1640  getValue(label, auxFile, id);
1641 
1642  if (auxFile.isInStack())
1643  {
1644  size_t id = auxFile.find('@',0);
1645  auxFile.insert(id+1,aux_string_path);
1646  setValue(label, auxFile, id);
1647  }
1648  else
1649  {
1650  auxFile.addPrefix(aux_string_path);
1651  setValue(label, auxFile, id);
1652  }
1653  }
1654 }
Just to locate unclassified errors.
Definition: xmipp_error.h:192
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
bool getValue(MDObject &mdValueOut, size_t id) const override
HBITMAP buffer
Definition: svm-toy.cpp:37
virtual IdIteratorProxy< false > ids()
FileName addPrefix(const String &prefix) const
size_t firstRowId() const override
bool setValue(const MDObject &mdValueIn, size_t id) override
Definition: metadata_db.cpp:90
std::string String
Definition: xmipp_strings.h:34
bool isInStack() const

◆ merge()

void MetaDataDb::merge ( const MetaData md2)

Merge of two Metadata. This function reads another metadata and add all columns values. The size of the two Metadatas should be the same. If there are common columns, the values in md2 will be setted.

Definition at line 1120 of file metadata_db.cpp.

1121 {
1122  if (size() != md2.size())
1123  REPORT_ERROR(ERR_MD, "Size of two metadatas should coincide for merging.");
1124 
1125  for (const auto& row : md2)
1126  this->setRow(row, row.id());
1127 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MetaData error.
Definition: xmipp_error.h:154
virtual size_t size() const =0
size_t size() const override
bool setRow(const MDRow &row, size_t id)

◆ metadataToVec()

void MetaDataDb::metadataToVec ( std::vector< MDRowSql > &  vd)

Definition at line 1707 of file metadata_db.cpp.

1708 {
1709  for (const auto& row : *this)
1710  vd.emplace_back(dynamic_cast<const MDRowSql&>(row));
1711 }

◆ operate()

void MetaDataDb::operate ( const String expression)

Basic operations on columns data. Mainly perform replacements on string values and basic algebraic operations on numerical ones.

Definition at line 1435 of file metadata_db.cpp.

1436 {
1437  if (!myMDSql->operate(expression))
1438  REPORT_ERROR(ERR_MD, "MetaDataDb::operate: error doing operation");
1439 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MDSql * myMDSql
Definition: metadata_db.h:62
MetaData error.
Definition: xmipp_error.h:154

◆ operator=()

MetaDataDb & MetaDataDb::operator= ( const MetaDataDb md)

Assignment operator

Copies MetaDataDb from an existing MetaData object.

Definition at line 527 of file metadata_db.cpp.

528 {
529  copyMetadata(md);
530  return *this;
531 }
void copyMetadata(const MetaDataDb &md, bool copyObjects=true)
Definition: metadata_db.cpp:71

◆ operator==()

bool MetaDataDb::operator== ( const MetaDataDb op) const

'is equal to' (equality).

Definition at line 1721 of file metadata_db.cpp.

1722 {
1723  return myMDSql->equals(*(op.myMDSql));
1724 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ randomize()

void MetaDataDb::randomize ( const MetaDataDb MDin)

Randomize a metadata. MDin is input and the "randomized" result will be in the "calling" Metadata.

Definition at line 1450 of file metadata_db.cpp.

1451 {
1452  std::random_device rd;
1453  auto g = std::mt19937(rd());
1454  std::vector<size_t> objects;
1455  MDin.myMDSql->selectObjects(objects);
1456  std::shuffle(objects.begin(), objects.end(), g);
1457  importObjects(MDin, objects);
1458 }
doublereal * g
MDSql * myMDSql
Definition: metadata_db.h:62
void importObjects(const MetaData &md, const std::vector< size_t > &objectsToAdd, bool doClear=true) override

◆ read()

void MetaDataDb::read ( const FileName inFile,
const std::vector< MDLabel > *  desiredLabels = NULL,
bool  decomposeStack = true 
)
overridevirtual

Read data from file. Guess the blockname from the filename

inFilename="first@md1.doc" -> filename = md1.doc, blockname = first

Implements MetaData.

Definition at line 912 of file metadata_db.cpp.

915 {
916  String blockName;
917  FileName inFile;
918 
919  blockName=_filename.getBlockName();
920  // if (blockName.empty())
921  // blockName = DEFAULT_BLOCK_NAME;
922  inFile = _filename.removeBlockName();
923  String extFile = _filename.getExtension();
924  blockName=escapeForRegularExpressions(blockName);
925 
926  _clear();
927  myMDSql->createMd();
928  this->setColumnFormat(true);
929 
930  if (extFile=="xml")
931  readXML(inFile, desiredLabels, blockName, decomposeStack);
932  else if(extFile=="sqlite")
933  readDB(inFile, desiredLabels, blockName, decomposeStack);
934  else
935  readStar(_filename, desiredLabels, blockName, decomposeStack);
936 }
String getBlockName() const
MDSql * myMDSql
Definition: metadata_db.h:62
String getExtension() const
void readXML(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, const String &blockRegExp=DEFAULT_BLOCK_NAME, bool decomposeStack=true)
void _clear(bool onlyData=false)
Definition: metadata_db.cpp:40
void readDB(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, const String &blockRegExp=DEFAULT_BLOCK_NAME, bool decomposeStack=true)
virtual void setColumnFormat(bool column)
String escapeForRegularExpressions(const String &str)
FileName removeBlockName() const
std::string String
Definition: xmipp_strings.h:34
virtual void readStar(const FileName &filename, const std::vector< MDLabel > *desiredLabels, const String &blockRegExp, bool decomposeStack)

◆ readDB()

void MetaDataDb::readDB ( const FileName inFile,
const std::vector< MDLabel > *  desiredLabels = NULL,
const String blockRegExp = DEFAULT_BLOCK_NAME,
bool  decomposeStack = true 
)

Read metadata from sqlite file

Definition at line 1041 of file metadata_db.cpp.

1045 {
1046  myMDSql->copyTableFromFileDB(blockRegExp, filename, desiredLabels, _maxRows);
1047 }
MDSql * myMDSql
Definition: metadata_db.h:62
size_t _maxRows

◆ readPlain()

void MetaDataDb::readPlain ( const FileName inFile,
const String labelsString,
const String separator = " " 
)

Try to read a metadata from plain text with some columns. Labels for each columns should be provided in an string separated by spaces. Return false if couldn't read

Definition at line 939 of file metadata_db.cpp.

940 {
941  constexpr size_t LINE_LENGTH = 1024;
942  clear();
943  std::vector<MDLabel> labels;
944  MDL::str2LabelVector(labelsString, labels);
945 
946  char lineBuffer[LINE_LENGTH];
947  String line;
948  std::ifstream is(inFile.c_str(), std::ios_base::in);
949  size_t lineCounter = 0;
950  size_t columnsNumber = labels.size();
951  size_t objId;
952  StringVector parts;
953 
954  while (is.getline(lineBuffer, LINE_LENGTH))
955  {
956  ++lineCounter;
957  line.assign(lineBuffer);
958  trim(line);
959  if (line[0]=='#') // This is an old Xmipp comment
960  continue;
961  if (!line.empty())
962  {
963  std::stringstream ss(line);
964  objId = addObject();
965  for (size_t i = 0; i < columnsNumber; ++i)
966  {
967  MDObject obj(labels[i]);
968  _parseObject(ss, obj, objId);
969  setValue(obj, objId);
970  }
971  }
972  }
973 }
void trim(std::string &s)
Definition: text.cpp:205
std::vector< String > StringVector
Definition: xmipp_strings.h:35
#define i
size_t addObject() override
int in
void clear() override
Definition: metadata_db.cpp:54
bool setValue(const MDObject &mdValueIn, size_t id) override
Definition: metadata_db.cpp:90
std::string String
Definition: xmipp_strings.h:34
void(* obj)()
static void str2LabelVector(const String &labelsStr, std::vector< MDLabel > &labels)
virtual void _parseObject(std::istream &is, MDObject &object, size_t id=BAD_OBJID)

◆ readXML()

void MetaDataDb::readXML ( const FileName inFile,
const std::vector< MDLabel > *  desiredLabels = NULL,
const String blockRegExp = DEFAULT_BLOCK_NAME,
bool  decomposeStack = true 
)

Read metadata from xml file

Definition at line 1033 of file metadata_db.cpp.

1037 {
1038  REPORT_ERROR(ERR_NOT_IMPLEMENTED,"readXML not implemented yet");
1039 }
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211

◆ removeDuplicates()

void MetaDataDb::removeDuplicates ( MetaDataDb MDin,
MDLabel  label = MDL_UNDEFINED 
)

Remove duplicate entries for attribute in label

Definition at line 1382 of file metadata_db.cpp.

1383 {
1384  if(MDin.isEmpty())
1385  return;
1386  _setOperates(MDin, label, REMOVE_DUPLICATE);
1387 }
virtual bool isEmpty() const
void _setOperates(const MetaDataDb &mdIn, const MDLabel label, SetOperation operation)

◆ removeIndex() [1/2]

void MetaDataDb::removeIndex ( MDLabel  label)

Definition at line 665 of file metadata_db.cpp.

666 {
667  std::vector<MDLabel> labels(1);
668  labels[0]=label;
669  removeIndex(labels);
670 }
void removeIndex(MDLabel label)

◆ removeIndex() [2/2]

void MetaDataDb::removeIndex ( const std::vector< MDLabel > &  desiredLabels)

Definition at line 672 of file metadata_db.cpp.

673 {
674  myMDSql->indexModify(desiredLabels, false);
675 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ removeItemId()

void MetaDataDb::removeItemId ( )

Remove item id.

Definition at line 683 of file metadata_db.cpp.

684 {
686 }
bool removeLabel(const MDLabel label) override
Unique identifier for items inside a list or set (std::size_t)

◆ removeLabel()

bool MetaDataDb::removeLabel ( const MDLabel  label)
overridevirtual

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.

Implements MetaData.

Definition at line 566 of file metadata_db.cpp.

567 {
568  std::vector<MDLabel>::iterator location;
569  location = std::find(this->_activeLabels.begin(), this->_activeLabels.end(), label);
570 
571  if (location == this->_activeLabels.end())
572  return false;
573 
574  this->_activeLabels.erase(location);
575  return true;
576 }
std::vector< SelLine >::iterator find(std::vector< SelLine > &text, const std::string &img_name)
Definition: selfile.cpp:553
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68

◆ removeObject()

bool MetaDataDb::removeObject ( size_t  id)
overridevirtual

Remove the object with this id. Returns true if the object was removed or false if the object did not exist

Implements MetaData.

Definition at line 629 of file metadata_db.cpp.

629  {
630  int removed = removeObjects(MDValueEQ(MDL_OBJID, id));
631  return (removed > 0);
632 }
object id (int), NOTE: This label is special and shouldn&#39;t be used
int removeObjects() override

◆ removeObjects() [1/3]

void MetaDataDb::removeObjects ( const std::vector< size_t > &  toRemove)
overridevirtual

Removes the collection of objects of given vector id's NOTE: The iterator will point to the first object after any of these operations

Implements MetaData.

Definition at line 634 of file metadata_db.cpp.

635 {
636  int size = toRemove.size();
637  for (int i = 0; i < size; i++)
638  removeObject(toRemove[i]);
639 }
#define i
size_t size() const override
bool removeObject(size_t id) override

◆ removeObjects() [2/3]

int MetaDataDb::removeObjects ( const MDQuery query)
overridevirtual

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

Implements MetaData.

Definition at line 641 of file metadata_db.cpp.

642 {
643  int removed = myMDSql->deleteObjects(&query);
644  return removed;
645 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ removeObjects() [3/3]

int MetaDataDb::removeObjects ( )
overridevirtual

Implements MetaData.

Definition at line 647 of file metadata_db.cpp.

648 {
649  int removed = myMDSql->deleteObjects();
650  return removed;
651 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ renameColumn() [1/2]

void MetaDataDb::renameColumn ( MDLabel  oldLabel,
MDLabel  newLabel 
)
overridevirtual

Rename column.

Implements MetaData.

Definition at line 1198 of file metadata_db.cpp.

1199 {
1200  if (!containsLabel(oldLabel))
1201  REPORT_ERROR(ERR_ARG_MISSING, formatString("Source label: '%s' doesn't exist on metadata",
1202  (MDL::label2Str(oldLabel)).c_str()));
1203  std::vector<MDLabel> vOldLabel(1);
1204  vOldLabel[0]=oldLabel;
1205  std::vector<MDLabel> vNewLabel(1);
1206  vNewLabel[0]=newLabel;
1207  renameColumn(vOldLabel,vNewLabel);
1208 }
Argument missing.
Definition: xmipp_error.h:114
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
String formatString(const char *format,...)
static String label2Str(const MDLabel &label)
void renameColumn(MDLabel oldLabel, MDLabel newLabel) override
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305

◆ renameColumn() [2/2]

void MetaDataDb::renameColumn ( const std::vector< MDLabel > &  oldLabel,
const std::vector< MDLabel > &  newLabel 
)
overridevirtual

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

Implements MetaData.

Definition at line 1210 of file metadata_db.cpp.

1212 {
1213  myMDSql->renameColumn(vOldLabel,vNewLabel);
1214 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ replace()

void MetaDataDb::replace ( const MDLabel  label,
const String oldStr,
const String newStr 
)

Replace an string in some column(label). The type of the column should be string. This function is a shortcut of the more genereal function operate

Definition at line 1441 of file metadata_db.cpp.

1442 {
1443  String labelStr = MDL::label2Str(label);
1444  String expression = formatString("%s=replace(%s,'%s', '%s')",
1445  labelStr.c_str(), labelStr.c_str(), oldStr.c_str(), newStr.c_str());
1446  if (!myMDSql->operate(expression))
1447  REPORT_ERROR(ERR_MD, "MetaDataDb::replace: error doing operation");
1448 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MDSql * myMDSql
Definition: metadata_db.h:62
MetaData error.
Definition: xmipp_error.h:154
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
static String label2Str(const MDLabel &label)

◆ selectPart()

void MetaDataDb::selectPart ( const MetaData mdIn,
size_t  startPosition,
size_t  numberOfObjects,
const MDLabel  sortLabel = MDL_OBJID 
)
overridevirtual

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.

Implements MetaData.

Definition at line 1601 of file metadata_db.cpp.

1603 {
1604  if (dynamic_cast<const MetaDataDb*>(&mdIn) != nullptr)
1605  return _selectPart(dynamic_cast<const MetaDataDb&>(mdIn), startPosition, numberOfObjects, sortLabel);
1606  throw std::logic_error("Not yet implemented"); // TODO: use universal functions just on MetaData
1607 }
void _selectPart(const MetaDataDb &mdIn, size_t startPosition, size_t numberOfObjects, const MDLabel sortLabel=MDL_OBJID)

◆ selectRandomSubset()

void MetaDataDb::selectRandomSubset ( const MetaData mdIn,
size_t  numberOfObjects,
const MDLabel  sortLabel = MDL_OBJID 
)
overridevirtual

Select random subset

Implements MetaData.

Definition at line 1584 of file metadata_db.cpp.

1585 {
1586  if (dynamic_cast<const MetaDataDb*>(&mdIn) != nullptr)
1587  return _selectRandomSubset(dynamic_cast<const MetaDataDb&>(mdIn), numberOfObjects, sortLabel);
1588  throw std::logic_error("Not yet implemented"); // TODO: use universal functions just on MetaData
1589 }
void _selectRandomSubset(const MetaDataDb &mdIn, size_t numberOfObjects, const MDLabel sortLabel=MDL_OBJID)

◆ selectSplitPart()

void MetaDataDb::selectSplitPart ( const MetaData mdIn,
size_t  n,
size_t  part,
const MDLabel  sortLabel = MDL_OBJID 
)

Take a part from MetaData. This function is equivallent to divide the input MetaData in n parts and take one. The result will be in "calling" MetaData.

Definition at line 1566 of file metadata_db.cpp.

1567 {
1568  if (dynamic_cast<const MetaDataDb*>(&mdIn) != nullptr)
1569  return _selectSplitPart(dynamic_cast<const MetaDataDb&>(mdIn), n, part, sortLabel);
1570  throw std::logic_error("Not yet implemented"); // TODO: use universal functions just on MetaData
1571 }
void _selectSplitPart(const MetaDataDb &mdIn, int n, int part, size_t mdSize, const MDLabel sortLabel)
int * n

◆ setColumnValues() [1/2]

void MetaDataDb::setColumnValues ( const std::vector< MDObject > &  valuesIn)
overridevirtual

Get all values of a column as a vector.

Implements MetaData.

Definition at line 134 of file metadata_db.cpp.

135 {
136  bool addObjects=false;
137  if (size()==0)
138  addObjects=true;
139  if (valuesIn.size()!=size() && !addObjects)
140  REPORT_ERROR(ERR_MD_OBJECTNUMBER,"Input vector must be of the same size as the metadata");
141  if (!addObjects)
142  {
143  size_t n = 0;
144  for (size_t objId : this->ids())
145  setValue(valuesIn[n++], objId);
146  }
147  else
148  {
149  size_t nmax=valuesIn.size();
150  for (size_t n=0; n<nmax; ++n)
151  setValue(valuesIn[n],addObject());
152  }
153 }
int * nmax
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
virtual IdIteratorProxy< false > ids()
Incorrect number of objects in Metadata.
Definition: xmipp_error.h:160
size_t addObject() override
size_t size() const override
bool setValue(const MDObject &mdValueIn, size_t id) override
Definition: metadata_db.cpp:90
int * n

◆ setColumnValues() [2/2]

template<class T >
void MetaDataDb::setColumnValues ( const MDLabel  label,
const std::vector< T > &  valuesIn 
)
inline

Definition at line 266 of file metadata_db.h.

266  {
267  return MetaData::setColumnValues(label, valuesIn);
268  }
void setColumnValues(const MDLabel label, const std::vector< T > &valuesIn)

◆ setRow()

bool MetaDataDb::setRow ( const MDRow row,
size_t  id 
)

Copy all the values in the input row in the current metadata

Definition at line 306 of file metadata_db.cpp.

307 {
308  if (row.empty()) {
309  return true;
310  }
311  addMissingLabels(row);
312 
313  // create mask of valid labels
314  std::vector<MDLabel> labels;
315  labels.reserve(row.size());
316  for (const MDObject* obj : row) {
317  labels.emplace_back(obj->label);
318  }
319  // extract values to be added
320  std::vector<const MDObject*> vals;
321  vals.reserve(row.size());
322  for (const auto &l : labels) {
323  vals.emplace_back(row.getObject(l));
324  }
325  // update values to db
326  return sqlUtils::update(vals, MDSql::db,
327  myMDSql->tableName(myMDSql->tableId), id);
328 }
virtual bool empty() const =0
MDSql * myMDSql
Definition: metadata_db.h:62
static bool update(const std::vector< const MDObject *> &values, sqlite3 *db, const std::string &table, size_t id)
Definition: sql_utils.cpp:206
void addMissingLabels(const MDRow &row)
virtual int size() const =0
void(* obj)()

◆ setValue() [1/2]

bool MetaDataDb::setValue ( const MDObject mdValueIn,
size_t  id 
)
overridevirtual

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

Implements MetaData.

Definition at line 90 of file metadata_db.cpp.

91 {
92  if (id == BAD_OBJID)
93  {
94  REPORT_ERROR(ERR_MD_NOACTIVE, "setValue: please provide objId other than -1");
95  exit(1);
96  }
97  //add label if not exists, this is checked in addlabel
98  addLabel(mdValueIn.label);
99  return myMDSql->setObjectValue(id, mdValueIn);
100 }
No active object in MetaData.
Definition: xmipp_error.h:155
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MDSql * myMDSql
Definition: metadata_db.h:62
MDLabel label
bool addLabel(const MDLabel label, int pos=-1) override
#define BAD_OBJID
Definition: metadata_base.h:55

◆ setValue() [2/2]

template<class T >
bool MetaDataDb::setValue ( const MDLabel  label,
const T &  valueIn,
size_t  id 
)
inline

Definition at line 230 of file metadata_db.h.

230  {
231  return MetaData::setValue(label, valueIn, id);
232  }
bool setValue(const MDLabel label, const T &valueIn, size_t id)

◆ setValueCol() [1/2]

bool MetaDataDb::setValueCol ( const MDObject mdValueIn)
overridevirtual

Set the value of all objects in an specified column (both value and column are specified in mdValueIn)

Implements MetaData.

Definition at line 102 of file metadata_db.cpp.

103 {
104  //add label if not exists, this is checked in addlabel
105  addLabel(mdValueIn.label);
106  return myMDSql->setObjectValue(mdValueIn);
107 }
MDSql * myMDSql
Definition: metadata_db.h:62
MDLabel label
bool addLabel(const MDLabel label, int pos=-1) override

◆ setValueCol() [2/2]

template<class T >
bool MetaDataDb::setValueCol ( const MDLabel  label,
const T &  valueIn 
)
inline

Definition at line 215 of file metadata_db.h.

215  {
216  return MetaData::setValueCol(label, valueIn);
217  }
virtual bool setValueCol(const MDObject &mdValueIn)=0

◆ size()

size_t MetaDataDb::size ( ) const
overridevirtual

Number of objects contained in the metadata.

Implements MetaData.

Definition at line 549 of file metadata_db.cpp.

550 {
551  return myMDSql->size();
552 }
MDSql * myMDSql
Definition: metadata_db.h:62

◆ sort() [1/2]

void MetaDataDb::sort ( MetaDataDb MDin,
const MDLabel  sortLabel,
bool  asc = true,
int  limit = -1,
int  offset = 0 
)

Definition at line 1460 of file metadata_db.cpp.

1461 {
1462  if (MDin.containsLabel(sortLabel))
1463  {
1464  init(MDin._activeLabels);
1465  copyInfo(MDin);
1466  //if you sort just once the index will not help much
1467  addIndex(sortLabel);
1468  MDQuery query(limit, offset, sortLabel,asc);
1469  MDin.myMDSql->copyObjects(this, &query);
1470  }
1471  else
1472  *this=MDin;
1473 }
MDSql * myMDSql
Definition: metadata_db.h:62
void copyInfo(const MetaData &md)
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59
void addIndex(MDLabel label) const
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305

◆ sort() [2/2]

void MetaDataDb::sort ( MetaDataDb MDin,
const String sortLabel,
bool  asc = true,
int  limit = -1,
int  offset = 0 
)

Definition at line 1475 of file metadata_db.cpp.

1476 {
1477  // Check if the label has semicolon
1478  size_t ipos=sortLabel.find(':');
1479  MDLabelType type = MDL::labelType(sortLabel);
1480  if (ipos!=String::npos || type == LABEL_VECTOR_DOUBLE || type == LABEL_VECTOR_SIZET)
1481  {
1482  if(limit != -1 || offset != 0)
1483  REPORT_ERROR(ERR_ARG_INCORRECT,"Limit and Offset are not implemented for vector sorting.");
1484 
1485  MDLabel label;
1486  size_t column;
1487  if (ipos!=String::npos)
1488  {
1489  // Check that the label is a vector field
1490  std::vector< String > results;
1491  splitString(sortLabel,":",results);
1492  column=textToInteger(results[1]);
1493  MDLabelType type = MDL::labelType(results[0]);
1494  if (type != LABEL_VECTOR_DOUBLE || type != LABEL_VECTOR_SIZET)
1495  REPORT_ERROR(ERR_ARG_INCORRECT,"Column specifications cannot be used with non-vector labels");
1496  label = MDL::str2Label(results[0]);
1497  }
1498  else
1499  {
1500  label = MDL::str2Label(sortLabel);
1501  column = 0;
1502  }
1503 
1504  // Get the column values
1506  v.resizeNoCopy(MDin.size());
1507  std::vector<double> vectorValues;
1508  int i = 0;
1509  for (size_t id : MDin.ids())
1510  {
1511  MDin.getValue(label, vectorValues, id);
1512  if (column >= vectorValues.size())
1513  REPORT_ERROR(ERR_MULTIDIM_SIZE,"Trying to access to inexistent column in vector");
1514  DIRECT_A1D_ELEM(v, i) = vectorValues[column];
1515  i++;
1516  }
1517 
1518  // Sort
1519  MultidimArray<int> idx;
1520  v.indexSort(idx);
1521 
1522  // Construct output Metadata
1523  init(MDin._activeLabels);
1524  copyInfo(MDin);
1525  size_t id;
1527  {
1528  MDRowSql row;
1529  MDin.getRow(row,DIRECT_A1D_ELEM(idx,i));
1530  id = addObject();
1531  setRow(row, id);
1532  }
1533  }
1534  else
1535  {
1536  sort(MDin, MDL::str2Label(sortLabel),asc, limit, offset);
1537  }
1538 }
static MDLabel str2Label(const String &labelName)
MDLabelType
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void resizeNoCopy(const MultidimArray< T1 > &v)
bool getValue(MDObject &mdValueOut, size_t id) const override
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
virtual IdIteratorProxy< false > ids()
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY1D(v)
#define i
static MDLabelType labelType(const MDLabel label)
std::unique_ptr< MDRow > getRow(size_t id) override
#define DIRECT_A1D_ELEM(v, i)
viol type
size_t addObject() override
int splitString(const String &input, const String &delimiter, StringVector &results, bool includeEmpties)
Incorrect argument received.
Definition: xmipp_error.h:113
void copyInfo(const MetaData &md)
void init(const std::vector< MDLabel > &labelsVector)
Definition: metadata_db.cpp:59
size_t size() const override
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
bool setRow(const MDRow &row, size_t id)
void sort(MetaDataDb &MDin, const MDLabel sortLabel, bool asc=true, int limit=-1, int offset=0)
int textToInteger(const char *str)
MDLabel
void indexSort(MultidimArray< int > &indx) const

◆ split()

void MetaDataDb::split ( size_t  n,
std::vector< MetaDataDb > &  results,
const MDLabel  sortLabel = MDL_OBJID 
)

Split Metadata in several Metadatas. The Metadata will be divided in 'n' almost equally parts and the result will be a vector of Metadatas. The "calling" Metadata will no be modified.

// Divide the images metadata in 10 metadatas.
std::vector<MetaData> imagesGroups;
imageMD.split(10, imagesGroups);

Definition at line 1540 of file metadata_db.cpp.

1541 {
1542  size_t mdSize = size();
1543  if (n > mdSize)
1544  REPORT_ERROR(ERR_MD, "MetaDataDb::split: Couldn't split a metadata in more parts than its size");
1545 
1546  results.clear();
1547  results.resize(n);
1548  for (size_t i = 0; i < n; i++)
1549  {
1550  MetaDataDb &md = results.at(i);
1551  md._selectSplitPart(*this, n, i, mdSize, sortLabel);
1552  }
1553 }
void _selectSplitPart(const MetaDataDb &mdIn, int n, int part, size_t mdSize, const MDLabel sortLabel)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define i
MetaData error.
Definition: xmipp_error.h:154
size_t size() const override
int * n

◆ subtraction()

void MetaDataDb::subtraction ( const MetaDataDb mdIn,
const MDLabel  label 
)

Subtract two Metadatas. Result in "calling" metadata

Definition at line 1396 of file metadata_db.cpp.

1397 {
1398  if(mdIn.isEmpty())
1399  return;
1400  _setOperates(mdIn, label, SUBSTRACTION);
1401 }
virtual bool isEmpty() const
void _setOperates(const MetaDataDb &mdIn, const MDLabel label, SetOperation operation)

◆ unionAll()

void MetaDataDb::unionAll ( const MetaDataDb mdIn)

Union of all elements in two Metadata, duplicating common elements. Result in calling metadata object Repetition are allowed

Definition at line 1366 of file metadata_db.cpp.

1367 {
1368  if(mdIn.isEmpty())
1369  return;
1370  _setOperates(mdIn, MDL_UNDEFINED, UNION);//label not needed for unionAll operation
1371 }
virtual bool isEmpty() const
void _setOperates(const MetaDataDb &mdIn, const MDLabel label, SetOperation operation)

◆ unionDistinct()

void MetaDataDb::unionDistinct ( const MetaDataDb mdIn,
const MDLabel  label = MDL_OBJID 
)

Union of elements in two Metadatas, without duplicating. Result in calling metadata object union is a reserved word so I called this method unionDistinct

Definition at line 1359 of file metadata_db.cpp.

1360 {
1361  if(mdIn.isEmpty())
1362  return;
1363  _setOperates(mdIn, label, UNION_DISTINCT);
1364 }
virtual bool isEmpty() const
void _setOperates(const MetaDataDb &mdIn, const MDLabel label, SetOperation operation)

◆ vecToMetadata()

void MetaDataDb::vecToMetadata ( const std::vector< MDRow > &  rowMetadata)

Definition at line 1713 of file metadata_db.cpp.

1714 {
1715  const MDRowSql row;
1716 
1717  for (size_t i=0;i<rowMetadata.size();i++)
1718  this->addRow(rowMetadata[i]);
1719 }
#define i
size_t addRow(const MDRow &row) override

◆ write() [1/2]

void MetaDataDb::write ( const FileName outFile,
WriteModeMetaData  mode = MD_OVERWRITE 
) const
overridevirtual

Write metadata to disk. Guess blockname from filename

outFilename="first@md1.doc" -> filename = md1.doc, blockname = first

Implements MetaData.

Definition at line 748 of file metadata_db.cpp.

749 {
750  String blockName;
751  FileName outFile;
752  FileName extFile;
753 
754  blockName=_outFile.getBlockName();
755  if (blockName.empty())
756  blockName = DEFAULT_BLOCK_NAME;
757  outFile = _outFile.removeBlockName();
758  extFile = _outFile.getExtension();
759 
760  if (extFile=="xml")
761  {
762  writeXML(outFile, blockName, mode);
763  }
764  else if(extFile=="sqlite")
765  {
766  writeDB(outFile, blockName, mode);
767  }
768  else
769  {
770  writeStar(outFile, blockName, mode);
771  }
772 }
String getBlockName() const
virtual void writeStar(const FileName &outFile, const String &blockName, WriteModeMetaData mode) const
void writeXML(const FileName fn, const FileName blockname, WriteModeMetaData mode) const override
String getExtension() const
void mode
FileName removeBlockName() const
std::string String
Definition: xmipp_strings.h:34
void writeDB(const FileName fn, const FileName blockname, WriteModeMetaData mode) const
#define DEFAULT_BLOCK_NAME
Definition: metadata_base.h:60

◆ write() [2/2]

void MetaDataDb::write ( std::ostream &  os,
const String blockName = "",
WriteModeMetaData  mode = MD_OVERWRITE 
) const
overridevirtual

Implements MetaData.

Definition at line 795 of file metadata_db.cpp.

796 {
797  if(mode==MD_OVERWRITE)
798  os << FileNameVersion << " * "// << (isColumnFormat ? "column" : "row")
799  << '\n' //write which type of format (column or row) and the path;
800  << WordWrap(this->_comment, line_max); //write md comment in the 2nd comment line of header
801  //write data block
802  String _szBlockName("data_");
803  _szBlockName += blockName;
804 
805  if (this->isColumnFormat())
806  {
807  //write md columns in 3rd comment line of the header
808  os << _szBlockName << '\n';
809  os << "loop_" << '\n';
810  auto sortedLabels = this->_activeLabels;
811  std::sort(sortedLabels.begin(), sortedLabels.end());
812  for (size_t i = 0; i < sortedLabels.size(); i++)
813  {
814  const auto &label = sortedLabels.at(i);
815  if (label != MDL_STAR_COMMENT)
816  {
817  os << " _" << MDL::label2Str(label) << '\n';
818  }
819  }
820  _writeRows(os);
821 
822  //Put the activeObject to the first, if exists
823  }
824  else //rowFormat
825  {
826  os << _szBlockName << '\n';
827 
828  // Get first object. In this case (row format) there is a single object
829  size_t id = firstRowId();
830 
831  if (id != BAD_OBJID)
832  {
833  auto sortedLabels = this->_activeLabels;
834  std::sort(sortedLabels.begin(), sortedLabels.end());
835  for (size_t i = 0; i < sortedLabels.size(); i++)
836  {
837  const auto &label = sortedLabels.at(i);
838  if (label != MDL_STAR_COMMENT)
839  {
840  MDObject mdValue(label);
841  os << " _" << MDL::label2Str(label) << " ";
842  myMDSql->getObjectValue(id, mdValue);
843  mdValue.toStream(os);
844  os << '\n';
845  }
846  }
847  }
848 
849  }
850 }//write
virtual bool isColumnFormat() const
void _writeRows(std::ostream &os) const override
String WordWrap(const String &inputString, size_t lineLength)
MDSql * myMDSql
Definition: metadata_db.h:62
String FileNameVersion
String _comment
#define i
void mode
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
size_t firstRowId() const override
std::string String
Definition: xmipp_strings.h:34
#define line_max
comment is wraped in char_max length lines
static String label2Str(const MDLabel &label)
#define BAD_OBJID
Definition: metadata_base.h:55
A comment for this object /*** NOTE THIS IS A SPECIAL CASE AND SO IS TREATED ***/.

◆ writeDB()

void MetaDataDb::writeDB ( const FileName  fn,
const FileName  blockname,
WriteModeMetaData  mode 
) const

Write metadata in sqlite3 file.

Definition at line 1656 of file metadata_db.cpp.

1657 {
1658  if(mode==MD_OVERWRITE)
1659  unlink(fn.c_str());
1660  myMDSql->copyTableToFileDB(blockname,fn);
1661 }
MDSql * myMDSql
Definition: metadata_db.h:62
void mode

◆ writeText()

void MetaDataDb::writeText ( const FileName  fn,
const std::vector< MDLabel > *  desiredLabels 
) const
overridevirtual

Write metadata in text file as plain data without header.

Implements MetaData.

Definition at line 1692 of file metadata_db.cpp.

1693 {
1694  std::ofstream ofs(fn.c_str(), std::ios_base::trunc|std::ios_base::out);
1695 
1696  if (desiredLabels != NULL)
1697  {
1698  MetaDataDb mdAux(*this);
1699  mdAux._activeLabels = *desiredLabels;
1700  mdAux._writeRows(ofs);
1701  }
1702  else
1703  _writeRows(ofs);
1704  ofs.close();
1705 }
void _writeRows(std::ostream &os) const override
int trunc(double x)
Definition: ap.cpp:7248

◆ writeXML()

void MetaDataDb::writeXML ( const FileName  fn,
const FileName  blockname,
WriteModeMetaData  mode 
) const
overridevirtual

Export medatada to xml file.

Implements MetaData.

Definition at line 1663 of file metadata_db.cpp.

1664 {
1665  //fixme
1667  if(mode!=MD_OVERWRITE)
1668  REPORT_ERROR(ERR_NOT_IMPLEMENTED,"XML is only implemented for overwrite mode");
1669  std::ofstream ofs(fn.c_str(), std::ios_base::out|std::ios_base::trunc);
1670  size_t size = this->_activeLabels.size();
1671  ofs << "<" << blockname << ">"<< '\n';
1672  for (size_t id : this->ids())
1673  {
1674  ofs << "<ROW ";
1675  for (size_t i = 0; i < size; i++)
1676  {
1677  if (this->_activeLabels[i] != MDL_STAR_COMMENT)
1678  {
1679  ofs << MDL::label2Str(this->_activeLabels[i]) << "=\"";
1680  MDObject mdValue(this->_activeLabels[i]);
1681  //ofs.width(1);
1682  myMDSql->getObjectValue(id, mdValue);
1683  mdValue.toStream(ofs, true);
1684  ofs << "\" ";
1685  }
1686  }
1687  ofs << " />" << '\n';
1688  }
1689  ofs << "</" << blockname << ">"<< '\n';
1690 }
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MDSql * myMDSql
Definition: metadata_db.h:62
virtual IdIteratorProxy< false > ids()
#define i
void mode
size_t size() const override
std::vector< MDLabel > _activeLabels
Definition: metadata_db.h:68
int trunc(double x)
Definition: ap.cpp:7248
static String label2Str(const MDLabel &label)
A comment for this object /*** NOTE THIS IS A SPECIAL CASE AND SO IS TREATED ***/.

Friends And Related Function Documentation

◆ MDSql

friend class MDSql
friend

This variables should only be used by MDSql for handling db status of metadataThe table id to do db operations

Definition at line 61 of file metadata_db.h.

Member Data Documentation

◆ _activeLabels

std::vector<MDLabel> MetaDataDb::_activeLabels
protected

What labels have been read from a docfile/metadata file and/or will be stored on a new metadata file when "save" is called

Definition at line 68 of file metadata_db.h.

◆ myMDSql

MDSql* MetaDataDb::myMDSql
protected

Definition at line 62 of file metadata_db.h.


The documentation for this class was generated from the following files: