ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Crest::CrestContainer Class Reference

#include <CrestContainer.h>

Collaboration diagram for Crest::CrestContainer:

Public Member Functions

 CrestContainer ()
 
 ~CrestContainer ()
 
void addColumn (const std::string &name, TypeId type)
 It adds a column to the payload specification. More...
 
void addColumn (const std::string &name, const char *type)
 
void addColumn (const std::string &name, uint32_t type)
 
bool isVectorPayload ()
 It sets the mode of the container. More...
 
void setVectorPayload (bool isVectorPayload)
 
Crest::TypeId stringToTypeId (const std::string &type) const
 
Crest::TypeId intToTypeId (int value) const
 
void putRow2Vector ()
 It adds row data to vector. More...
 
void addNullRecord (const char *name)
 It adds a null value to the payload. More...
 
void addRecord (const char *name, int number,...)
 It adds a record to the payload. More...
 
void addData (const char *channel_id)
 It associate the payload row to a channel_id. More...
 
void addExternalData (const char *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 ()
 
template<typename T >
getRecord (const std::string &name)
 
const nlohmann::jsongetPayload ()
 
const nlohmann::jsongetIovData ()
 
const nlohmann::jsongetPayloadChannel (const char *channel_id)
 
void setIovData (const nlohmann::json &j)
 
void setPayload (const nlohmann::json &j)
 
nlohmann::json getPayloadSpec ()
 
void setPayloadSpec (const nlohmann::json &j)
 
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 ()
 
void selectIov (const uint64_t since)
 
std::vector< std::string > channelIds ()
 
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 dump_json_to_file (const nlohmann::json &j, const std::string &filename)
 It creates a file with the json representation of the container. More...
 
nlohmann::json read_json_from_file (const std::string &filename, const std::string &spec_filename)
 It reads a json file and returns the json object. More...
 
void from_json (const uint64_t since, const nlohmann::json &j)
 It reads a json object to fill the containers. More...
 
void parseOldFormat (std::string &colName, TypeId &typespec, const nlohmann::json &j)
 

Static Public Member Functions

static std::string base64_encode (const uint8_t *bytes_to_encode, unsigned int in_len)
 It encodes the input string to base64. More...
 
static std::vector< unsigned char > base64_decode (const std::string &encodedData)
 It decodes the input string from base64. More...
 

Private Member Functions

void validatePayloadSize (const nlohmann::json &data) const
 
nlohmann::json createRowArray (const nlohmann::json &data_row) const
 
const nlohmann::jsongetRow ()
 

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()
 
nlohmann::json m_full_data ={}
 
ModeId m_modeId
 
bool m_isVectorPayload =false
 

Detailed Description

Definition at line 54 of file CrestContainer.h.

Constructor & Destructor Documentation

◆ CrestContainer()

Crest::CrestContainer::CrestContainer ( )

Definition at line 17 of file CrestContainer.cxx.

◆ ~CrestContainer()

Crest::CrestContainer::~CrestContainer ( )

Definition at line 18 of file CrestContainer.cxx.

19 {
20  flush();
21 }

Member Function Documentation

◆ addColumn() [1/3]

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

Definition at line 84 of file CrestContainer.cxx.

85 {
87 }

◆ addColumn() [2/3]

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

80 {
81  m_payload_spec.emplace_back(name, type);
82 }

◆ addColumn() [3/3]

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

Definition at line 89 of file CrestContainer.cxx.

90 {
91  addColumn(name, static_cast<TypeId>(type));
92 }

◆ addData()

void Crest::CrestContainer::addData ( const char *  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 160 of file CrestContainer.cxx.

161 {
163 }

◆ addExternalData()

void Crest::CrestContainer::addExternalData ( const char *  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 165 of file CrestContainer.cxx.

166 {
167 
169  nlohmann::json arr_data = m_isVectorPayload ? nlohmann::json::array() : nlohmann::json();
170 
171  for (const auto &data_row : data)//m_vector_data)
172  {
173  auto row_arr_data = createRowArray(data_row);
174 
175  if (m_isVectorPayload)
176  {
177  arr_data.push_back(row_arr_data);
178  }
179  else
180  {
181  arr_data = row_arr_data;
182  }
183  }
184  m_payload[channel_id] = arr_data;
185  m_vector_data.clear();
186  m_row.clear();
187 }

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

215 {
216  m_iov_data["since"] = since;
217  m_iov_data["data"] = m_payload;
219  m_payload.clear();
220 }

◆ addNullRecord()

void Crest::CrestContainer::addNullRecord ( const char *  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 94 of file CrestContainer.cxx.

95 {
96  auto it = std::find_if(m_payload_spec.begin(), m_payload_spec.end(),
97  [&name](const auto &column)
98  { return column.first == name; });
99 
100  if (it != m_payload_spec.end())
101  {
102  m_row[name] = nlohmann::json::value_t::null;
103  }
104 }

◆ addRecord()

void Crest::CrestContainer::addRecord ( const char *  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 106 of file CrestContainer.cxx.

107 {
108 
109  va_list ap;
110  va_start(ap, number);
111 
112  for (auto &column : m_payload_spec)
113  {
114  if (column.first != name)
115  {
116  continue;
117  }
118 
119  switch (column.second)
120  {
121  case TypeId::Bool:
122  m_row[name] = va_arg(ap, int);
123  break;
124  case TypeId::UChar:
125  m_row[name] = static_cast<unsigned char>(va_arg(ap, int));
126  break;
127  case TypeId::Int16:
128  case TypeId::Int32:
129  m_row[name] = va_arg(ap, int);
130  break;
131  case TypeId::UInt16:
132  case TypeId::UInt32:
133  m_row[name] = va_arg(ap, unsigned int);
134  break;
135  case TypeId::UInt63:
136  m_row[name] = va_arg(ap, uint64_t);
137  break;
138  case TypeId::Int64:
139  m_row[name] = va_arg(ap, int64_t);
140  break;
141  case TypeId::Float:
142  case TypeId::Double:
143  m_row[name] = va_arg(ap, double);
144  break;
145  case TypeId::String255:
146  case TypeId::String4k:
147  case TypeId::String64k:
148  case TypeId::String16M:
149  case TypeId::Blob64k:
150  case TypeId::Blob16M:
151  m_row[name] = std::string(va_arg(ap, const char *));
152  break;
153  default:
154  throw CommonCrestException("Unsupported column type.");
155  }
156  }
157  va_end(ap);
158 }

◆ base64_decode()

std::vector< unsigned char > Crest::CrestContainer::base64_decode ( const std::string &  encodedData)
static

It decodes the input string from base64.

Definition at line 65 of file CrestContainer.cxx.

66 {
67  using namespace boost::archive::iterators;
68  typedef transform_width<binary_from_base64<std::string::const_iterator>, 8, 6> base64_decoder;
69 
70  std::string encodedDataNoPadding = encodedData;
71  boost::algorithm::erase_all(encodedDataNoPadding, "=");
72 
73  std::vector<unsigned char> decodedData;
74  std::copy(base64_decoder(encodedDataNoPadding.begin()), base64_decoder(encodedDataNoPadding.end()), std::back_inserter(decodedData));
75 
76  return decodedData;
77 }

◆ base64_encode()

std::string Crest::CrestContainer::base64_encode ( const uint8_t *  bytes_to_encode,
unsigned int  in_len 
)
static

It encodes the input string to base64.

Definition at line 50 of file CrestContainer.cxx.

51 {
52  using namespace boost::archive::iterators;
53  typedef base64_from_binary<transform_width<const char *, 6, 8>> base64_encoder;
54 
55  std::string encodedData;
56  std::copy(base64_encoder(data), base64_encoder(data + len), std::back_inserter(encodedData));
57 
58  size_t numPaddingChars = (3 - len % 3) % 3;
59  encodedData.append(numPaddingChars, '=');
60 
61  return encodedData;
62 }

◆ channelIds()

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

Definition at line 227 of file CrestContainer.cxx.

227  {
228  std::vector<std::string> chs;
229  for (auto& x : m_iov_data["data"].items()){
230  chs.push_back(x.key());
231  }
232  return chs;
233 }

◆ clear()

void Crest::CrestContainer::clear ( )

Definition at line 394 of file CrestContainer.cxx.

394  {
395  m_payload.clear();
396  m_iov_data.clear();
397  m_row.clear();
398  m_vector_data.clear();
399  m_full_data={};
400 }

◆ createRowArray()

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

Definition at line 199 of file CrestContainer.cxx.

200 {
201  nlohmann::json row_arr_data = nlohmann::json::array();
202  for (const auto &column : m_payload_spec)
203  {
204  if (data_row.find(column.first) == data_row.end())
205  {
206  std::string msg = "The data does not contain the column: " + column.first;
207  throw CommonCrestException(msg.c_str());
208  }
209  row_arr_data.push_back(data_row[column.first]);
210  }
211  return row_arr_data;
212 }

◆ dump_json_to_file()

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

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

Definition at line 403 of file CrestContainer.cxx.

404 {
405  std::ofstream file(filename);
406  if (file.is_open())
407  {
408  file << std::setprecision(6) << j.dump(4);
409  file.close();
410  }
411  else
412  {
413  std::cerr << "CondContainer::dump_json_to_file: Error opening file: " << filename << std::endl;
414  }
415 }

◆ flush()

void Crest::CrestContainer::flush ( )

It reinitializes the containers.

Definition at line 386 of file CrestContainer.cxx.

387 {
388  m_iov_data.clear();
389  m_row.clear();
390  m_vector_data.clear();
391  m_full_data={};
392 }

◆ from_json()

void Crest::CrestContainer::from_json ( const uint64_t  since,
const nlohmann::json j 
)

It reads a json object to fill the containers.

Definition at line 547 of file CrestContainer.cxx.

548 {
549  nlohmann::json j = j_in;
550  if (j.is_string()){
551  std::istringstream ss(to_string(j));
552  std::string st;
553  ss >> std::quoted(st);
554  j = json::parse(st);
555  }
557  throw CommonCrestException("Unsupported type of payload.");
558  // Accessing the "data" object
559  if (j.contains("data") && j["data"].is_object())
560  {
561  const auto &data = j["data"];
562 
563  // Loop over each channel in the data
564  for (const auto &channel : data.items())
565  {
566  std::string channelKey = channel.key();
567  const auto &data_ch = channel.value();
570  vecJson=data_ch;
571  else
572  vecJson.push_back(data_ch);
573 
574  for (const auto &values : vecJson)
575  {
576  // TODO: this will not work for vector payloads
577  // Check if the number of values in the array matches the expected number of columns
578  if (values.is_array() && values.size() == m_payload_spec.size())
579  {
580  for (size_t i = 0; i < values.size(); ++i)
581  {
582  const auto &spec = m_payload_spec[i];
583  std::string colName = spec.first;
584  TypeId colType = spec.second;
585  if(values[i].is_string() &&( colType==TypeId::Bool || colType==TypeId::Int16 || colType==TypeId::UInt16
586  || colType==TypeId::Int32 || colType==TypeId::UInt32 || colType==TypeId::Int64 || colType==TypeId::UInt63 || colType==TypeId::Float || colType==TypeId::Double))
587  {
588  parseOldFormat(colName,colType,values[i]);
589  continue;
590  }
591  switch (colType)
592  {
593  case TypeId::Bool:
594  m_row[colName] = values[i].get<bool>();
595  break;
596  case TypeId::UChar:
597  m_row[colName] = values[i].get<unsigned char>();
598  break;
599  case TypeId::Int16:
600  case TypeId::Int32:
601  m_row[colName] = values[i].get<int>();
602  break;
603  case TypeId::UInt16:
604  case TypeId::UInt32:
605  m_row[colName] = values[i].get<unsigned int>();
606  break;
607  case TypeId::UInt63:
608  m_row[colName] = values[i].get<uint64_t>();
609  break;
610  case TypeId::Int64:
611  m_row[colName] = values[i].get<int64_t>();
612  break;
613  case TypeId::Float:
614  case TypeId::Double:
615  m_row[colName] = values[i].get<double>();
616  break;
617  case TypeId::String255:
618  case TypeId::String4k:
619  case TypeId::String64k:
620  case TypeId::String16M:
621  case TypeId::String128M:
622  m_row[colName] = values[i].get<std::string>();
623  break;
624  case TypeId::Blob128M:
625  case TypeId::Blob64k:
626  case TypeId::Blob16M:
627  m_row[colName] = values[i].get<std::string>();
628  break;
629  default:
630  throw CommonCrestException("Unsupported column type.");
631  }
632  }
633  }
634  else
635  {
636  std::cerr << "CrestContainer::from_json: Mismatch in number of values for channel " << channelKey << std::endl;
637  }
639  putRow2Vector();
640  }
641  addData(channelKey.c_str());
642  }
643  }
644  else
645  {
646  std::cerr << "CrestContainer::from_json: JSON does not contain a 'data' object or it is not a JSON object." << std::endl;
647  std::cerr << "CrestContainer::from_json json:"<<j<<std::endl;
648  }
649  addIov(since);
650 }

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

267 {
268  auto it = std::find_if(m_payload_spec.begin(), m_payload_spec.end(),
269  [&name](const auto &column)
270  { return column.first == name; });
271 
272  if (it != m_payload_spec.end())
273  {
274  return std::distance(m_payload_spec.begin(), it);
275  }
276  else
277  {
278  throw CommonCrestException("The column name is not found.");
279  }
280 }

◆ getIovData()

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

Definition at line 318 of file CrestContainer.cxx.

319 {
320  if (m_iov_data.empty())
321  {
322  std::string msg = "The iov data is empty.";
323  throw CommonCrestException(msg.c_str());
324  }
325  return m_iov_data;
326 }

◆ getJsonIovData()

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

It returns the json representation of the container.

Definition at line 343 of file CrestContainer.cxx.

344 {
345  return m_iov_data.dump();
346 }

◆ getJsonPayload()

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

It returns the json representation of the container.

Definition at line 338 of file CrestContainer.cxx.

339 {
340  return getPayload().dump();
341 }

◆ getMPayloadSpec()

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

Definition at line 234 of file CrestContainer.cxx.

235 {
236  return m_payload_spec;
237 }

◆ getPayload()

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

Definition at line 304 of file CrestContainer.cxx.

305 {
306  if (m_payload.empty() && m_iov_data.empty())
307  {
308  std::string msg = "The payload is empty.";
309  throw CommonCrestException(msg.c_str());
310  }
311  if (m_payload.empty())
312  {
313  m_payload = m_iov_data["data"];
314  }
315  return m_payload;
316 }

◆ getPayloadChannel()

const nlohmann::json & Crest::CrestContainer::getPayloadChannel ( const char *  channel_id)

Definition at line 239 of file CrestContainer.cxx.

240 {
241  if (m_payload.empty())
242  {
243  m_payload = m_iov_data["data"];
244  }
245  auto it = m_payload.find(channel_id);
246  if (it == m_payload.end())
247  {
248  std::string msg = "Channel id " + std::string(channel_id) + " is not found.";
249  throw CommonCrestException(msg.c_str());
250  }
251  if (m_row.empty())
252  {
253  for (const auto &column : m_payload_spec)
254  {
255  int index = getColumnIndex(column.first);
256  if (index == -1)
257  {
258  throw std::runtime_error("Column name not found.");
259  }
260  m_row[column.first] = it.value()[index];
261  }
262  }
263  return it.value();
264 }

◆ getPayloadSpec()

json Crest::CrestContainer::getPayloadSpec ( )

Definition at line 348 of file CrestContainer.cxx.

349 {
350  json pspec_data=json::array();
351  for (auto &column : m_payload_spec)
352  {
353  json j={};
354  std::map<TypeId, std::string>::const_iterator pos = Crest::s_typeToString.find(column.second);
355  if (pos == Crest::s_typeToString.end()) {
356  throw CommonCrestException("Type do not exist in the map.");
357  } else {
358  j[column.first] = pos->second;
359  }
360  pspec_data.push_back(j);
361  }
362  return pspec_data;
363 }

◆ getRecord()

template<typename T >
T Crest::CrestContainer::getRecord ( const std::string &  name)
inline

Definition at line 143 of file CrestContainer.h.

144  {
145  for (const auto& column : m_payload_spec) {
146  if (column.first == name) {
147  try {
148  return m_row.at(name).get<T>();
149  } catch (nlohmann::json::exception& e) {
150  throw std::runtime_error("JSON exception for key: " + name);
151  }
152  }
153  }
154  throw std::runtime_error("Column name not found or type mismatch.");
155  }

◆ getRow()

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

Definition at line 296 of file CrestContainer.cxx.

297 {
298  if (m_isVectorPayload)
299  return m_vector_data;
300  m_vector_data.push_back(m_row);
301  return m_vector_data;
302 }

◆ intToTypeId()

Crest::TypeId Crest::CrestContainer::intToTypeId ( int  value) const

Definition at line 42 of file CrestContainer.cxx.

43 {
44  if (value < 0 || value >= static_cast<int>(Crest::TypeId::TypeIdCount)) {
45  throw std::out_of_range("Invalid integer value for TypeId");
46  }
47  return static_cast<Crest::TypeId>(value);
48 }

◆ isVectorPayload()

bool Crest::CrestContainer::isVectorPayload ( )

It sets the mode of the container.

Definition at line 23 of file CrestContainer.cxx.

24 {
25  return m_isVectorPayload;
26 }

◆ parseOldFormat()

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

Definition at line 449 of file CrestContainer.cxx.

449  {
450  try{
451  if (thisVal.is_null()){
452  m_row[colName] ="NULL";
453  return;
454  }
455  std::string strVal = to_string(thisVal);
456  if(strVal.size()>2&& strVal[0]=='"'&& strVal[strVal.size()-1]=='"')
457  strVal=strVal.substr(1,strVal.size()-2);
458  if((strVal.compare("NULL")==0||strVal.compare("null")==0)&&
459  (typespec==TypeId::Bool || typespec==TypeId::Int16 || typespec==TypeId::UInt16
460  || typespec==TypeId::Int32 || typespec==TypeId::UInt32
461  || typespec==TypeId::Int64 || typespec==TypeId::UInt63
462  || typespec==TypeId::Float || typespec==TypeId::Double)){
463  m_row[colName] ="NULL";
464  return;
465  }
466  switch (typespec) {
467  case TypeId::Bool:
468  {
469  const bool newVal=(strVal == "true");
470  m_row[colName] = newVal;
471  break;
472  }
473  case TypeId::UChar:
474  {
475  m_row[colName]=std::stoul(strVal);
476  break;
477  }
478  case TypeId::Int16:
479  {
480  m_row[colName]=std::stol(strVal);
481  break;
482  }
483  case TypeId::UInt16:
484  {
485  m_row[colName]=std::stoul(strVal);
486  break;
487  }
488  case TypeId::Int32:
489  {
490  m_row[colName]=std::stoi(strVal);
491  break;
492  }
493  case TypeId::UInt32:
494  {
495  m_row[colName]=std::stoull(strVal);
496  break;
497  }
498  case TypeId::UInt63:
499  {
500  m_row[colName]=std::stoull(strVal);
501  break;
502  }
503  case TypeId::Int64:
504  {
505  m_row[colName]=std::stoll(strVal);
506  break;
507  }
508  case TypeId::Float:
509  {
510  m_row[colName]=std::stof(strVal);
511  break;
512  }
513  case TypeId::Double:
514  {
515  m_row[colName]=std::stod(strVal);
516  break;
517  }
518  case TypeId::String255:
519  case TypeId::String4k:
520  case TypeId::String64k:
521  case TypeId::String16M:
522  case TypeId::String128M:
523  {
524  m_row[colName]=thisVal.get<std::string>();
525  break;
526  }
527  case TypeId::Blob128M:
528  case TypeId::Blob16M:
529  case TypeId::Blob64k:
530  {
531  m_row[colName]=thisVal.get<std::string>();
532  break;
533  }
534  default:
535  {
536  throw std::runtime_error("UNTREATED TYPE!");
537  break;
538  }
539  }
540 
541  }
542  catch(json::exception& e){
543  std::cerr << e.what() << std::endl;
544  throw std::runtime_error(e.what());
545  }
546 }

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

283 {
284  if (m_isVectorPayload)
285  {
286  m_vector_data.push_back(m_row);
287  m_row.clear();
288  }
289  else
290  {
291  std::string msg = "The payload is not a vector.";
292  throw CommonCrestException(msg.c_str());
293  }
294 }

◆ read_json_from_file()

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

It reads a json file and returns the json object.

Definition at line 418 of file CrestContainer.cxx.

419 {
420 
421  std::ifstream specfile(spec_filename);
422  nlohmann::json jspec;
423  if (specfile.is_open())
424  {
425  specfile >> jspec;
426  specfile.close();
427  }
428  else
429  {
430  std::cerr << "CondContainer::read_json_from_file: Error opening file: " << spec_filename << std::endl;
431  }
432  // Set the payload spec
433  setPayloadSpec(jspec);
434  // Read data file
435  std::ifstream file(filename);
436  nlohmann::json j;
437  if (file.is_open())
438  {
439  file >> j;
440  file.close();
441  }
442  else
443  {
444  std::cerr << "CondContainer::read_json_from_file: Error opening file: " << filename << std::endl;
445  }
446  return j;
447 }

◆ selectIov()

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

Definition at line 222 of file CrestContainer.cxx.

222  {
223  m_iov_data["since"]=since;
225 }

◆ setIovData()

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

Definition at line 328 of file CrestContainer.cxx.

329 {
330  m_iov_data = j;
331 }

◆ setPayload()

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

Definition at line 333 of file CrestContainer.cxx.

334 {
335  m_payload = j;
336 }

◆ setPayloadSpec()

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

Definition at line 365 of file CrestContainer.cxx.

366 {
367  if (j.is_array())
368  {
369  for (const auto &column : j)
370  {
371  for (const auto &[name, type] : column.items())
372  {
373  addColumn(name, static_cast<TypeId>(std::stoi(type.get<std::string>())));
374  }
375  }
376  }
377  else
378  {
379  for (const auto &[name, type] : j.items())
380  {
381  addColumn(name, static_cast<TypeId>(type.get<int>()));
382  }
383  }
384 }

◆ setVectorPayload()

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

Definition at line 27 of file CrestContainer.cxx.

28 {
30 }

◆ stringToTypeId()

Crest::TypeId Crest::CrestContainer::stringToTypeId ( const std::string &  type) const

Definition at line 32 of file CrestContainer.cxx.

33 {
34  for(auto& t: s_typeToString){
35  if(t.second.compare(type)==0)
36  return t.first;
37  }
38  throw CommonCrestException("The type of parameter is not defined.");
39 }

◆ validatePayloadSize()

void Crest::CrestContainer::validatePayloadSize ( const nlohmann::json data) const
private

Definition at line 189 of file CrestContainer.cxx.

190 {
191  if (!data.is_array())
192  throw CommonCrestException("The format of data is wrong. It should be the vector (size 1 for non vector payload)");
193  if (!m_isVectorPayload && m_vector_data.size() > 1)
194  {
195  throw CommonCrestException("The payload is not a vector, but the size seems to be larger than 1....");
196  }
197 }

Member Data Documentation

◆ m_full_data

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

Definition at line 61 of file CrestContainer.h.

◆ m_iov_data

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

Definition at line 59 of file CrestContainer.h.

◆ m_isVectorPayload

bool Crest::CrestContainer::m_isVectorPayload =false
private

Definition at line 63 of file CrestContainer.h.

◆ m_modeId

ModeId Crest::CrestContainer::m_modeId
private

Definition at line 62 of file CrestContainer.h.

◆ m_payload

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

Definition at line 57 of file CrestContainer.h.

◆ m_payload_spec

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

Definition at line 56 of file CrestContainer.h.

◆ m_row

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

Definition at line 58 of file CrestContainer.h.

◆ m_vector_data

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

Definition at line 60 of file CrestContainer.h.


The documentation for this class was generated from the following files:
Crest::CrestContainer::stringToTypeId
Crest::TypeId stringToTypeId(const std::string &type) const
Definition: CrestContainer.cxx:32
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Crest::CrestContainer::addData
void addData(const char *channel_id)
It associate the payload row to a channel_id.
Definition: CrestContainer.cxx:160
json
nlohmann::json json
Definition: CrestContainer.cxx:15
Crest::CrestContainer::setPayloadSpec
void setPayloadSpec(const nlohmann::json &j)
Definition: CrestContainer.cxx:365
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:79
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
Crest::CrestContainer::parseOldFormat
void parseOldFormat(std::string &colName, TypeId &typespec, const nlohmann::json &j)
Definition: CrestContainer.cxx:449
Crest::TypeId::UInt16
@ UInt16
json
nlohmann::json json
Definition: HistogramDef.cxx:9
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
Crest::TypeId::Blob128M
@ Blob128M
index
Definition: index.py:1
Crest::CrestContainer::m_payload
nlohmann::json m_payload
Definition: CrestContainer.h:57
Crest::CrestContainer::m_full_data
nlohmann::json m_full_data
Definition: CrestContainer.h:61
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
Crest::CrestContainer::getRow
const nlohmann::json & getRow()
Definition: CrestContainer.cxx:296
skel.it
it
Definition: skel.GENtoEVGEN.py:396
Crest::TypeId::UInt63
@ UInt63
DeMoUpdate.column
dictionary column
Definition: DeMoUpdate.py:1110
Crest::CrestContainer::getPayload
const nlohmann::json & getPayload()
Definition: CrestContainer.cxx:304
Crest::CrestContainer::isVectorPayload
bool isVectorPayload()
It sets the mode of the container.
Definition: CrestContainer.cxx:23
athena.value
value
Definition: athena.py:124
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Crest::CrestContainer::flush
void flush()
It reinitializes the containers.
Definition: CrestContainer.cxx:386
x
#define x
python.AtlRunQueryParser.ap
ap
Definition: AtlRunQueryParser.py:826
Crest::TypeId::String16M
@ String16M
Crest::CrestContainer::getColumnIndex
int getColumnIndex(const std::string &name)
It returns the index of the column with the given name.
Definition: CrestContainer.cxx:266
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
Crest::CrestContainer::m_vector_data
nlohmann::json m_vector_data
Definition: CrestContainer.h:60
Crest::CrestContainer::m_iov_data
nlohmann::json m_iov_data
Definition: CrestContainer.h:59
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
Crest::TypeId::String255
@ String255
Crest::TypeId::Blob64k
@ Blob64k
Crest::TypeId::Float
@ Float
Crest::TypeId::Bool
@ Bool
Crest::TypeId::Blob16M
@ Blob16M
Crest::CrestContainer::m_modeId
ModeId m_modeId
Definition: CrestContainer.h:62
lumiFormat.i
int i
Definition: lumiFormat.py:85
Crest::TypeId::UChar
@ UChar
Crest::TypeId::UInt32
@ UInt32
calibdata.exception
exception
Definition: calibdata.py:496
createCoolChannelIdFile.channel_id
channel_id
Definition: createCoolChannelIdFile.py:52
file
TFile * file
Definition: tile_monitor.h:29
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
Crest::TypeId::Int32
@ Int32
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:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
Crest::CrestContainer::validatePayloadSize
void validatePayloadSize(const nlohmann::json &data) const
Definition: CrestContainer.cxx:189
Crest::CrestContainer::addExternalData
void addExternalData(const char *channel_id, const nlohmann::json &data)
It associate the payload row to a channel_id.
Definition: CrestContainer.cxx:165
Crest::ModeId::Standard
@ Standard
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Crest::TypeId::Int64
@ Int64
DeMoScan.index
string index
Definition: DeMoScan.py:364
Crest::TypeId::String64k
@ String64k
Crest::TypeId::TypeIdCount
@ TypeIdCount
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Crest::CrestContainer::m_payload_spec
std::vector< std::pair< std::string, TypeId > > m_payload_spec
Definition: CrestContainer.h:56
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
TypeId
Definition: IdDictMgr.cxx:29
Crest::CrestContainer::createRowArray
nlohmann::json createRowArray(const nlohmann::json &data_row) const
Definition: CrestContainer.cxx:199
Crest::TypeId::String4k
@ String4k
Crest::TypeId::Int16
@ Int16
calibdata.copy
bool copy
Definition: calibdata.py:27
Crest::CrestContainer::addIov
void addIov(const uint64_t since)
It adds an IOV to the json object m_iov_data.
Definition: CrestContainer.cxx:214
Crest::TypeId
TypeId
Definition: CrestContainer.h:24
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
Crest::CrestContainer::m_isVectorPayload
bool m_isVectorPayload
Definition: CrestContainer.h:63
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Crest::CrestContainer::m_row
nlohmann::json m_row
Definition: CrestContainer.h:58
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
Crest::TypeId::Double
@ Double
Crest::CrestContainer::putRow2Vector
void putRow2Vector()
It adds row data to vector.
Definition: CrestContainer.cxx:282