Project
Loading...
Searching...
No Matches
testTimeL1PhaseCalib.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#define BOOST_TEST_MODULE Test_EMCAL_Calib
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15
16#include <boost/test/unit_test.hpp>
17#include "EMCALCalib/TimeCalibParamL1Phase.h" // local header
18#include <iostream>
19#include <fstream>
20
22
23namespace o2
24{
25namespace emcal
26{
27
28BOOST_AUTO_TEST_CASE(testTimeL1PhaseCalib)
29{
30
31 // Single channel test
32 //
33 // For each channel test set and update, and compare read value
34 // against set value
35 for (unsigned short iSM = 0; iSM < 20; iSM++) {
36 TimeCalibParamL1Phase singletest;
37
38 singletest.addTimeCalibParamL1Phase(iSM, 0);
40
41 singletest.addTimeCalibParamL1Phase(iSM, 2);
43 }
44
45 // Pattern test
46 //
47 // For each channel check the wheather the L1 phase shifts are correctly written
48 // Test data obtained from LHC18q run 295585
49 TimeCalibParamL1Phase parameter;
50
51 const char* aliceO2env = std::getenv("O2_ROOT");
52 std::string inputDir = " ";
53 if (aliceO2env) {
54 inputDir = aliceO2env;
55 }
56 inputDir += "/share/Detectors/EMC/files/";
57
58 std::string file = inputDir + "TimeL1Phase_LHC18q_295585.txt";
59 std::ifstream fileL1Phase(file, std::ifstream::in);
60 if (!fileL1Phase.is_open()) {
61 std::cout << "The file TimeL1Phase_LHC18q_295585 was not opened\n";
62 }
63
64 unsigned char L1Phase[20];
65
66 unsigned short iSM = 0;
67 std::string line;
68
69 // Write to the container
70 while (std::getline(fileL1Phase, line)) {
71 std::stringstream streamLine(line);
72 unsigned short sm;
73 streamLine >> sm >> L1Phase[iSM];
74 parameter.addTimeCalibParamL1Phase(sm, L1Phase[iSM]);
75 iSM++;
76 }
77
78 for (unsigned short iSM = 0; iSM < 20; iSM++) {
79 BOOST_CHECK_EQUAL(parameter.getTimeCalibParamL1Phase(iSM), L1Phase[iSM]);
80 }
81
82 // Comparison test
83
84 //comparison file
85 TimeCalibParamL1Phase parameterLHC18q;
86
87 std::string fileLHC18q = inputDir + "TimeL1Phase_LHC18q_296623.txt";
88 std::ifstream fileL1PhaseLHC18q(fileLHC18q, std::ifstream::in);
89 if (!fileL1PhaseLHC18q.is_open()) {
90 std::cout << "The file TimeL1Phase_LHC18q_296623 was not opened\n";
91 }
92
93 unsigned char L1Phase_LHC18q;
94
95 iSM = 0;
96 // Write to the container
97 while (std::getline(fileL1PhaseLHC18q, line)) {
98 std::stringstream streamLine(line);
99 unsigned short sm;
100 streamLine >> sm >> L1Phase_LHC18q;
101 parameterLHC18q.addTimeCalibParamL1Phase(sm, L1Phase_LHC18q);
102 iSM++;
103 }
104
105 // Equal
106 //
107 // - Compare L1 phase shifts for LHC18q run 295585 with itself. The result must be true.
108 // - Compare L1 phase shifts for LHC18q run 295585 with L1 phase shifts for LHC18q run 296623. The result must be false
109 BOOST_CHECK_EQUAL(parameter == parameter, true);
110 BOOST_CHECK_EQUAL(parameter == parameterLHC18q, false);
111
112 fileL1Phase.close();
113 fileL1PhaseLHC18q.close();
114}
115} // namespace emcal
116} // namespace o2
unsigned char getTimeCalibParamL1Phase(unsigned short iSM) const
Get the L1 phase for a certain SM.
void addTimeCalibParamL1Phase(unsigned short iSM, unsigned char L1Phase)
Add L1 phase shifts to the container.
BOOST_AUTO_TEST_CASE(asynch_schedule_test)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())