Commit ada8168e authored by Håkan Wennlöf's avatar Håkan Wennlöf
Browse files

Changed tree pre-filling to play nicer when events are skipped.

Added magic_enum include to fix compilation error for the runmanagers.
parent db0e3515
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -171,17 +171,18 @@ void ROOTObjectWriterModule::run(Event* event) {
                branch_name.c_str(), (std::string("std::vector<") + class_name_with_namespace + "*>").c_str(), addr);

            // Prefill new tree or new branch with empty records for all events that were missed since the start
            if(last_event_ > 0) {
            if(trees_["Event"]->GetEntries() > 0) {
                if(new_tree) {
                    LOG(DEBUG) << "Pre-filling new tree of " << class_name << " with " << last_event_ << " empty events";
                    for(uint64_t i = 0; i < last_event_; ++i) {
                    LOG(DEBUG) << "Pre-filling new tree of " << class_name << " with " << trees_["Event"]->GetEntries()
                               << " empty events";
                    for(Long64_t i = 0; i < trees_["Event"]->GetEntries(); ++i) {
                        trees_[class_name]->Fill();
                    }
                } else {
                    LOG(DEBUG) << "Pre-filling new branch " << branch_name << " of " << class_name << " with " << last_event_
                               << " empty events";
                    LOG(DEBUG) << "Pre-filling new branch " << branch_name << " of " << class_name << " with "
                               << trees_["Event"]->GetEntries() << " empty events";
                    auto* branch = trees_[class_name]->GetBranch(branch_name.c_str());
                    for(uint64_t i = 0; i < last_event_; ++i) {
                    for(Long64_t i = 0; i < trees_["Event"]->GetEntries(); ++i) {
                        branch->Fill();
                    }
                }
@@ -202,9 +203,6 @@ void ROOTObjectWriterModule::run(Event* event) {
    LOG(TRACE) << "Writing new objects to tree";
    output_file_->cd();

    // Save last event number for trees created later
    last_event_ = event->number;

    // Fill the tree with the current received messages
    for(auto& tree : trees_) {
        tree.second->Fill();
+0 −3
Original line number Diff line number Diff line
@@ -86,9 +86,6 @@ namespace allpix {
        // Current random seed
        uint64_t current_seed_{0};

        // Last event processed
        uint64_t last_event_{0};

        // List of trees that are stored in data file
        std::map<std::string, std::unique_ptr<TTree>> trees_;

+2 −1
Original line number Diff line number Diff line
@@ -54,7 +54,8 @@ void RunManager::AbortRun(bool softAbort) {
        }
        // Ready for new event, set the state back to G4State_Idle
        G4StateManager::GetStateManager()->SetNewState(G4State_Idle);
        LOG(DEBUG) << "Reset Geant4 state to " << magic_enum::enum_name(G4StateManager::GetStateManager()->GetCurrentState());;
        LOG(DEBUG) << "Reset Geant4 state to "
                   << magic_enum::enum_name(G4StateManager::GetStateManager()->GetCurrentState());
    } else {
        LOG(WARNING) << "Run is not in progress. AbortRun() ignored." << G4endl;
    }
+4 −1
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
#include "SensitiveDetectorAndFieldConstruction.hpp"
#include "core/module/exceptions.h"

#include <magic_enum/magic_enum.hpp>

#include <atomic>

#include <G4MTRunManager.hh>
@@ -234,7 +236,8 @@ void WorkerRunManager::AbortRun(bool softAbort) {
        }
        // Ready for new event, set the state back to G4State_Idle
        G4StateManager::GetStateManager()->SetNewState(G4State_Idle);
        LOG(DEBUG) << "Reset Geant4 state to " << magic_enum::enum_name(G4StateManager::GetStateManager()->GetCurrentState());;
        LOG(DEBUG) << "Reset Geant4 state to "
                   << magic_enum::enum_name(G4StateManager::GetStateManager()->GetCurrentState());
    } else {

        LOG(WARNING) << "Run is not in progress. AbortRun() ignored." << G4endl;