ATLAS Offline Software
IOVDbJsonStringFunctions.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
5 #include <regex>
6 #include <iostream>
7 #include <algorithm>
8 #include "IOVDbStringFunctions.h"
9 #include "Base64Codec.h"
10 #include "CoralBase/Blob.h"
11 #include "FolderTypes.h"
12 
13 namespace IOVDbNamespace{
14  std::string
15  jsonAttribute(const coral::Attribute & attr){
16  std::ostringstream os;
17  attr.toOutputStream(os);
18  const std::string native=os.str();
19  const bool stringPayload=(native.find(" (string) ") != std::string::npos);
20  const bool blobPayload=(native.find(" (blob) ") != std::string::npos);
21  //take away anything between brackets in the original
22  const std::string regex=R"delim( \‍(.*\))delim";
23  const std::string deleted= deleteRegex(native,regex);
24  const std::string sep(" : ");
25  const auto separatorPosition = deleted.find(sep);
26  const std::string payloadOnly=deleted.substr(separatorPosition+3);
27  if (stringPayload) return quote(sanitiseJsonString(payloadOnly));
28  if (blobPayload){
29  return quote(IOVDbNamespace::base64Encode(attr.data<coral::Blob>()));
30  }
31  std::string result(payloadOnly);
32  if (result=="NULL"){
33  result="null";
34  }
35 
36  return result;
37  }
38 
39  std::string
41  std::string os("[");
42  const unsigned int nelement=atrlist.size();
43  std::string delimiter(" ");
44  for (unsigned int i(0);i!=nelement;++i){
45  if (i==1) delimiter = s_delimiterJson;
46  os+=delimiter;
47  os+=jsonAttribute(atrlist[i]);
48  }
49  os+="]";
50  return os;
51  }
52 
53 }
54 
IOVDbNamespace::base64Encode
std::string base64Encode(const coral::Blob &blob)
Definition: Base64Codec.cxx:18
get_generator_info.result
result
Definition: get_generator_info.py:21
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
IOVDbNamespace::deleteRegex
std::string deleteRegex(const std::string &original, const std::string &regex)
Delete characters of a matching regex from the input string.
Definition: IOVDbStringFunctions.cxx:79
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
IOVDbNamespace::sanitiseJsonString
std::string sanitiseJsonString(const std::string &dataString)
Sanitise json string, escaping raw carriage returns.
Definition: IOVDbStringFunctions.cxx:52
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
IOVDbStringFunctions.h
IOVDbJsonStringFunctions.h
python.AthDsoLogger.delimiter
delimiter
Definition: AthDsoLogger.py:71
lumiFormat.i
int i
Definition: lumiFormat.py:85
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
grepfile.sep
sep
Definition: grepfile.py:38
Base64Codec.h
IOVDbNamespace::jsonAttributeList
std::string jsonAttributeList(const coral::AttributeList &atrlist)
Produce a representation of a coral::AttributeList as a json string.
Definition: IOVDbJsonStringFunctions.cxx:40
IOVDbNamespace::jsonAttribute
std::string jsonAttribute(const coral::Attribute &attr)
Produce a representation of a coral::Attribute as a json string.
Definition: IOVDbJsonStringFunctions.cxx:15
FolderTypes.h
IOVDbNamespace::quote
std::string quote(const std::string &sentence)
Enclose a string in ".
Definition: IOVDbStringFunctions.cxx:85
IOVDbNamespace
Definition: Base64Codec.cxx:16