RAOFile.hpp 3.13 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
 */

#pragma once

20
21
22
#include <utility>
#include <list>

23
24
25
26
#include "FilePositionInfos.hpp"

namespace castor { namespace tape { namespace tapeserver { namespace rao {

27
28
29
30
31
/**
 * This class represents an RAO file. It contains the index of the file in the vector
 * of jobs passed in the RAOAlgorithm::performRAO() method and the file position informations.
 * It also stores the distance this file has with other files.
 */  
32
33
34
35
36
37
class RAOFile {
public:
  RAOFile(const uint64_t index, const FilePositionInfos & filePositionInfos);
  RAOFile(const RAOFile & other);
  RAOFile &operator=(const RAOFile & other);
  uint64_t getIndex() const;
38
39
40
41
  /**
   * Get the position informations about this file
   * @return the position informations about this file
   */
42
  FilePositionInfos getFilePositionInfos() const;
43
44
45
46
47
  /**
   * Add a distance between this file and another RAOFile
   * @param distance the distance to go from this file to another RAOFile
   * @param file the destination file
   */
48
  void addDistanceToFile(const double distance, const RAOFile & file);
49
50
51
52
  /**
   * Get the closest file index i.e the file to which the cost to go to is the lowest
   * @return the closest file index.
   */
53
  uint64_t getClosestFileIndex() const;
54
55
  bool operator<(const RAOFile &other) const;
  bool operator==(const RAOFile & other) const;
56
  virtual ~RAOFile();
57
  
58
59
60
61
62
63
64
65
66
67
private:
  uint64_t m_index;
  FilePositionInfos m_filePositionInfos;
  
  /**
   * This class holds information about the 
   * cost to go to the destination file
   * @param cost the cost to go to the file located at the destinationFileIndex
   * @param destinationFileIndex the file to which we store the cost to go to
   */
68
69
70
71
  class DistanceToFile {
  public:
    DistanceToFile(const double cost, const uint64_t destinationFileIndex);
    bool operator<(const DistanceToFile &other) const;
72
73
74
75
    /**
     * Returns the cost to go to the destination file located at the destinationFileIndex
     * @return the cost to go to the destination file
     */
76
    double getCost() const;
77
78
79
80
    /**
     * Get the destination file index
     * @return the destination file index
     */
81
82
83
84
85
86
    uint64_t getDestinationFileIndex() const;
  private:
    double m_cost;
    uint64_t m_destinationFileIndex;
  };
  
87
  std::list<DistanceToFile> m_distancesWithOtherFiles;
88
89
90
};

}}}}