Skip to content
Snippets Groups Projects
Commit a50d4635 authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[lto_rao] Refactored CTACostHeuristic with RAOHelpers function

parent 5158072e
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@
*/
#include "CTACostHeuristic.hpp"
#include "RAOHelpers.hpp"
#include <cmath>
namespace castor { namespace tape { namespace tapeserver { namespace rao {
......@@ -43,21 +44,13 @@ double CTACostHeuristic::getCost(const FilePositionInfos& file1, const FilePosit
uint8_t startFile2LandingZone = file2.getStartLandingZone();
uint64_t distance = std::abs(endFile1Position.getLPos() - startFile2Position.getLPos());
//TODO : Refactor with the RAOHelpers
int wrapChange = (endFile1Wrap != startFile2Wrap);
int bandChange = (endFile1Band != startFile2Band);
int landingZoneChange = (endFile1LandingZone != startFile2LandingZone);
int directionChange = ((endFile1Wrap % 2) != (startFile2Wrap % 2));
int stepBack = 0;
int wrapChange = RAOHelpers::doesWrapChange(endFile1Wrap,startFile2Wrap);
int bandChange = RAOHelpers::doesBandChange(endFile1Band,startFile2Band);
int landingZoneChange = RAOHelpers::doesLandingZoneChange(endFile1LandingZone,startFile2LandingZone);
int directionChange = RAOHelpers::doesDirectionChange(endFile1Wrap,startFile2Wrap);
if(endFile1Wrap == startFile2Wrap){
if((endFile1Wrap % 2) == 0 && (startFile2LPos < endFile1LPos)){
stepBack = 1;
} else if ((endFile1Wrap % 2) == 1 && (startFile2LPos > endFile1LPos)){
stepBack = 1;
}
}
int stepBack = RAOHelpers::doesStepBack(endFile1LPos,endFile1Wrap,startFile2Wrap,startFile2LPos);
cost = 4.29 + wrapChange * 6.69 + bandChange * 3.2 + landingZoneChange * (-6.04) + directionChange * 5.22 + stepBack * 11.32 + distance * 0.0006192;
return cost;
......
......@@ -38,12 +38,45 @@ namespace castor { namespace tape { namespace tapeserver { namespace rao {
uint8_t RAOHelpers::determineBand(uint32_t nbWrapsOnTape, uint32_t wrapNumber){
//As a tape has always 4 bands the following formula will give the band number to which the wrapNumber
//belongs to
return (wrapNumber / (nbWrapsOnTape / 4));
unsigned int nbBandsTape = 4;
if(wrapNumber > nbWrapsOnTape - 1){
std::string errorMsg = "In RAOHelpers::determineBand(), the wrapNumber (" + std::to_string(wrapNumber) + ") of the file is greater than the number of wraps the tape contains (" + std::to_string(nbWrapsOnTape) + ").";
throw cta::exception::Exception(errorMsg);
}
return (wrapNumber / (nbWrapsOnTape / nbBandsTape));
}
uint8_t RAOHelpers::determineLandingZone(uint64_t minTapeLpos, uint64_t maxTapeLpos, uint64_t fileLpos){
uint64_t mid = (maxTapeLpos - minTapeLpos) / 2;
return fileLpos < mid ? 0 : 1;
}
bool RAOHelpers::doesWrapChange(uint32_t wrap1, uint32_t wrap2){
return (wrap1 != wrap2);
}
bool RAOHelpers::doesBandChange(uint8_t band1, uint8_t band2){
return (band1 != band2);
}
bool RAOHelpers::doesLandingZoneChange(uint8_t landingZone1, uint8_t landingZone2){
return (landingZone1 != landingZone2);
}
uint8_t RAOHelpers::determineLandingZone(uint64_t minTapeLPos, uint64_t maxTapeLpos, uint64_t fileLPos){
uint64_t mid = (maxTapeLpos - minTapeLPos) / 2;
return fileLPos < mid ? 0 : 1;
bool RAOHelpers::doesDirectionChange(uint32_t wrap1, uint32_t wrap2){
return ((wrap1 % 2) != (wrap2 % 2));
}
bool RAOHelpers::doesStepBack(uint32_t wrap1, uint64_t lpos1, uint32_t wrap2, uint64_t lpos2){
bool stepBack = false;
if(wrap1 == wrap2){
if((wrap1 % 2 == 0) && (lpos1 > lpos2)){
stepBack = true;
} else if((wrap1 % 2 == 1) && (lpos1 < lpos2)){
stepBack = true;
}
}
return stepBack;
}
}}}}
\ No newline at end of file
......@@ -36,7 +36,17 @@ public:
static uint8_t determineBand(uint32_t nbWrapsOnTape, uint32_t wrapNumber);
static uint8_t determineLandingZone(uint64_t minTapeLPos, uint64_t maxTapeLpos, uint64_t fileLPos);
static uint8_t determineLandingZone(uint64_t minTapeLpos, uint64_t maxTapeLpos, uint64_t fileLpos);
static bool doesWrapChange(uint32_t wrap1, uint32_t wrap2);
static bool doesBandChange(uint8_t band1, uint8_t band2);
static bool doesLandingZoneChange(uint8_t landingZone1, uint8_t landingZone2);
static bool doesDirectionChange(uint32_t wrap1, uint32_t wrap2);
static bool doesStepBack(uint32_t wrap1, uint64_t lpos1, uint32_t wrap2, uint64_t lpos2);
};
......
......@@ -158,7 +158,7 @@ namespace unitTests {
}
}
TEST_F(RAOTest,ImproveLastEOWPIfPossible){
TEST_F(RAOTest,RAOHelpersImproveLastEOWPIfPossible){
std::vector<drive::endOfWrapPosition> eowPositions = RAOTestEnvironment::getEndOfWrapPositions();
drive::endOfWrapPosition eowpBeforeImprovement = eowPositions.at(eowPositions.size()-1);
rao::RAOHelpers::improveEndOfLastWrapPositionIfPossible(eowPositions);
......@@ -166,4 +166,59 @@ namespace unitTests {
ASSERT_LT(eowpBeforeImprovement.blockId,eowpAfterImprovement.blockId);
}
TEST_F(RAOTest,RAOHelpersDetermineBand){
uint32_t nbWrapsLTO7 = 112;
ASSERT_EQ(0,rao::RAOHelpers::determineBand(nbWrapsLTO7,0));
ASSERT_EQ(0,rao::RAOHelpers::determineBand(nbWrapsLTO7,27));
ASSERT_EQ(1,rao::RAOHelpers::determineBand(nbWrapsLTO7,28));
ASSERT_EQ(3,rao::RAOHelpers::determineBand(nbWrapsLTO7,111));
ASSERT_THROW(rao::RAOHelpers::determineBand(nbWrapsLTO7,112),cta::exception::Exception);
}
TEST_F(RAOTest,RAOHelpersDetermineLandingZone){
auto LTO7MediaType = RAOTestEnvironment::getLTO7MMediaType();
uint64_t minTapeLpos = LTO7MediaType.minLPos.value();
uint64_t maxTapeLpos = LTO7MediaType.maxLPos.value();
uint64_t file1Lpos = minTapeLpos + 50;
uint64_t file2Lpos = maxTapeLpos - 50;
uint64_t file3Lpos = (maxTapeLpos - minTapeLpos) / 2;
ASSERT_EQ(0,rao::RAOHelpers::determineLandingZone(minTapeLpos,maxTapeLpos,file1Lpos));
ASSERT_EQ(1,rao::RAOHelpers::determineLandingZone(minTapeLpos,maxTapeLpos,file2Lpos));
ASSERT_EQ(1,rao::RAOHelpers::determineLandingZone(minTapeLpos,maxTapeLpos,file3Lpos));
}
TEST_F(RAOTest,RAOHelpersDoesWrapChange){
ASSERT_TRUE(rao::RAOHelpers::doesWrapChange(0,1));
ASSERT_FALSE(rao::RAOHelpers::doesWrapChange(5,5));
}
TEST_F(RAOTest,RAOHelpersDoesBandChange){
ASSERT_TRUE(rao::RAOHelpers::doesBandChange(0,1));
ASSERT_FALSE(rao::RAOHelpers::doesBandChange(5,5));
}
TEST_F(RAOTest,RAOHelpersDoesLandingZoneChange){
ASSERT_TRUE(rao::RAOHelpers::doesLandingZoneChange(0,1));
ASSERT_FALSE(rao::RAOHelpers::doesLandingZoneChange(0,0));
}
TEST_F(RAOTest,RAOHelpersDoesDirectionChange){
ASSERT_TRUE(rao::RAOHelpers::doesDirectionChange(0,1));
ASSERT_FALSE(rao::RAOHelpers::doesDirectionChange(0,0));
ASSERT_FALSE(rao::RAOHelpers::doesDirectionChange(0,2));
ASSERT_FALSE(rao::RAOHelpers::doesDirectionChange(1,3));
}
TEST_F(RAOTest,RAOHelpersDoesStepBack){
//Wrap 0 lpos1 > lpos 2: stepback
ASSERT_TRUE(rao::RAOHelpers::doesStepBack(0,1,0,0));
//Wrap 1 lpos1 < lpos2: steback
ASSERT_TRUE(rao::RAOHelpers::doesStepBack(1,0,1,1));
//Wrap 0 lpos 1 < lpos 2: no stepback
ASSERT_FALSE(rao::RAOHelpers::doesStepBack(0,0,0,1));
//Wrap 1 lpos 1 > lpos 2: no stepback
ASSERT_FALSE(rao::RAOHelpers::doesStepBack(1,1,1,0));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment