ATLAS Offline Software
Loading...
Searching...
No Matches
IOVDbNamespace::Cool2Json Class Reference

#include <Cool2Json.h>

Collaboration diagram for IOVDbNamespace::Cool2Json:

Public Member Functions

 Cool2Json (const cool::IFolderPtr &pFolder, const cool::ValidityKey &since, const cool::ValidityKey &until, const cool::ChannelSelection &m_chansel, const std::string &folderTag)
std::string description () const
 Folder description string.
const std::string & payloadSpec () const
 Payload specification for this folder.
std::string payload ()
 Payload (data for the given channel selection and iov)
std::string iov () const
 Formatted iov as '[<since>, <until>]'.
unsigned int nchans () const
 Number of channels in the folder.
std::string iovBase () const
 'time' (ns of epoch) or 'run-lumi'
const std::string & tag () const
 Simply the tag string passed to the constructor.

Static Public Member Functions

static std::string open ()
 json open tag, '{'
static std::string close ()
 json close tag, '}'
static std::string delimiter ()
 json standard delimiter ', '

Private Types

enum  FolderType {
  AttrList =0 , AttrListColl , PoolRef , PoolRefColl ,
  CoraCool , CoolVector , JSON , NUM_FOLDER_TYPES
}

Static Private Member Functions

static std::string formatCvp (const cool::IObjectIteratorPtr &itr)
static std::string formatAttrList (const cool::IObjectIteratorPtr &itr)
static std::string formatPoolRef (const cool::IObjectIteratorPtr &itr)

Private Attributes

const cool::IFolderPtr m_pFolder
const cool::ValidityKey m_start
const cool::ValidityKey m_stop
const cool::ChannelSelection m_chansel
const std::string m_tag
const std::string m_desc
const std::string m_spec
unsigned int m_nchans

Friends

std::ostream & operator<< (std::ostream &o, const Cool2Json &c)

Detailed Description

Definition at line 26 of file Cool2Json.h.

Member Enumeration Documentation

◆ FolderType

Enumerator
AttrList 
AttrListColl 
PoolRef 
PoolRefColl 
CoraCool 
CoolVector 
JSON 
NUM_FOLDER_TYPES 

Definition at line 70 of file Cool2Json.h.

Constructor & Destructor Documentation

◆ Cool2Json()

IOVDbNamespace::Cool2Json::Cool2Json ( const cool::IFolderPtr & pFolder,
const cool::ValidityKey & since,
const cool::ValidityKey & until,
const cool::ChannelSelection & m_chansel,
const std::string & folderTag )

Definition at line 59 of file Cool2Json.cxx.

63 :
64 m_pFolder(pFolder),
65 m_start(since),
66 m_stop(until),
67 m_chansel(chansel),
68 m_tag(folderTag),
69 m_desc(pFolder->description()),
70 m_spec(spec2String(pFolder)),
71 m_nchans(0){
72 const auto & channums=pFolder->listChannels();
73 //find channels in the chansel which are chan nums
74 //theres no 'size' method in the ChannelSelection class
75 for (const auto &i:channums){
76 m_nchans+=m_chansel.inSelection(i);//bool casts to 0 or 1
77 }
78 }
const cool::ChannelSelection m_chansel
Definition Cool2Json.h:83
const std::string m_spec
Definition Cool2Json.h:86
const cool::ValidityKey m_stop
Definition Cool2Json.h:82
const cool::IFolderPtr m_pFolder
Definition Cool2Json.h:80
const cool::ValidityKey m_start
Definition Cool2Json.h:81
const std::string m_tag
Definition Cool2Json.h:84
const std::string m_desc
Definition Cool2Json.h:85

Member Function Documentation

◆ close()

std::string IOVDbNamespace::Cool2Json::close ( )
static

json close tag, '}'

◆ delimiter()

std::string IOVDbNamespace::Cool2Json::delimiter ( )
static

json standard delimiter ', '

◆ description()

std::string IOVDbNamespace::Cool2Json::description ( ) const

Folder description string.

Definition at line 81 of file Cool2Json.cxx.

81 {
82 std::string saneXml=sanitiseXml(m_desc);
83 saneXml = std::regex_replace(saneXml, std::regex("\\\\\""), "\"");
84 std::string out = "\"node_description\" : \"";
85 out += saneXml;
86 out += '\"';
87 return out;
88 }
std::string sanitiseXml(const std::string &pseudoXmlString)
for use when converting cool folder description JSON

◆ formatAttrList()

std::string IOVDbNamespace::Cool2Json::formatAttrList ( const cool::IObjectIteratorPtr & itr)
staticprivate

Definition at line 176 of file Cool2Json.cxx.

176 {
177 const cool::IObject& ref=itr->currentRef();
178 const coral::AttributeList& atrlist=ref.payload().attributeList();
179 std::string sep="";
180 return IOVDbNamespace::jsonAttributeList(atrlist);
181 }
const boost::regex ref(r_ef)
std::string jsonAttributeList(const coral::AttributeList &atrlist)
Produce a representation of a coral::AttributeList as a json string.

◆ formatCvp()

std::string IOVDbNamespace::Cool2Json::formatCvp ( const cool::IObjectIteratorPtr & itr)
staticprivate

Definition at line 158 of file Cool2Json.cxx.

158 {
159 std::string os;
160 const cool::IObject& ref=itr->currentRef();
161 cool::IRecordIterator& pitr=ref.payloadIterator();
162 auto pvec=pitr.fetchAllAsVector();
163 std::string sep="";
164 os+='[';//vector of vectors
165 for (const auto & vitr:*pvec){
166 os+=sep;
167 const coral::AttributeList& atrlist=(vitr)->attributeList();
170 }
171 os+=']';
172 return os;
173 }
std::array< fp_t, 2 > pvec
static const std::string s_delimiterJson
json standard delimiter ', '

◆ formatPoolRef()

std::string IOVDbNamespace::Cool2Json::formatPoolRef ( const cool::IObjectIteratorPtr & itr)
staticprivate

Definition at line 184 of file Cool2Json.cxx.

184 {
185 const cool::IObject& ref=itr->currentRef();
186 const coral::AttributeList& atrlist=ref.payload().attributeList();
187 std::ostringstream os;
188 atrlist[0].toOutputStream(os);
189 auto res=os.str();
190 const std::string sep(" : ");
191 const auto separatorPosition = res.find(sep);
192 const std::string payloadOnly=res.substr(separatorPosition+3);
193 return quote(payloadOnly);
194 }
std::pair< std::vector< unsigned int >, bool > res
std::string quote(const std::string &sentence)
Enclose a string in ".

◆ iov()

std::string IOVDbNamespace::Cool2Json::iov ( ) const

Formatted iov as '[<since>, <until>]'.

Definition at line 197 of file Cool2Json.cxx.

197 {
198 std::string iovString("\"iov\" : ");
199 return iovString+"["+std::to_string(m_start)+", "+std::to_string(m_stop)+"]";
200 }

◆ iovBase()

std::string IOVDbNamespace::Cool2Json::iovBase ( ) const

'time' (ns of epoch) or 'run-lumi'

Definition at line 143 of file Cool2Json.cxx.

143 {
144 std::string result("");
145 //run-lumi and run-event can both be found in our database, but the meaning is run-lumi
146 if (m_desc.find("<timeStamp>run-lumi</timeStamp>") != std::string::npos) result = "run-lumi";
147 if (m_desc.find("<timeStamp>run-event</timeStamp>") != std::string::npos) result = "run-lumi";
148 if (m_desc.find("<timeStamp>time</timeStamp>") != std::string::npos) result = "time";
149 return result;
150 }

◆ nchans()

unsigned int IOVDbNamespace::Cool2Json::nchans ( ) const

Number of channels in the folder.

Definition at line 138 of file Cool2Json.cxx.

138 {
139 return m_nchans;
140 }

◆ open()

std::string IOVDbNamespace::Cool2Json::open ( )
static

json open tag, '{'

◆ payload()

std::string IOVDbNamespace::Cool2Json::payload ( )

Payload (data for the given channel selection and iov)

Definition at line 97 of file Cool2Json.cxx.

97 {
98 std::string result("\"data_array\" : [");
99 cool::IObjectIteratorPtr itr=m_pFolder->browseObjects(m_start,m_stop,m_chansel,m_tag);
101 std::string sep="";
102 while (itr->goToNext()){
103 const cool::IObject& ref=itr->currentRef();
104 result+=sep;
105 const long long cId=ref.channelId();
106 result+=s_openJson+quote(std::to_string(cId))+" : ";
107 switch (ftype){
109 result+=formatCvp(itr);
110 break;
112 result +=formatAttrList(itr);
113 break;
115 result +=formatAttrList(itr);
116 break;
118 result +=formatPoolRef(itr);
119 break;
121 result += formatAttrList(itr);
122 break;
124 result += " CoraCool";
125 break;
126 default:
127 result+=" a_data_value";
128 }
129 if (sep.empty()) sep=",";
131 }
132 result+=']';
133 itr->close();
134 return result;
135 }
static std::string formatPoolRef(const cool::IObjectIteratorPtr &itr)
static std::string formatAttrList(const cool::IObjectIteratorPtr &itr)
static std::string formatCvp(const cool::IObjectIteratorPtr &itr)
FolderType determineFolderType(const std::string &folderDescription, const std::string &spec, const std::vector< cool::ChannelId > &chans)
Determine folder type with optional check using clid service to check clid matches typename.
static const std::string s_closeJson
json close tag, '}'
static const std::string s_openJson
json open tag, '{'

◆ payloadSpec()

const std::string & IOVDbNamespace::Cool2Json::payloadSpec ( ) const

Payload specification for this folder.

Definition at line 91 of file Cool2Json.cxx.

91 {
92 return m_spec;
93 }

◆ tag()

const std::string & IOVDbNamespace::Cool2Json::tag ( ) const

Simply the tag string passed to the constructor.

Definition at line 153 of file Cool2Json.cxx.

153 {
154 return m_tag;
155 }

◆ operator<<

std::ostream & operator<< ( std::ostream & o,
const Cool2Json & c )
friend

Definition at line 202 of file Cool2Json.cxx.

202 {
203 o << c.description() << std::endl;
204 return o;
205 }

Member Data Documentation

◆ m_chansel

const cool::ChannelSelection IOVDbNamespace::Cool2Json::m_chansel
private

Definition at line 83 of file Cool2Json.h.

◆ m_desc

const std::string IOVDbNamespace::Cool2Json::m_desc
private

Definition at line 85 of file Cool2Json.h.

◆ m_nchans

unsigned int IOVDbNamespace::Cool2Json::m_nchans
private

Definition at line 87 of file Cool2Json.h.

◆ m_pFolder

const cool::IFolderPtr IOVDbNamespace::Cool2Json::m_pFolder
private

Definition at line 80 of file Cool2Json.h.

◆ m_spec

const std::string IOVDbNamespace::Cool2Json::m_spec
private

Definition at line 86 of file Cool2Json.h.

◆ m_start

const cool::ValidityKey IOVDbNamespace::Cool2Json::m_start
private

Definition at line 81 of file Cool2Json.h.

◆ m_stop

const cool::ValidityKey IOVDbNamespace::Cool2Json::m_stop
private

Definition at line 82 of file Cool2Json.h.

◆ m_tag

const std::string IOVDbNamespace::Cool2Json::m_tag
private

Definition at line 84 of file Cool2Json.h.


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