ATLAS Offline Software
Loading...
Searching...
No Matches
IOVDbParser Class Reference

#include <IOVDbParser.h>

Collaboration diagram for IOVDbParser:

Public Member Functions

 IOVDbParser ()=delete
 IOVDbParser (const std::string &input, MsgStream &log)
bool isValid () const
std::pair< std::string, bool > at (const std::string &searchKey, const std::string &defaultValue="") const
 'at' accessor with an optional default; the bool is true if the key was found
bool getKey (const std::string &key, const std::string &devvalue, std::string &value) const
 original 'getKey' method, now implemented using 'at'
std::string folderName () const
 give the folder name contained in the parsed description
std::string key () const
bool hasKey () const
std::string tag () const
std::string eventStoreName () const
bool timebaseIs_nsOfEpoch () const
std::string cache () const
int cachehint () const
bool named () const
std::string addressHeader () const
std::vector< std::string > symLinks () const
bool noTagOverride () const
CLID classId (MsgStream &msg) const
bool onlyReadMetadata () const
bool extensible () const
unsigned applyOverrides (const IOVDbParser &other, MsgStream &log)
bool overridesIov (MsgStream &msg) const
 return true if this description overrides the timestamp or runlumi
bool overridesIov (MsgStream &msg, const bool folderIs_nsOfEpoch) const
 as for overridesIov(), but with a check that the folder time unit is compatible with the override time unit
unsigned long long iovOverrideValue (MsgStream &msg) const
bool operator== (const IOVDbParser &other) const
std::string toString () const

Private Types

typedef std::map< std::string, std::string, std::less<> > KeyValMap

Private Member Functions

bool overridesIovImpl (MsgStream &msg, const bool performFolderCheck, const bool folderIs_nsOfEpoch=true) const
 implementation of overridesIov, with or without check on folder compatibility

Private Attributes

bool m_valid {}
KeyValMap m_keys

Detailed Description

Definition at line 19 of file IOVDbParser.h.

Member Typedef Documentation

◆ KeyValMap

typedef std::map<std::string, std::string, std::less<> > IOVDbParser::KeyValMap
private

Definition at line 59 of file IOVDbParser.h.

Constructor & Destructor Documentation

◆ IOVDbParser() [1/2]

IOVDbParser::IOVDbParser ( )
delete

◆ IOVDbParser() [2/2]

IOVDbParser::IOVDbParser ( const std::string & input,
MsgStream & log )

Definition at line 12 of file IOVDbParser.cxx.

12 :
13 m_valid(true)
14{
15 // parse the input string as XML, decode into Key/Value pairs
16 m_keys.clear();
17 // slot for the data outside of XML
18 m_keys[""]="";
19 // work through the string to build list of tags
20 std::string::size_type iofs=0;
21 std::string::size_type len=input.size();
22 while (iofs!=std::string::npos && iofs<len) {
23 // look for the start of the next XML tag
24 std::string::size_type iofs1=input.find('<',iofs);
25 if (iofs1>iofs && iofs1!=std::string::npos) {
26 // take any unmarked-up text into the 'outside' data slot
27 m_keys[""]+=IOVDbNamespace::spaceStrip(input.substr(iofs,iofs1-iofs));
28 }
29 if (iofs1!=std::string::npos) {
30 // have an opening XML tag - process it
31 // first find the end of the tag, either '>' or ' ', whichever first
32 std::string::size_type iofs2=input.find('>',iofs1);
33 std::string::size_type iofs3=input.find("/>",iofs1);
34 bool noClosingTag = (iofs2 == std::string::npos);
35 if (noClosingTag){
36 log << MSG::FATAL <<
37 "Badly formed XML string, no closing tag in " << input << endmsg;
38 m_valid=false;
39 iofs=std::string::npos;
40 return;
41 }
42 if (iofs2!=std::string::npos && iofs2<iofs3) {
43 // found a closing >, so tag is standard <tag>value</tag> form
44 std::string tag=IOVDbNamespace::spaceStrip(input.substr(iofs1+1,iofs2-iofs1-1));
45 // now need to find the closing </tag>
46 std::string::size_type iofs4=input.find("</"+tag,iofs2+1);
47 if (iofs4!=std::string::npos) {
48 // found closing tag, store tag and text
49 m_keys[tag]=IOVDbNamespace::spaceStrip(input.substr(iofs2+1,iofs4-iofs2-1));
50 // advance to the next part of the string, after '>' on closing tag
51 iofs=input.find('>',iofs4);
52 if (iofs == std::string::npos) {
53 log << MSG::FATAL <<
54 "Badly formed XML string, no closing tag in " << input << endmsg;
55 m_valid=false;
56 iofs=std::string::npos;
57 return;
58 } else {
59 iofs+=1;
60 }
61 } else {
62 log << MSG::FATAL <<
63 "Badly formed XML string, no closing tag in " << input << endmsg;
64 m_valid=false;
65 iofs=std::string::npos;
66 return;
67 }
68 } else if (iofs3!=std::string::npos) {
69 // found a />, so tag is of form <tag values info/>
70 // find the end of the tag part to see if a value is present
71 std::string::size_type iofs4=input.find(' ',iofs1+1);
72 std::string value,tag;
73 if (iofs4!=std::string::npos && iofs4<iofs3) {
74 value=IOVDbNamespace::spaceStrip(input.substr(iofs4,iofs3-iofs4));
75 tag=IOVDbNamespace::spaceStrip(input.substr(iofs1+1,iofs4-iofs1-1));
76 } else {
77 tag=input.substr(iofs1+1,iofs3-iofs1-1);
78 value="";
79 }
81 // advance to next part of string after closing />
82 iofs=iofs3+2;
83 } else {
84 // found a < but no closing >
85 log << MSG::FATAL << "Badly formed XML string, no closing > in input " <<
86 input << endmsg;
87 iofs=std::string::npos;
88 m_valid=false;
89 return;
90 }
91 } else {
92 // no more < in input, take the rest into 'outside' data slot
93 m_keys[""]+=IOVDbNamespace::spaceStrip(input.substr(iofs));
94 iofs=len;
95 }
96 }
97
98 if (log.level()<=MSG::VERBOSE) {
99 log << MSG::VERBOSE << "parseXML processed input string: " << input << endmsg;
100 for (KeyValMap::const_iterator itr=m_keys.begin();itr!=m_keys.end();++itr) {
101 log << MSG::VERBOSE << "Key: " << itr->first << " value:" <<
102 itr->second << endmsg;
103 }
104 }
105}
#define endmsg
KeyValMap m_keys
Definition IOVDbParser.h:60
std::string tag() const
std::string spaceStrip(const std::string &input)
Trim leading and trailing spaces,return a new trimmed string.

