 |
ATLAS Offline Software
|
Go to the documentation of this file.
6 #include "CrestApi/CrestCondException.h"
21 return m_isVectorPayload;
25 m_isVectorPayload = isVectorPayload;
29 auto a = std::stol(as);
30 auto b = std::stol(bs);
36 m_payload_spec.emplace_back(
name,
type);
42 for(
auto&
t: s_typeToString){
43 if(
t.second.compare(
type)==0){
44 addColumn(
name,
t.first);
48 throw CommonCrestException(
"The type of parameter is not defined.");
53 auto it = std::find_if(m_payload_spec.begin(), m_payload_spec.end(),
55 { return column.first == name; });
57 if (
it != m_payload_spec.end())
59 m_row[
name] = nlohmann::json::value_t::null;
68 for (
auto &
column : m_payload_spec)
78 m_row[
name] = va_arg(
ap,
int)==1;
81 m_row[
name] =
static_cast<unsigned char>(va_arg(
ap,
int));
85 m_row[
name] = va_arg(
ap,
int);
89 m_row[
name] = va_arg(
ap,
unsigned int);
95 m_row[
name] = va_arg(
ap, int64_t);
99 m_row[
name] = va_arg(
ap,
double);
109 m_row[
name] = std::string(va_arg(
ap,
const char *));
112 throw CommonCrestException(
"Unsupported column type.");
126 if (m_isVectorPayload){
127 for (
const auto &data_row :
data)
129 arr_data.emplace_back(createRowArray(data_row));
136 m_vector_data.clear();
143 for (
const auto &
column : m_payload_spec)
145 if (data_row.find(
column.first) == data_row.end())
147 std::string
msg =
"The data does not contain the column: " +
column.first;
148 throw CommonCrestException(
msg.c_str());
150 row_arr_data.push_back(data_row[
column.first]);
157 m_iov_data[
"since"] =
since;
158 m_iov_data[
"data"] = m_payload;
159 m_full_data[
since]=m_payload;
164 m_iov_data[
"since"]=
since;
165 if(m_full_data.contains(
since)){
166 m_iov_data[
"data"]=m_full_data[
since];
167 m_payload=m_full_data[
since];
170 m_iov_data[
"data"]={};
176 if(m_full_data.size()==0)
178 throw CommonCrestException(
"No IOV in CrestContainer");
180 return m_full_data.begin()->first;
184 std::vector<std::string> chs;
185 for (
auto&
x : m_iov_data[
"data"].
items()){
186 chs.push_back(
x.key());
193 return m_payload_spec;
198 if (m_payload.empty())
200 m_payload = m_iov_data[
"data"];
203 if (
it == m_payload.end())
205 std::string
msg =
"Channel id " + std::string(
channel_id) +
" is not found.";
206 throw CommonCrestException(
msg.c_str());
213 auto it = std::find_if(m_payload_spec.begin(), m_payload_spec.end(),
215 { return column.first == name; });
217 if (
it != m_payload_spec.end())
223 throw CommonCrestException(
"The column name is not found.");
229 if (m_isVectorPayload)
231 m_vector_data.push_back(m_row);
236 std::string
msg =
"The payload is not a vector.";
237 throw CommonCrestException(
msg.c_str());
243 if (m_isVectorPayload)
244 return m_vector_data;
250 if (m_payload.empty() && m_iov_data.empty())
252 std::string
msg =
"The payload is empty.";
253 throw CommonCrestException(
msg.c_str());
255 if (m_payload.empty())
257 m_payload = m_iov_data[
"data"];
264 if (m_iov_data.empty())
266 std::string
msg =
"The iov data is empty.";
267 throw CommonCrestException(
msg.c_str());
284 return getPayload().dump();
289 return m_iov_data.dump();
295 for (
auto &
column : m_payload_spec)
298 std::map<TypeId, std::string>::const_iterator
pos = Crest::s_typeToString.find(
column.second);
299 if (
pos == Crest::s_typeToString.
end()) {
300 throw CommonCrestException(
"Type do not exist in the map.");
304 pspec_data.push_back(j);
313 for (
const auto &
column : j)
317 addColumn(
name,
static_cast<TypeId>(std::stoi(
type.get<std::string>())));
323 for (
const auto &[
name,
type] : j.items())
334 m_vector_data.clear();
342 m_vector_data.clear();
352 file << std::setprecision(6) << j.dump(4);
357 std::cerr <<
"CondContainer::dumpJsonToFile: Error opening file: " <<
filename << std::endl;
358 throw std::runtime_error(
"CondContainer::dumpJsonToFile: Error opening file.");
366 std::ifstream specfile(spec_filename);
368 if (specfile.is_open())
375 std::cerr <<
"CondContainer::readJsonFromFile: Error opening file: " << spec_filename << std::endl;
376 throw std::runtime_error(
"CondContainer::readJsonFromFile: Error opening file. ");
379 setPayloadSpec(jspec);
390 std::cerr <<
"CondContainer::readJsonFromFile: Error opening file: " <<
filename << std::endl;
391 throw std::runtime_error(
"CondContainer::readJsonFromFile: Error opening file. ");
398 if (thisVal.is_null()){
399 m_row[colName] =
"NULL";
403 if(strVal.size()>2&& strVal[0]==
'"'&& strVal[strVal.size()-1]==
'"')
404 strVal=strVal.substr(1,strVal.size()-2);
405 if((strVal.compare(
"NULL")==0||strVal.compare(
"null")==0)&&
410 m_row[colName] =
"NULL";
416 const bool newVal=(strVal ==
"true");
417 m_row[colName] = newVal;
422 m_row[colName]=std::stoul(strVal);
427 m_row[colName]=std::stol(strVal);
432 m_row[colName]=std::stoul(strVal);
437 m_row[colName]=std::stoi(strVal);
442 m_row[colName]=std::stoull(strVal);
447 m_row[colName]=std::stoull(strVal);
452 m_row[colName]=std::stoll(strVal);
457 m_row[colName]=std::stof(strVal);
462 m_row[colName]=std::stod(strVal);
471 m_row[colName]=thisVal.get<std::string>();
478 m_row[colName]=thisVal.get<std::string>();
483 throw std::runtime_error(
"UNTREATED TYPE!");
489 std::cerr <<
e.what() << std::endl;
490 throw std::runtime_error(
e.what());
495 if (
values.is_array() &&
values.size() == m_payload_spec.size())
497 for (
size_t i = 0;
i <
values.size(); ++
i)
499 const auto & [colName,colType] = m_payload_spec[
i];
505 parseOldFormat(colName,colType,
values[
i]);
509 m_row[colName] =
nullptr;
515 m_row[colName] =
values[
i].get<
bool>();
518 m_row[colName] =
values[
i].get<
unsigned char>();
522 m_row[colName] =
values[
i].get<
int>();
526 m_row[colName] =
values[
i].get<
unsigned int>();
532 m_row[colName] =
values[
i].get<int64_t>();
536 m_row[colName] =
values[
i].get<
double>();
543 m_row[colName] =
values[
i].get<std::string>();
548 m_row[colName] =
values[
i].get<std::string>();
551 throw CommonCrestException(
"CrestContainer::parseData: Unsupported column type.");
558 std::cerr <<
"CrestContainer::parseData values is not array"<<std::endl;
560 std::cerr <<
"CrestContainer::parseData values number="<<
values.size() <<
" m_payload_spec.size()="<<m_payload_spec.size()<<std::endl;
561 throw CommonCrestException(
"CrestContainer::parseData: Mismatch in number of values.");
572 ss >> std::quoted(st);
576 if (j.contains(
"data") && j[
"data"].is_object())
579 readCommonType(
since,j_in);
581 else if(j.is_object()){
582 readCommonType(
since,j);
586 std::cerr <<
"CrestContainer::fromJson json:"<<j<<std::endl;
587 throw CommonCrestException(
"CrestContainer::fromJson: JSON is not a JSON object.");
589 std::vector<uint64_t> ret;
590 ret.push_back(
since);
595 return readDcsFullType(j_in);
599 throw CommonCrestException(
"CrestContainer::fromJson: Unsupported type of payload.");
608 ss >> std::quoted(st);
612 if (j.contains(
"data") && j[
"data"].is_object())
614 dcs_data = j[
"data"];
618 std::vector<uint64_t> ret;
621 for (
const auto& [
key,
value] : dcs_data.items()){
624 ret.push_back(
since);
636 for (
const auto &
channel : j_in.items())
638 std::string channelKey =
channel.key();
639 const auto &data_ch =
channel.value();
641 if(m_isVectorPayload)
644 vecJson.push_back(data_ch);
646 for (
const auto &
values : vecJson)
649 if(m_isVectorPayload)
664 for (
const auto& [
key,
value] : m_full_data)
666 storeDto[
"since"] =
key;
667 storeDto[
"data"] =
value.dump();
668 storeDto[
"streamerInfo"] =
"";
669 resources.push_back(storeDto);
677 for (
const auto& [
key,
value] : m_full_data)
679 curPayload.update(
value);
682 storeDto[
"since"]=
since;
683 storeDto[
"data"]=dcs_payload.dump();
684 storeDto[
"streamerInfo"] =
"";
685 resources.push_back(storeDto);
690 if(dcs_payload.size()>0){
691 storeDto[
"since"]=
since;
692 storeDto[
"data"]=dcs_payload.dump();
693 storeDto[
"streamerInfo"] =
"";
694 resources.push_back(storeDto);
697 j[
"resources"] = resources;
698 j[
"format"] =
"StoreSetDto";
699 j[
"datatype"] =
"data";
700 j[
"size"] = resources.size();
char data[hepevt_bytes_allocation_ATLAS]
void setPayloadSpec(const nlohmann::json &j)
uint64_t getFirstTime()
It return minimal timestamp in concainer.
void addNullRecord(const std::string &name)
It adds a null value to the payload.
void addColumn(const std::string &name, TypeId type)
It adds a column to the payload specification.
void addRecord(const std::string &name, int number,...)
It adds a record to the payload.
std::vector< uint64_t > fromJson(uint64_t since, const nlohmann::json &j)
It reads a json object to fill the container.
nlohmann::json readJsonFromFile(const std::string &filename, const std::string &spec_filename)
It reads a json file and returns the json object.
const nlohmann::json & getIovData()
Return selected IOV in json format.
void setVectorPayload(bool isVectorPayload)
Set the Vectore mode of the container.
const nlohmann::json & getRow()
const nlohmann::json & getPayload()
Return current payload in json format.
bool isVectorPayload()
It sets the Vector mode of the container.
std::string getJsonPayload()
It returns the json representation of the container.
void flush()
It reinitializes the containers.
void setIovData(const nlohmann::json &j)
int getColumnIndex(const std::string &name)
It returns the index of the column with the given name.
std::vector< std::string > channelIds()
Return list of channel id in string format.
const std::vector< std::pair< std::string, TypeId > > & getMPayloadSpec()
Return tag specification in vector format.
void addExternalData(const std::string &channel_id, const nlohmann::json &data)
It associate the payload row to a channel_id.
void parseOldFormat(const std::string &colName, const TypeId &typespec, const nlohmann::json &j)
~CrestContainer()
Destructor of CrestContainer.
void dumpJsonToFile(const nlohmann::json &j, const std::string &filename)
It creates a file with the json representation of the container.
void clear()
It clear data the container.
nlohmann::json getStoreSetDto(uint64_t period=-1)
It return StoreSetDto in json format.
void addData(const std::string &channel_id)
It associate the payload row to a channel_id.
void parseData(const nlohmann::json &values)
It reads a json object, parse it and fill the container.
std::vector< uint64_t > readDcsFullType(const nlohmann::json &j_in)
nlohmann::json getPayloadSpec()
Return payload specification in json format.
std::string to_string(const DetectorType &type)
CrestContainer(ModeId mode=ModeId::Standard)
Constructor of CrestContainer.
const nlohmann::json getPayloadChannel(const std::string &channel_id)
Return payload in json format for selected channel id.
Header file for CrestContainer class.
void selectIov(const uint64_t since)
It select timestamp as active.
void setPayload(const nlohmann::json &j)
void readCommonType(uint64_t since, const nlohmann::json &j_in)
std::string getJsonIovData()
It returns the json representation of the container.
nlohmann::json createRowArray(const nlohmann::json &data_row) const
void addIov(const uint64_t since)
It adds an IOV to the json object m_iov_data.
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
bool compareStrTimestamp(std::string &as, std::string &bs)
void putRow2Vector()
It adds row data to vector.