Project
Loading...
Searching...
No Matches
DetectorLists.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
13#include <fairlogger/Logger.h>
14#include <rapidjson/document.h>
15#include <rapidjson/error/en.h>
16#include <rapidjson/istreamwrapper.h>
17#include <fstream>
18
19namespace o2::conf
20{
21
22bool parseDetectorMapfromJSON(const std::string& path, DetectorMap_t& map)
23{
24 // Parse JSON file to build map
25 std::ifstream fileStream(path, std::ios::in);
26 if (!fileStream.is_open()) {
27 LOGP(error, "Cannot open '{}'!", path);
28 return false;
29 }
30 rapidjson::IStreamWrapper isw(fileStream);
31 rapidjson::Document doc;
32 doc.ParseStream(isw);
33 if (doc.HasParseError()) {
34 LOGP(error, "Error parsing provided json file '{}':", path);
35 LOGP(error, " - Error -> {}", rapidjson::GetParseError_En(doc.GetParseError()));
36 LOGP(error, " - Offset -> {}", doc.GetErrorOffset());
37 return false;
38 }
39
40 // Clear and rebuild map
41 map.clear();
42 try {
43 for (auto verItr = doc.MemberBegin(); verItr != doc.MemberEnd(); ++verItr) {
44 const auto& version = verItr->name.GetString();
45 DetectorList_t list;
46 const auto& elements = doc[version];
47 for (const auto& ele : elements.GetArray()) {
48 list.emplace_back(ele.GetString());
49 }
50 map.emplace(version, list);
51 }
52 } catch (const std::exception& e) {
53 LOGP(error, "Failed to build detector map from file '{}' with '{}'", path, e.what());
54 return false;
55 }
56
57 return true;
58}
59
60void printDetMap(const DetectorMap_t& map, const std::string& list)
61{
62 if (list.empty()) {
63 LOGP(error, "List of all available versions including their detectors:");
64 for (int i{0}; const auto& [version, elements] : map) {
65 LOGP(error, " - {: >2d}. {}:", i++, version);
66 for (int j{0}; const auto& element : elements) {
67 LOGP(error, "\t\t* {: >2d}.\t{}", j++, element);
68 }
69 }
70 } else {
71 LOGP(error, "List of available modules for version {}:", list);
72 for (int j{0}; const auto& element : map.at(list)) {
73 LOGP(error, "\t* {: >2d}.\t{}", j++, element);
74 }
75 }
76}
77
78} // namespace o2::conf
atype::type element
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
char error[CURL_ERROR_SIZE]
uint32_t j
Definition RawData.h:0
uint32_t version
Definition RawData.h:8
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
std::vector< std::string > DetectorList_t
void printDetMap(const DetectorMap_t &map, const std::string &list="")
std::unordered_map< std::string, DetectorList_t > DetectorMap_t
bool parseDetectorMapfromJSON(const std::string &path, DetectorMap_t &map)