CMS 3D CMS Logo

Functions
Test.h File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <utility>
#include <stdexcept>
#include "CondFormats/Serialization/interface/Archive.h"
#include "CondFormats/Serialization/interface/Equal.h"

Go to the source code of this file.

Functions

template<typename T >
void testSerialization ()
 

Function Documentation

◆ testSerialization()

template<typename T >
void testSerialization ( )

Definition at line 50 of file Test.h.

References gather_cfg::cout, corrVsCorr::filename, recoMuon::in, Skims_PA_cff::name, MillePedeFileConverter_cfg::out, and AlCaHLTBitMon_QueryRunRegistry::string.

50  {
51  const std::string filename(std::string(typeid(T).name()) + ".bin");
52 
53  // C++ does not allow to construct const objects
54  // of non-POD types without user-provided default constructor
55  // (since it would be uninitialized), so we always create
56  // a non-const object.
57  T originalObject{};
58  const T& originalObjectRef = originalObject;
59  {
60  std::ofstream ofs(filename, std::ios::out | std::ios::binary);
62  std::cout << "Serializing " << typeid(T).name() << " ..." << std::endl;
63  oa << originalObjectRef;
64  }
65 
66  T deserializedObject;
67  {
68  std::ifstream ifs(filename, std::ios::in | std::ios::binary);
70  std::cout << "Deserializing " << typeid(T).name() << " ..." << std::endl;
71  ia >> deserializedObject;
72  }
73 
74  // TODO: First m,ake the Boost IO compile and run properly,
75  // then focus again on the equal() functions.
76  //std::cout << "Checking " << typeid(T).name() << " ..." << std::endl;
77  //if (not cond::serialization::equal(originalObject, deserializedObject))
78  // throw std::logic_error("Object is not equal.");
79 }
eos::portable_oarchive OutputArchive
Definition: Archive.h:18
eos::portable_iarchive InputArchive
Definition: Archive.h:17
long double T