1 #ifndef YODA_INDEX_H 2 #define YODA_INDEX_H 3 4 #include <sstream> 5 #include <unordered_map> 6 7 namespace YODA { 8 9 /// @class Index Index.h "YODA/Index.h" 10 /// @brief Index of a file 11 /// 12 /// This class holds index of a file in form of nested unordered_map. 13 class Index { 14 public: 15 16 /// @brief Alias for nested unordered_map for index. 17 /// 18 /// 19 /// Structure: 20 /// { 21 /// "Scatter2D": { 22 /// "/ATLAS_2017_I1514251/d09-x01-y01": 3 23 /// } 24 /// } 25 using AOIndex = 26 std::unordered_map<std::string, std::unordered_map<std::string, int>>; 27 28 Index() = default; 29 Index(AOIndex && idx)30 Index(AOIndex&& idx) noexcept : _index(idx) {} 31 Index(const AOIndex & idx)32 Index(const AOIndex& idx) : _index(idx) {} 33 Index(Index && other)34 Index(Index&& other) : _index(std::move(other._index)) {} 35 36 Index& operator=(const Index& rhs) { 37 _index = rhs._index; 38 return *this; 39 } 40 41 Index& operator=(Index&& rhs) { 42 _index = std::move(rhs._index); 43 return *this; 44 } 45 46 ///@brief Implicitly cast to a nested index map. AOIndex()47 operator AOIndex() const {return _index; } 48 49 ///@brief Get nested index map. getAOIndex()50 AOIndex getAOIndex() const { return _index; } 51 52 /// @brief Get string representation of index. toString()53 std::string toString() const { 54 std::ostringstream indexStr; 55 for (const auto& kv : this->_index) { 56 indexStr << "OBJECT TYPE: " << kv.first << "\n"; 57 58 for (const auto& path_to_bincount : kv.second) { 59 indexStr << " ----------\n"; 60 indexStr << " " 61 << "PATH: " << path_to_bincount.first << "\n"; 62 indexStr << " " 63 << "BIN COUNT: " << path_to_bincount.second << "\n"; 64 indexStr << " ----------\n"; 65 } 66 } 67 return indexStr.str(); 68 } 69 70 private: 71 /// @brief Holds index. 72 AOIndex _index; 73 }; 74 75 } 76 77 #endif