------------------------------------------------------------------------------
| 154 | |
| 155 | //------------------------------------------------------------------------------ |
| 156 | bool vtkXMLPartitionedDataSetCollectionWriter::WriteSummaryXML( |
| 157 | vtkPartitionedDataSetCollection* input, const std::vector<std::vector<std::string>>& allFilenames) |
| 158 | { |
| 159 | assert(static_cast<unsigned int>(allFilenames.size()) == input->GetNumberOfPartitionedDataSets()); |
| 160 | |
| 161 | vtkNew<vtkXMLDataWriterHelper> helper; |
| 162 | helper->SetWriter(this); |
| 163 | helper->SetDataSetVersion(this->GetDataSetMajorVersion(), this->GetDataSetMinorVersion()); |
| 164 | helper->SetDataSetName(input->GetClassName()); |
| 165 | if (!helper->OpenFile()) |
| 166 | { |
| 167 | return false; |
| 168 | } |
| 169 | this->AddArtifact(this->FileName); |
| 170 | |
| 171 | if (!helper->BeginWriting()) |
| 172 | { |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | // build and serialize the DOM. |
| 177 | vtkNew<vtkXMLDataElement> root; |
| 178 | root->SetName(input->GetClassName()); |
| 179 | int pindex = 0; |
| 180 | for (const auto& partitionNames : allFilenames) |
| 181 | { |
| 182 | int dindex = 0; |
| 183 | vtkNew<vtkXMLDataElement> parent; |
| 184 | parent->SetName("Partitions"); |
| 185 | parent->SetIntAttribute("index", pindex); |
| 186 | for (const auto& fname : partitionNames) |
| 187 | { |
| 188 | if (!fname.empty()) // fname will be empty for null nodes in the input. |
| 189 | { |
| 190 | vtkNew<vtkXMLDataElement> child; |
| 191 | child->SetName("DataSet"); |
| 192 | child->SetIntAttribute("index", dindex); |
| 193 | child->SetAttribute("file", fname.c_str()); |
| 194 | parent->AddNestedElement(child); |
| 195 | } |
| 196 | ++dindex; |
| 197 | } |
| 198 | |
| 199 | const bool hasName = |
| 200 | input->HasMetaData(pindex) && input->GetMetaData(pindex)->Has(vtkCompositeDataSet::NAME()); |
| 201 | |
| 202 | // skip empty partitions, however do preserve name, if present. |
| 203 | if (parent->GetNumberOfNestedElements() > 0 || hasName) |
| 204 | { |
| 205 | if (hasName) |
| 206 | { |
| 207 | parent->SetAttribute("name", input->GetMetaData(pindex)->Get(vtkCompositeDataSet::NAME())); |
| 208 | } |
| 209 | root->AddNestedElement(parent); |
| 210 | } |
| 211 | ++pindex; |
| 212 | } |
| 213 |
no test coverage detected