Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /acts/Examples/Io/Root/src/RootMaterialTrackReader.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Io/Root/RootMaterialTrackReader.hpp"
0010 
0011 #include "Acts/Utilities/Logger.hpp"
0012 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0013 #include "ActsExamples/Io/Root/RootUtility.hpp"
0014 
0015 #include <cstdint>
0016 #include <stdexcept>
0017 
0018 namespace ActsExamples {
0019 
0020 RootMaterialTrackReader::RootMaterialTrackReader(const Config& config,
0021                                                  Acts::Logging::Level level)
0022     : IReader(),
0023       m_logger{Acts::getDefaultLogger(name(), level)},
0024       m_cfg(config),
0025       m_accessor({false, config.readCachedSurfaceInformation}) {
0026   if (m_cfg.fileList.empty()) {
0027     throw std::invalid_argument{"No input files given"};
0028   }
0029 
0030   m_inputChain = std::make_unique<TChain>(m_cfg.treeName.c_str());
0031 
0032   // loop over the input files
0033   for (const auto& inputFile : m_cfg.fileList) {
0034     // add file to the input chain
0035     m_inputChain->Add(inputFile.c_str());
0036     ACTS_DEBUG("Adding File " << inputFile << " to tree '" << m_cfg.treeName
0037                               << "'.");
0038   }
0039 
0040   // Connect the branches
0041   m_accessor.connectForRead(*m_inputChain);
0042 
0043   // get the number of entries, which also loads the tree
0044   std::size_t nentries = m_inputChain->GetEntries();
0045   m_events = static_cast<std::size_t>(m_inputChain->GetMaximum("event_id") + 1);
0046   m_batchSize = nentries / m_events;
0047   ACTS_DEBUG("The full chain has "
0048              << nentries << " entries for " << m_events
0049              << " events this corresponds to a batch size of: " << m_batchSize);
0050 
0051   // Sort the entry numbers of the events
0052   {
0053     // necessary to guarantee that m_inputChain->GetV1() is valid for the
0054     // entire range
0055     m_inputChain->SetEstimate(nentries + 1);
0056 
0057     m_entryNumbers.resize(nentries);
0058     m_inputChain->Draw("event_id", "", "goff");
0059     RootUtility::stableSort(m_inputChain->GetEntries(), m_inputChain->GetV1(),
0060                             m_entryNumbers.data(), false);
0061   }
0062 
0063   m_outputMaterialTracks.initialize(m_cfg.outputMaterialTracks);
0064 }
0065 
0066 std::string RootMaterialTrackReader::name() const {
0067   return "RootMaterialTrackReader";
0068 }
0069 
0070 std::pair<std::size_t, std::size_t> RootMaterialTrackReader::availableEvents()
0071     const {
0072   return {0u, m_events};
0073 }
0074 
0075 ProcessCode RootMaterialTrackReader::read(const AlgorithmContext& context) {
0076   ACTS_DEBUG("Trying to read recorded material from tracks.");
0077 
0078   if (m_inputChain == nullptr || context.eventNumber >= m_events) {
0079     return ProcessCode::SUCCESS;
0080   }
0081 
0082   // lock the mutex
0083   std::lock_guard<std::mutex> lock(m_read_mutex);
0084   // now read
0085 
0086   // The collection to be written
0087   std::unordered_map<std::size_t, Acts::RecordedMaterialTrack> mtrackCollection;
0088 
0089   // Loop over the entries for this event
0090   for (std::size_t ib = 0; ib < m_batchSize; ++ib) {
0091     // Read the correct entry: startEntry + ib
0092     auto entry = m_batchSize * context.eventNumber + ib;
0093     entry = m_entryNumbers.at(entry);
0094     ACTS_VERBOSE("Reading event: " << context.eventNumber
0095                                    << " with stored entry: " << entry);
0096     m_inputChain->GetEntry(entry);
0097 
0098     Acts::RecordedMaterialTrack rmTrack = m_accessor.read();
0099 
0100     ACTS_VERBOSE("Track vertex:  " << rmTrack.first.first);
0101     ACTS_VERBOSE("Track momentum:" << rmTrack.first.second);
0102 
0103     mtrackCollection[ib] = (std::move(rmTrack));
0104   }
0105 
0106   // Write to the collection to the EventStore
0107   m_outputMaterialTracks(context, std::move(mtrackCollection));
0108 
0109   // Return success flag
0110   return ProcessCode::SUCCESS;
0111 }
0112 
0113 }  // namespace ActsExamples