<commit_before>/*=========================================================================

  Program:   ParaView
  Module:    vtkXMLUniformGridAMRReader.cxx

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkXMLUniformGridAMRReader.h"

#include "vtkAMRBox.h"
#include "vtkAMRInformation.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkDataObjectTypes.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkNonOverlappingAMR.h"
#include "vtkObjectFactory.h"
#include "vtkOverlappingAMR.h"
#include "vtkSmartPointer.h"
#include "vtkUniformGrid.h"
#include "vtkXMLDataElement.h"

#include <cassert>
#include <vector>

namespace
{
  // Data type used to store a 3-tuple of doubles.
  template <class T, int N> class vtkTuple
    {
  public:
    T Data[N];
    vtkTuple()
      {
      for (int cc=0; cc < N; cc++)
        {
        this->Data[cc] = 0;
        }
      }
    operator T* ()
      {
      return this->Data;
      }
    };

  typedef vtkTuple<double, 3> vtkSpacingType;

  // Helper routine to parse the XML to collect information about the AMR.
  bool vtkReadMetaData(
    vtkXMLDataElement* ePrimary,
    std::vector<unsigned int> &blocks_per_level,
    std::vector<vtkSpacingType> &level_spacing,
    std::vector<std::vector<vtkAMRBox> > &amr_boxes)
    {
    unsigned int numElems = ePrimary->GetNumberOfNestedElements();
    for (unsigned int cc=0; cc < numElems; cc++)
      {
      vtkXMLDataElement* blockXML = ePrimary->GetNestedElement(cc);
      if (!blockXML || !blockXML->GetName() ||
        strcmp(blockXML->GetName(), "Block") != 0)
        {
        continue;
        }

      int level = 0;
      if (!blockXML->GetScalarAttribute("level", level))
        {
        vtkGenericWarningMacro("Missing 'level' on 'Block' element in XML. Skipping");
        continue;
        }
      if (level < 0)
        {
        // sanity check.
        continue;
        }
      if (blocks_per_level.size() <= level)
        {
        blocks_per_level.resize(level+1, 0);
        level_spacing.resize(level+1);
        amr_boxes.resize(level+1);
        }

      double spacing[3];
      if (blockXML->GetVectorAttribute("spacing", 3, spacing))
        {
        level_spacing[level][0] = spacing[0];
        level_spacing[level][1] = spacing[1];
        level_spacing[level][2] = spacing[2];
        }

      // now read the <DataSet/> elements for boxes and counting the number of
      // nodes per level.
      int numDatasets = blockXML->GetNumberOfNestedElements();
      for (int kk=0; kk < numDatasets; kk++)
        {
        vtkXMLDataElement* datasetXML = blockXML->GetNestedElement(kk);
        if (!datasetXML || !datasetXML->GetName() ||
          strcmp(datasetXML->GetName(), "DataSet") != 0)
          {
          continue;
          }

        int index = 0;
        if (!datasetXML->GetScalarAttribute("index", index))
          {
          vtkGenericWarningMacro("Missing 'index' on 'DataSet' element in XML. Skipping");
          continue;
          }
        if (index >= static_cast<int>(blocks_per_level[level]))
          {
          blocks_per_level[level] = index+1;
          }
        if (index >= amr_boxes[level].size())
          {
          amr_boxes[level].resize(index + 1);<commit_msg>Fixed dashboard warnings.<commit_after>/*=========================================================================

  Program:   ParaView
  Module:    vtkXMLUniformGridAMRReader.cxx

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkXMLUniformGridAMRReader.h"

#include "vtkAMRBox.h"
#include "vtkAMRInformation.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkDataObjectTypes.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkNonOverlappingAMR.h"
#include "vtkObjectFactory.h"
#include "vtkOverlappingAMR.h"
#include "vtkSmartPointer.h"
#include "vtkUniformGrid.h"
#include "vtkXMLDataElement.h"

#include <cassert>
#include <vector>

namespace
{
  // Data type used to store a 3-tuple of doubles.
  template <class T, int N> class vtkTuple
    {
  public:
    T Data[N];
    vtkTuple()
      {
      for (int cc=0; cc < N; cc++)
        {
        this->Data[cc] = 0;
        }
      }
    operator T* ()
      {
      return this->Data;
      }
    };

  typedef vtkTuple<double, 3> vtkSpacingType;

  // Helper routine to parse the XML to collect information about the AMR.
  bool vtkReadMetaData(
    vtkXMLDataElement* ePrimary,
    std::vector<unsigned int> &blocks_per_level,
    std::vector<vtkSpacingType> &level_spacing,
    std::vector<std::vector<vtkAMRBox> > &amr_boxes)
    {
    unsigned int numElems = ePrimary->GetNumberOfNestedElements();
    for (unsigned int cc=0; cc < numElems; cc++)
      {
      vtkXMLDataElement* blockXML = ePrimary->GetNestedElement(cc);
      if (!blockXML || !blockXML->GetName() ||
        strcmp(blockXML->GetName(), "Block") != 0)
        {
        continue;
        }

      int level = 0;
      if (!blockXML->GetScalarAttribute("level", level))
        {
        vtkGenericWarningMacro("Missing 'level' on 'Block' element in XML. Skipping");
        continue;
        }
      if (level < 0)
        {
        // sanity check.
        continue;
        }
      if (blocks_per_level.size() <= static_cast<size_t>(level))
        {
        blocks_per_level.resize(level+1, 0);
        level_spacing.resize(level+1);
        amr_boxes.resize(level+1);
        }

      double spacing[3];
      if (blockXML->GetVectorAttribute("spacing", 3, spacing))
        {
        level_spacing[level][0] = spacing[0];
        level_spacing[level][1] = spacing[1];
        level_spacing[level][2] = spacing[2];
        }

      // now read the <DataSet/> elements for boxes and counting the number of
      // nodes per level.
      int numDatasets = blockXML->GetNumberOfNestedElements();
      for (int kk=0; kk < numDatasets; kk++)
        {
        vtkXMLDataElement* datasetXML = blockXML->GetNestedElement(kk);
        if (!datasetXML || !datasetXML->GetName() ||
          strcmp(datasetXML->GetName(), "DataSet") != 0)
          {
          continue;
          }

        int index = 0;
        if (!datasetXML->GetScalarAttribute("index", index))
          {
          vtkGenericWarningMacro("Missing 'index' on 'DataSet' element in XML. Skipping");
          continue;
          }
        if (index >= static_cast<int>(blocks_per_level[level]))
          {
          blocks_per_level[level] = index+1;
          }
        if (static_cast<size_t>(index) >= amr_boxes[level].size())
          {
          amr_boxes[level].resize(index + 1);
{'fraction_non_alphanumeric': 0.1560968971148612, 'fraction_numerical': 0.006804572672836146, 'mean_word_length': 2.7153690596562186, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4807148', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2227, 'n_words': 513}