tstF71toGapi.cc 1.38 KB
Newer Older
LEFEBVREJP email's avatar
LEFEBVREJP email committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

#include "gtest/gtest.h"
#include "radixcore/system.hh"
#include "radixio/f71togapi.hh"

#include <fstream>
using namespace radix;
TEST(Radixio, F71toGapi)
{
  // test reading a scale 6.1 formated f71 file from DELFIC
  F71Stream stream(radix::to_native_path(
      std::string(dirname(__FILE__) + "/data/test.s61.f71")));
  std::vector<F71Case> cases;
  bool result = true;
  while (result)
  {
    F71Case single_case;
    result = stream.read_case(single_case);
    if (result) cases.emplace_back(single_case);
  }
  ASSERT_TRUE(cases.size() == 1);
  F71Case& first = cases[0];
  DataObject obj;
  F71toGapi::to_gapi_json(first, 100.f, 1000.f, 1, obj);
  EXPECT_EQ(100., obj["detector height"].to_double());
  EXPECT_EQ(1000., obj["detector distance"].to_double());
  EXPECT_EQ(1., obj["live time"].to_double());
  ASSERT_TRUE(obj.contains("sources"));
  const DataArray& sources = obj["sources"].as_array();
  EXPECT_EQ(231, sources.size());
  float total_activity = 0.;
  float blessed_total  = 253.6866455078125;
  for (size_t i = 0; i < sources.size(); ++i)
  {
    const DataObject& source = sources[i].as_object();
    std::string name         = source["name"].to_string();
    float activity           = float(source["activity"].to_double());
    std::cout << name << " " << activity << " curies" << std::endl;
    total_activity += activity;
  }
  EXPECT_NEAR(blessed_total, total_activity, 1e-3);
}