ATLAS Offline Software
Loading...
Searching...
No Matches
Crest::CrestContainer Class Reference

It compares timestamp in string format. More...

#include <CrestContainer.h>

Collaboration diagram for Crest::CrestContainer:

Public Member Functions

 CrestContainer (ModeId mode=ModeId::Standard)
 Constructor of CrestContainer.
 ~CrestContainer ()
 Destructor of CrestContainer.
void addColumn (const std::string &name, TypeId type)
 It adds a column to the payload specification.
void addColumn (const std::string &name, const std::string &type)
 It adds a column to the payload specification.
bool isVectorPayload ()
 It sets the Vector mode of the container.
void setVectorPayload (bool isVectorPayload)
 Set the Vectore mode of the container.
void putRow2Vector ()
 It adds row data to vector.
void addNullRecord (const std::string &name)
 It adds a null value to the payload.
void addRecord (const std::string &name, int number,...)
 It adds a record to the payload.
void addData (const std::string &channel_id)
 It associate the payload row to a channel_id.
void addExternalData (const std::string &channel_id, const nlohmann::json &data)
 It associate the payload row to a channel_id.
void addIov (const uint64_t since)
 It adds an IOV to the json object m_iov_data.
const std::vector< std::pair< std::string, TypeId > > & getMPayloadSpec ()
 Return tag specification in vector format.
const nlohmann::json & getPayload ()
 Return current payload in json format.
const nlohmann::json & getIovData ()
 Return selected IOV in json format.
const nlohmann::json getPayloadChannel (const std::string &channel_id)
 Return payload in json format for selected channel id.
nlohmann::json getPayloadSpec ()
 Return payload specification in json format.
int getColumnIndex (const std::string &name)
 It returns the index of the column with the given name.
void flush ()
 It reinitializes the containers.
void clear ()
 It clear data the container.
void selectIov (const uint64_t since)
 It select timestamp as active.
std::vector< std::string > channelIds ()
 Return list of channel id in string format.
std::string getJsonPayload ()
 It returns the json representation of the container.
std::string getJsonIovData ()
 It returns the json representation of the container.
void dumpJsonToFile (const nlohmann::json &j, const std::string &filename)
 It creates a file with the json representation of the container.
nlohmann::json readJsonFromFile (const std::string &filename, const std::string &spec_filename)
 It reads a json file and returns the json object.
std::vector< uint64_t > fromJson (uint64_t since, const nlohmann::json &j)
 It reads a json object to fill the container.
nlohmann::json getStoreSetDto (uint64_t period=-1)
 It return StoreSetDto in json format.
uint64_t getFirstTime ()
 It return minimal timestamp in concainer.
void parseData (const nlohmann::json &values)
 It reads a json object, parse it and fill the container.

Private Member Functions

nlohmann::json createRowArray (const nlohmann::json &data_row) const
const nlohmann::json & getRow ()
void parseOldFormat (const std::string &colName, const TypeId &typespec, const nlohmann::json &j)
void readCommonType (uint64_t since, const nlohmann::json &j_in)
std::vector< uint64_t > readDcsFullType (const nlohmann::json &j_in)
void setIovData (const nlohmann::json &j)
void setPayload (const nlohmann::json &j)
void setPayloadSpec (const nlohmann::json &j)

Private Attributes

std::vector< std::pair< std::string, TypeId > > m_payload_spec
nlohmann::json m_payload ={}
nlohmann::json m_row ={}
nlohmann::json m_iov_data ={}
nlohmann::json m_vector_data =nlohmann::json::array()
std::map< uint64_t, nlohmann::json > m_full_data
ModeId m_modeId
bool m_isVectorPayload =false

Detailed Description

It compares timestamp in string format.

Definition at line 60 of file CrestContainer.h.

Constructor & Destructor Documentation

◆ CrestContainer()

Crest::CrestContainer::CrestContainer ( Crest::ModeId mode = ModeId::Standard)

Constructor of CrestContainer.

Parameters
modeSet mode of data. In current moment support two mode: Standard (default mode) and DCS_FULL (DCS mode with full data for each timestamp)

Definition at line 13 of file CrestContainer.cxx.

13: m_modeId(mode) { ; }

◆ ~CrestContainer()

Crest::CrestContainer::~CrestContainer ( )

Destructor of CrestContainer.

Definition at line 14 of file CrestContainer.cxx.

15{
16 flush();
17}
void flush()
It reinitializes the containers.

Member Function Documentation

◆ addColumn() [1/2]

void Crest::CrestContainer::addColumn ( const std::string & name,
const std::string & type )

It adds a column to the payload specification.

Parameters
nameThe name of the column.
typeThe type of the column in string format.

This method adds a column to the payload specification. filling the vector m_payload_spec. The methods with a different signature are just overloads to make it easier to use.

Definition at line 39 of file CrestContainer.cxx.

40{
41
42 for(auto& t: s_typeToString){
43 if(t.second.compare(type)==0){
44 addColumn(name, t.first);
45 return;
46 }
47 }
48 std::string errStr="The type [" + type + "] of parameter [" + name + "] is not defined.";
49 throw CommonCrestException(errStr.c_str());
50}
void addColumn(const std::string &name, TypeId type)
It adds a column to the payload specification.
static const std::map< TypeId, std::string > s_typeToString

◆ addColumn() [2/2]

void Crest::CrestContainer::addColumn ( const std::string & name,
TypeId type )

It adds a column to the payload specification.

Parameters
nameThe name of the column.
typeThe type of the column.

This method adds a column to the payload specification. filling the vector m_payload_spec. The methods with a different signature are just overloads to make it easier to use.

Definition at line 34 of file CrestContainer.cxx.

35{
36 m_payload_spec.emplace_back(name, type);
37}
std::vector< std::pair< std::string, TypeId > > m_payload_spec

◆ addData()

void Crest::CrestContainer::addData ( const std::string & channel_id)

It associate the payload row to a channel_id.

Parameters
channel_idThe channel_id to associate the payload row.

The method adds the current payload row to the json object m_payload. The row is associated with the channel_id.

Definition at line 121 of file CrestContainer.cxx.

122{
123 addExternalData(channel_id, getRow());
124}
void addExternalData(const std::string &channel_id, const nlohmann::json &data)
It associate the payload row to a channel_id.
const nlohmann::json & getRow()

◆ addExternalData()

void Crest::CrestContainer::addExternalData ( const std::string & channel_id,
const nlohmann::json & data )

It associate the payload row to a channel_id.

Parameters
channel_idThe channel_id to associate the payload row.
dataThe data to be associated with the channel_id.

The method adds the payload row to the json object m_payload. The row is associated with the channel_id. The data is the data to be associated with the channel_id, and they belong to a previously filled payload row.

Definition at line 126 of file CrestContainer.cxx.

127{
128 nlohmann::json arr_data = m_isVectorPayload ? nlohmann::json::array() : nlohmann::json();
130 for (const auto &data_row : data)
131 {
132 arr_data.emplace_back(createRowArray(data_row));
133 }
134 m_payload[channel_id] = std::move(arr_data);
135 }
136 else{
138 }
139 m_vector_data.clear();
140 m_row.clear();
141}
nlohmann::json json
nlohmann::json m_payload
nlohmann::json m_vector_data
nlohmann::json createRowArray(const nlohmann::json &data_row) const

◆ addIov()

void Crest::CrestContainer::addIov ( const uint64_t since)

It adds an IOV to the json object m_iov_data.

Parameters
sinceThe since value of the IOV.

The data is a json object containing all channels stored before, and kept in m_payload.

Definition at line 158 of file CrestContainer.cxx.

159{
160 m_iov_data["since"] = since;
161 m_iov_data["data"] = m_payload;
163 m_payload.clear();
164}
nlohmann::json m_iov_data
std::map< uint64_t, nlohmann::json > m_full_data

◆ addNullRecord()

void Crest::CrestContainer::addNullRecord ( const std::string & name)

It adds a null value to the payload.

Parameters
nameThe name of the column.

This method adds a null to the payload. It fills the json object m_row.

Definition at line 52 of file CrestContainer.cxx.

53{
54 auto it = std::find_if(m_payload_spec.begin(), m_payload_spec.end(),
55 [&name](const auto &column)
56 { return column.first == name; });
57
58 if (it != m_payload_spec.end())
59 {
60 m_row[name] = nlohmann::json::value_t::null;
61 }
62}

◆ addRecord()

void Crest::CrestContainer::addRecord ( const std::string & name,
int number,
... )

It adds a record to the payload.

Parameters
nameThe name of the column.
numberThe number of parameters.
...The values of the record.

This method adds a record to the payload. It fills the json object m_row.

Definition at line 64 of file CrestContainer.cxx.

65{
66 va_list ap;
67 va_start(ap, number);
68
69 for (auto &column : m_payload_spec)
70 {
71 if (column.first != name)
72 {
73 continue;
74 }
75
76 switch (column.second)
77 {
78 case TypeId::Bool:
79 m_row[name] = va_arg(ap, int)==1;
80 break;
81 case TypeId::UChar:
82 m_row[name] = static_cast<unsigned char>(va_arg(ap, int));
83 break;
84 case TypeId::Int16:
85 case TypeId::Int32:
86 m_row[name] = va_arg(ap, int);
87 break;
88 case TypeId::UInt16:
89 case TypeId::UInt32:
90 m_row[name] = va_arg(ap, unsigned int);
91 break;
92 case TypeId::UInt63:
93 m_row[name] = va_arg(ap, uint64_t);
94 break;
95 case TypeId::Int64:
96 m_row[name] = va_arg(ap, int64_t);
97 break;
98 case TypeId::Float:
99 case TypeId::Double:
100 m_row[name] = va_arg(ap, double);
101 break;
102 case TypeId::String:
104 case TypeId::String4k:
108 case TypeId::Blob64k:
109 case TypeId::Blob16M:
110 case TypeId::Blob128M:
111 case TypeId::Blob:
112 m_row[name] = std::string(va_arg(ap, const char *));
113 break;
114 default:
115 throw CommonCrestException("Unsupported column type.");
116 }
117 }
118 va_end(ap);
119}
std::string number(const double &d, const std::string &s)
Definition utils.cxx:186

◆ channelIds()

std::vector< std::string > Crest::CrestContainer::channelIds ( )

Return list of channel id in string format.

Definition at line 186 of file CrestContainer.cxx.

186 {
187 std::vector<std::string> chs;
188 for (auto& x : m_iov_data["data"].items()){
189 chs.push_back(x.key());
190 }
191 sort(chs.begin(), chs.end(), compareStrTimestamp);
192 return chs;
193}
bool compareStrTimestamp(std::string &as, std::string &bs)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
#define x

◆ clear()

void Crest::CrestContainer::clear ( )

It clear data the container.

Definition at line 341 of file CrestContainer.cxx.

341 {
342 m_payload.clear();
343 m_iov_data.clear();
344 m_row.clear();
345 m_vector_data.clear();
346 m_full_data={};
347}

◆ createRowArray()

nlohmann::json Crest::CrestContainer::createRowArray ( const nlohmann::json & data_row) const
private

Definition at line 143 of file CrestContainer.cxx.

144{
145 nlohmann::json row_arr_data = nlohmann::json::array();
146 for (const auto &column : m_payload_spec)
147 {
148 if (data_row.find(column.first) == data_row.end())
149 {
150 std::string msg = "The data does not contain the column: " + column.first;
151 throw CommonCrestException(msg.c_str());
152 }
153 row_arr_data.push_back(data_row[column.first]);
154 }
155 return row_arr_data;
156}
MsgStream & msg
Definition testRead.cxx:32

◆ dumpJsonToFile()

void Crest::CrestContainer::dumpJsonToFile ( const nlohmann::json & j,
const std::string & filename )

It creates a file with the json representation of the container.

Definition at line 350 of file CrestContainer.cxx.

351{
352 std::ofstream file(filename);
353 if (file.is_open())
354 {
355 file << std::setprecision(6) << j.dump(4);
356 file.close();
357 }
358 else
359 {
360 std::cerr << "CondContainer::dumpJsonToFile: Error opening file: " << filename << std::endl;
361 throw std::runtime_error("CondContainer::dumpJsonToFile: Error opening file.");
362 }
363}
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
TFile * file

◆ flush()

void Crest::CrestContainer::flush ( )

It reinitializes the containers.

Definition at line 333 of file CrestContainer.cxx.

334{
335 m_iov_data.clear();
336 m_row.clear();
337 m_vector_data.clear();
338 m_full_data={};
339}

◆ fromJson()

std::vector< uint64_t > Crest::CrestContainer::fromJson ( uint64_t since,
const nlohmann::json & j )

It reads a json object to fill the container.

Definition at line 572 of file CrestContainer.cxx.

572 {
574 {
575 nlohmann::json j = j_in;
576 if (j.is_string()){
577 std::istringstream ss(to_string(j));
578 std::string st;
579 ss >> std::quoted(st);
580 j = json::parse(st);
581 }
582 // Accessing the "data" object
583 if (j.contains("data") && j["data"].is_object())
584 {
585 //const auto &data = j["data"];
586 readCommonType(since,j_in);
587 }
588 else if(j.is_object()){
589 readCommonType(since,j);
590 }
591 else
592 {
593 std::cerr << "CrestContainer::fromJson json:"<<j<<std::endl;
594 throw CommonCrestException("CrestContainer::fromJson: JSON is not a JSON object.");
595 }
596 std::vector<uint64_t> ret;
597 ret.push_back(since);
598 return ret;
599 }
601 {
602 return readDcsFullType(j_in);
603 }
604 else
605 {
606 throw CommonCrestException("CrestContainer::fromJson: Unsupported type of payload.");
607 }
608}
static std::string to_string(const std::vector< T > &v)
static Double_t ss
void readCommonType(uint64_t since, const nlohmann::json &j_in)
std::vector< uint64_t > readDcsFullType(const nlohmann::json &j_in)

◆ getColumnIndex()

int Crest::CrestContainer::getColumnIndex ( const std::string & name)

It returns the index of the column with the given name.

Parameters
nameThe name of the column. It checks the payload spec array to get the index back.

Definition at line 214 of file CrestContainer.cxx.

215{
216 auto it = std::find_if(m_payload_spec.begin(), m_payload_spec.end(),
217 [&name](const auto &column)
218 { return column.first == name; });
219
220 if (it != m_payload_spec.end())
221 {
222 return std::distance(m_payload_spec.begin(), it);
223 }
224 else
225 {
226 throw CommonCrestException("The column name is not found.");
227 }
228}

◆ getFirstTime()

uint64_t Crest::CrestContainer::getFirstTime ( )

It return minimal timestamp in concainer.

Definition at line 178 of file CrestContainer.cxx.

178 {
179 if(m_full_data.size()==0)
180 {
181 throw CommonCrestException("No IOV in CrestContainer");
182 }
183 return m_full_data.begin()->first;
184}

◆ getIovData()

const nlohmann::json & Crest::CrestContainer::getIovData ( )

Return selected IOV in json format.

JSON has two filed: since (for timestamp) and data (for payload).

Definition at line 265 of file CrestContainer.cxx.

266{
267 if (m_iov_data.empty())
268 {
269 std::string msg = "The iov data is empty.";
270 throw CommonCrestException(msg.c_str());
271 }
272 return m_iov_data;
273}

◆ getJsonIovData()

std::string Crest::CrestContainer::getJsonIovData ( )

It returns the json representation of the container.

Definition at line 290 of file CrestContainer.cxx.

291{
292 return m_iov_data.dump();
293}

◆ getJsonPayload()

std::string Crest::CrestContainer::getJsonPayload ( )

It returns the json representation of the container.

Definition at line 285 of file CrestContainer.cxx.

286{
287 return getPayload().dump();
288}
const nlohmann::json & getPayload()
Return current payload in json format.

◆ getMPayloadSpec()

const std::vector< std::pair< std::string, Crest::TypeId > > & Crest::CrestContainer::getMPayloadSpec ( )

Return tag specification in vector format.

Elements of vector is pair: name and type.

Definition at line 194 of file CrestContainer.cxx.

195{
196 return m_payload_spec;
197}

◆ getPayload()

