libStatGen Software  1
MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass > Class Template Reference
Inheritance diagram for MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >:
Collaboration diagram for MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >:

Public Member Functions

void constructorClear ()
 
const std::string & getErrorString ()
 
arrayHeaderClass & getHeader ()
 
void setContentCookie (uint32_t c)
 
void setContentVersion (uint32_t v)
 
elementT operator[] (indexT i)
 
void set (indexT i, elementT v)
 
int create (const char *file, indexT elementCount, int optionalHeaderCount=0)
 Create a vector with elementCount memebers. More...
 
int create (indexT elementCount, int optionalHeaderCount=0)
 allow anonymous (malloc) create. More...
 
bool open (const char *file, int flags=O_RDONLY)
 open a previously created mapped vector More...
 
bool close ()
 
void debugPrint (FILE *f)
 
size_t getElementCount () const
 
- Public Member Functions inherited from MemoryMap
void debug_print ()
 
void constructor_clear ()
 
void destructor_clear ()
 
virtual bool allocate ()
 
virtual bool create (const char *file, size_t size)
 create the memory mapped file on disk More...
 
virtual bool create (size_t size)
 store in allocated memory (malloc), not mmap: More...
 
bool close ()
 
void test ()
 
size_t length ()
 
char operator[] (unsigned int index)
 
int prefetch ()
 
void useMemoryMap (bool flag=true)
 

Protected Attributes

arrayHeaderClass * header
 
char * data
 
std::string errorStr
 

Additional Inherited Members

- Public Attributes inherited from MemoryMap
void * data
 

Detailed Description

template<class elementT, typename indexT, unsigned int cookieVal, unsigned int versionVal, elementT accessorFunc, void setterFunc, size_t elementCount2BytesFunc, class arrayHeaderClass>
class MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >

Definition at line 141 of file MemoryMapArray.h.

Member Function Documentation

◆ create() [1/2]

template<class elementT , typename indexT , unsigned int cookieVal, unsigned int versionVal, elementT accessorFunc, void setterFunc, size_t elementCount2BytesFunc, class arrayHeaderClass >
int MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::create ( const char *  file,
indexT  elementCount,
int  optionalHeaderCount = 0 
)
inline

Create a vector with elementCount memebers.

Does administrative setup of the header and populating this class members. User will need to finish populating the contents of the metaData and data sections.

If file==NULL, the underlying allocation is done via malloc(), so that the results of write access to this vecor are not saved in a file.

If file!=NULL, a file will be created on disk, and all write accesses done via the method ::set will be persistent in that file.

Definition at line 208 of file MemoryMapArray.h.

209  {
210  size_t len = elementCount2BytesFunc(elementCount) +
211  header->getHeaderSize(optionalHeaderCount);
212  int rc;
213  rc = MemoryMap::create(file, len);
214  if (rc)
215  {
216  std::ostringstream buf;
217  buf << file << ": failed to create file";
218  errorStr = buf.str();
219  close();
220  return rc;
221  }
222  header = (arrayHeaderClass *) MemoryMap::data;
223  header->constructorClear();
224  header->typeCookie = cookieVal;
225  header->typeVersion = versionVal;
226  header->headerSize = header->getHeaderSize(optionalHeaderCount);
227  header->elementCount = elementCount;
228  data = (char *)((char *) MemoryMap::data + header->headerSize);
229 
230  const char *env;
231  char hostname[256];
232  env = getenv("USER");
233  if (env) header->setCreationUser(env);
234  header->creationDate = time(NULL);
235 #if defined(_WIN32)
236  hostname[0] = '\0';
237 #else
238  gethostname(hostname, sizeof(hostname));
239 #endif
240  header->setCreationHost(hostname);
241  return 0;
242  }
virtual bool create(const char *file, size_t size)
create the memory mapped file on disk
Definition: MemoryMap.cpp:243

References MemoryMap::create().

Referenced by MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::create(), and GenomeSequence::loadDBSNP().

◆ create() [2/2]

template<class elementT , typename indexT , unsigned int cookieVal, unsigned int versionVal, elementT accessorFunc, void setterFunc, size_t elementCount2BytesFunc, class arrayHeaderClass >
int MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::create ( indexT  elementCount,
int  optionalHeaderCount = 0 
)
inline

allow anonymous (malloc) create.

we do this when we don't expect to save the results.

The single use case so far is in GenomeSequence::populateDBSNP.

Definition at line 250 of file MemoryMapArray.h.

251  {
252  return create(NULL, elementCount, optionalHeaderCount);
253  }
int create(const char *file, indexT elementCount, int optionalHeaderCount=0)
Create a vector with elementCount memebers.

References MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::create().

◆ open()

template<class elementT , typename indexT , unsigned int cookieVal, unsigned int versionVal, elementT accessorFunc, void setterFunc, size_t elementCount2BytesFunc, class arrayHeaderClass >
bool MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::open ( const char *  file,
int  flags = O_RDONLY 
)
inlinevirtual

open a previously created mapped vector

useMemoryMapFlag will determine whether it uses mmap() or malloc()/read() to populate the memory

Reimplemented from MemoryMap.

Definition at line 269 of file MemoryMapArray.h.

270  {
271  int rc = MemoryMap::open(file, flags);
272  if (rc)
273  {
274  std::ostringstream buf;
275  buf << file << ": open() failed (error=" << strerror(errno) << ").";
276  errorStr = buf.str();
277  return true;
278  }
279  header = (arrayHeaderClass *) MemoryMap::data;
280  data = (char *)((char *) MemoryMap::data + header->headerSize);
281  if (header->typeCookie!=cookieVal)
282  {
283  std::ostringstream buf;
284  buf << file << ": wrong type of file (expected type "
285  << cookieVal << " but got " << header->typeCookie << ")";
286  errorStr = buf.str();
287  // XXX insert better error handling
288  close();
289  return true;
290  }
291  if (header->typeVersion!=versionVal)
292  {
293  std::ostringstream buf;
294  buf << file << ": wrong version of file (expected version "
295  << versionVal << " but got " << header->typeVersion << ")";
296  errorStr = buf.str();
297  // XXX insert better error handling
298  close();
299  return true;
300  }
301  return false;
302  }
virtual bool open(const char *file, int flags=O_RDONLY)
open a previously created mapped vector
Definition: MemoryMap.cpp:156

References MemoryMap::open().

Referenced by GenomeSequence::loadDBSNP(), and GenomeSequence::open().


The documentation for this class was generated from the following file: