Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions source/GETCore/GETDecoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void GETDecoder::Initialize()
if ( fMutantFrame == NULL) fMutantFrame = new GETMutantFrame();
else fMutantFrame -> Clear();

fInitialPosition = 0;
fPrevDataID = 0;
fPrevPosition = 0;
}
Expand All @@ -131,6 +132,7 @@ void GETDecoder::Clear() {

fDataSize = 0;
fCurrentDataID = -1;
fInitialPosition = 0;

fFrameInfoIdx = 0;
fCoboFrameInfoIdx = 0;
Expand Down Expand Up @@ -226,6 +228,54 @@ Bool_t GETDecoder::SetData(Int_t index)
std::cout << "== [GETDecoder] " << filename << " is opened!" << std::endl;

fData.seekg(0);

std::string startOfFileHeader = "<File_Header><";
std::string endofFileHeader = "</File_Header>";
UInt_t sizeOfString = endofFileHeader.size();

std::string lastString = endofFileHeader;
for (UInt_t iChar = 0; iChar < sizeOfString; ++iChar)
lastString[iChar] = ' ';

Bool_t isExistFileHeader = kFALSE;
Char_t buffer;

for (UInt_t iRead = 0; iRead < 100; ++iRead) {
fData.read(&buffer, sizeof(Char_t));

for (UInt_t iChar = 1; iChar < sizeOfString; ++iChar)
lastString[iChar-1] = lastString[iChar];
lastString[sizeOfString-1] = buffer;

if (lastString == startOfFileHeader) {
isExistFileHeader = kTRUE;
break;
}
}

if (!isExistFileHeader)
fInitialPosition = 0;
else {
std::cout << "== [GETDecoder] File Header do exist!" << std::endl;
for (UInt_t iRead = 0; iRead < 10000; ++iRead) {
fData.read(&buffer, sizeof(Char_t));

for (UInt_t iChar = 1; iChar < sizeOfString; ++iChar)
lastString[iChar-1] = lastString[iChar];
lastString[sizeOfString-1] = buffer;

if (lastString == endofFileHeader) {
fInitialPosition = fData.tellg();
break;
}
}
if (fInitialPosition == 0) {
std::cout << "== [GETDecoder] Cannot find end of File Header!" << std::endl;
return kFALSE;
}
}

fData.seekg(fInitialPosition);

if (!fIsDataInfo) {
fHeaderBase -> Read(fData, kTRUE);
Expand Down Expand Up @@ -667,7 +717,7 @@ Bool_t GETDecoder::SetWriteFile(TString filename, Bool_t overwrite)
SetData(0);

std::ofstream outFile(fWriteFile.Data(), std::ios::ate|std::ios::binary|std::ios::app);
fData.seekg(0);
fData.seekg(fInitialPosition);
fData.read(fBuffer, fTopologyFrame -> GetFrameSize());
outFile.write(fBuffer, fTopologyFrame -> GetFrameSize());
outFile.close();
Expand Down Expand Up @@ -834,7 +884,7 @@ void GETDecoder::SaveMetaData(Int_t runNo, TString filename, Int_t coboIdx) {
}
}

void GETDecoder::LoadMetaData(TString filename) {
UInt_t GETDecoder::LoadMetaData(TString filename) {
TFile *metaFile = new TFile(filename);

UInt_t dataID = 0, eventID = 0, deltaT = 0;
Expand Down Expand Up @@ -897,4 +947,6 @@ void GETDecoder::LoadMetaData(TString filename) {

fIsDoneAnalyzing = kTRUE;
fIsMetaData = kTRUE;

return numEntries;
}
6 changes: 4 additions & 2 deletions source/GETCore/GETDecoder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class GETDecoder
void GoToEnd();
//! Write metadata into ROOT file
void SaveMetaData(Int_t runNo = -1, TString filename = "", Int_t coboIdx = -1);
//! Load metadata from ROOT file
void LoadMetaData(TString filename);
//! Load metadata from ROOT file. Return number of entries
UInt_t LoadMetaData(TString filename);

//! Set topology frame information manually
void SetPseudoTopologyFrame(Int_t asadMask, Bool_t check = kFALSE);
Expand Down Expand Up @@ -154,6 +154,8 @@ class GETDecoder
Int_t fPrevDataID; ///< Data ID for going back to original data
ULong64_t fPrevPosition; ///< Byte number for going back to original data

ULong64_t fInitialPosition; ///< Initial file position just after end of File Header

ClassDef(GETDecoder, 1); /// added for making dictionary by ROOT
};

Expand Down