Member Function Documentation

◆ addressHeader()

std::string IOVDbParser::addressHeader ( ) const

Definition at line 206 of file IOVDbParser.cxx.

206 {
207 return at("addrHeader").first;
208}
std::pair< std::string, bool > at(const std::string &searchKey, const std::string &defaultValue="") const
'at' accessor with an optional default; the bool is true if the key was found

◆ applyOverrides()

unsigned IOVDbParser::applyOverrides ( const IOVDbParser & other,
MsgStream & log )

Definition at line 223 of file IOVDbParser.cxx.

223 {
224 unsigned keyCounter=0;
225 for (const auto& otherKeyValue : other.m_keys) {
226 const std::string& otherKey=otherKeyValue.first;
227 const std::string& otherValue=otherKeyValue.second;
228 if (otherKey.empty()) continue; //Ignore Foldername
229 if (otherKey=="prefix") continue; //Ignore prefix
230 KeyValMap::iterator it=m_keys.find(otherKey);
231 if (it==m_keys.end()) {
232 log << MSG::INFO << "Folder " << m_keys[""] << ", adding new key " << otherKey
233 << " with value " << otherValue << endmsg;
234 m_keys[otherKey]=otherValue;
235 }
236 else {
237 log << MSG::INFO << "Folder " << m_keys[""] << ", Key: " << otherKey
238 << "Overriding existing value " << m_keys[otherKey] << " to new value " << otherValue << endmsg;
239 it->second=otherValue;
240 }
241 ++keyCounter;
242 } //End loop over keys in other
243 return keyCounter;
244}

◆ at()

std::pair< std::string, bool > IOVDbParser::at ( const std::string & searchKey,
const std::string & defaultValue = "" ) const

'at' accessor with an optional default; the bool is true if the key was found

Definition at line 123 of file IOVDbParser.cxx.

123 {
124 KeyValMap::const_iterator it = m_keys.find(searchKey);
125 if (it != m_keys.end()) {
126 //may contain return or newline character
127 return std::pair<std::string, bool>(IOVDbNamespace::spaceStrip(it->second), true);
128 }
129 return std::pair<std::string, bool> (defaultValue, false);
130}

◆ cache()

std::string IOVDbParser::cache ( ) const

Definition at line 163 of file IOVDbParser.cxx.

163 {
164 return at("cache").first;
165}

◆ cachehint()

int IOVDbParser::cachehint ( ) const

Definition at line 168 of file IOVDbParser.cxx.

168 {
169 auto valuePair=at("cachehint");
170 return valuePair.second ? std::stoi(valuePair.first) : 0;
171}

◆ classId()

CLID IOVDbParser::classId ( MsgStream & msg) const

Definition at line 190 of file IOVDbParser.cxx.

190 {
191 CLID result{};
192 auto [addrHeader,foundHeader]=at("addrHeader");
193 if (foundHeader) {
195 msg << MSG::DEBUG <<"Decode addrHeader "<< addrHeader << endmsg;
196 IOVDbParser addrH(addrHeader,msg);
197 if (auto addrPair=addrH.at("address_header");addrPair.second) {
198 result = IOVDbNamespace::parseClid(addrPair.first);
199 msg << MSG::DEBUG << "Got CLID " << result << " from " << addrPair.first << endmsg;
200 }
201 }
202 return result;
203}
uint32_t CLID
The Class ID type.
IOVDbParser()=delete
bool replaceServiceType71(std::string &addrHeader)
int parseClid(const std::string &addrHeaderStr)
Extract the Class ID (an integer) from a string of form <addrHeader><address_header service_type="256...
MsgStream & msg
Definition testRead.cxx:32

◆ eventStoreName()

std::string IOVDbParser::eventStoreName ( ) const

Definition at line 153 of file IOVDbParser.cxx.

153 {
154 return at("eventStoreName","StoreGateSvc").first;
155}

◆ extensible()

bool IOVDbParser::extensible ( ) const

Definition at line 184 of file IOVDbParser.cxx.

184 {
185 return at("extensible").second;
186}

◆ folderName()

std::string IOVDbParser::folderName ( ) const

give the folder name contained in the parsed description

Definition at line 133 of file IOVDbParser.cxx.

133 {
134 return at("").first;
135}

◆ getKey()

bool IOVDbParser::getKey ( const std::string & key,
const std::string & devvalue,
std::string & value ) const

original 'getKey' method, now implemented using 'at'

Definition at line 108 of file IOVDbParser.cxx.

109 {
110 // check if key is present in keyval, if so set value to it
111 // if not set value to supplied default
112 // return true or false depending on whether a matching key was found
113 if (!m_valid) {
114 value=defvalue;
115 return false;
116 }
117 auto [theValue,found] = at(key,defvalue);
118 value=std::move(theValue);
119 return found;
120}
std::string key() const

◆ hasKey()

bool IOVDbParser::hasKey ( ) const

Definition at line 143 of file IOVDbParser.cxx.

143 {
144 return at("key").second;
145}

◆ iovOverrideValue()

unsigned long long IOVDbParser::iovOverrideValue ( MsgStream & msg) const

Definition at line 291 of file IOVDbParser.cxx.

291 {
292 unsigned long long value{};
293 if (not overridesIov(msg)) return value;
294 auto pTsPair = m_keys.find("forceTimestamp");
295 if (pTsPair!=m_keys.end()){
296 value = IOVDbNamespace::iovFromTimeString(pTsPair->second);
297 }
298 else {
299 auto pRunPair = m_keys.find("forceRunNumber");
300 auto pLumiPair = m_keys.find("forceLumiblockNumber");
301 const auto & runString = (pRunPair!=m_keys.end()) ? pRunPair->second : "";
302 const auto & lumiString = (pLumiPair!=m_keys.end()) ? pLumiPair->second : "";
303 //could check that values were actually given here
305 }
306 return value;
307}
bool overridesIov(MsgStream &msg) const
return true if this description overrides the timestamp or runlumi
unsigned long long iovFromRunString(const std::string &runString)
Take a string run number and convert it to an ULL representing run<<32.
unsigned long long iovFromLumiBlockString(const std::string &lbString)
String representation of lumiblock just converted to LL (as in original code) and returned as a ULL.
unsigned long long iovFromTimeString(const std::string &iovString)
Take a string integer giving a time in seconds and convert it to a ULL in nanoseconds.

◆ isValid()

bool IOVDbParser::isValid ( ) const
inline

Definition at line 66 of file IOVDbParser.h.

66{ return m_valid; }

◆ key()

std::string IOVDbParser::key ( ) const

Definition at line 138 of file IOVDbParser.cxx.

138 {
139 return at("key",folderName()).first;
140}
std::string folderName() const
give the folder name contained in the parsed description

◆ named()

bool IOVDbParser::named ( ) const

Definition at line 174 of file IOVDbParser.cxx.

174 {
175 return at("named").second;
176}

◆ noTagOverride()

bool IOVDbParser::noTagOverride ( ) const

Definition at line 217 of file IOVDbParser.cxx.

217 {
218 return at("noover").second;
219}

◆ onlyReadMetadata()

bool IOVDbParser::onlyReadMetadata ( ) const

