35 #ifndef OPENMS_FORMAT_MS2FILE_H 
   36 #define OPENMS_FORMAT_MS2FILE_H 
   76     template <
typename MapType>
 
   93       exp.setLoadedFileType(filename);
 
   94       exp.setLoadedFilePath(filename);
 
   96       std::ifstream in(filename.c_str());
 
   98       UInt spectrum_number = 0;
 
   99       typename MapType::SpectrumType spec;
 
  103       bool first_spec(
true);
 
  106       Size line_number = 0;
 
  108       while (getline(in, line, 
'\n'))
 
  113         if (line.empty()) 
continue;
 
  127             spec.setNativeID(
String(
"index=") + (spectrum_number++));
 
  128             exp.addSpectrum(spec);
 
  136           std::vector<String> split;
 
  137           line.
split(
' ', split);
 
  138           if (split.size() != 4)
 
  140             throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, 
"line (" + 
String(line_number) + 
") '" + line  + 
"' should contain four values, got " + 
String(split.size()) + 
"!", 
"");
 
  142           spec.getPrecursors().resize(1);
 
  143           spec.getPrecursors()[0].setMZ(split[3].toDouble());
 
  167         std::vector<String> split;
 
  168         line.
split(
' ', split);
 
  169         if (split.size() != 2)
 
  171           throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, 
"line (" + 
String(line_number) + 
") '" + line  + 
"' should contain two values, got " + 
String(split.size()) + 
"!", 
"");
 
  176           p.setPosition(split[0].toDouble());
 
  177           p.setIntensity(split[1].toFloat());
 
  181           throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, 
"ConversionError: line (" + 
String(line_number) + 
") '" + line  + 
"' does not contain two numbers!", 
"");
 
  189         spec.setNativeID(
String(
"index=") + (spectrum_number++));
 
  190         exp.addSpectrum(spec);
 
  207 #endif // OPENMS_FORMAT_MS2FILE_H 
String & simplify()
merges subsequent whitespaces to one blank character 
A more convenient string class. 
Definition: String.h:56
Peak2D PeakType
Definition: MassTrace.h:49
File not found exception. 
Definition: Exception.h:524
File not readable exception. 
Definition: Exception.h:538
static bool exists(const String &file)
Method used to test if a file exists. 
void load(const String &filename, MapType &exp)
Definition: MS2File.h:77
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
Invalid conversion exception. 
Definition: Exception.h:363
size_t Size
Size type e.g. used as variable which can hold result of size() 
Definition: Types.h:144
Base class for all classes that want to report their progess. 
Definition: ProgressLogger.h:56
MS2 input file adapter. 
Definition: MS2File.h:65
static bool readable(const String &file)
Return true if the file exists and is readable. 
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const 
Splits a string into substrings using splitter as delimiter. 
Parse Error exception. 
Definition: Exception.h:608