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

Private Member Functions

nlohmann::json createRowArray (const nlohmann::json &data_row) const
 
const nlohmann::jsongetRow ()
 
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::jsonm_full_data
 
ModeId m_modeId
 
bool m_isVectorPayload =false
 

Detailed Description

It compares timestamp in string format.

Definition at line 58 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 }

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  throw CommonCrestException("The type of parameter is not defined.");
49 }

◆ 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 }

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

119 {
121 }

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

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

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

156 {
157  m_iov_data["since"] = since;
158  m_iov_data["data"] = m_payload;
160  m_payload.clear();
161 }

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

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

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

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

◆ channelIds()

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

Return list of channel id in string format.

Definition at line 183 of file CrestContainer.cxx.

183  {
184  std::vector<std::string> chs;
185  for (auto& x : m_iov_data["data"].items()){
186  chs.push_back(x.key());
187  }
188  sort(chs.begin(), chs.end(), compareStrTimestamp);
189  return chs;
190 }

◆ clear()

void Crest::CrestContainer::clear ( )

It clear data the container.

Definition at line 338 of file CrestContainer.cxx.

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

◆ createRowArray()

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

Definition at line 140 of file CrestContainer.cxx.

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

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

348 {
349  std::ofstream file(filename);
350  if (file.is_open())
351  {
352  file << std::setprecision(6) << j.dump(4);
353  file.close();
354  }
355  else
356  {
357  std::cerr << "CondContainer::dumpJsonToFile: Error opening file: " << filename << std::endl;
358  throw std::runtime_error("CondContainer::dumpJsonToFile: Error opening file.");
359  }
360 }

◆ flush()

void Crest::CrestContainer::flush ( )

It reinitializes the containers.

Definition at line 330 of file CrestContainer.cxx.

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

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

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

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

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

◆ getFirstTime()

uint64_t Crest::CrestContainer::getFirstTime ( )

It return minimal timestamp in concainer.

Definition at line 175 of file CrestContainer.cxx.

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

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

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

◆ getJsonIovData()

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

It returns the json representation of the container.

Definition at line 287 of file CrestContainer.cxx.

288 {
289  return m_iov_data.dump();
290 }

◆ getJsonPayload()

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

It returns the json representation of the container.

Definition at line 282 of file CrestContainer.cxx.

283 {
284  return getPayload().dump();
285 }

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

192 {
193  return m_payload_spec;
194 }

◆ getPayload()

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

Return current payload in json format.

Definition at line 248 of file CrestContainer.cxx.

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

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

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

◆ getPayloadSpec()

json Crest::CrestContainer::getPayloadSpec ( )

Return payload specification in json format.

Definition at line 292 of file CrestContainer.cxx.

293 {
294  json pspec_data=json::array();
295  for (auto &column : m_payload_spec)
296  {
297  json j={};
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.");
301  } else {
302  j[column.first] = pos->second;
303  }
304  pspec_data.push_back(j);
305  }
306  return pspec_data;
307 }

◆ getRow()

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

Definition at line 241 of file CrestContainer.cxx.

242 {
243  if (m_isVectorPayload)
244  return m_vector_data;
245  return m_row;
246 }

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

658 {
659  nlohmann::json j;
662  nlohmann::json storeDto;
663  // Loop over the iov list container to add the data to the storeDto
664  for (const auto& [key, value] : m_full_data)
665  {
666  storeDto["since"] = key;
667  storeDto["data"] = value.dump();
668  storeDto["streamerInfo"] = "";//m_streamer_info_data.dump();
669  resources.push_back(storeDto);
670  }
671  }
674  nlohmann::json storeDto;
675  nlohmann::json dcs_payload;
676  nlohmann::json curPayload=m_full_data[since];
677  for (const auto& [key, value] : m_full_data)
678  {
679  curPayload.update(value);
680  dcs_payload[std::to_string(key)]=curPayload;
681  if(period>0 && (key-since)>period){
682  storeDto["since"]=since;
683  storeDto["data"]=dcs_payload.dump();
684  storeDto["streamerInfo"] = "";
685  resources.push_back(storeDto);
686  since=key;
687  dcs_payload={};
688  }
689  }
690  if(dcs_payload.size()>0){
691  storeDto["since"]=since;
692  storeDto["data"]=dcs_payload.dump();
693  storeDto["streamerInfo"] = "";
694  resources.push_back(storeDto);
695  }
696  }
697  j["resources"] = resources;
698  j["format"] = "StoreSetDto";
699  j["datatype"] = "data";
700  j["size"] = resources.size();
701 
702  return j;
703 }

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

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

