From ecae85e9a8a8f090b7a85290e3f0f6d92bf9dac6 Mon Sep 17 00:00:00 2001 From: Laura Kieras Date: Tue, 4 Nov 2014 16:30:46 -0500 Subject: [PATCH] mm2dTable now opens its data file read-only, using mapped_file_source, so that we don't need write permissions on the file --- moses/TranslationModel/UG/mm/ug_mm_2d_table.h | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/moses/TranslationModel/UG/mm/ug_mm_2d_table.h b/moses/TranslationModel/UG/mm/ug_mm_2d_table.h index 6f1abed9e..cfc86b8fc 100644 --- a/moses/TranslationModel/UG/mm/ug_mm_2d_table.h +++ b/moses/TranslationModel/UG/mm/ug_mm_2d_table.h @@ -52,12 +52,13 @@ namespace ugdiss VAL operator[](ID key) const; }; - Cell* data; - VAL *M1, *M2; - OFFSET * index; + Cell const* data; + VAL const* M1; + VAL const* M2; + OFFSET const* index; ID numRows; ID numCols; - boost::shared_ptr file; + boost::shared_ptr file; VAL m1(ID key) const { @@ -120,8 +121,8 @@ namespace ugdiss string foo = msg.str(); UTIL_THROW(util::Exception,foo.c_str()); } - file.reset(new bio::mapped_file()); - file->open(fname,ios::in|ios::out); + file.reset(new bio::mapped_file_source()); + file->open(fname); if (!file->is_open()) { ostringstream msg; @@ -130,14 +131,14 @@ namespace ugdiss string foo = msg.str(); UTIL_THROW(util::Exception,foo.c_str()); } - char* p = file->data(); - filepos_type offset = *reinterpret_cast(p); - index = reinterpret_cast(p+offset); p += sizeof(offset); + char const* p = file->data(); + filepos_type offset = *reinterpret_cast(p); + index = reinterpret_cast(p+offset); p += sizeof(offset); numRows = *reinterpret_cast(p); p += sizeof(id_type); numCols = *reinterpret_cast(p); p += sizeof(id_type); - data = reinterpret_cast(p); + data = reinterpret_cast(p); // cout << numRows << " rows; " << numCols << " columns " << endl; - M1 = reinterpret_cast(index+numRows+1); + M1 = reinterpret_cast(index+numRows+1); M2 = M1+numRows; // cout << "Table " << fname << " has " << numRows << " rows and " // << numCols << " columns." << endl;