RAOFile.cpp 2.76 KB
Newer Older
1
/*
2
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2003-2021 CERN
4
5
6
7
 * @license        This program is free software: you can redistribute it and/or modify
 *                 it under the terms of the GNU General Public License as published by
 *                 the Free Software Foundation, either version 3 of the License, or
 *                 (at your option) any later version.
8
 *
9
10
11
12
 *                 This program is distributed in the hope that it will be useful,
 *                 but WITHOUT ANY WARRANTY; without even the implied warranty of
 *                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *                 GNU General Public License for more details.
13
 *
14
15
 *                 You should have received a copy of the GNU General Public License
 *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17
18
19
 */

#include "RAOFile.hpp"

20
21
#include <algorithm>

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace castor { namespace tape { namespace tapeserver { namespace rao {

RAOFile::RAOFile(const uint64_t index, const FilePositionInfos & filePositionInfos):m_index(index),m_filePositionInfos(filePositionInfos) {
}

RAOFile::RAOFile(const RAOFile & other) {
  if(this != &other){
    m_index = other.m_index;
    m_filePositionInfos = other.m_filePositionInfos;
  }
}

RAOFile & RAOFile::operator=(const RAOFile & other){
  if(this != &other){
    m_index = other.m_index;
    m_filePositionInfos = other.m_filePositionInfos;
  }
  return *this;
}

uint64_t RAOFile::getIndex() const{
  return m_index;
}

FilePositionInfos RAOFile::getFilePositionInfos() const{
  return m_filePositionInfos;
}

50
void RAOFile::addDistanceToFile(const double distance, const RAOFile& file){
51
52
53
54
55
56
57
  m_distancesWithOtherFiles.push_back(DistanceToFile(distance,file.getIndex()));
}

uint64_t RAOFile::getClosestFileIndex() const {
  //The closest file is the one that has the lower cost
  auto minElementItor = std::min_element(m_distancesWithOtherFiles.begin(), m_distancesWithOtherFiles.end());
  //This method should never throw as there is always at least two files in a RAO batch
58
59
60
61
62
63
64
65
66
  return minElementItor->getDestinationFileIndex();
}

bool RAOFile::operator <(const RAOFile& other) const {
  return m_index < other.m_index;
}

bool RAOFile::operator ==(const RAOFile& other) const {
  return m_index == m_index;
67
68
}

69
70
71
RAOFile::~RAOFile() {
}

72
73
74
75
76
77
78
79
80
81
82
83
84
85
RAOFile::DistanceToFile::DistanceToFile(const double cost, const uint64_t destinationFileIndex):m_cost(cost),m_destinationFileIndex(destinationFileIndex){
}

bool RAOFile::DistanceToFile::operator <(const DistanceToFile& other) const {
  return m_cost < other.m_cost;
}

double RAOFile::DistanceToFile::getCost() const{
  return m_cost;
}

uint64_t RAOFile::DistanceToFile::getDestinationFileIndex() const {
  return m_destinationFileIndex;
}
86
}}}}