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 59 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 120 of file CrestContainer.cxx.

121{
122 addExternalData(channel_id, getRow());
123}
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 125 of file CrestContainer.cxx.

126{
127 nlohmann::json arr_data = m_isVectorPayload ? nlohmann::json::array() : nlohmann::json();
129 for (const auto &data_row : data)
130 {
131 arr_data.emplace_back(createRowArray(data_row));
132 }
133 m_payload[channel_id] = std::move(arr_data);
134 }
135 else{
137 }
138 m_vector_data.clear();
139 m_row.clear();
140}
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 157 of file CrestContainer.cxx.

158{
159 m_iov_data["since"] = since;
160 m_iov_data["data"] = m_payload;
162 m_payload.clear();
163}
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;
103 case TypeId::String4k:
107 case TypeId::Blob64k:
108 case TypeId::Blob16M:
109 case TypeId::Blob128M:
110 case TypeId::Blob:
111 m_row[name] = std::string(va_arg(ap, const char *));
112 break;
113 default:
114 throw CommonCrestException("Unsupported column type.");
115 }
116 }
117 va_end(ap);
118}
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 185 of file CrestContainer.cxx.

185 {
186 std::vector<std::string> chs;
187 for (auto& x : m_iov_data["data"].items()){
188 chs.push_back(x.key());
189 }
190 sort(chs.begin(), chs.end(), compareStrTimestamp);
191 return chs;
192}
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 340 of file CrestContainer.cxx.

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

◆ createRowArray()

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

Definition at line 142 of file CrestContainer.cxx.

143{
144 nlohmann::json row_arr_data = nlohmann::json::array();
145 for (const auto &column : m_payload_spec)
146 {
147 if (data_row.find(column.first) == data_row.end())
148 {
149 std::string msg = "The data does not contain the column: " + column.first;
150 throw CommonCrestException(msg.c_str());
151 }
152 row_arr_data.push_back(data_row[column.first]);
153 }
154 return row_arr_data;
155}
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 349 of file CrestContainer.cxx.

350{
351 std::ofstream file(filename);
352 if (file.is_open())
353 {
354 file << std::setprecision(6) << j.dump(4);
355 file.close();
356 }
357 else
358 {
359 std::cerr << "CondContainer::dumpJsonToFile: Error opening file: " << filename << std::endl;
360 throw std::runtime_error("CondContainer::dumpJsonToFile: Error opening file.");
361 }
362}
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 332 of file CrestContainer.cxx.

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

◆ 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 569 of file CrestContainer.cxx.

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

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

◆ getFirstTime()

uint64_t Crest::CrestContainer::getFirstTime ( )

It return minimal timestamp in concainer.

Definition at line 177 of file CrestContainer.cxx.

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

◆ 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 264 of file CrestContainer.cxx.

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

◆ getJsonIovData()

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

It returns the json representation of the container.

Definition at line 289 of file CrestContainer.cxx.

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

◆ getJsonPayload()

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

It returns the json representation of the container.

Definition at line 284 of file CrestContainer.cxx.

285{
286 return getPayload().dump();
287}
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 193 of file CrestContainer.cxx.

194{
195 return m_payload_spec;
196}

◆ getPayload()

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

Return current payload in json format.

Definition at line 250 of file CrestContainer.cxx.

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

◆ 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 198 of file CrestContainer.cxx.

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

◆ getPayloadSpec()

json Crest::CrestContainer::getPayloadSpec ( )

Return payload specification in json format.

Definition at line 294 of file CrestContainer.cxx.

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

◆ getRow()

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

Definition at line 243 of file CrestContainer.cxx.

244{
246 return m_vector_data;
247 return m_row;
248}

◆ 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 661 of file CrestContainer.cxx.

662{
663 nlohmann::json j;
664 nlohmann::json resources = nlohmann::json::array();
666 nlohmann::json storeDto;
667 // Loop over the iov list container to add the data to the storeDto
668 for (const auto& [key, value] : m_full_data)
669 {
670 storeDto["since"] = key;
671 storeDto["data"] = value.dump();
672 storeDto["streamerInfo"] = "";//m_streamer_info_data.dump();
673 resources.push_back(storeDto);
674 }
675 }
678 nlohmann::json storeDto;
679 nlohmann::json dcs_payload;
680 nlohmann::json curPayload=m_full_data[since];
681 for (const auto& [key, value] : m_full_data)
682 {
683 curPayload.update(value);
684 dcs_payload[std::to_string(key)]=curPayload;
685 if(period>0 && (key-since)>period){
686 storeDto["since"]=since;
687 storeDto["data"]=dcs_payload.dump();
688 storeDto["streamerInfo"] = "";
689 resources.push_back(storeDto);
690 since=key;
691 dcs_payload={};
692 }
693 }
694 if(dcs_payload.size()>0){
695 storeDto["since"]=since;
696 storeDto["data"]=dcs_payload.dump();
697 storeDto["streamerInfo"] = "";
698 resources.push_back(storeDto);
699 }
700 }
701 j["resources"] = resources;
702 j["format"] = "StoreSetDto";
703 j["datatype"] = "data";
704 j["size"] = resources.size();
705
706 return j;
707}
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 497 of file CrestContainer.cxx.

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

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

◆ 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 229 of file CrestContainer.cxx.

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

◆ readCommonType()

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

Definition at line 633 of file CrestContainer.cxx.

634{
635 if(j_in.empty()){
636 addIov(since);
637 return;
638 }
639 // Loop over each channel in the data
640 for (const auto &channel : j_in.items())
641 {
642 std::string channelKey = channel.key();
643 const auto &data_ch = channel.value();
644 nlohmann::json vecJson(json::value_t::array);
646 vecJson=data_ch;
647 else
648 vecJson.push_back(data_ch);
649
650 for (const auto &values : vecJson)
651 {
652 parseData(values);
655 }
656 addData(channelKey);
657 }
658 addIov(since);
659}
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 606 of file CrestContainer.cxx.

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

◆ 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 365 of file CrestContainer.cxx.

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

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

◆ setIovData()

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

Definition at line 274 of file CrestContainer.cxx.

275{
276 m_iov_data = j;
277}

◆ setPayload()

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

Definition at line 279 of file CrestContainer.cxx.

280{
281 m_payload = j;
282}

◆ setPayloadSpec()

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

Definition at line 311 of file CrestContainer.cxx.

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

◆ 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 228 of file CrestContainer.h.

◆ m_iov_data

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

Definition at line 226 of file CrestContainer.h.

◆ m_isVectorPayload

bool Crest::CrestContainer::m_isVectorPayload =false
private

Definition at line 230 of file CrestContainer.h.

◆ m_modeId

ModeId Crest::CrestContainer::m_modeId
private

Definition at line 229 of file CrestContainer.h.

◆ m_payload

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

Definition at line 224 of file CrestContainer.h.

◆ m_payload_spec

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

Definition at line 223 of file CrestContainer.h.

◆ m_row

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

Definition at line 225 of file CrestContainer.h.

◆ m_vector_data

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

Definition at line 227 of file CrestContainer.h.


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