Definition at line 179 of file IOVDbParser.cxx.

179 {
180 return at("metaOnly").second;
181}

◆ operator==()

bool IOVDbParser::operator== ( const IOVDbParser & other) const

Definition at line 247 of file IOVDbParser.cxx.

247 {
248 return ((this->m_keys) == other.m_keys);
249}

◆ overridesIov() [1/2]

bool IOVDbParser::overridesIov ( MsgStream & msg) const

return true if this description overrides the timestamp or runlumi

Definition at line 252 of file IOVDbParser.cxx.

252 {
253 //no check on folder time unit compatibility
254 return overridesIovImpl(msg, false);
255}
bool overridesIovImpl(MsgStream &msg, const bool performFolderCheck, const bool folderIs_nsOfEpoch=true) const
implementation of overridesIov, with or without check on folder compatibility

◆ overridesIov() [2/2]

bool IOVDbParser::overridesIov ( MsgStream & msg,
const bool folderIs_nsOfEpoch ) const

as for overridesIov(), but with a check that the folder time unit is compatible with the override time unit

Definition at line 258 of file IOVDbParser.cxx.

258 {
259 //check folder time unit compatibility
260 return overridesIovImpl(msg ,true, folderIs_nsOfEpoch);
261}

◆ overridesIovImpl()

bool IOVDbParser::overridesIovImpl ( MsgStream & msg,
const bool performFolderCheck,
const bool folderIs_nsOfEpoch = true ) const
private

implementation of overridesIov, with or without check on folder compatibility

Definition at line 264 of file IOVDbParser.cxx.

264 {
265 bool overrideIs_nsEpochIov{true};
266 const bool overridingTimestamp=(m_keys.find("forceTimestamp")!=m_keys.end());
267 const bool overridingRun=(m_keys.find("forceRunNumber")!=m_keys.end());
268 const bool overridingLumi=(m_keys.find("forceLumiblockNumber")!=m_keys.end());
269 //check for nonsense scenarios:
270 //1. overriding Lumi but not the Run number
271 if (overridingLumi and not overridingRun){
272 msg << MSG::WARNING<<"Trying to override lumi block without specifying the run"<<endmsg;
273 return false;
274 }
275 //2. Trying to override both
276 if (overridingRun and overridingTimestamp){
277 msg << MSG::WARNING<<"Trying to override using both run-lumi and ns timestamp"<<endmsg;
278 return false;
279 }
280 // now we are consistent, so set the 'is_ns' variable if it's different from default
281 if (overridingRun) overrideIs_nsEpochIov=false;
282 //3. Overriding a folder in ns format with a run-lumi IOV, or folder in run-lumi with ns timestamp
283 if (performFolderCheck and (overrideIs_nsEpochIov != folderIs_nsOfEpoch)){
284 msg << MSG::WARNING<<"Trying to override run-lumi for a ns folder, or ns for a run-lumi folder"<<endmsg;
285 return false;
286 }
287 return (overridingTimestamp or overridingRun);
288}

◆ symLinks()

std::vector< std::string > IOVDbParser::symLinks ( ) const

Definition at line 211 of file IOVDbParser.cxx.

211 {
212 const auto & symLinkString = at("symlinks").first;
213 return IOVDbNamespace::parseLinkNames(symLinkString);
214}
std::vector< std::string > parseLinkNames(const std::string &linktext)
Parse string of format "A:X::B:C" to "A" , "X::B", "C".

◆ tag()

std::string IOVDbParser::tag ( ) const

Definition at line 148 of file IOVDbParser.cxx.

148 {
149 return at("tag").first;
150}

◆ timebaseIs_nsOfEpoch()

bool IOVDbParser::timebaseIs_nsOfEpoch ( ) const

Definition at line 158 of file IOVDbParser.cxx.

158 {
159 return (at("timeStamp").first=="time");
160}

◆ toString()

std::string IOVDbParser::toString ( ) const

Definition at line 310 of file IOVDbParser.cxx.

310 {
311 std::stringstream retval;
312 retval <<"Folder:";
313 retval << folderName();
314 retval << ", Attributes: ";
315 auto it=m_keys.begin();
316 auto it_e=m_keys.end();
317 for (;it!=it_e;++it) {
318 if (it->first.empty()) continue;
319 retval << "[" << it->first << ":" << it->second << "] ";
320 }
321 return retval.str();
322
323}

Member Data Documentation

◆ m_keys

KeyValMap IOVDbParser::m_keys
private

Definition at line 60 of file IOVDbParser.h.

◆ m_valid

bool IOVDbParser::m_valid {}
private

Definition at line 58 of file IOVDbParser.h.

58{};

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