const nlohmann::json & Crest::CrestContainer::getPayload ( )

Return current payload in json format.

Definition at line 251 of file CrestContainer.cxx.

252{
253 if (m_payload.empty() && m_iov_data.empty())
254 {
255 std::string msg = "The payload is empty.";
256 throw CommonCrestException(msg.c_str());
257 }
258 if (m_payload.empty())
259 {
260 m_payload = m_iov_data["data"];
261 }
262 return m_payload;
263}

◆ getPayloadChannel()

const nlohmann::json Crest::CrestContainer::getPayloadChannel ( const std::string & channel_id)

Return payload in json format for selected channel id.

Parameters
channel_idThe channel id.

Definition at line 199 of file CrestContainer.cxx.

200{
201 if (m_payload.empty())
202 {
203 m_payload = m_iov_data["data"];
204 }
205 auto it = m_payload.find(channel_id);
206 if (it == m_payload.end())
207 {
208 std::string msg = "Channel id " + std::string(channel_id) + " is not found.";
209 throw CommonCrestException(msg.c_str());
210 }
211 return it.value();
212}

◆ getPayloadSpec()

json Crest::CrestContainer::getPayloadSpec ( )

Return payload specification in json format.

Definition at line 295 of file CrestContainer.cxx.

296{
297 json pspec_data=json::array();
298 for (auto &column : m_payload_spec)
299 {
300 json j={};
301 std::map<TypeId, std::string>::const_iterator pos = Crest::s_typeToString.find(column.second);
302 if (pos == Crest::s_typeToString.end()) {
303 throw CommonCrestException("Type do not exist in the map.");
304 } else {
305 j[column.first] = pos->second;
306 }
307 pspec_data.push_back(j);
308 }
309 return pspec_data;
310}

◆ getRow()

const nlohmann::json & Crest::CrestContainer::getRow ( )
private

Definition at line 244 of file CrestContainer.cxx.

245{
247 return m_vector_data;
248 return m_row;
249}

◆ getStoreSetDto()

nlohmann::json Crest::CrestContainer::getStoreSetDto ( uint64_t period = -1)

It return StoreSetDto in json format.

Parameters
periodIt set max interval for DSC data. Value '-1' mean that store all DCS data in one StoreDto. This parameter do not use for standard mode.

Definition at line 664 of file CrestContainer.cxx.

665{
666 nlohmann::json j;
667 nlohmann::json resources = nlohmann::json::array();
669 nlohmann::json storeDto;
670 // Loop over the iov list container to add the data to the storeDto
671 for (const auto& [key, value] : m_full_data)
672 {
673 storeDto["since"] = key;
674 storeDto["data"] = value.dump();
675 storeDto["streamerInfo"] = "";//m_streamer_info_data.dump();
676 resources.push_back(storeDto);
677 }
678 }
681 nlohmann::json storeDto;
682 nlohmann::json dcs_payload;
683 nlohmann::json curPayload=m_full_data[since];
684 for (const auto& [key, value] : m_full_data)
685 {
686 curPayload.update(value);
687 dcs_payload[std::to_string(key)]=curPayload;
688 if(period>0 && (key-since)>period){
689 storeDto["since"]=since;
690 storeDto["data"]=dcs_payload.dump();
691 storeDto["streamerInfo"] = "";
692 resources.push_back(storeDto);
693 since=key;
694 dcs_payload={};
695 }
696 }
697 if(dcs_payload.size()>0){
698 storeDto["since"]=since;
699 storeDto["data"]=dcs_payload.dump();
700 storeDto["streamerInfo"] = "";
701 resources.push_back(storeDto);
702 }
703 }
704 j["resources"] = resources;
705 j["format"] = "StoreSetDto";
706 j["datatype"] = "data";
707 j["size"] = resources.size();
708
709 return j;
710}
uint64_t getFirstTime()
It return minimal timestamp in concainer.

◆ isVectorPayload()

bool Crest::CrestContainer::isVectorPayload ( )

It sets the Vector mode of the container.

Definition at line 19 of file CrestContainer.cxx.

20{
21 return m_isVectorPayload;
22}

◆ parseData()

