ArchiveFile.cpp 5.21 KB
Newer Older
1
/*
2
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2015-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
 */

#include "common/dataStructures/ArchiveFile.hpp"
19
#include "common/dataStructures/utils.hpp"
20
21
#include "common/exception/Exception.hpp"

22
23
#include <algorithm>

24
25
26
27
namespace cta {
namespace common {
namespace dataStructures {

Daniele Kruse's avatar
Daniele Kruse committed
28
29
30
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
31
ArchiveFile::ArchiveFile():
Daniele Kruse's avatar
Daniele Kruse committed
32
  archiveFileID(0),
33
  fileSize(0),
34
  creationTime(0),
35
36
  reconciliationTime(0) {
}
Daniele Kruse's avatar
Daniele Kruse committed
37

38
//------------------------------------------------------------------------------
39
// operator==
40
//------------------------------------------------------------------------------
41
bool ArchiveFile::operator==(const ArchiveFile &rhs) const {
42
  return archiveFileID == rhs.archiveFileID
43
      && diskFileId    == rhs.diskFileId
44
45
      && diskInstance  == rhs.diskInstance
      && fileSize      == rhs.fileSize
46
      && checksumBlob  == rhs.checksumBlob
47
      && storageClass  == rhs.storageClass
48
      && diskFileInfo  == rhs.diskFileInfo
49
      && tapeFiles    == rhs.tapeFiles;
50
51
52
}

//------------------------------------------------------------------------------
53
// operator!=
54
//------------------------------------------------------------------------------
55
bool ArchiveFile::operator!=(const ArchiveFile &rhs) const {
56
  return !operator==(rhs);
57
58
}

59
60
61
//------------------------------------------------------------------------------
// ArchiveFile::TapeFilesList::at()
//------------------------------------------------------------------------------
62
TapeFile& ArchiveFile::TapeFilesList::at(uint8_t copyNb) {
Cedric Caffy's avatar
Cedric Caffy committed
63
  auto ret = std::find_if(begin(), end(), [=](TapeFile& tf){ return tf.matchesCopyNb(copyNb);});
64
65
66
67
68
69
70
  if (ret == end()) throw cta::exception::Exception("In ArchiveFile::TapeFilesList::at(): not found.");
  return *ret;
}

//------------------------------------------------------------------------------
// ArchiveFile::TapeFilesList::at() const
//------------------------------------------------------------------------------
71
const TapeFile& ArchiveFile::TapeFilesList::at(uint8_t copyNb) const {
Cedric Caffy's avatar
Cedric Caffy committed
72
  auto ret = std::find_if(cbegin(), cend(), [=](const TapeFile& tf){ return tf.matchesCopyNb(copyNb);});
73
74
75
76
77
78
79
  if (ret == end()) throw cta::exception::Exception("In ArchiveFile::TapeFilesList::at(): not found.");
  return *ret;
}

//------------------------------------------------------------------------------
// ArchiveFile::TapeFilesList::find() 
//------------------------------------------------------------------------------
80
ArchiveFile::TapeFilesList::iterator ArchiveFile::TapeFilesList::find(uint8_t copyNb) {
Cedric Caffy's avatar
Cedric Caffy committed
81
  return std::find_if(begin(), end(), [=](TapeFile& tf){ return tf.matchesCopyNb(copyNb);});
82
83
84
85
86
}

//------------------------------------------------------------------------------
// ArchiveFile::TapeFilesList::find() const
//------------------------------------------------------------------------------
87
ArchiveFile::TapeFilesList::const_iterator ArchiveFile::TapeFilesList::find(uint8_t copyNb) const {
Cedric Caffy's avatar
Cedric Caffy committed
88
  return std::find_if(cbegin(), cend(), [=](const TapeFile& tf){ return tf.matchesCopyNb(copyNb);});
89
90
}

Michael Davis's avatar
Michael Davis committed
91
92
93
94
95
96
//------------------------------------------------------------------------------
// ArchiveFile::TapeFilesList::removeAllVidsExcept()
//------------------------------------------------------------------------------
void ArchiveFile::TapeFilesList::removeAllVidsExcept(const std::string &vid) {
  remove_if([=](TapeFile& tf){ return tf.vid != vid; });
}
97
98
99



100
//------------------------------------------------------------------------------
101
// operator<<
102
//------------------------------------------------------------------------------
103
std::ostream &operator<<(std::ostream &os, const ArchiveFile &obj) {
104
105
106
  os <<
    "{"
    "archiveFileID="      << obj.archiveFileID      << ","
107
    "diskFileID="         << obj.diskFileId         << ","
108
109
    "diskInstance="       << obj.diskInstance       << ","
    "fileSize="           << obj.fileSize           << ","
110
    "checksumBlob="       << obj.checksumBlob       << ","
111
    "storageClass="       << obj.storageClass       << ","
112
113
    "diskFileInfo="       << obj.diskFileInfo       << ","
    "tapeFiles="          << obj.tapeFiles          << ","
114
115
116
    "creationTime="       << obj.creationTime       << ","
    "reconciliationTime=" << obj.reconciliationTime <<
    "}";
117
  return os;
118
119
}

120
121
122
} // namespace dataStructures
} // namespace common
} // namespace cta