Project
Loading...
Searching...
No Matches
test_DataOutputDirector.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <catch_amalgamated.hpp>
13#include "Headers/DataHeader.h"
15#include <fstream>
16
17TEST_CASE("TestDataOutputDirector")
18{
19 using namespace o2::header;
20 using namespace o2::framework;
21
23 auto dh = DataHeader(DataDescription{"UNO"},
24 DataOrigin{"AOD"},
26 std::string mydfn("myresultfile");
27
28 // test keepString reader
29 std::string keepString("AOD/UNO/0:tr1:c1/c2/c3:fn1,AOD/UNO/0::c4");
30 dod.readString(keepString);
31 dod.setFilenameBase(mydfn);
32
33 auto ds = dod.getDataOutputDescriptors(dh);
34
35 REQUIRE(ds.size() == 2);
36
37 REQUIRE(ds[0]->tablename == std::string("UNO"));
38 REQUIRE(ds[0]->treename == std::string("tr1"));
39 REQUIRE(ds[0]->colnames.size() == 3);
40 REQUIRE(ds[0]->getFilenameBase() == std::string("fn1"));
41
42 REQUIRE(ds[1]->tablename == std::string("UNO"));
43 REQUIRE(ds[1]->treename == std::string("O2uno"));
44 REQUIRE(ds[1]->colnames.size() == 1);
45 REQUIRE(ds[1]->getFilenameBase() == std::string("myresultfile"));
46
47 // test jsonString reader
48 std::string rdn("./");
49 std::string dfn("");
50 std::string fmode("");
51 float mfs = -1.;
52 int ntf = -1;
53
54 dh = DataHeader(DataDescription{"DUE"},
55 DataOrigin{"AOD"},
57 std::string jsonString(R"({"OutputDirector": {"resfile": "defresults", "resfilemode": "RECREATE", "ntfmerge": 10, "OutputDescriptors": [{"table": "AOD/UNO/0", "columns": ["fEta1","fMom1"], "treename": "uno", "filename": "unoresults"}, {"table": "AOD/DUE/0", "columns": ["fPhi2"], "treename": "due"}]}})");
58
59 dod.reset();
60 std::tie(rdn, dfn, fmode, mfs, ntf) = dod.readJsonString(jsonString);
62
63 REQUIRE(ds.size() == 1);
64 REQUIRE(dfn == std::string("defresults"));
65 REQUIRE(fmode == std::string("RECREATE"));
66 REQUIRE(ntf == 10);
67
68 REQUIRE(ds[0]->tablename == std::string("DUE"));
69 REQUIRE(ds[0]->treename == std::string("due"));
70 REQUIRE(ds[0]->colnames.size() == 1);
71 REQUIRE(ds[0]->getFilenameBase() == std::string("defresults"));
72
73 // test json file reader
74 std::string jsonFile("testO2config.json");
75 std::ofstream jf(jsonFile, std::ofstream::out);
76 jf << R"({)" << std::endl;
77 jf << R"( "OutputDirector": {)" << std::endl;
78 jf << R"( "resfile": "defresults",)" << std::endl;
79 jf << R"( "resfilemode": "NEW",)" << std::endl;
80 jf << R"( "ntfmerge": 10,)" << std::endl;
81 jf << R"( "OutputDescriptors": [)" << std::endl;
82 jf << R"( {)" << std::endl;
83 jf << R"( "table": "AOD/DUE/0",)" << std::endl;
84 jf << R"( "columns": [)" << std::endl;
85 jf << R"( "fEta1",)" << std::endl;
86 jf << R"( "fMom1")" << std::endl;
87 jf << R"( ],)" << std::endl;
88 jf << R"( "treename": "uno",)" << std::endl;
89 jf << R"( "filename": "unoresults")" << std::endl;
90 jf << R"( },)" << std::endl;
91 jf << R"( {)" << std::endl;
92 jf << R"( "table": "AOD/DUE/0",)" << std::endl;
93 jf << R"( "columns": [)" << std::endl;
94 jf << R"( "fPhi2")" << std::endl;
95 jf << R"( ],)" << std::endl;
96 jf << R"( "treename": "due",)" << std::endl;
97 jf << R"( "filename": "dueresults")" << std::endl;
98 jf << R"( })" << std::endl;
99 jf << R"( ])" << std::endl;
100 jf << R"( })" << std::endl;
101 jf << R"(})" << std::endl;
102 jf.close();
103
104 dod.reset();
105 std::tie(rdn, dfn, fmode, mfs, ntf) = dod.readJson(jsonFile);
106 dod.setFilenameBase("AnalysisResults");
108
109 REQUIRE(ds.size() == 2);
110 REQUIRE(dfn == std::string("defresults"));
111 REQUIRE(fmode == std::string("NEW"));
112 REQUIRE(ntf == 10);
113
114 REQUIRE(ds[0]->getFilenameBase() == std::string("unoresults"));
115 REQUIRE(ds[0]->tablename == std::string("DUE"));
116 REQUIRE(ds[0]->treename == std::string("uno"));
117 REQUIRE(ds[0]->colnames.size() == 2);
118
119 REQUIRE(ds[1]->getFilenameBase() == std::string("dueresults"));
120 REQUIRE(ds[1]->tablename == std::string("DUE"));
121 REQUIRE(ds[1]->treename == std::string("due"));
122 REQUIRE(ds[1]->colnames.size() == 1);
123}
o2::header::DataHeader DataHeader
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
O2 data header classes and API, v0.1.
Definition DetID.h:49
void readString(std::string const &keepString)
std::tuple< std::string, std::string, std::string, float, int > readJson(std::string const &fnjson)
std::tuple< std::string, std::string, std::string, float, int > readJsonString(std::string const &stjson)
std::vector< DataOutputDescriptor * > getDataOutputDescriptors(header::DataHeader dh)
uint32_t SubSpecificationType
Definition DataHeader.h:620
o2::mch::DsIndex ds
TEST_CASE("TestDataOutputDirector")