void Crest::CrestContainer::parseData ( const nlohmann::json & values)

It reads a json object, parse it and fill the container.

Parameters
valuesThe input json with data.

Definition at line 499 of file CrestContainer.cxx.

499 {
500 if (values.is_array() && values.size() == m_payload_spec.size())
501 {
502 for (size_t i = 0; i < values.size(); ++i)
503 {
504 const auto & [colName,colType] = m_payload_spec[i];
505 //const std::string & colName = spec.first;
506 //TypeId colType = spec.second;
507 if(values[i].is_string() &&( colType== TypeId::UChar || colType==TypeId::Bool || colType==TypeId::Int16 || colType==TypeId::UInt16
508 || colType==TypeId::Int32 || colType==TypeId::UInt32 || colType==TypeId::Int64 || colType==TypeId::UInt63 || colType==TypeId::Float || colType==TypeId::Double))
509 {
510 parseOldFormat(colName,colType,values[i]);
511 continue;
512 }
513 if(values[i].is_null()){
514 m_row[colName] = nullptr;
515 continue;
516 }
517 switch (colType)
518 {
519 case TypeId::Bool:
520 m_row[colName] = values[i].get<bool>();
521 break;
522 case TypeId::UChar:
523 m_row[colName] = values[i].get<unsigned char>();
524 break;
525 case TypeId::Int16:
526 case TypeId::Int32:
527 m_row[colName] = values[i].get<int>();
528 break;
529 case TypeId::UInt16:
530 case TypeId::UInt32:
531 m_row[colName] = values[i].get<unsigned int>();
532 break;
533 case TypeId::UInt63:
534 m_row[colName] = values[i].get<uint64_t>();
535 break;
536 case TypeId::Int64:
537 m_row[colName] = values[i].get<int64_t>();
538 break;
539 case TypeId::Float:
540 case TypeId::Double:
541 m_row[colName] = values[i].get<double>();
542 break;
544 case TypeId::String4k:
548 case TypeId::String:
549 m_row[colName] = values[i].get<std::string>();
550 break;
551 case TypeId::Blob128M:
552 case TypeId::Blob64k:
553 case TypeId::Blob16M:
554 case TypeId::Blob:
555 m_row[colName] = values[i].get<std::string>();
556 break;
557 default:
558 throw CommonCrestException("CrestContainer::parseData: Unsupported column type.");
559 }
560 }
561 }
562 else
563 {
564 if(!values.is_array())
565 std::cerr << "CrestContainer::parseData values is not array"<<std::endl;
566 else
567 std::cerr << "CrestContainer::parseData values number="<<values.size() << " m_payload_spec.size()="<<m_payload_spec.size()<<std::endl;
568 throw CommonCrestException("CrestContainer::parseData: Mismatch in number of values.");
569 }
570}
void parseOldFormat(const std::string &colName, const TypeId &typespec, const nlohmann::json &j)

◆ parseOldFormat()

void Crest::CrestContainer::parseOldFormat ( const std::string & colName,
const TypeId & typespec,
const nlohmann::json & j )
private

Definition at line 399 of file CrestContainer.cxx.

