| 220 | } |
| 221 | |
| 222 | bool RawGenerator::GenerateFilteredFeatures() |
| 223 | { |
| 224 | SourceReader reader = m_genInfo.m_osmFileName.empty() ? SourceReader() : SourceReader(m_genInfo.m_osmFileName); |
| 225 | |
| 226 | std::unique_ptr<ProcessorOsmElementsInterface> sourceProcessor; |
| 227 | switch (m_genInfo.m_osmFileType) |
| 228 | { |
| 229 | case feature::GenerateInfo::OsmSourceType::O5M: |
| 230 | sourceProcessor = std::make_unique<ProcessorOsmElementsFromO5M>(reader); |
| 231 | break; |
| 232 | case feature::GenerateInfo::OsmSourceType::XML: |
| 233 | sourceProcessor = std::make_unique<ProcessorOsmElementsFromXml>(reader); |
| 234 | break; |
| 235 | } |
| 236 | CHECK(sourceProcessor, ()); |
| 237 | |
| 238 | // Create translators threads. |
| 239 | // Each thread may contain separate translators for countries and World |
| 240 | // They process chunks of source data and pass features to a chain of processors. |
| 241 | // The last processor writes to a "processed" queue. |
| 242 | TranslatorsPool translators(m_translators, m_threadsCount); |
| 243 | |
| 244 | // The writer thread pops from the "processed" queue and writes to per-country files. |
| 245 | RawGeneratorWriter rawGeneratorWriter(m_queue, m_genInfo.m_tmpDir); |
| 246 | rawGeneratorWriter.Run(); |
| 247 | |
| 248 | Stats stats(100 * m_threadsCount /* logCallCountThreshold */); |
| 249 | |
| 250 | bool isEnd = false; |
| 251 | do |
| 252 | { |
| 253 | std::vector<OsmElement> elements(m_chunkSize); |
| 254 | size_t idx = 0; |
| 255 | while (idx < m_chunkSize && sourceProcessor->TryRead(elements[idx])) |
| 256 | ++idx; |
| 257 | |
| 258 | isEnd = idx < m_chunkSize; |
| 259 | stats.Log(elements, reader.Pos(), isEnd /* forcePrint */); |
| 260 | |
| 261 | if (isEnd) |
| 262 | elements.resize(idx); |
| 263 | translators.Emit(std::move(elements)); |
| 264 | } |
| 265 | while (!isEnd); |
| 266 | |
| 267 | LOG(LINFO, ("OSM source input was processed.")); |
| 268 | LOG(LINFO, ("Finishing translators...")); |
| 269 | if (!translators.Finish()) |
| 270 | return false; |
| 271 | |
| 272 | rawGeneratorWriter.ShutdownAndJoin(); |
| 273 | m_names = rawGeneratorWriter.GetNames(); |
| 274 | /// @todo: compare to the input list of countries loaded in borders::LoadCountriesList(). |
| 275 | if (m_names.empty()) |
| 276 | LOG(LWARNING, ("No feature data " DATA_FILE_EXTENSION_TMP " files were generated for any country!")); |
| 277 | else |
| 278 | LOG(LINFO, ("Feature data " DATA_FILE_EXTENSION_TMP " files were written for following countries:", m_names)); |
| 279 | |