Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:52:20

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