399 {
400 try{
401 if (thisVal.is_null()){
402 m_row[colName] ="NULL";
403 return;
404 }
405 std::string strVal = to_string(thisVal);
406 if(strVal.size()>2&& strVal[0]=='"'&& strVal[strVal.size()-1]=='"')
407 strVal=strVal.substr(1,strVal.size()-2);
408 if((strVal.compare("NULL")==0||strVal.compare("null")==0)&&
409 (typespec==TypeId::Bool || typespec==TypeId::Int16 || typespec==TypeId::UInt16
410 || typespec==TypeId::Int32 || typespec==TypeId::UInt32
411 || typespec==TypeId::Int64 || typespec==TypeId::UInt63
412 || typespec==TypeId::Float || typespec==TypeId::Double)){
413 m_row[colName] ="NULL";
414 return;
415 }
416 switch (typespec) {
417 case TypeId::Bool:
418 {
419 const bool newVal=(strVal == "true");
420 m_row[colName] = newVal;
421 break;
422 }
423 case TypeId::UChar:
424 {
425 m_row[colName]=std::stoul(strVal);
426 break;
427 }
428 case TypeId::Int16:
429 {
430 m_row[colName]=std::stol(strVal);
431 break;
432 }
433 case TypeId::UInt16:
434 {
435 m_row[colName]=std::stoul(strVal);
436 break;
437 }
438 case TypeId::Int32:
439 {
440 m_row[colName]=std::stoi(strVal);
441 break;
442 }
443 case TypeId::UInt32:
444 {
445 m_row[colName]=std::stoull(strVal);
446 break;
447 }
448 case TypeId::UInt63:
449 {
450 m_row[colName]=std::stoull(strVal);
451 break;
452 }
453 case TypeId::Int64:
454 {
455 m_row[colName]=std::stoll(strVal);
456 break;
457 }
458 case TypeId::Float:
459 {
460 m_row[colName]=std::stof(strVal);
461 break;
462 }
463 case TypeId::Double:
464 {
465 m_row[colName]=std::stod(strVal);
466 break;
467 }
469 case TypeId::String4k:
473 case TypeId::String:
474 {
475 m_row[colName]=thisVal.get<std::string>();
476 break;
477 }
478 case TypeId::Blob128M:
479 case TypeId::Blob16M:
480 case TypeId::Blob64k:
481 case TypeId::Blob:
482 {
483 m_row[colName]=thisVal.get<std::string>();
484 break;
485 }
486 default:
487 {
488 throw std::runtime_error("UNTREATED TYPE!");
489 }
490 }
491
492 }
493 catch(json::exception& e){
494 std::cerr << e.what() << std::endl;
495 throw std::runtime_error(e.what());
496 }
497}

◆ putRow2Vector()

void Crest::CrestContainer::putRow2Vector ( )

It adds row data to vector.

This method should use for Vector type of data. It should call after all data of row is added.

Definition at line 230 of file CrestContainer.cxx.

231{
233 {
234 m_vector_data.push_back(m_row);
235 m_row.clear();
236 }
237 else
238 {
239 std::string msg = "The payload is not a vector.";
240 throw CommonCrestException(msg.c_str());
241 }
242}

◆ readCommonType()

void Crest::CrestContainer::readCommonType ( uint64_t since,
const nlohmann::json & j_in )
private

Definition at line 636 of file CrestContainer.cxx.

637{
638 if(j_in.empty()){
639 addIov(since);
640 return;
641 }
642 // Loop over each channel in the data
643 for (const auto &channel : j_in.items())
644 {
645 std::string channelKey = channel.key();
646 const auto &data_ch = channel.value();
647 nlohmann::json vecJson(json::value_t::array);
649 vecJson=data_ch;
650 else
651 vecJson.push_back(data_ch);
652
653 for (const auto &values : vecJson)
654 {
655 parseData(values);
658 }
659 addData(channelKey);
660 }
661 addIov(since);
662}
void addIov(const uint64_t since)
It adds an IOV to the json object m_iov_data.
void parseData(const nlohmann::json &values)
It reads a json object, parse it and fill 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.

◆ readDcsFullType()

std::vector< uint64_t > Crest::CrestContainer::readDcsFullType ( const nlohmann::json & j_in)
private

Definition at line 609 of file CrestContainer.cxx.

610{
611 nlohmann::json j = j_in;
612 if (j.is_string()){
613 std::istringstream ss(to_string(j));
614 std::string st;
615 ss >> std::quoted(st);
616 j = json::parse(st);
617 }
618 nlohmann::json dcs_data;
619 if (j.contains("data") && j["data"].is_object())
620 {
621 dcs_data = j["data"];
622 }
623 else
624 dcs_data=j;
625 std::vector<uint64_t> ret;
626 if(j.is_object())
627 {
628 for (const auto& [key, value] : dcs_data.items()){
629 uint64_t since=std::stoull(key);
630 readCommonType(since,value);
631 ret.push_back(since);
632 }
633 }
634 return ret;
635}

◆ readJsonFromFile()

nlohmann::json Crest::CrestContainer::readJsonFromFile ( const std::string & filename,
const std::string & spec_filename )

