Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:21

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2022-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/ext/RootUniquePtr.hh
0007 //! \brief Helpers to prevent ROOT from propagating to downstream code.
0008 //---------------------------------------------------------------------------//
0009 #pragma once
0010 
0011 #include <memory>
0012 
0013 #include "corecel/Config.hh"
0014 
0015 #include "corecel/Assert.hh"
0016 
0017 class TFile;
0018 class TTree;
0019 
0020 namespace celeritas
0021 {
0022 //---------------------------------------------------------------------------//
0023 /*!
0024  * Call `TFile->Write()` before deletion.
0025  */
0026 struct RootFileWritableDeleter
0027 {
0028     void operator()(TFile* ptr);
0029 };
0030 
0031 //---------------------------------------------------------------------------//
0032 /*!
0033  * Call `TTree->AutoSave()` before deletion in order to update `gDirectory`
0034  * accordingly before writing the TTree.
0035  */
0036 struct RootTreeAutoSaveDeleter
0037 {
0038     void operator()(TTree* ptr);
0039 };
0040 
0041 //---------------------------------------------------------------------------//
0042 /*!
0043  * Custom deleter to avoid propagating any dependency-specific implementation
0044  * downstream the code.
0045  */
0046 template<class T>
0047 struct ExternDeleter
0048 {
0049     void operator()(T* ptr);
0050 };
0051 
0052 //---------------------------------------------------------------------------//
0053 // Type aliases
0054 using UPRootFileWritable = std::unique_ptr<TFile, RootFileWritableDeleter>;
0055 using UPRootTreeWritable = std::unique_ptr<TTree, RootTreeAutoSaveDeleter>;
0056 
0057 template<class T>
0058 using UPExtern = std::unique_ptr<T, ExternDeleter<T>>;
0059 
0060 //---------------------------------------------------------------------------//
0061 #if !CELERITAS_USE_ROOT
0062 inline void RootFileWritableDeleter::operator()(TFile*)
0063 {
0064     CELER_NOT_CONFIGURED("ROOT");
0065 }
0066 
0067 inline void RootTreeAutoSaveDeleter::operator()(TTree*)
0068 {
0069     CELER_NOT_CONFIGURED("ROOT");
0070 }
0071 
0072 template<class T>
0073 void ExternDeleter<T>::operator()(T*)
0074 {
0075     CELER_NOT_CONFIGURED("ROOT");
0076 }
0077 #endif
0078 
0079 //---------------------------------------------------------------------------//
0080 }  // namespace celeritas