|
| 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 | +#if !defined(__CLING__) || defined(__ROOTCLING__) |
| 12 | +#include <iostream> |
| 13 | +#include <array> |
| 14 | + |
| 15 | +R__LOAD_LIBRARY(libO2CommonUtils) |
| 16 | +R__LOAD_LIBRARY(libO2DataFormatsFIT) |
| 17 | + |
| 18 | +#include "CommonUtils/ConfigurableParamHelper.h" |
| 19 | +#include "DataFormatsFIT/LookUpTable.h" |
| 20 | +#include "Framework/Logger.h" |
| 21 | +#include "CommonConstants/LHCConstants.h" |
| 22 | +#include "lut.h" |
| 23 | + |
| 24 | +#endif |
| 25 | + |
| 26 | +namespace compare_lut { |
| 27 | +std::vector<o2::fit::EntryFEE> readLutFromFile(const std::string filePath, const std::string objectName) |
| 28 | +{ |
| 29 | + TFile file(filePath.c_str(), "READ"); |
| 30 | + if (file.IsOpen() == false) { |
| 31 | + std::cerr << "Failed to open " << filePath << std::endl; |
| 32 | + return {}; |
| 33 | + } |
| 34 | + std::cout << "Successfully opened " << std::endl << filePath; |
| 35 | + |
| 36 | + std::vector<o2::fit::EntryFEE>* lut = nullptr; |
| 37 | + file.GetObject<std::vector<o2::fit::EntryFEE>>(objectName.c_str(), lut); |
| 38 | + |
| 39 | + if (lut == nullptr) { |
| 40 | + std::cerr << "Failed to read object " << objectName << std::endl; |
| 41 | + return {}; |
| 42 | + } |
| 43 | + std::cout << "Successfully get "<< objectName << " object" << std::endl; |
| 44 | + |
| 45 | + std::vector<o2::fit::EntryFEE> lutCopy = *lut; |
| 46 | + file.Close(); |
| 47 | + |
| 48 | + return std::move(lutCopy); |
| 49 | +} |
| 50 | +} |
| 51 | + |
| 52 | +inline bool operator==(const o2::fit::EntryFEE& lhs, const o2::fit::EntryFEE& rhs) |
| 53 | +{ |
| 54 | + auto comparer = [](const o2::fit::EntryFEE& e) { |
| 55 | + return std::tie( |
| 56 | + e.mEntryCRU.mLinkID, e.mEntryCRU.mEndPointID, e.mEntryCRU.mCRUID, e.mEntryCRU.mFEEID, |
| 57 | + e.mChannelID, e.mLocalChannelID, e.mModuleType, e.mModuleName, |
| 58 | + e.mBoardHV, e.mChannelHV, e.mSerialNumberMCP, e.mCableHV, e.mCableSignal); |
| 59 | + }; |
| 60 | + return comparer(lhs) == comparer(rhs); |
| 61 | +} |
| 62 | + |
| 63 | +void compareLut(const std::string fileA, const std::string fileB, const bool compareEvenForDifferentSize = false, const std::string objectName = "ccdb_object") |
| 64 | +{ |
| 65 | + std::vector<o2::fit::EntryFEE> lutA = compare_lut::readLutFromFile(fileA, objectName); |
| 66 | + std::vector<o2::fit::EntryFEE> lutB = compare_lut::readLutFromFile(fileB, objectName); |
| 67 | + if(lutA.empty() || lutB.empty()) { |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + bool lutAreSame = true; |
| 72 | + |
| 73 | + if (lutA.size() != lutB.size()) { |
| 74 | + std::cerr << "Different number of entries: " << lutA.size() << " for " << fileA << " vs " << lutB.size() << " for file " << fileB.c_str() << std::endl; |
| 75 | + lutAreSame = false; |
| 76 | + if (compareEvenForDifferentSize == false) { |
| 77 | + return; |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + size_t size = (lutA.size() < lutB.size()) ? lutA.size() : lutB.size(); |
| 82 | + |
| 83 | + std::cout << "--- Comparision ---" << std::endl; |
| 84 | + |
| 85 | + for (size_t idx = 0; idx < size; idx++) { |
| 86 | + if (lutA[idx] == lutB[idx]) { |
| 87 | + continue; |
| 88 | + } else { |
| 89 | + std::cout << "Entry " << idx << " in " << fileA << " entry: " << lutA[idx] << std::endl; |
| 90 | + std::cout << "Entry " << idx << " in " << fileB << " entry: " << lutB[idx] << std::endl; |
| 91 | + lutAreSame = false; |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + for (size_t idx = size; idx < lutA.size(); idx++) { |
| 96 | + std::cout << "Extra entry " << idx << " in " << fileA << ": " << lutA[idx] << std::endl; |
| 97 | + } |
| 98 | + |
| 99 | + for (size_t idx = size; idx < lutB.size(); idx++) { |
| 100 | + std::cout << "Extra entry " << idx << " in " << fileB << ": " << lutB[idx] << std::endl; |
| 101 | + } |
| 102 | + |
| 103 | + if (lutAreSame) { |
| 104 | + std::cout << "LUTs are the same!" << std::endl; |
| 105 | + } else { |
| 106 | + std::cout << "LUTs are different!" << std::endl; |
| 107 | + } |
| 108 | +} |
0 commit comments