ATLAS Offline Software
Loading...
Searching...
No Matches
CrestContainer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
11
12
13#ifndef CREST_COND_CONTAINER_H
14#define CREST_COND_CONTAINER_H
15#include <vector>
16#include <string>
17#include <utility>
18#include <map>
19#include "nlohmann/json.hpp"
20
21namespace Crest {
28 const static std::map<TypeId, std::string> s_typeToString = {
29 { TypeId::Bool, "Bool" },
30 { TypeId::UChar, "UChar" },
31 { TypeId::Int16, "Int16" },
32 { TypeId::UInt16, "UInt16" },
33 { TypeId::Int32, "Int32" },
34 { TypeId::UInt32, "UInt32" },
35 { TypeId::UInt63, "UInt63" },
36 { TypeId::Int64, "Int64" },
37 { TypeId::Float, "Float" },
38 { TypeId::Double, "Double" },
39 {TypeId::String, "String"},
40 { TypeId::String255, "String255" },
41 { TypeId::String4k, "String4k" },
42 { TypeId::String64k, "String64k" },
43 { TypeId::String16M, "String16M" },
44 { TypeId::String128M,"String128M"},
45 { TypeId::Blob64k, "Blob64k" },
46 { TypeId::Blob16M, "Blob16M" },
47 { TypeId::Blob128M, "Blob128M" },
48 { TypeId::Blob, "Blob" }
49 };
50
51 enum class ModeId{
53 };
54
58 //static bool compareStrTimestamp(std::string& as, std::string& bs);
59
61 public:
79 void addColumn(const std::string& name, TypeId type);
88 void addColumn(const std::string& name, const std::string& type);
92 bool isVectorPayload();
103 void putRow2Vector();
110 void addNullRecord(const std::string& name);
119 void addRecord(const std::string& name,int number, ...);
126 void addData(const std::string& channel_id);
135 void addExternalData(const std::string& channel_id, const nlohmann::json& data);
142 void addIov(const uint64_t since);
146 const std::vector<std::pair<std::string,TypeId>>& getMPayloadSpec();
150 const nlohmann::json& getPayload();
154 const nlohmann::json& getIovData();
159 const nlohmann::json getPayloadChannel(const std::string& channel_id);
160
164 nlohmann::json getPayloadSpec();
170 int getColumnIndex(const std::string& name);
174 void flush();
178 void clear();
183 void selectIov(const uint64_t since);
187 std::vector<std::string> channelIds();
191 std::string getJsonPayload();
195 std::string getJsonIovData();
199 void dumpJsonToFile(const nlohmann::json& j, const std::string& filename);
203 nlohmann::json readJsonFromFile(const std::string& filename, const std::string& spec_filename);
207 std::vector<uint64_t> fromJson(uint64_t since,const nlohmann::json& j);
212 nlohmann::json getStoreSetDto(uint64_t period=-1);
216 uint64_t getFirstTime();
221 void parseData(const nlohmann::json & values);
222
223 private:
224 std::vector<std::pair<std::string,TypeId>> m_payload_spec;
225 nlohmann::json m_payload={};
226 nlohmann::json m_row={};
227 nlohmann::json m_iov_data={};
228 nlohmann::json m_vector_data=nlohmann::json::array();
229 std::map<uint64_t,nlohmann::json> m_full_data;
232
233 nlohmann::json createRowArray(const nlohmann::json& data_row) const;
234 const nlohmann::json& getRow();
235 void parseOldFormat(const std::string& colName, const TypeId& typespec, const nlohmann::json & j);
236 void readCommonType(uint64_t since, const nlohmann::json &j_in);
237 std::vector<uint64_t> readDcsFullType(const nlohmann::json &j_in);
238 void setIovData(const nlohmann::json& j);
239 void setPayload(const nlohmann::json& j);
240 void setPayloadSpec(const nlohmann::json& j);
241
242 };
243}
244#endif
std::string getJsonPayload()
It returns the json representation of the container.
std::vector< uint64_t > fromJson(uint64_t since, const nlohmann::json &j)
It reads a json object to fill the container.
bool isVectorPayload()
It sets the Vector mode of the container.
int getColumnIndex(const std::string &name)
It returns the index of the column with the given name.
nlohmann::json m_payload
nlohmann::json getStoreSetDto(uint64_t period=-1)
It return StoreSetDto in json format.
void dumpJsonToFile(const nlohmann::json &j, const std::string &filename)
It creates a file with the json representation of the container.
void parseOldFormat(const std::string &colName, const TypeId &typespec, const nlohmann::json &j)
void addIov(const uint64_t since)
It adds an IOV to the json object m_iov_data.
std::string getJsonIovData()
It returns the json representation of the container.
std::vector< std::string > channelIds()
Return list of channel id in string format.
void addRecord(const std::string &name, int number,...)
It adds a record to the payload.
void readCommonType(uint64_t since, const nlohmann::json &j_in)
nlohmann::json getPayloadSpec()
Return payload specification in json format.
void selectIov(const uint64_t since)
It select timestamp as active.
CrestContainer(ModeId mode=ModeId::Standard)
Constructor of CrestContainer.
uint64_t getFirstTime()
It return minimal timestamp in concainer.
void addColumn(const std::string &name, TypeId type)
It adds a column to the payload specification.
const nlohmann::json & getIovData()
Return selected IOV in json format.
void addExternalData(const std::string &channel_id, const nlohmann::json &data)
It associate the payload row to a channel_id.
nlohmann::json m_vector_data
nlohmann::json m_iov_data
const nlohmann::json getPayloadChannel(const std::string &channel_id)
Return payload in json format for selected channel id.
std::vector< std::pair< std::string, TypeId > > m_payload_spec
void parseData(const nlohmann::json &values)
It reads a json object, parse it and fill the container.
void addNullRecord(const std::string &name)
It adds a null value to the payload.
~CrestContainer()
Destructor of CrestContainer.
const std::vector< std::pair< std::string, TypeId > > & getMPayloadSpec()
Return tag specification in vector format.
std::map< uint64_t, nlohmann::json > m_full_data
void flush()
It reinitializes the containers.
nlohmann::json createRowArray(const nlohmann::json &data_row) const
const nlohmann::json & getPayload()
Return current payload in json format.
void setPayloadSpec(const nlohmann::json &j)
std::vector< uint64_t > readDcsFullType(const nlohmann::json &j_in)
const nlohmann::json & getRow()
void setIovData(const nlohmann::json &j)
void clear()
It clear data the container.
void addData(const std::string &channel_id)
It associate the payload row to a channel_id.
void putRow2Vector()
It adds row data to vector.
nlohmann::json readJsonFromFile(const std::string &filename, const std::string &spec_filename)
It reads a json file and returns the json object.
void setPayload(const nlohmann::json &j)
void setVectorPayload(bool isVectorPayload)
Set the Vectore mode of the container.
static const std::map< TypeId, std::string > s_typeToString
std::string number(const double &d, const std::string &s)
Definition utils.cxx:186