| 221 | } |
| 222 | |
| 223 | std::map<UInt, MzMLFile::SpecInfo> MzMLFile::getCentroidInfo(const String& filename, const Size first_n_spectra_only) |
| 224 | { |
| 225 | bool oldoption = options_.getFillData(); |
| 226 | options_.setFillData(true); // we want the data as well (to allow estimation from data if metadata is missing) |
| 227 | std::map<UInt, SpecInfo> ret; |
| 228 | Size first_n_spectra_only_remaining = first_n_spectra_only; |
| 229 | auto f = [&ret, &first_n_spectra_only_remaining](const MSSpectrum& s) |
| 230 | { |
| 231 | UInt lvl = s.getMSLevel(); |
| 232 | switch (s.getType(true)) |
| 233 | { |
| 234 | case (MSSpectrum::SpectrumType::CENTROID): |
| 235 | ++ret[lvl].count_centroided; |
| 236 | --first_n_spectra_only_remaining; |
| 237 | break; |
| 238 | case (MSSpectrum::SpectrumType::PROFILE): |
| 239 | ++ret[lvl].count_profile; |
| 240 | --first_n_spectra_only_remaining; |
| 241 | break; |
| 242 | case (MSSpectrum::SpectrumType::UNKNOWN): // this can only happen for spectra with very few peaks (or completely empty spectra) |
| 243 | ++ret[lvl].count_unknown; |
| 244 | break; |
| 245 | default: |
| 246 | // make sure we did not forget a case |
| 247 | throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION); |
| 248 | } |
| 249 | |
| 250 | // stop parsing after 10 or so spectra |
| 251 | if (first_n_spectra_only_remaining == 0) |
| 252 | { |
| 253 | throw Internal::XMLHandler::EndParsingSoftly(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION); |
| 254 | } |
| 255 | }; |
| 256 | MSDataTransformingConsumer c; |
| 257 | c.setSpectraProcessingFunc(f); |
| 258 | transform(filename, &c, true, true); // no first pass |
| 259 | |
| 260 | // restore old state |
| 261 | options_.setFillData(oldoption); |
| 262 | |
| 263 | return ret; |
| 264 | } |
| 265 | |
| 266 | } // namespace OpenMS |
no test coverage detected