Xmipp  v3.23.11-Nereus
metadata_base.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Jan Horacek (xhorace4@fi.muni.cz)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include <fstream>
27 #include <algorithm>
28 #include "metadata_base.h"
29 #include "xmipp_image.h"
30 
31 #include <sys/stat.h>
32 #include <fcntl.h>
33 #ifdef XMIPP_MMAP
34 #include <sys/mman.h>
35 #endif
36 #include "metadata_db.h"
37 #include "xmipp_funcs.h"
38 
39 // Get the blocks available
40 void getBlocksInMetaDataFile(const FileName &inFile, StringVector& blockList)
41 {
42  if (!inFile.isMetaData())
43  return;
44  if (inFile.getBlockName() != "")
45  return;
46  blockList.clear();
47  String extFile = inFile.getExtension();
48 
49  if (extFile == "xml") {
50  REPORT_ERROR(ERR_NOT_IMPLEMENTED, "getBlocksInMetaDataFile");
51  } else if(extFile == "sqlite") {
52  getBlocksInMetaDataFileDB(inFile, blockList);
53  } else { //map file
54  int fd;
55  MetaDataDb mdAux;
56  mdAux.setMaxRows(1);
57  mdAux.read(inFile);
58  BUFFER_CREATE(bufferMap);
59  mapFile(inFile, bufferMap.begin, bufferMap.size, fd);
60  BUFFER_COPY(bufferMap, buffer);
61  BLOCK_CREATE(block);
62  String blockName;
63  while (mdAux.nextBlock(buffer, block)) {
64  BLOCK_NAME(block, blockName);
65  blockList.emplace_back(blockName);
66  }
67 
68  unmapFile(bufferMap.begin, bufferMap.size, fd);
69  }
70 }
71 
72 // Does the blocks exist
73 bool existsBlockInMetaDataFile(const FileName &inFileWithBlock) {
74  return existsBlockInMetaDataFile(inFileWithBlock.removeBlockName(),
75  inFileWithBlock.getBlockName());
76 }
77 
78 bool existsBlockInMetaDataFile(const FileName &inFile, const String& inBlock) {
79  if (!inFile.isMetaData())
80  return false;
81  if (!inFile.getBlockName().empty())
82  return inBlock == inFile.getBlockName();
83 
84  MetaDataDb MDaux(inFile);
85  //map file
86  int fd;
87  BUFFER_CREATE(bufferMap);
88  mapFile(inFile, bufferMap.begin, bufferMap.size, fd);
89  BUFFER_COPY(bufferMap, buffer);
90  BLOCK_CREATE(block);
91  String blockName;
92  bool result = false;
93  while (MDaux.nextBlock(buffer, block)) {
94  BLOCK_NAME(block, blockName);
95  if (inBlock == blockName) {
96  result = true;
97  break;
98  }
99  }
100 
101  unmapFile(bufferMap.begin, bufferMap.size, fd);
102  return result;
103 }
104 
106 
107 bool MetaData::setValueFromStr(const MDLabel label, const String &value, size_t id) {
108  addLabel(label);
109  MDObject mdValue(label);
110  mdValue.fromString(value);
111  this->setValue(mdValue, id);
112  return true;
113 }
114 
115 bool MetaData::getStrFromValue(const MDLabel label, String &strOut, size_t id) const {
116  MDObject mdValueOut(label);
117  if (!getValue(mdValueOut, id))
118  return false;
119  strOut = mdValueOut.toString();
120  return true;
121 }
122 
125  removeObjects(MDValueLE(MDL_ENABLED, 0)); // Remove values -1 and 0 on MDL_ENABLED label
126 }
127 
129  toLower(mode);
130  if (mode.npos != mode.find("overwrite"))
131  return MD_OVERWRITE;
132  if (mode.npos != mode.find("append"))
133  return MD_APPEND;
134  REPORT_ERROR(ERR_ARG_INCORRECT,"metadataModeConvert: Invalid mode: "+mode);
135 }
136 
137 bool vectorContainsLabel(const std::vector<MDLabel>& labelsVector, const MDLabel label) {
138  std::vector<MDLabel>::const_iterator location;
139  location = std::find(labelsVector.begin(), labelsVector.end(), label);
140  return (location != labelsVector.end());
141 }
142 
143 void MetaData::keepLabels(const std::vector<MDLabel> &labels) {
144  auto active = this->getActiveLabels();
145  for (const auto &l : active) {
146  if (!vectorContainsLabel(labels, l)) {
147  this->removeLabel(l);
148  }
149  }
150 }
151 
153  _comment.clear();
154  _fastStringSearch.clear();
156 
157  _isColumnFormat = true;
158  _inFile = FileName();
159  _precision = 1000;
160  _parsedLines = 0;
161 }
162 
163 void MetaData::copyInfo(const MetaData& md) {
164  _comment = md._comment;
167 
168  _isColumnFormat = md._isColumnFormat;
169  _inFile = md._inFile;
170 }
171 
172 double MetaData::precision() const {
173  return 1./this->_precision;
174 }
175 
177  BLOCK_INIT(block);
178  if (buffer.size == 0)
179  return false;
180  // Search for data_ after a newline
181  block.begin = BUFFER_FIND(buffer, "data_", 5);
182 
183  if (block.begin) // data_ FOUND!!!
184  {
185  block.begin += 5; //Shift data_
186  size_t n = block.begin - buffer.begin;
187  BUFFER_MOVE(buffer, n);
188  //Search for the end of line
189  char *newLine = BUFFER_FIND(buffer, "\n", 1);
190  //Calculate length of block name, counting after data_
191  block.nameSize = newLine - buffer.begin;
192  //Search for next block if exists one
193  //use assign and check if not NULL at same time
194  if (!(block.end = BUFFER_FIND(buffer, "\ndata_", 6))) {
195  block.end = block.begin + buffer.size; }
196  else {
197  block.end += 1; // to include terminal \n
198  }
199  block.loop = BUFFER_FIND(buffer, "\nloop_", 6);
200  //If loop_ is not found or is found outside block
201  //scope, the block is in column format
202  if (block.loop)
203  {
204  if (block.loop < block.end)
205  block.loop += 6; // Shift \nloop_
206  else
207  block.loop = NULL;
208  }
209  //Move buffer to end of block
210  n = block.end - buffer.begin;
211  BUFFER_MOVE(buffer, n);
212  return true;
213  }
214 
215  return false;
216 }
217 
218 /* This function will read the possible columns from the file
219  * and mark as MDL_UNDEFINED those who aren't valid labels
220  * or those who appears in the IgnoreLabels vector
221  * also set the activeLabels (for OLD doc files)
222  */
223 void MetaData::_readColumns(std::istream& is, std::vector<MDObject*> & columnValues,
224  const std::vector<MDLabel>* desiredLabels) {
225  String token;
226  MDLabel label;
227 
228  while (is >> token)
229  if (token.find('(') == String::npos)
230  {
231  //label is not recognized, the MDValue will be created
232  //with MDL_UNDEFINED, which will be ignored while reading data
233  label = MDL::str2Label(token);
234 
235  // Try to read undefined labels as String using the buffer approach
236  if (label == MDL_UNDEFINED)
237  label = MDL::getNewAlias(token);
238 
239  if (desiredLabels != NULL && !vectorContainsLabel(*desiredLabels, label))
240  label = MDL_UNDEFINED; //ignore if not present in desiredLabels
241  columnValues.emplace_back(new MDObject(label));
242  if (label != MDL_UNDEFINED)
243  addLabel(label);
244 
245  }
246 }
247 
248 /* This function will read the possible columns from the file
249  * and mark as MDL_UNDEFINED those who aren't valid labels
250  * or those who appears in the IgnoreLabels vector
251  * also set the activeLabels (for new STAR files)
252  */
254  std::vector<MDObject*> & columnValues,
255  const std::vector<MDLabel>* desiredLabels,
256  bool addColumns,
257  size_t id) {
258  char * end = block.end;
259  char * newline = NULL;
260  bool found_column;
261  MDLabel label;
262  char * iter = block.loop;
263  if (!_isColumnFormat)
264  {
265  iter = block.begin;
266  iter = END_OF_LINE() + 1; //this should point at first label, after data_XXX
267  }
268 
269  do
270  {
271  found_column = false;
272  while (iter[0] == '#') //Skip comment
273  iter = END_OF_LINE() + 1;
274 
275  //trim spaces and newlines at the beginning
276  while ( isspace(iter[0]))
277  ++iter;
278 
279  if (iter < end && iter[0] == '_')
280  {
281  found_column = true;
282  ++iter; //shift _
283  std::stringstream ss;
284  newline = END_OF_LINE();
285  //Last label and no data needs this check
286  if (newline == NULL)
287  newline = end;
288  String s(iter, newline - iter);//get current line
289  ss.str(s);//set the string of the stream
290  //Take the first token which is the label
291  //if the label contain spaces will fail
292  ss >> s; //get the first token, the label
293  label = MDL::str2Label(s);
294  if (label == MDL_UNDEFINED)
295  label = MDL::getNewAlias(s);
296  if (desiredLabels != NULL && !vectorContainsLabel(*desiredLabels, label))
297  label = MDL_UNDEFINED; //ignore if not present in desiredLabels
298 
299  if (label != MDL_UNDEFINED)
300  addLabel(label);
301 
302  if (addColumns)
303  {
304  MDObject * _mdObject = new MDObject(label);
305  columnValues.emplace_back(_mdObject);//add the value here with a char
306  if(!_isColumnFormat)
307  _parseObject(ss, *_mdObject, id);
308  }
309  iter = newline + 1;//go to next line character
310  }
311  }
312  while (found_column)
313  ;
314 
315  // This condition fails for empty blocks
316  // if (iter < block.end)
317  if (iter <= block.end +1)
318  block.loop = iter; //Move loop pointer to position of last found column
319 }
320 
321 /* Helper function to parse an MDObject and set its value.
322  * The parsing will be from an input stream(istream)
323  * and if parsing fails, an error will be raised
324  */
325 void MetaData::_parseObject(std::istream &is, MDObject &object, size_t id) {
326  object.fromStream(is);
327  if (is.fail()) {
328  String errorMsg = formatString("MetaData: Error parsing column '%s' value.", MDL::label2Str(object.label).c_str());
329  object.failed = true;
330  std::cerr << "WARNING: " << errorMsg << std::endl;
331  //REPORT_ERROR(ERR_MD_BADLABEL, (String)"read: Error parsing data column, expecting " + MDL::label2Str(object.label));
332  } else {
333  if (object.label != MDL_UNDEFINED)
334  setValue(object, id);
335  }
336 }
337 
338 /* This function parses rows data in START format
339  */
340 void MetaData::_readRowsStar(mdBlock &block, std::vector<MDObject*> & columnValues,
341  const std::vector<MDLabel> *desiredLabels) {
342  String line;
343  std::stringstream ss;
344  size_t n = block.end - block.loop;
345  bool firstTime = true;
346 
347  if (n == 0)
348  return;
349 
350  char * buffer = new char[n];
351  memcpy(buffer, block.loop, n);
352  char *iter = buffer, *end = iter + n, * newline = NULL;
353  _parsedLines = 0; //Check how many lines the md have
354 
355  while (iter < end) { //while there are data lines
356  //Adding \n position and check if NULL at the same time
357  if (!(newline = END_OF_LINE()))
358  newline = end;
359  line.assign(iter, newline - iter);
360  trim(line);
361 
362  if (!line.empty() && line[0] != '#') {
363  //_maxRows would be > 0 if we only want to read some
364  // rows from the md for performance reasons...
365  // anyway the number of lines will be counted in _parsedLines
366  if (_maxRows == 0 || _parsedLines < _maxRows) {
367  std::stringstream ss(line);
368  this->_parseObjects(ss, columnValues, desiredLabels, firstTime);
369  firstTime = false;
370  }
371  _parsedLines++;
372  }
373  iter = newline + 1; //go to next line
374  }
375 
376  delete[] buffer;
377 }
378 
379 void MetaData::_readRows(std::istream& is, std::vector<MDObject*>& columnValues, bool useCommentAsImage) {
380  String line = "";
381  while (!is.eof() && !is.fail()) {
382  // Move until the ';' or the first alphanumeric character
383  while (is.peek() != ';' && isspace(is.peek()) && !is.eof())
384  is.ignore(1);
385  if (!is.eof()) {
386  if (is.peek() == ';') { //is a comment
387  is.ignore(1); //ignore the ';'
388  getline(is, line);
389  trim(line);
390  } else if (!isspace(is.peek())) {
391  size_t id = addObject();
392  if (line != "") { //this is for old format files
393  if (!useCommentAsImage)
394  this->setValue(MDObject(MDL_STAR_COMMENT, line), id);
395  else
396  this->setValue(MDObject(MDL_IMAGE, line), id);
397  }
398  int nCol = columnValues.size();
399  for (int i = 0; i < nCol; ++i)
400  this->_parseObject(is, *(columnValues[i]), id);
401  }
402  }
403  }
404 }
405 
406 void MetaData::readStar(const FileName &filename, const std::vector<MDLabel> *desiredLabels,
407  const String &blockRegExp, bool decomposeStack) {
408  // First try to open the file as a metadata
409  size_t id;
410  FileName inFile = filename.removeBlockName();
411 
412  if (!(isMetadataFile = inFile.isMetaData())) { //if not a metadata, try to read as image or stack
413  Image<char> image;
414  if (decomposeStack) // If not decomposeStack it is no necessary to read the image header
415  image.read(filename, HEADER);
416  if (!decomposeStack || image().ndim == 1) { // single image; !decomposeStack must be first
417  id = this->addObject();
418  MetaData::setValue(MDL_IMAGE, filename, id);
420  } else { // stack
421  FileName fnTemp;
422  for (size_t i = 1; i <= image().ndim; ++i) {
423  fnTemp.compose(i, filename);
424  id = addObject();
425  MetaData::setValue(MDL_IMAGE, fnTemp, id);
427  }
428  }
429  return;
430  }
431 
432  std::ifstream is(inFile.c_str(), std::ios_base::in);
433  std::stringstream ss;
434  String line, token,_comment;
435  std::vector<MDObject*> columnValues;
436 
437  getline(is, line); //get first line to identify the type of file
438 
439  if (is.fail())
440  REPORT_ERROR(ERR_IO_NOTEXIST, formatString("MetaDataDb::read: File doesn't exists: %s", inFile.c_str()) );
441 
442  bool useCommentAsImage = false;
443  this->_inFile = inFile;
444  bool oldFormat = true;
445 
446  is.seekg(0, std::ios::beg);//reset the stream position to the beginning to start parsing
447 
448  if (line.find(FileNameVersion) != String::npos ||
449  filename.getExtension() == "xmd" || filename.getExtension() == "star") {
450  oldFormat = false;
451  _comment.clear();
452 
453  // Skip comment parsing if we found the data key in the first line
454  if (line.find("data_") != 0) {
455  // Read comment
456  // is.ignore(256,'#');//format line
457  is.ignore(256, '\n');//skip first line
458  bool addspace = false;
459  while (1) {
460  getline(is, line);
461  trim(line);
462  if (line[0] == '#')
463  {
464  line[0] = ' ';
465  trim(line);
466  if (addspace)
467  _comment += " " + line;
468  else
469  _comment += line;
470  addspace = true;
471  } else
472  break;
473  }
474  this->setComment(_comment);
475  }
476 
477  //map file
478  int fd;
479  BUFFER_CREATE(bufferMap);
480  mapFile(inFile, bufferMap.begin, bufferMap.size, fd);
481 
482  BLOCK_CREATE(block);
483  regex_t re;
484  int rc = regcomp(&re, (blockRegExp+"$").c_str(), REG_EXTENDED|REG_NOSUB);
485  if (blockRegExp.size() && rc != 0)
486  REPORT_ERROR(ERR_ARG_INCORRECT, formatString("Pattern '%s' cannot be parsed: %s",
487  blockRegExp.c_str(), inFile.c_str()));
488  BUFFER_COPY(bufferMap, buffer);
489  bool firstBlock = true;
490  bool singleBlock = blockRegExp.find_first_of(".[*+")==String::npos;
491 
492  String blockName;
493 
494  while (nextBlock(buffer, block)) {
495  //startingPoint, remainingSize, firstData, secondData, firstloop))
496  BLOCK_NAME(block, blockName);
497  if (blockRegExp.size() == 0 || regexec(&re, blockName.c_str(), (size_t) 0, NULL, 0) == 0) {
498  //Read column labels from the datablock that starts at firstData
499  //Label ends at firstloop
500  if ((_isColumnFormat = (block.loop != NULL))) {
501  _readColumnsStar(block, columnValues, desiredLabels, firstBlock);
502  // If block is empty, makes block.loop and block.end equal
503  if (block.loop == (block.end + 1))
504  block.loop--;
505  _readRowsStar(block, columnValues, desiredLabels);
506  } else {
507  id = this->addObject();
508  _parsedLines = 1;
509  this->_readColumnsStar(block, columnValues, desiredLabels, firstBlock, id);
510  }
511  firstBlock = false;
512 
513  if (singleBlock)
514  break;
515  }
516  }
517 
518  unmapFile(bufferMap.begin, bufferMap.size, fd);
519  regfree(&re);
520  if (firstBlock)
521  REPORT_ERROR(ERR_MD_BADBLOCK, formatString("Block: '%s': %s",
522  blockRegExp.c_str(), inFile.c_str()));
523 
524  } else if (line.find("Headerinfo columns:") != String::npos) {
525  // This looks like an old DocFile, parse header
526  std::cerr << "WARNING: ** You are using an old file format (DOCFILE) which is going "
527  << "to be deprecated in next Xmipp release **" << std::endl;
528  is.ignore(256, ':'); //ignore all until ':' to start parsing column labels
529  getline(is, line);
530  ss.str(line);
531  columnValues.emplace_back(new MDObject(MDL_UNDEFINED));
532  columnValues.emplace_back(new MDObject(MDL_UNDEFINED));
533 
534  this->addLabel(MDL_IMAGE);
535  this->_readColumns(ss, columnValues, desiredLabels);
536  useCommentAsImage = true;
537 
538  } else {
539  std::cerr << "WARNING: ** You are using an old file format (SELFILE) which is going "
540  << "to be deprecated in next Xmipp release **" << std::endl;
541  // I will assume that is an old SelFile, so only need to add two columns
542  columnValues.emplace_back(new MDObject(MDL_IMAGE));//addLabel(MDL_IMAGE);
543  columnValues.emplace_back(new MDObject(MDL_ENABLED));//addLabel(MDL_ENABLED);
544  }
545 
546  if (oldFormat)
547  this->_readRows(is, columnValues, useCommentAsImage);
548 
549  //free memory of column values
550  int nCols = columnValues.size();
551  for (int i = 0; i < nCols; ++i)
552  delete columnValues[i];
553 
554  is.close();
555 }
556 
557 void MetaData::writeStar(const FileName &outFile, const String & blockName, WriteModeMetaData mode) const {
558  // Move to MetaData?
559 #ifdef XMIPP_MMAP
560  if (outFile.hasImageExtension())
561  REPORT_ERROR(ERR_IO,"MetaData:writeStar Trying to write metadata with image extension");
562 
563  struct stat file_status;
564  int fd;
565  char *map = NULL;
566  char *tailMetadataFile = NULL; // auxiliary variable to keep metadata file tail in memory
567  size_t size=-1;
568  char *target, * target2 = NULL;
569 
570  //check if file exists or not block name has been given
571  //in our format no two identical data_xxx strings may exists
572  if (mode == MD_APPEND) {
573  if (blockName.empty() || !outFile.exists())
574  mode = MD_OVERWRITE;
575  else {
576  //does blockname exists?
577  //remove it from file in this case
578  // get length of file:
579  if(stat(outFile.c_str(), &file_status) != 0)
580  REPORT_ERROR(ERR_IO_NOPATH,"MetaData:writeStar can not get filesize for file "+outFile);
581  size = file_status.st_size;
582  if (size == 0)
583  mode = MD_OVERWRITE;
584  }
585 
586  if (mode == MD_APPEND) { //size=0 for /dev/stderr
587  fd = open(outFile.c_str(), O_RDWR, S_IREAD | S_IWRITE);
588  if (fd == -1)
589  REPORT_ERROR(ERR_IO_NOPATH,"MetaData:writeStar can not read file named "+outFile);
590 
591  map = (char *) mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
592  if (map == MAP_FAILED)
593  REPORT_ERROR(ERR_MEM_BADREQUEST,"MetaData:writeStar can not map memory ");
594 
595  // Is this a metadata formatted FILE
596  if(strncmp(map,FileNameVersion.c_str(),FileNameVersion.length()) != 0) {
597  mode = MD_OVERWRITE;
598  } else {
599  //block name
600  String _szBlockName = formatString("\ndata_%s\n", blockName.c_str());
601  size_t blockNameSize = _szBlockName.size();
602 
603  //search for the string
604  target = (char *) _memmem(map, size, _szBlockName.c_str(), blockNameSize);
605 
606  if (target != NULL)
607  {
608  target2 = (char *) _memmem(target+1, size - (target - map), "\ndata_", 6);
609 
610  if (target2 != NULL)
611  {
612  //target block is not the last one, so we need to
613  //copy file from target2 to auxiliary memory and truncate
614  tailMetadataFile = (char *) malloc( ((map + size) - target2));
615  memmove(tailMetadataFile,target2, (map + size) - target2);
616  }
617  if (ftruncate(fd, target - map+1)==-1) //truncate rest of the file
618  REPORT_ERROR(ERR_UNCLASSIFIED,"Cannot truncate file");
619  }
620  }
621  close(fd);
622 
623  if (munmap(map, size) == -1)
624  REPORT_ERROR(ERR_MEM_NOTDEALLOC, "MetaData:writeStar, Can not unmap memory");
625  }
626  }
627 
628  std::ios_base::openmode openMode = (mode == MD_OVERWRITE) ? std::ios_base::out : std::ios_base::app;
629  std::ofstream ofs(outFile.c_str(), openMode);
630 
631  write(ofs, blockName, mode);
632 
633  if (tailMetadataFile != NULL) {
634  //append memory buffer to file
635  //may a cat a buffer to a ofstream
636  ofs.write(tailMetadataFile,(map + size) - target2);
637  free(tailMetadataFile);
638  }
639  ofs.close();
640 
641 #else
642 
643  REPORT_ERROR(ERR_MMAP,"Mapping not supported in Windows");
644 #endif
645 }
646 
647 void MetaData::append(const FileName &outFile) const
648 {
649  if (outFile.exists())
650  {
651  std::ofstream ofs(outFile.c_str(), std::ios_base::app);
652  _writeRows(ofs);
653  ofs.close();
654  }
655  else
656  write(outFile);
657 }
Just to locate unclassified errors.
Definition: xmipp_error.h:192
virtual void setMaxRows(size_t maxRows=0)
#define BUFFER_FIND(b, str, n)
Definition: metadata_base.h:91
virtual size_t addObject()=0
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
char * begin
Definition: metadata_base.h:82
WriteModeMetaData metadataModeConvert(String mode)
static MDLabel str2Label(const String &labelName)
virtual bool removeLabel(const MDLabel label)=0
String getBlockName() const
virtual ~MetaData()
virtual void clear()
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define END_OF_LINE()
Definition: metadata_base.h:69
virtual void writeStar(const FileName &outFile, const String &blockName, WriteModeMetaData mode) const
size_t _parsedLines
void keepLabels(const std::vector< MDLabel > &labels)
Global mmap error.
Definition: xmipp_error.h:170
virtual bool nextBlock(mdBuffer &buffer, mdBlock &block)
virtual bool containsLabel(const MDLabel label) const =0
char * end
Definition: metadata_base.h:96
std::vector< SelLine >::iterator find(std::vector< SelLine > &text, const std::string &img_name)
Definition: selfile.cpp:553
virtual void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const =0
HBITMAP buffer
Definition: svm-toy.cpp:37
void trim(std::string &s)
Definition: text.cpp:205
bool existsBlockInMetaDataFile(const FileName &inFileWithBlock)
#define BUFFER_CREATE(b)
Some macros to use the buffer.
Definition: metadata_base.h:88
void compose(const String &str, const size_t no, const String &ext="")
Input/Output general error.
Definition: xmipp_error.h:134
bool hasImageExtension() const
#define BUFFER_COPY(b1, b2)
Definition: metadata_base.h:89
glob_prnt iter
Memory has not been deallocated.
Definition: xmipp_error.h:167
virtual void _readRows(std::istream &is, std::vector< MDObject *> &columnValues, bool useCommentAsImage)
bool isMetadataFile
int getBlocksInMetaDataFileDB(const FileName &inFile, StringVector &blockList)
String FileNameVersion
void getBlocksInMetaDataFile(const FileName &inFile, StringVector &blockList)
FileName _inFile
Bad amount of memory requested.
Definition: xmipp_error.h:165
String _comment
#define BLOCK_CREATE(b)
Some macros to use the block pointers.
std::vector< String > StringVector
Definition: xmipp_strings.h:35
virtual bool getValue(MDObject &mdValueOut, size_t id) const =0
#define i
Is this image enabled? (int [-1 or 1])
virtual void setComment(const String &newComment="No comment")
#define BLOCK_INIT(b)
String getExtension() const
#define BLOCK_NAME(b, s)
virtual void _readRowsStar(mdBlock &block, std::vector< MDObject *> &columnValues, const std::vector< MDLabel > *desiredLabels)
void * _memmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len)
virtual void _writeRows(std::ostream &os) const =0
virtual void _parseObjects(std::istream &is, std::vector< MDObject *> &columnValues, const std::vector< MDLabel > *desiredLabels, bool firstTime)=0
void unmapFile(char *&map, size_t &size, int &fileDescriptor)
size_t _maxRows
int in
Incorrect argument received.
Definition: xmipp_error.h:113
virtual int removeObjects()=0
std::map< String, size_t > _fastStringSearch
static MDLabel getNewAlias(const String &alias, MDLabelType type=LABEL_NOTYPE)
bool fromString(const String &str)
void copyInfo(const MetaData &md)
free((char *) ob)
bool vectorContainsLabel(const std::vector< MDLabel > &labelsVector, const MDLabel label)
File or directory does not exist.
Definition: xmipp_error.h:136
void mode
This block does not exist.
Definition: xmipp_error.h:163
virtual size_t size() const =0
size_t nameSize
Definition: metadata_base.h:95
char * loop
Definition: metadata_base.h:97
basic_istream< char, std::char_traits< char > > istream
Definition: utilities.cpp:815
bool exists() const
String toString(bool withFormat=false, bool isSql=false) const
#define BUFFER_MOVE(b, n)
Definition: metadata_base.h:90
char * begin
Definition: metadata_base.h:94
bool setValue(const MDLabel label, const T &valueIn, size_t id)
void mapFile(const FileName &filename, char *&map, size_t &size, int &fileDescriptor, bool readOnly)
bool isMetaData(bool failIfNotExists=true) const
double precision() const
FileName removeBlockName() const
virtual void removeDisabled()
virtual void _readColumns(std::istream &is, std::vector< MDObject *> &columnValues, const std::vector< MDLabel > *desiredLabels=nullptr)
void append(const FileName &outFile) const
std::string String
Definition: xmipp_strings.h:34
virtual bool addLabel(const MDLabel label, int pos=-1)=0
virtual bool getStrFromValue(const MDLabel label, String &strOut, size_t id) const
String formatString(const char *format,...)
virtual void _readColumnsStar(mdBlock &block, std::vector< MDObject *> &columnValues, const std::vector< MDLabel > *desiredLabels, bool addColumns=true, size_t id=BAD_OBJID)
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, bool decomposeStack=true) override
virtual std::vector< MDLabel > getActiveLabels() const =0
MDLabel _fastStringSearchLabel
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Environment PATH cannot be read.
Definition: xmipp_error.h:143
static String label2Str(const MDLabel &label)
virtual bool setValueFromStr(const MDLabel label, const String &value, size_t id)
void toLower(char *_str)
virtual void readStar(const FileName &filename, const std::vector< MDLabel > *desiredLabels, const String &blockRegExp, bool decomposeStack)
virtual iterator end()=0
size_t size
Definition: metadata_base.h:83
WriteModeMetaData
int * n
Name of an image (std::string)
MDLabel
int _precision
virtual void _parseObject(std::istream &is, MDObject &object, size_t id=BAD_OBJID)
A comment for this object /*** NOTE THIS IS A SPECIAL CASE AND SO IS TREATED ***/.