Skip to content

Commit

Permalink
Merge pull request #393 from rest-for-physics/nkx111-single-event-file
Browse files Browse the repository at this point in the history
Fix bug when processing files with a single event
  • Loading branch information
jgalan authored Apr 28, 2023
2 parents babeff3 + 39568e8 commit 324cf3d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
10 changes: 10 additions & 0 deletions pipeline/ValidateTrees.C
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ Int_t ValidateTrees(const char* validationFilename, const char* inputFilename =
printf(" value: %.15f, should be: %.15f\n", (*inputObservableVector)[m],
(*validationObservableVector)[m]);

cout << "Validation vector contents: " << endl;
for (int m = 0; m < (*validationObservableVector).size(); m++)
cout << (*validationObservableVector)[m] << "\t";
cout << endl;

cout << "Results vector contents: " << endl;
for (int m = 0; m < (*inputObservableVector).size(); m++)
cout << (*inputObservableVector)[m] << "\t";
cout << endl;

if (!TMath::IsNaN((*inputObservableVector)[m] - (*validationObservableVector)[m]) &&
abs(((*inputObservableVector)[m] - (*validationObservableVector)[m]) /
(*inputObservableVector)[m]) < 1e-15) {
Expand Down
Binary file modified pipeline/trex/validation.root
Binary file not shown.
54 changes: 29 additions & 25 deletions source/framework/core/src/TRestRun.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -828,36 +828,40 @@ Int_t TRestRun::GetNextEvent(TRestEvent* targetevt, TRestAnalysisTree* targettre
//}
fCurrentEvent++;
} else {
RESTDebug << "TRestRun: getting next event from root file" << RESTendl;
if (fAnalysisTree == nullptr) {
RESTWarning << "error to get event from input file, missing analysis tree from input file"
<< RESTendl;
eve = nullptr;
if (eve == nullptr) {
RESTDebug << "TRestRun::GetNextEvent(): input event has not been initialized!" << RESTendl;
} else {
if (fCurrentEvent >= fAnalysisTree->GetTree()->GetEntriesFast()) {
RESTDebug << "TRestRun: getting next event from root file" << RESTendl;
if (fAnalysisTree == nullptr) {
RESTWarning << "error to get event from input file, missing analysis tree from input file"
<< RESTendl;
eve = nullptr;
} else {
if (targettree != nullptr) {
// normal reading procedure
eve->Initialize();
fBytesRead += fAnalysisTree->GetEntry(fCurrentEvent);
targettree->SetEventInfo(fAnalysisTree);
for (int n = 0; n < fAnalysisTree->GetNumberOfObservables(); n++)
targettree->SetObservable(n, fAnalysisTree->GetObservable(n));
}
if (fEventTree != nullptr) {
if (fEventTree->IsA() == TChain::Class()) {
Long64_t entry = fEventTree->LoadTree(fCurrentEvent);
fBytesRead += ((TBranch*)fEventTree->GetTree()->GetListOfBranches()->UncheckedAt(
fEventBranchLoc))
->GetEntry(entry);
} else {
fBytesRead +=
((TBranch*)fEventTree->GetListOfBranches()->UncheckedAt(fEventBranchLoc))
->GetEntry(fCurrentEvent);
if (fCurrentEvent >= fAnalysisTree->GetTree()->GetEntriesFast()) {
eve = nullptr;
} else {
if (targettree != nullptr) {
// normal reading procedure
eve->Initialize();
fBytesRead += fAnalysisTree->GetEntry(fCurrentEvent);
targettree->SetEventInfo(fAnalysisTree);
for (int n = 0; n < fAnalysisTree->GetNumberOfObservables(); n++)
targettree->SetObservable(n, fAnalysisTree->GetObservable(n));
}
if (fEventTree != nullptr) {
if (fEventTree->IsA() == TChain::Class()) {
Long64_t entry = fEventTree->LoadTree(fCurrentEvent);
fBytesRead += ((TBranch*)fEventTree->GetTree()->GetListOfBranches()->UncheckedAt(
fEventBranchLoc))
->GetEntry(entry);
} else {
fBytesRead +=
((TBranch*)fEventTree->GetListOfBranches()->UncheckedAt(fEventBranchLoc))
->GetEntry(fCurrentEvent);
}
}
fCurrentEvent++;
}
fCurrentEvent++;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/framework/core/src/TRestThread.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ bool TRestThread::TestRun() {
}

fOutputEvent = ProcessedEvent;
fHostRunner->GetNextevtFunc(fInputEvent, fAnalysisTree);
if (fOutputEvent != nullptr) {
RESTDebug << "Output Event ---- " << fOutputEvent->ClassName() << "(" << fOutputEvent << ")"
<< RESTendl;
break;
} else {
RESTDebug << "Null output, trying again" << RESTendl;
}
fHostRunner->GetNextevtFunc(fInputEvent, fAnalysisTree);
}
if (fOutputEvent == nullptr) {
// fOutputEvent = fProcessChain[fProcessChain.size() - 1]->GetOutputEvent();
Expand Down

0 comments on commit 324cf3d

Please sign in to comment.