Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Commit 34146b2

Browse files
committed
Dynamic loading of Ogawa sparse fields working.
1 parent 6819e8a commit 34146b2

File tree

9 files changed

+171
-127
lines changed

9 files changed

+171
-127
lines changed

export/OgawaFwd.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#ifndef _INCLUDED_Field3D_OgawaFwd_H_
4646
#define _INCLUDED_Field3D_OgawaFwd_H_
4747

48+
#include <boost/shared_ptr.hpp>
49+
4850
#include "ns.h"
4951

5052
//----------------------------------------------------------------------------//
@@ -66,6 +68,8 @@ class OgIDataset;
6668
template <typename T>
6769
class OgODataset;
6870

71+
typedef boost::shared_ptr<OgIGroup> OgIGroupPtr;
72+
6973
FIELD3D_NAMESPACE_HEADER_CLOSE
7074

7175
//----------------------------------------------------------------------------//
@@ -80,6 +84,8 @@ namespace Alembic {
8084
}
8185
}
8286

87+
typedef boost::shared_ptr<Alembic::Ogawa::IArchive> IArchivePtr;
88+
8389
//----------------------------------------------------------------------------//
8490

8591
#endif // include guard

export/SparseField.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ class SparseField
568568
//! Internal function to create a Reference for the current field,
569569
//! for use in dynamic reading.
570570
void addReference(const std::string &filename, const std::string &layerPath,
571-
int valuesPerBlock, int occupiedBlocks);
571+
int valuesPerBlock, int numVoxels, int occupiedBlocks);
572572
//! Internal function to setup the Reference's block pointers, for
573573
//! use with dynamic reading.
574574
void setupReferenceBlocks();
@@ -1336,6 +1336,7 @@ SparseField<Data_T>::copySparseField(const SparseField<Data_T> &o)
13361336
m_fileManager->reference<Data_T>(o.m_fileId);
13371337
addReference(oldReference->filename, oldReference->layerPath,
13381338
oldReference->valuesPerBlock,
1339+
oldReference->numVoxels,
13391340
oldReference->occupiedBlocks);
13401341
copyBlockStates(o);
13411342
setupReferenceBlocks();
@@ -1365,6 +1366,7 @@ template <class Data_T>
13651366
void SparseField<Data_T>::addReference(const std::string &filename,
13661367
const std::string &layerPath,
13671368
int valuesPerBlock,
1369+
int numVoxels,
13681370
int occupiedBlocks)
13691371
{
13701372
m_fileManager = &SparseFileManager::singleton();
@@ -1373,6 +1375,7 @@ void SparseField<Data_T>::addReference(const std::string &filename,
13731375
SparseFile::Reference<Data_T> *reference =
13741376
m_fileManager->reference<Data_T>(m_fileId);
13751377
reference->valuesPerBlock = valuesPerBlock;
1378+
reference->numVoxels = numVoxels;
13761379
reference->occupiedBlocks = occupiedBlocks;
13771380
reference->setNumBlocks(m_numBlocks);
13781381
}

export/SparseFile.h

Lines changed: 28 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
#include "Exception.h"
5656
#include "Hdf5Util.h"
57+
#include "OgawaFwd.h"
5758
#include "SparseDataReader.h"
5859
#include "Traits.h"
5960

@@ -77,6 +78,9 @@ namespace Sparse {
7778
template <typename Data_T>
7879
class SparseField;
7980

81+
template <typename Data_T>
82+
class OgSparseDataReader;
83+
8084
//----------------------------------------------------------------------------//
8185

8286
namespace SparseFile {
@@ -113,6 +117,7 @@ class Reference
113117
std::string filename;
114118
std::string layerPath;
115119
int valuesPerBlock;
120+
int numVoxels;
116121
int occupiedBlocks;
117122

118123
//! Index in file for each block
@@ -216,8 +221,19 @@ class Reference
216221
//! openFile().
217222
SparseDataReader<Data_T> *m_reader;
218223

224+
//! Shared pointer to the ogawa reader.
225+
boost::shared_ptr<OgSparseDataReader<Data_T> > m_ogReaderPtr;
226+
//! Pointer to the ogawa reader. NULL at construction time. Created in
227+
//! openFile().
228+
OgSparseDataReader<Data_T> *m_ogReader;
229+
//! Ogawa archive
230+
IArchivePtr m_ogArchive;
231+
//! Ogawa archive root
232+
OgIGroupPtr m_ogRoot;
233+
//! Ogawa layer group
234+
OgIGroupPtr m_ogLayerGroup;
235+
219236
//! Mutex to prevent two threads from modifying conflicting data
220-
// boost::mutex m_mutex;
221237
Mutex m_mutex;
222238

223239
//! Number of currently active blocks
@@ -520,8 +536,8 @@ template <class Data_T>
520536
Reference<Data_T>::Reference(const std::string a_filename,
521537
const std::string a_layerPath)
522538
: filename(a_filename), layerPath(a_layerPath),
523-
valuesPerBlock(-1), occupiedBlocks(-1),
524-
blockMutex(NULL), m_fileHandle(-1), m_reader(NULL),
539+
valuesPerBlock(-1), numVoxels(-1), occupiedBlocks(-1),
540+
blockMutex(NULL), m_fileHandle(-1), m_reader(NULL), m_ogReader(NULL),
525541
m_numActiveBlocks(0)
526542
{
527543
/* Empty */
@@ -534,8 +550,9 @@ Reference<Data_T>::~Reference()
534550
{
535551
closeFile();
536552

537-
if (m_reader)
553+
if (m_reader) {
538554
delete m_reader;
555+
}
539556

540557
if (blockMutex)
541558
delete [] blockMutex;
@@ -546,6 +563,8 @@ Reference<Data_T>::~Reference()
546563
template <class Data_T>
547564
Reference<Data_T>::Reference(const Reference<Data_T> &o)
548565
{
566+
m_ogReaderPtr.reset();
567+
m_ogReader = NULL;
549568
m_reader = NULL;
550569
blockMutex = NULL;
551570
*this = o;
@@ -565,6 +584,7 @@ Reference<Data_T>::operator=(const Reference<Data_T> &o)
565584
filename = o.filename;
566585
layerPath = o.layerPath;
567586
valuesPerBlock = o.valuesPerBlock;
587+
numVoxels = o.numVoxels;
568588
occupiedBlocks = o.occupiedBlocks;
569589
fileBlockIndices = o.fileBlockIndices;
570590
blockLoaded = o.blockLoaded;
@@ -594,6 +614,9 @@ Reference<Data_T>::operator=(const Reference<Data_T> &o)
594614
delete m_reader;
595615
m_reader = NULL;
596616

617+
m_ogReaderPtr.reset();
618+
m_ogReader = NULL;
619+
597620
return *this;
598621
}
599622

@@ -635,48 +658,6 @@ void Reference<Data_T>::setNumBlocks(int numBlocks)
635658

636659
//----------------------------------------------------------------------------//
637660

638-
template <class Data_T>
639-
void Reference<Data_T>::openFile()
640-
{
641-
using namespace Exc;
642-
using namespace Hdf5Util;
643-
644-
boost::mutex::scoped_lock lock_A(m_mutex);
645-
646-
// check that the file wasn't already opened before obtaining the lock
647-
if (fileIsOpen()) {
648-
return;
649-
}
650-
651-
{
652-
// Hold the global lock
653-
GlobalLock lock(g_hdf5Mutex);
654-
// Open the file
655-
m_fileHandle = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
656-
if (m_fileHandle < 0) {
657-
printf("openFile(): No file handle. Dying.\n");
658-
throw NoSuchFileException(filename);
659-
}
660-
// Open the layer group
661-
m_layerGroup.open(m_fileHandle, layerPath.c_str());
662-
if (m_layerGroup.id() < 0) {
663-
Msg::print(Msg::SevWarning, "In SparseFile::Reference::openFile: "
664-
"Couldn't find layer group " + layerPath +
665-
" in .f3d file ");
666-
throw FileIntegrityException(filename);
667-
}
668-
}
669-
670-
// Re-allocate reader
671-
if (m_reader) {
672-
delete m_reader;
673-
}
674-
m_reader = new SparseDataReader<Data_T>(m_layerGroup.id(), valuesPerBlock,
675-
occupiedBlocks);
676-
}
677-
678-
//----------------------------------------------------------------------------//
679-
680661
template <class Data_T>
681662
void Reference<Data_T>::closeFile()
682663
{
@@ -689,25 +670,6 @@ void Reference<Data_T>::closeFile()
689670

690671
//----------------------------------------------------------------------------//
691672

692-
template <class Data_T>
693-
void Reference<Data_T>::loadBlock(int blockIdx)
694-
{
695-
boost::mutex::scoped_lock lock(m_mutex);
696-
697-
// Allocate the block
698-
blocks[blockIdx]->resize(valuesPerBlock);
699-
assert(blocks[blockIdx]->data != NULL);
700-
// Read the data
701-
assert(m_reader);
702-
m_reader->readBlock(fileBlockIndices[blockIdx], *blocks[blockIdx]->data);
703-
// Mark block as loaded
704-
blockLoaded[blockIdx] = 1;
705-
// Track count
706-
m_numActiveBlocks++;
707-
}
708-
709-
//----------------------------------------------------------------------------//
710-
711673
template <class Data_T>
712674
void Reference<Data_T>::unloadBlock(int blockIdx)
713675
{
@@ -748,7 +710,7 @@ void Reference<Data_T>::decBlockRef(int blockIdx)
748710
template <class Data_T>
749711
int Reference<Data_T>::blockSize(int /* blockIdx */) const
750712
{
751-
return valuesPerBlock * sizeof(Data_T);
713+
return numVoxels * sizeof(Data_T);
752714
}
753715

754716
//----------------------------------------------------------------------------//

export/Types.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,38 +85,6 @@ struct Interval
8585

8686
typedef std::vector<Interval> IntervalVec;
8787

88-
//----------------------------------------------------------------------------//
89-
// Ogawa Types
90-
//----------------------------------------------------------------------------//
91-
92-
#if !defined(_MSC_VER)
93-
using ::uint8_t;
94-
using ::int8_t;
95-
using ::uint16_t;
96-
using ::int16_t;
97-
using ::uint32_t;
98-
using ::int32_t;
99-
using ::uint64_t;
100-
using ::int64_t;
101-
#else
102-
typedef unsigned char uint8_t;
103-
typedef signed char int8_t;
104-
typedef unsigned short uint16_t;
105-
typedef signed short int16_t;
106-
typedef unsigned int uint32_t;
107-
typedef int int32_t;
108-
typedef unsigned long long uint64_t;
109-
typedef long long int64_t;
110-
#endif
111-
112-
typedef half float16_t;
113-
typedef float float32_t;
114-
typedef double float64_t;
115-
116-
typedef Field3D::V3h vec16_t;
117-
typedef Field3D::V3f vec32_t;
118-
typedef Field3D::V3d vec64_t;
119-
12088
//----------------------------------------------------------------------------//
12189

12290
#endif // Include guard

include/MIPFieldIO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class GenericLazyLoadActionHDF5
278278
// Instantiate I/O
279279
FieldIO::Ptr io =
280280
ClassFactory::singleton().createFieldIO(Field_T::staticClassName());
281-
FieldBase::Ptr field = io->read(levelGroup, m_filename, m_path, m_typeEnum);
281+
FieldBase::Ptr field = io->read(*levelGroup, m_filename, m_path, m_typeEnum);
282282
if (!field) {
283283
throw Exc::MIPFieldIOException("Failed to read MIP level from disk.");
284284
}

src/Field3DFile.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,6 @@ Field3DInputFile::~Field3DInputFile()
712712

713713
bool Field3DInputFile::open(const string &filename)
714714
{
715-
GlobalLock lock(g_hdf5Mutex);
716-
717715
clear();
718716

719717
bool success = true;
@@ -1249,8 +1247,6 @@ Field3DOutputFile::writeGroupMembership()
12491247
using namespace std;
12501248
using namespace Hdf5Util;
12511249

1252-
GlobalLock lock(g_hdf5Mutex);
1253-
12541250
if (!m_groupMembership.size())
12551251
return true;
12561252

@@ -1316,14 +1312,10 @@ void Field3DFileBase::printHierarchy() const
13161312
cout << " Mapping: " << (**i).mapping->className() << endl;
13171313
else
13181314
cout << " Mapping: NULL" << endl;
1319-
cout << " Scalar layers: " << endl;
1320-
vector<string> sNames;
1321-
(**i).getScalarLayerNames(sNames);
1322-
for_each(sNames.begin(), sNames.end(), print<string>(4));
1323-
cout << " Vector layers: " << endl;
1324-
vector<string> vNames;
1325-
(**i).getVectorLayerNames(vNames);
1326-
for_each(vNames.begin(), vNames.end(), print<string>(4));
1315+
cout << " Layers: " << endl;
1316+
vector<string> names;
1317+
(**i).getLayerNames(names);
1318+
for_each(names.begin(), names.end(), print<string>(4));
13271319
}
13281320
}
13291321

src/Field3DFileHDF5.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,19 +1586,6 @@ void Field3DFileHDF5Base::printHierarchy() const
15861586
// Function Implementations
15871587
//----------------------------------------------------------------------------//
15881588

1589-
bool fileExists(const std::string &filename)
1590-
{
1591-
#ifdef WIN32
1592-
struct __stat64 statbuf;
1593-
return (_stat64(filename.c_str(), &statbuf) != -1);
1594-
#else
1595-
struct stat statbuf;
1596-
return (stat(filename.c_str(), &statbuf) != -1);
1597-
#endif
1598-
}
1599-
1600-
//----------------------------------------------------------------------------//
1601-
16021589
bool writeField(hid_t layerGroup, FieldBase::Ptr field)
16031590
{
16041591
ClassFactory &factory = ClassFactory::singleton();

src/SparseFieldIO.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,8 @@ SparseFieldIO::readData(const OgIGroup &location, const Box3i &extents,
761761
if (dynamicLoading) {
762762
// Set up the field reference
763763
//! \todo The valuesPerBlock is wrong. Fix
764-
result->addReference(filename, layerPath, valuesPerBlock, occupiedBlocks);
764+
result->addReference(filename, layerPath, valuesPerBlock, numVoxels,
765+
occupiedBlocks);
765766
}
766767

767768
// Read the block info data sets ---
@@ -1159,7 +1160,7 @@ bool SparseFieldIO::readData(hid_t location,
11591160
if (dynamicLoading) {
11601161
// Set up the field reference
11611162
result->addReference(filename, layerPath,
1162-
valuesPerBlock,
1163+
valuesPerBlock, numVoxels,
11631164
occupiedBlocks);
11641165
}
11651166

0 commit comments

Comments
 (0)