It reads a json file and returns the json object.

Definition at line 366 of file CrestContainer.cxx.

367{
368
369 std::ifstream specfile(spec_filename);
370 nlohmann::json jspec;
371 if (specfile.is_open())
372 {
373 specfile >> jspec;
374 specfile.close();
375 }
376 else
377 {
378 std::cerr << "CondContainer::readJsonFromFile: Error opening file: " << spec_filename << std::endl;
379 throw std::runtime_error("CondContainer::readJsonFromFile: Error opening file. ");
380 }
381 // Set the payload spec
382 setPayloadSpec(jspec);
383 // Read data file
384 std::ifstream file(filename);
385 nlohmann::json j;
386 if (file.is_open())
387 {
388 file >> j;
389 file.close();
390 }
391 else
392 {
393 std::cerr << "CondContainer::readJsonFromFile: Error opening file: " << filename << std::endl;
394 throw std::runtime_error("CondContainer::readJsonFromFile: Error opening file. ");
395 }
396 return j;
397}
void setPayloadSpec(const nlohmann::json &j)

◆ selectIov()

void Crest::CrestContainer::selectIov ( const uint64_t since)

It select timestamp as active.

Parameters
sinceIt is selected timastamp.

Definition at line 166 of file CrestContainer.cxx.

166 {
167 m_iov_data["since"]=since;
168 if(m_full_data.contains(since)){
171 }
172 else{
173 m_iov_data["data"]={};
174 m_payload={};
175 }
176}

◆ setIovData()

void Crest::CrestContainer::setIovData ( const nlohmann::json & j)
private

Definition at line 275 of file CrestContainer.cxx.

276{
277 m_iov_data = j;
278}

◆ setPayload()

void Crest::CrestContainer::setPayload ( const nlohmann::json & j)
private

Definition at line 280 of file CrestContainer.cxx.

281{
282 m_payload = j;
283}

◆ setPayloadSpec()

void Crest::CrestContainer::setPayloadSpec ( const nlohmann::json & j)
private

Definition at line 312 of file CrestContainer.cxx.

313{
314 if (j.is_array())
315 {
316 for (const auto &column : j)
317 {
318 for (const auto &[name, type] : column.items())
319 {
320 addColumn(name, static_cast<TypeId>(std::stoi(type.get<std::string>())));
321 }
322 }
323 }
324 else
325 {
326 for (const auto &[name, type] : j.items())
327 {
328 addColumn(name, static_cast<TypeId>(type.get<int>()));
329 }
330 }
331}

◆ setVectorPayload()

void Crest::CrestContainer::setVectorPayload ( bool isVectorPayload)

Set the Vectore mode of the container.

Parameters
isVectorPayloadTrue if it is Vector payload.

Definition at line 23 of file CrestContainer.cxx.

24{
26}
bool isVectorPayload()
It sets the Vector mode of the container.

Member Data Documentation

◆ m_full_data

std::map<uint64_t,nlohmann::json> Crest::CrestContainer::m_full_data
private

Definition at line 229 of file CrestContainer.h.

◆ m_iov_data

nlohmann::json Crest::CrestContainer::m_iov_data ={}
private

Definition at line 227 of file CrestContainer.h.

◆ m_isVectorPayload

bool Crest::CrestContainer::m_isVectorPayload =false
private

Definition at line 231 of file CrestContainer.h.

◆ m_modeId

ModeId Crest::CrestContainer::m_modeId
private

Definition at line 230 of file CrestContainer.h.

◆ m_payload

nlohmann::json Crest::CrestContainer::m_payload ={}
private

Definition at line 225 of file CrestContainer.h.

◆ m_payload_spec

std::vector<std::pair<std::string,TypeId> > Crest::CrestContainer::m_payload_spec
private

Definition at line 224 of file CrestContainer.h.

◆ m_row

nlohmann::json Crest::CrestContainer::m_row ={}
private

Definition at line 226 of file CrestContainer.h.

◆ m_vector_data

nlohmann::json Crest::CrestContainer::m_vector_data =nlohmann::json::array()
private

Definition at line 228 of file CrestContainer.h.


The documentation for this class was generated from the following files: