Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:13:42

0001 // This file contains boilerplate code for static writer functions in all
0002 // classes inheriting from Writer. These methods just forward to the methods on
0003 // the Writer base class, but code duplication can't be avoided without a
0004 // preprocessor hack like this, AFAIK.
0005 
0006 /// @name Writing a single analysis object.
0007 /// @{
0008 
0009 /// Write out object @a ao to output stream @a stream.
0010 static void write(std::ostream& stream, const AnalysisObject& ao) {
0011   create().write(stream, ao);
0012 }
0013 
0014 /// Write out pointer-like object @a ao to output stream @a stream.
0015 template <typename T>
0016 static typename std::enable_if<DerefableToAO<T>::value>::type //< -> void if valid
0017 write(std::ostream& stream, const T& ao, int precision=-1) { write(stream, *ao, precision); }
0018 
0019 /// Write out object @a ao to file @a filename.
0020 static void write(const std::string& filename, const AnalysisObject& ao, int precision=-1) {
0021   const size_t lastdot = filename.find_last_of(".");
0022   std::string fmt = Utils::toLower(lastdot == std::string::npos ? filename : filename.substr(lastdot+1));
0023   const bool compress = (fmt == "gz");
0024   Writer& w = create();
0025   if (precision > 0) w.setPrecision(precision);
0026   w.useCompression(compress);
0027   w.write(filename, ao);
0028 }
0029 
0030 /// Write out pointer-like object @a ao to file @a filename.
0031 template <typename T>
0032 static typename std::enable_if<DerefableToAO<T>::value>::type //< -> void if valid
0033 write(const std::string& filename, const T& ao, int precision=-1) { write(filename, *ao, precision); }
0034 
0035 /// @}
0036 
0037 
0038 /// @name Writing multiple analysis objects by collection.
0039 /// @{
0040 
0041 template <typename RANGE>
0042 static typename std::enable_if<CIterable<RANGE>::value>::type
0043 write(std::ostream& stream, const RANGE& aos, int precision=-1) {
0044   create().write(stream, std::begin(aos), std::end(aos), precision);
0045 }
0046 
0047 template <typename RANGE>
0048 static typename std::enable_if<CIterable<RANGE>::value>::type
0049 write(const std::string& filename, const RANGE& aos, int precision=-1) {
0050   const size_t lastdot = filename.find_last_of(".");
0051   std::string fmt = Utils::toLower(lastdot == std::string::npos ? filename : filename.substr(lastdot+1));
0052   const bool compress = (fmt == "gz");
0053   Writer& w = create();
0054   if (precision > 0) w.setPrecision(precision);
0055   w.useCompression(compress);
0056   w.write(filename, std::begin(aos), std::end(aos));
0057 }
0058 
0059 /// @}
0060 
0061 
0062 /// @name Writing multiple analysis objects by iterator range.
0063 /// @{
0064 
0065 /// Write out the objects specified by start iterator @a begin and end
0066 /// iterator @a end to output stream @a stream.
0067 ///
0068 /// @todo Add SFINAE trait checking for AOITER = DerefableToAO
0069 template <typename AOITER>
0070 static void write(std::ostream& stream, const AOITER& begin, const AOITER& end, int precision=-1) {
0071   create().write(stream, begin, end, precision);
0072 }
0073 
0074 /// Write out the objects specified by start iterator @a begin and end
0075 /// iterator @a end to file @a filename.
0076 ///
0077 /// @todo Add SFINAE trait checking for AOITER = DerefableToAO
0078 template <typename AOITER>
0079 static void write(const std::string& filename, const AOITER& begin, const AOITER& end, int precision=-1) {
0080   const size_t lastdot = filename.find_last_of(".");
0081   std::string fmt = Utils::toLower(lastdot == std::string::npos ? filename : filename.substr(lastdot+1));
0082   const bool compress = (fmt == "gz");
0083   Writer& w = create();
0084   if (precision > 0) w.setPrecision(precision);
0085   w.useCompression(compress);
0086   w.write(filename, begin, end);
0087 }
0088 
0089 /// @}