Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:08

0001 // TRENTO: Reduced Thickness Event-by-event Nuclear Topology
0002 // Copyright 2015 Jonah E. Bernhard, J. Scott Moreland
0003 // MIT License
0004 
0005 #ifndef UTIL_H
0006 #define UTIL_H
0007 
0008 #include <iostream>
0009 #include <sstream>
0010 
0011 #include <boost/filesystem.hpp>
0012 #include <boost/program_options/variables_map.hpp>
0013 
0014 #include "../src/fwd_decl.h"
0015 
0016 // testing utilities
0017 
0018 // Factory function; create a dummy boost::program_options::variables_map.
0019 VarMap make_var_map(std::map<std::string, boost::any>&& args);
0020 
0021 // redirect stdout to a stringstream and safely restore upon destruction
0022 struct capture_stdout {
0023   capture_stdout() {
0024     // replace stdout buffer
0025     cout_orig = std::cout.rdbuf(stream.rdbuf());
0026   }
0027 
0028   ~capture_stdout() {
0029     // restore stdout to working state
0030     std::cout.rdbuf(cout_orig);
0031   }
0032 
0033   std::streambuf* cout_orig;
0034   std::stringstream stream;
0035 };
0036 
0037 // path that deletes itself when it goes out of scope
0038 struct temporary_path {
0039   temporary_path(const fs::path& ext = fs::path{})
0040       : path(
0041           fs::temp_directory_path() /
0042           fs::unique_path().replace_extension(ext)
0043         )
0044     {}
0045   ~temporary_path() {
0046     fs::remove_all(path);
0047   }
0048   const fs::path path;
0049 };
0050 
0051 #endif  // UTIL_H