Page MenuHomeHEPForge

No OneTemporary

diff --git a/include/YODA/Utils/Traits.h b/include/YODA/Utils/Traits.h
--- a/include/YODA/Utils/Traits.h
+++ b/include/YODA/Utils/Traits.h
@@ -1,19 +1,26 @@
// -*- C++ -*-
//
// This file is part of YODA -- Yet more Objects for Data Analysis
// Copyright (C) 2008-2015 The YODA collaboration (see AUTHORS for details)
//
#ifndef YODA_TRAITS_H
#define YODA_TRAITS_H
+#include <boost/type_traits/has_dereference.hpp>
+
namespace YODA{
//SFINAE struct to check for iterator concept at compile time
template<typename T>
struct Iterable{
typedef char yes[1]; typedef char no[2];
template <typename C> static yes& test(typename C::const_iterator* c);
template <typename> static no& test(...);
static const bool value = sizeof(test<T>(0)) == sizeof(yes);
};
+
+ template<typename T>
+ struct DerefAO{
+ static const bool value = boost::has_dereference<T,const YODA::AnalysisObject&>::value;
+ };
}
#endif
diff --git a/include/YODA/Writer.h b/include/YODA/Writer.h
--- a/include/YODA/Writer.h
+++ b/include/YODA/Writer.h
@@ -1,142 +1,151 @@
// -*- C++ -*-
//
// This file is part of YODA -- Yet more Objects for Data Analysis
// Copyright (C) 2008-2015 The YODA collaboration (see AUTHORS for details)
//
#ifndef YODA_Writer_h
#define YODA_Writer_h
#include "YODA/AnalysisObject.h"
#include "YODA/Counter.h"
#include "YODA/Histo1D.h"
#include "YODA/Histo2D.h"
#include "YODA/Profile1D.h"
#include "YODA/Profile2D.h"
#include "YODA/Scatter1D.h"
#include "YODA/Scatter2D.h"
#include "YODA/Scatter3D.h"
#include "YODA/Utils/Traits.h"
#include "boost/range.hpp"
#include "boost/utility/enable_if.hpp"
#include <string>
#include <fstream>
namespace YODA {
/// Pure virtual base class for various output writers.
class Writer {
public:
/// Virtual destructor
virtual ~Writer() {}
/// @name Writing a single analysis object.
//@{
/// Write out object @a ao to output stream @a stream.
void write(std::ostream& stream, const AnalysisObject& ao);
/// Write out object @a ao to file @a filename.
void write(const std::string& filename, const AnalysisObject& ao);
//@}
/// @name Writing multiple analysis objects by collection.
//@{
/// Write out a collection of objects @a objs to output stream @a stream.
/// Note: the enable_if call checks whether RANGE is const_iterable, if yes the return
/// type is void. If not, this template will not be a candidate in the lookup
template <typename RANGE>
- typename std::enable_if<Iterable<RANGE>::value,void>::type write(std::ostream& stream, const RANGE& aos) {
+ typename boost::enable_if_c<Iterable<RANGE>::value>::type write(std::ostream& stream, const RANGE& aos) {
//typedef typename boost::range_iterator<const RANGE>::type const_iterator;
write(stream, boost::begin(aos), boost::end(aos));
}
/// Write out a collection of objects @a objs to file @a filename.
template <typename RANGE>
- typename std::enable_if<Iterable<RANGE>::value,void>::type write(const std::string& filename, const RANGE& aos) {
+ typename boost::enable_if_c<Iterable<RANGE>::value>::type write(const std::string& filename, const RANGE& aos) {
//typedef typename boost::range_iterator<const RANGE>::type const_iterator;
write(filename, boost::begin(aos), boost::end(aos));
}
//@}
/// @name Writing multiple analysis objects by iterator range.
//@{
/// Write out the objects specified by start iterator @a begin and end
/// iterator @a end to output stream @a stream.
template <typename AOITER>
void write(std::ostream& stream, const AOITER& begin, const AOITER& end) {
writeHeader(stream);
for (AOITER ipao = begin; ipao != end; ++ipao) {
writeBody(stream, *ipao);
}
writeFooter(stream);
}
/// Write out the objects specified by start iterator @a begin and end
/// iterator @a end to file @a filename.
template <typename AOITER>
void write(const std::string& filename,
const AOITER& begin,
const AOITER& end) {
std::ofstream outstream;
outstream.exceptions ( std::ifstream::failbit | std::ifstream::badbit );
try{
outstream.open(filename.c_str());
write(outstream, begin, end);
outstream.close();
} catch(std::ifstream::failure e) {
throw WriteError("writing to filename " + filename + " failed: " + e.what());
}
}
//@}
/// Set precision of numerical quantities in this writer's output.
void setPrecision(int precision) {
_precision = precision;
}
protected:
/// Main writer elements
virtual void writeHeader(std::ostream& stream) = 0;
+
+
+ //note: DerefAO<T> is a trait that's true if T has a derefence operator
+ // that is convertible to an AnalysisObject
+ template<typename T>
+ typename boost::enable_if_c<DerefAO<T>::value>::type writeBody(std::ostream& stream, const T& ao){
+ writeBody(stream,*ao);
+ }
+
virtual void writeBody(std::ostream& stream, const AnalysisObject* ao);
virtual void writeBody(std::ostream& stream, const AnalysisObject& ao);
virtual void writeFooter(std::ostream& stream) = 0;
/// Specific AO type writer implementations
virtual void writeCounter(std::ostream& stream, const Counter& c) = 0;
virtual void writeHisto1D(std::ostream& os, const Histo1D& h) = 0;
virtual void writeHisto2D(std::ostream& os, const Histo2D& h) = 0;
virtual void writeProfile1D(std::ostream& os, const Profile1D& p) = 0;
virtual void writeProfile2D(std::ostream& os, const Profile2D& p) = 0;
virtual void writeScatter1D(std::ostream& os, const Scatter1D& s) = 0;
virtual void writeScatter2D(std::ostream& os, const Scatter2D& s) = 0;
virtual void writeScatter3D(std::ostream& os, const Scatter3D& s) = 0;
/// Output precision
int _precision;
};
/// Factory function to make a writer object by format name or a filename
Writer& mkWriter(const std::string& format_name);
}
#endif

File Metadata

Mime Type
text/x-diff
Expires
Wed, May 14, 11:03 AM (20 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5111329
Default Alt Text
(6 KB)

Event Timeline