yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
WriterFLAT.cc
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of YODA -- Yet more Objects for Data Analysis
4// Copyright (C) 2008-2024 The YODA collaboration (see AUTHORS for details)
5//
6#include "YODA/WriterFLAT.h"
7#include "YODA/Scatter.h"
8
9#include <iostream>
10#include <iomanip>
11
12using namespace std;
13
14namespace YODA {
15
18 static WriterFLAT _instance;
19 _instance.setPrecision(6);
20 return _instance;
21 }
22
23 // Version-formatting helper function
24 void WriterFLAT::_writeAnnotations(std::ostream& os, const AnalysisObject& ao) {
25 os << scientific << setprecision(_aoprecision);
26 for (const string& a : ao.annotations()) {
27 if (a.empty()) continue;
28 if (a == "Type") continue;
30 os << a << "=" << ao.annotation(a) << "\n";
31 }
32 }
33
34
35 void WriterFLAT::writeAO(std::ostream& os, const AnalysisObject& ao) {
36 ios_base::fmtflags oldflags = os.flags();
37 os << scientific << showpoint << setprecision(_aoprecision);
38 os << "BEGIN SCATTER" << std::to_string(ao.dim()) << "D " << ao.path() << "\n";
39 _writeAnnotations(os, ao);
40 ao._renderFLAT(os, _aoprecision+7); // = "-1." + _aoprecision + "e+23"
41 os << "END SCATTER" << std::to_string(ao.dim()) << "D" << "\n\n";
42
43 os << flush;
44 os.flags(oldflags);
45 }
46
47}
AnalysisObject is the base class for histograms and scatters.
virtual size_t dim() const noexcept=0
Get the dimension of the analysis object type.
const std::string path() const
Get the AO path.
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
Persistency writer for flat text format.
Definition WriterFLAT.h:15
void writeAO(std::ostream &stream, const AnalysisObject &ao)
Definition WriterFLAT.cc:35
static Writer & create()
Singleton creation function.
Definition WriterFLAT.cc:17
Pure virtual base class for various output writers.
Definition Writer.h:19
void setPrecision(int precision)
Set precision of numerical quantities in this writer's output.
Definition Writer.h:143
Anonymous namespace to limit visibility.