◆ parseOldFormat()

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

Definition at line 396 of file CrestContainer.cxx.

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

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

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

◆ readCommonType()

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

Definition at line 629 of file CrestContainer.cxx.

630 {
631  if(j_in.empty()){
632  addIov(since);
633  return;
634  }
635  // Loop over each channel in the data
636  for (const auto &channel : j_in.items())
637  {
638  std::string channelKey = channel.key();
639  const auto &data_ch = channel.value();
642  vecJson=data_ch;
643  else
644  vecJson.push_back(data_ch);
645 
646  for (const auto &values : vecJson)
647  {
648  parseData(values);
650  putRow2Vector();
651  }
652  addData(channelKey);
653  }
654  addIov(since);
655 }

◆ readDcsFullType()

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

Definition at line 602 of file CrestContainer.cxx.

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

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

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

◆ selectIov()

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

It select timestamp as active.

Parameters
sinceIt is selected timastamp.

Definition at line 163 of file CrestContainer.cxx.

163  {
164  m_iov_data["since"]=since;
165  if(m_full_data.contains(since)){
166  m_iov_data["data"]=m_full_data[since];
168  }
169  else{
170  m_iov_data["data"]={};
171  m_payload={};
172  }
173 }

◆ setIovData()

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

Definition at line 272 of file CrestContainer.cxx.

273 {
274  m_iov_data = j;
275 }

◆ setPayload()

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

Definition at line 277 of file CrestContainer.cxx.

278 {
279  m_payload = j;
280 }

◆ setPayloadSpec()

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

Definition at line 309 of file CrestContainer.cxx.

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

◆ 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 }

Member Data Documentation

◆ m_full_data

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

Definition at line 227 of file CrestContainer.h.

◆ m_iov_data

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

Definition at line 225 of file CrestContainer.h.

◆ m_isVectorPayload

bool Crest::CrestContainer::m_isVectorPayload =false
private

Definition at line 229 of file CrestContainer.h.

◆ m_modeId

ModeId Crest::CrestContainer::m_modeId
private

Definition at line 228 of file CrestContainer.h.

◆ m_payload

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

Definition at line 223 of file CrestContainer.h.

◆ m_payload_spec

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

Definition at line 222 of file CrestContainer.h.

◆ m_row

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

Definition at line 224 of file CrestContainer.h.

◆ m_vector_data

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

Definition at line 226 of file CrestContainer.h.


