SLTFRAOAlgorithm.hpp 3.41 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
20
 */

#pragma once

#include "RAOAlgorithm.hpp"
21
#include "RAOParams.hpp"
22
23
24
#include "CostHeuristic.hpp"
#include "FilePositionEstimator.hpp"
#include "castor/tape/tapeserver/drive/DriveInterface.hpp"
25
#include "RAOFile.hpp"
26

27
28
#include <map>

29
30
31
32
namespace castor { namespace tape { namespace tapeserver { namespace rao {
  
class SLTFRAOAlgorithm : public RAOAlgorithm {
public:
33
34
35
36
37
38
39
40
41
42
43
  /**
   * Constructor of a ShortLocateTimeFirst RAO Algorithm
   * @param filePositionEstimator the file position estimator to determine the position of all files given to the performRAO() method
   * @param costHeuristic the cost heuristic to use to determine the cost between two files
   */
  SLTFRAOAlgorithm(std::unique_ptr<FilePositionEstimator> & filePositionEstimator, std::unique_ptr<CostHeuristic> & costHeuristic);
  /**
   * Perform the SLTF RAO algorithm on the Retrieve jobs passed in parameter
   * @param jobs the jobs to perform the SLTF RAO algorithm
   * @return the vector of the indexes of the jobs rearranged with the SLTF method
   */
44
  std::vector<uint64_t> performRAO(const std::vector<std::unique_ptr<cta::RetrieveJob> >& jobs) override;
45
  std::string getName() const override;
46
47
  virtual ~SLTFRAOAlgorithm();
  
48
49
50
51
52
53
54
  /**
   * This builder helps to build the SLTF RAO algorithm. It initializes the file position estimator and the cost heuristic
   * according to what are the parameters of the RAO but also by asking to the drive the drive'
   * @param data
   * @param drive
   * @param catalogue
   */
55
56
  class Builder {
  public:
57
58
59
    Builder(const RAOParams & data);
    void setCatalogue(cta::catalogue::Catalogue * catalogue);
    void setDrive(drive::DriveInterface * drive);
60
61
62
63
64
    std::unique_ptr<SLTFRAOAlgorithm> build();
  private:
    void initializeFilePositionEstimator();
    void initializeCostHeuristic();
    std::unique_ptr<SLTFRAOAlgorithm> m_algorithm;
65
    RAOParams m_raoParams;
66
67
    drive::DriveInterface * m_drive = nullptr;
    cta::catalogue::Catalogue * m_catalogue = nullptr;
68
69
70
71
72
73
  };
  
private:
  SLTFRAOAlgorithm();
  std::unique_ptr<FilePositionEstimator> m_filePositionEstimator;
  std::unique_ptr<CostHeuristic> m_costHeuristic;
74
    
75
76
77
78
79
  typedef std::map<uint64_t,RAOFile> RAOFilesContainer;
  
  RAOFilesContainer computeAllFilesPosition(const std::vector<std::unique_ptr<cta::RetrieveJob> > & jobs) const;
  void computeCostBetweenFileAndOthers(RAOFile & file, const RAOFilesContainer & files) const;
  std::vector<uint64_t> performSLTF(RAOFilesContainer & files) const;
80
  std::unique_ptr<cta::RetrieveJob> createFakeRetrieveJobForFileAtBeginningOfTape() const;
81
82
83
84
};

}}}}