Skip to content

Commit

Permalink
Fix GriffDataReader
Browse files Browse the repository at this point in the history
  • Loading branch information
tkittel committed Jul 28, 2024
1 parent 67a50c1 commit b632b9b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace EvtFile {
//eventActive() returns false if not at a readable event. This can occur as
//a result of a failed navigation attempt or right after the constructor in
//case the file has 0 events:
bool eventActive() const { return m_currentEventInfo!=0; }
bool eventActive() const { return m_currentEventInfo!=nullptr; }

//Actual data access. Do not call before testing eventActive above.
unsigned runNumber() const { return m_currentEventInfo->runNumber; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "EvtFile/DBEntryReader.hh"
#include "Utils/ByteStream.hh"
#include "Utils/MemPool.hh"
#include "Utils/DynBuffer.hh"
#include <cassert>
#include <vector>
#include <string>
Expand Down Expand Up @@ -147,7 +148,7 @@ private:
//current file:
unsigned m_fileIdx;
EvtFile::FileReader * m_fr;
char m_mempool_filereader[sizeof(EvtFile::FileReader)];
alignas(EvtFile::FileReader) char m_mempool_filereader[sizeof(EvtFile::FileReader)];
//event data:
mutable bool m_needsLoad;
mutable bool m_tracksContiguous;
Expand All @@ -165,10 +166,11 @@ private:
mutable const GriffDataRead::Track* m_primaryTracksBegin;
mutable const GriffDataRead::Track* m_primaryTracksEnd;
mutable std::vector<GriffDataRead::Track> m_tracks;
mutable std::vector<char> m_mempool_segments;
//mutable std::vector<char> m_mempool_segments;//fixme align!
mutable Utils::DynBuffer<char> m_mempool_segments;//fixme align!
static const unsigned MEMPOOL_STEPS_NSTEPS = 10;
static const unsigned STEP_SIZE = 2*sizeof(void*);//to avoid include loop
Utils::MemPool<STEP_SIZE*MEMPOOL_STEPS_NSTEPS> m_mempool_steps;
Utils::MemPool<STEP_SIZE*MEMPOOL_STEPS_NSTEPS> m_mempool_steps;//fixme align
std::vector<char*> m_mempool_dynamic;//stuff to delete[] in clearEvent

//db:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ void GriffDataReader::initFile(unsigned i)
m_fileIdx = i;
return;
}
m_fr->EvtFile::FileReader::~FileReader();
m_fr = 0;
m_fr->EvtFile::FileReader::~FileReader();//fixme std::optional would be better!
m_fr = nullptr;
}
m_fr = new(&(m_mempool_filereader[0])) EvtFile::FileReader(GriffFormat::Format::getFormat(),m_inputFiles[i].c_str(),&m_dbmgr);
bool ok = m_fr->init();
Expand Down Expand Up @@ -316,7 +316,8 @@ void GriffDataReader::actualLoadTracks() const
assert(m_primaryTracksEnd>=m_primaryTracksBegin);

//Segments:
m_mempool_segments.reserve(nsegments*sizeof(GriffDataRead::Segment));
// m_mempool_segments.reserve(nsegments*sizeof(GriffDataRead::Segment));
m_mempool_segments.resize_without_init(nsegments*sizeof(GriffDataRead::Segment));
unsigned iseg(0);
for (GriffDataRead::Track* it=const_cast<GriffDataRead::Track*>(m_tracksBegin);it!=const_cast<GriffDataRead::Track*>(m_tracksEnd);++it) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Utils {
static const unsigned chunksize = NBytes;

MemPool() { grow(); }
~MemPool() { releaseAll(); delete[] m_areas[0]; }
~MemPool() { releaseAll(); free(m_areas[0]); }
char* acquire()
{
if (m_next == Count)
Expand All @@ -30,15 +30,17 @@ namespace Utils {
auto itE = m_areas.end();
++it;//keep the first area for next time
for(;it!=itE;++it)
delete[] *it;
// delete[] *it;
free(*it);
m_areas.resize(1);
m_current = m_areas.front();
}
private:
void grow()
{
m_next = 0;
m_areas.push_back(m_current = new char[NBytes*Count]);
//m_areas.push_back(m_current = new char[NBytes*Count]);
m_areas.push_back(m_current = (char*)malloc(NBytes*Count));
}
unsigned m_next;
char * m_current;
Expand Down

0 comments on commit b632b9b

Please sign in to comment.