MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / findIndexListOffset

Method findIndexListOffset

src/openms/source/FORMAT/HANDLERS/IndexedMzMLDecoder.cpp:124–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122 }
123
124 std::streampos IndexedMzMLDecoder::findIndexListOffset(const String& filename, int buffersize)
125 {
126 // return value
127 std::streampos indexoffset = -1;
128
129 //-------------------------------------------------------------
130 // Open file, jump to end and read last n bytes into buffer.
131 //-------------------------------------------------------------
132 std::ifstream f(filename.c_str());
133
134 if (!f.is_open())
135 {
136 throw Exception::FileNotFound(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, filename);
137 }
138
139 // Read the last few bytes and hope our offset is there to be found
140 std::unique_ptr<char[]> buffer(new char[buffersize + 1]);
141 f.seekg(-buffersize, f.end);
142 f.read(buffer.get(), buffersize);
143 buffer.get()[buffersize] = '\0';
144
145#ifdef DEBUG_READER
146 std::cout << " reading file " << filename << " with size " << buffersize << std::endl;
147 std::cout << buffer << std::endl;
148#endif
149
150 //-------------------------------------------------------------
151 // Since we could be anywhere in the XML structure, use regex to find
152 // indexListOffset and read its content.
153 //-------------------------------------------------------------
154 boost::regex listoffset_rx(R"(<[^>/]*indexListOffset\s*>\s*(\d*))");
155 boost::cmatch matches;
156 boost::regex_search(buffer.get(), matches, listoffset_rx);
157 String thismatch(matches[1].first, matches[1].second);
158 if (!thismatch.empty())
159 {
160 try
161 {
162 indexoffset = OpenMS::IndexedMzMLUtils::stringToStreampos(thismatch);
163 }
164 catch (Exception::ConversionError& /*e*/)
165 {
166 std::cerr << "Corrupted / unreadable value in <indexListOffset> : " << thismatch << std::endl;
167 // free resources and re-throw
168 throw; // re-throw conversion error
169 }
170 }
171 else
172 {
173 std::cerr << "IndexedMzMLDecoder::findIndexListOffset Error: Could not find element indexListOffset in the last "
174 << buffersize << " bytes. Maybe this is not a indexedMzML."
175 << buffer.get() << std::endl;
176 }
177
178 return indexoffset;
179 }
180
181 int IndexedMzMLDecoder::domParseIndexedEnd_(const std::string& in, OffsetVector& spectra_offsets, OffsetVector& chromatograms_offsets)

Callers 4

testIndexedMzMLDecoderFunction · 0.95
main_Method · 0.80
parseFooter_Method · 0.80

Calls 4

stringToStreamposFunction · 0.85
readMethod · 0.45
getMethod · 0.45
emptyMethod · 0.45

Tested by 1

testIndexedMzMLDecoderFunction · 0.76