Project
Loading...
Searching...
No Matches
test_DataInputDirector.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#define BOOST_TEST_MODULE Test Framework DatainputDirector
12#define BOOST_TEST_MAIN
13#define BOOST_TEST_DYN_LINK
14
15#include <fstream>
16#include <boost/test/unit_test.hpp>
17
18#include "Headers/DataHeader.h"
19#include "../src/DataInputDirector.h"
20
21BOOST_AUTO_TEST_CASE(TestDatainputDirector)
22{
23 using namespace o2::header;
24 using namespace o2::framework;
25
26 // test json file reader
27 std::string jsonFile("testO2config.json");
28 std::ofstream jf(jsonFile, std::ofstream::out);
29 jf << R"({)" << std::endl;
30 jf << R"( "InputDirector": {)" << std::endl;
31 jf << R"( "resfiles": [)" << std::endl;
32 jf << R"( "Aresults_0.root",)" << std::endl;
33 jf << R"( "Aresults_1.root",)" << std::endl;
34 jf << R"( "Bresults_0.root",)" << std::endl;
35 jf << R"( "Bresults_1.root")" << std::endl;
36 jf << R"( ],)" << std::endl;
37 jf << R"delimiter( "fileregex": "(Ares)(.*)",)delimiter" << std::endl;
38 jf << R"( "InputDescriptors": [)" << std::endl;
39 jf << R"( {)" << std::endl;
40 jf << R"( "table": "AOD/UNO/0",)" << std::endl;
41 jf << R"( "treename": "uno")" << std::endl;
42 jf << R"( },)" << std::endl;
43 jf << R"( {)" << std::endl;
44 jf << R"( "table": "AOD/DUE/0",)" << std::endl;
45 jf << R"( "treename": "due",)" << std::endl;
46 jf << R"delimiter( "fileregex": "(Bres)(.*)")delimiter" << std::endl;
47 jf << R"( })" << std::endl;
48 jf << R"( ])" << std::endl;
49 jf << R"( })" << std::endl;
50 jf << R"(})" << std::endl;
51 jf.close();
52
53 DataInputDirector didir1;
54 BOOST_CHECK(didir1.readJson(jsonFile));
55 didir1.printOut();
56 printf("\n\n");
57
59
60 auto dh = DataHeader(DataDescription{"DUE"},
61 DataOrigin{"AOD"},
63 //auto [file1, directory1] = didir1.getFileFolder(dh, 1, 0);
64 //BOOST_CHECK_EQUAL(file1->GetName(), "Bresults_1.root");
65
66 auto didesc = didir1.getDataInputDescriptor(dh);
67 BOOST_CHECK(didesc);
68 BOOST_CHECK_EQUAL(didesc->getNumberInputfiles(), 2);
69
70 // test initialization with "std::vector<std::string> inputFiles"
71 // in this case "resfile" of the InputDataDirector in the json file must be
72 // empty, otherwise files specified in the json file will be added to the
73 // list of input files
74 jf.open("testO2config.json", std::ofstream::out);
75 jf << R"({)" << std::endl;
76 jf << R"( "InputDirector": {)" << std::endl;
77 jf << R"delimiter( "fileregex": "(Ares)(.*)",)delimiter" << std::endl;
78 jf << R"( "InputDescriptors": [)" << std::endl;
79 jf << R"( {)" << std::endl;
80 jf << R"( "table": "AOD/UNO/0",)" << std::endl;
81 jf << R"( "treename": "uno")" << std::endl;
82 jf << R"( },)" << std::endl;
83 jf << R"( {)" << std::endl;
84 jf << R"( "table": "AOD/DUE/0",)" << std::endl;
85 jf << R"( "treename": "due",)" << std::endl;
86 jf << R"delimiter( "fileregex": "(Bres)(.*)")delimiter" << std::endl;
87 jf << R"( })" << std::endl;
88 jf << R"( ])" << std::endl;
89 jf << R"( })" << std::endl;
90 jf << R"(})" << std::endl;
91 jf.close();
92
93 std::vector<std::string> inputFiles = {"Aresults_0.root",
94 "Aresults_1.root",
95 "Bresults_0.root",
96 "Aresults_2.root",
97 "Bresults_1.root",
98 "Bresults_2.root"};
99 DataInputDirector didir2(inputFiles);
100 didir2.printOut();
101 printf("\n\n");
102 BOOST_CHECK(didir2.readJson(jsonFile));
103
104 //auto [file2, directory2] = didir2.getFileFolder(dh, 1, 0);
105 //BOOST_CHECK_EQUAL(file2->GetName(), "Bresults_1.root");
106
107 didesc = didir2.getDataInputDescriptor(dh);
108 BOOST_CHECK(didesc);
109 BOOST_CHECK_EQUAL(didesc->getNumberInputfiles(), 3);
110}
DataInputDescriptor * getDataInputDescriptor(header::DataHeader dh)
bool readJson(std::string const &fnjson)
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
uint32_t SubSpecificationType
Definition DataHeader.h:620
BOOST_AUTO_TEST_CASE(TestDatainputDirector)
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())