The documentation for this class was generated from the following files:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
python.AtlRunQueryAMI.period
period
Definition: AtlRunQueryAMI.py:224
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
json
nlohmann::json json
Definition: CrestContainer.cxx:11
Crest::CrestContainer::setPayloadSpec
void setPayloadSpec(const nlohmann::json &j)
Definition: CrestContainer.cxx:309
Crest::CrestContainer::getFirstTime
uint64_t getFirstTime()
It return minimal timestamp in concainer.
Definition: CrestContainer.cxx:175
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
Crest::CrestContainer::addColumn
void addColumn(const std::string &name, TypeId type)
It adds a column to the payload specification.
Definition: CrestContainer.cxx:34
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
Crest::TypeId::UInt16
@ UInt16
json
nlohmann::json json
Definition: HistogramDef.cxx:9
Crest::TypeId::Blob128M
@ Blob128M
Crest::CrestContainer::m_payload
nlohmann::json m_payload
Definition: CrestContainer.h:223
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1113
Crest::CrestContainer::getRow
const nlohmann::json & getRow()
Definition: CrestContainer.cxx:241
skel.it
it
Definition: skel.GENtoEVGEN.py:407
Crest::TypeId::UInt63
@ UInt63
DeMoUpdate.column
dictionary column
Definition: DeMoUpdate.py:1110
Crest::CrestContainer::getPayload
const nlohmann::json & getPayload()
Return current payload in json format.
Definition: CrestContainer.cxx:248
Crest::CrestContainer::isVectorPayload
bool isVectorPayload()
It sets the Vector mode of the container.
Definition: CrestContainer.cxx:19
athena.value
value
Definition: athena.py:124
Crest::ModeId::DCS_FULL
@ DCS_FULL
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Crest::CrestContainer::flush
void flush()
It reinitializes the containers.
Definition: CrestContainer.cxx:330
x
#define x
python.AtlRunQueryParser.ap
ap
Definition: AtlRunQueryParser.py:825
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:554
Crest::TypeId::String16M
@ String16M
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:808
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
Crest::CrestContainer::m_vector_data
nlohmann::json m_vector_data
Definition: CrestContainer.h:226
Crest::CrestContainer::m_iov_data
nlohmann::json m_iov_data
Definition: CrestContainer.h:225
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
Crest::TypeId::String255
@ String255
Crest::CrestContainer::m_full_data
std::map< uint64_t, nlohmann::json > m_full_data
Definition: CrestContainer.h:227
Crest::CrestContainer::addExternalData
void addExternalData(const std::string &channel_id, const nlohmann::json &data)
It associate the payload row to a channel_id.
Definition: CrestContainer.cxx:123
Crest::TypeId::Blob64k
@ Blob64k
Crest::TypeId::Float
@ Float
Crest::CrestContainer::parseOldFormat
void parseOldFormat(const std::string &colName, const TypeId &typespec, const nlohmann::json &j)
Definition: CrestContainer.cxx:396
Crest::TypeId::Bool
@ Bool
Crest::TypeId::Blob16M
@ Blob16M
Crest::CrestContainer::m_modeId
ModeId m_modeId
Definition: CrestContainer.h:228
lumiFormat.i
int i
Definition: lumiFormat.py:85
Crest::CrestContainer::addData
void addData(const std::string &channel_id)
It associate the payload row to a channel_id.
Definition: CrestContainer.cxx:118
Crest::TypeId::UChar
@ UChar
Crest::TypeId::UInt32
@ UInt32
calibdata.exception
exception
Definition: calibdata.py:495
createCoolChannelIdFile.channel_id
channel_id
Definition: createCoolChannelIdFile.py:51
file
TFile * file
Definition: tile_monitor.h:29
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
Crest::CrestContainer::parseData
void parseData(const nlohmann::json &values)
It reads a json object, parse it and fill the container.
Definition: CrestContainer.cxx:494
Preparation.mode
mode
Definition: Preparation.py:107
Crest::TypeId::Int32
@ Int32
Crest::CrestContainer::readDcsFullType
std::vector< uint64_t > readDcsFullType(const nlohmann::json &j_in)
Definition: CrestContainer.cxx:602
Crest::TypeId::String128M
@ String128M
lumiFormat.array
array
Definition: lumiFormat.py:91
python.selection.number
number
Definition: selection.py:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
Crest::ModeId::Standard
@ Standard
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:71
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
Crest::TypeId::Int64
@ Int64
Crest::TypeId::String64k
@ String64k
Crest::CrestContainer::readCommonType
void readCommonType(uint64_t since, const nlohmann::json &j_in)
Definition: CrestContainer.cxx:629
Crest::CrestContainer::m_payload_spec
std::vector< std::pair< std::string, TypeId > > m_payload_spec
Definition: CrestContainer.h:222
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:23
TypeId
Definition: IdDictMgr.cxx:29
Crest::CrestContainer::createRowArray
nlohmann::json createRowArray(const nlohmann::json &data_row) const
Definition: CrestContainer.cxx:140
Crest::TypeId::String4k
@ String4k
Crest::TypeId::Int16
@ Int16
Crest::CrestContainer::addIov
void addIov(const uint64_t since)
It adds an IOV to the json object m_iov_data.
Definition: CrestContainer.cxx:155
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
compareStrTimestamp
bool compareStrTimestamp(std::string &as, std::string &bs)
Definition: CrestContainer.cxx:28
Crest::CrestContainer::m_isVectorPayload
bool m_isVectorPayload
Definition: CrestContainer.h:229
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Crest::CrestContainer::m_row
nlohmann::json m_row
Definition: CrestContainer.h:224
Crest::TypeId::Double
@ Double
Crest::CrestContainer::putRow2Vector
void putRow2Vector()
It adds row data to vector.
Definition: CrestContainer.cxx:227
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37