ATLAS Offline Software
Loading...
Searching...
No Matches
IOVDbNamespace Namespace Reference

Classes

class  Cool2Json
class  FMDReadLock
class  IovStore

Enumerations

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

Functions

std::string base64Encode (const coral::Blob &blob)
coral::Blob base64Decode (const std::string &base64String)
std::ostream & operator<< (std::ostream &o, const Cool2Json &c)
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.
FolderType determineFolderType (const cool::IFolderPtr &pFolder, IClassIDSvc *clidsvc=nullptr)
 Determine folder type with optional check using clid service to check clid matches typename.
FolderType determineFolderType (const CondAttrListCollection *pAttrListColl)
 Determine folder type using the CondAttrListCollection pointer.
FolderType determineFolderType (const CondAttrListCollection &pAttrListColl)
 Determine folder typeusing the CondAttrListCollection reference.
FolderType determineFolderType (const coral::AttributeSpecification &spec)
 Determine folder type using the coral::AttributeSpecification.
bool poolCompatible (const cool::IRecordSpecification &rspec)
 Is the folder type compatible with Pool storage type?
bool poolCompatible (const std::string &specString)
bool poolCompatible (const CondAttrListCollection *pAttrListColl)
bool poolCompatible (const CondAttrListCollection &attrListColl)
std::string folderTypeName (const FolderType f)
 Give a string name for the folder type.
const coral::AttributeListSpecification & attrList2Spec (const coral::AttributeList &atrlist)
 return the AttributeListSpecification of an AttributeList
unsigned int attributeSize (const coral::Attribute &attribute)
 return the size (in bytes) of an Attribute
bool typeSizeIsKnown (const coral::Attribute &attribute)
 Return a bool indicating whether the size of a given Attribute can be determined.
unsigned int attributeListSize (const coral::AttributeList &atrlist)
 return the size (in bytes) of an AttributeList
int countSelectedChannels (const std::vector< cool::ChannelId > &channels, const cool::ChannelSelection &selected)
 Count the number of selected channels in a vector of channels according to cool::Channel selection.
IOVTime makeEpochOrRunLumi (const cool::ValidityKey key, const bool timeIsEpoch)
 Create an IOVTime in ns of epoch or run-lumi (determined by the bool) from a ValidityKey.
unsigned long long iovTimeFromSeconds (const unsigned long long seconds)
 Create a long long time in ns from s.
unsigned long long iovTimeFromRunLumi (const unsigned long long run, const unsigned long long lumi=0)
 Create a long long representing the IOV from run, lumi.
std::pair< unsigned long long, unsigned long long > runLumiFromIovTime (const unsigned long long iovTime)
 Return a [run,lumi] pair from an IOV time.
IOVRange makeRange (const cool::ValidityKey since, const cool::ValidityKey until, const bool timeIsEpoch)
 Make an IOVRange from two validity keys.
cool::ChannelId makeChannel (const std::string &strval, const cool::ChannelId defchan)
 Create a ChannelId from a string; if string is empty, return the default channel number given.
std::pair< bool, std::string > folderMetadata (IOVDbConn *pConnection, const std::string &folderName)
 Retrieve (bool) multiversion flag and folder description.
std::pair< std::vector< cool::ChannelId >, std::vector< std::string > > channelList (IOVDbConn *pConnection, const std::string &folderName, const bool named=false)
 Retrieve channel information.
template<class NumericType>
bool inRange (const NumericType &val, const std::pair< NumericType, NumericType > &range)
 Function to check whether a number is in the inclusive range, given as a pair.
template<class NumericType>
bool inRange (const NumericType &val, const std::vector< std::pair< NumericType, NumericType > > &ranges)
std::string jsonAttribute (const coral::Attribute &)
 Produce a representation of a coral::Attribute as a json string.
std::string jsonAttributeList (const coral::AttributeList &)
 Produce a representation of a coral::AttributeList as a json string.
std::string spaceStrip (const std::string &input)
 Trim leading and trailing spaces,return a new trimmed string.
int makeChannel (const std::string &strval, const int defchan)
 Produce a channel number from the string; default to 'defchan' if empty.
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.
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.
std::string sanitiseJsonString (const std::string &dataString)
 Sanitise json string, escaping raw carriage returns.
int parseClid (const std::string &addrHeaderStr)
 Extract the Class ID (an integer) from a string of form <addrHeader><address_header service_type="256" clid="12345" ></addrHeader>
std::string parseTypename (const std::string &description)
 Extract the typename from a folder description.
std::string deleteRegex (const std::string &original, const std::string &regex)
 Delete characters of a matching regex from the input string.
std::string quote (const std::string &sentence)
 Enclose a string in ".
std::string unescapeQuotes (const std::string &original)
std::string unescapeBackslash (const std::string &original)
std::string sanitiseFilename (const std::string &fname)
 Replace the '/' of a file path with '^'.
std::string sanitiseCrestTag (const std::string &fname)
 return valid CREST tag name from folder name
std::string replaceNULL (const std::string &possibleNULL)
 replace an uppercase NULL (such as returned by oracle) in string with a lowercase null (such as used in JSON)
std::string sanitiseXml (const std::string &pseudoXmlString)
 for use when converting cool folder description JSON
bool looksLikeMagicTag (const std::string &candidateTag)
 Looks like it should be magic.
bool tagIsMagic (const std::string &candidateTag)
 Resolve magic tag.
std::vector< std::string > parseMagicTag (const std::string &candidateTag)
 Takes a tag of form TagInfo{Major|Minor}/<tag> or TagInfo{Major|Minor}/<prefix>/<tag> and resolve it to a string vector{"Major|Minor", <prefix>, <tag>} returns an empty vector if a match is not found.
std::vector< std::string > parseLinkNames (const std::string &linktext)
 Parse string of format "A:X::B:C" to "A" , "X::B", "C".
std::pair< std::string, std::string > tag2PrefixTarget (const std::vector< std::string > &parseResult)
 Takes a vector<string> containing {"<fulltag>", "Major|Minor", "<prefix>", "<tag>"} and returns a pair of {"<prefix>", "<tag>"}.
bool replaceServiceType71 (std::string &addrHeader)
template<class IntType>
std::vector< std::pair< IntType, IntType > > parseChannelSpec (const std::string &chanspecString)
 Parse a channel specification string of the format ":3, 65:67,100:120, 130: " into a vector of pairs.
std::string getTagInfo (const std::string &tag, const ITagInfoMgr *tagInfoMgr)
 Retrieve the TagInfo.
std::string getGeoAtlasVersion ()
 Get the GeoAtlas version directly from GeoModelSvc.
std::optional< bool > checkTagLock (const cool::IFolderPtr &fptr, const std::string &tag)
 Check whether a tag is locked on a folder, if possible.
std::string resolveUsingTagInfo (const std::string &tag, const ITagInfoMgr *tagInfoMgr)

Variables

constexpr unsigned long long ALL_LUMI_BLOCKS {0xFFFFFFFF}
 All the lumi blocks in one run.
static const std::string s_openJson = "{"
 json open tag, '{'
static const std::string s_closeJson = "}"
 json close tag, '}'
static const std::string s_delimiterJson = ", "
 json standard delimiter ', '

Enumeration Type Documentation

◆ FolderType

Enumerator
UNKNOWN 
AttrList 
AttrListColl 
PoolRef 
PoolRefColl 
CoraCool 
CoolVector 
JSON 
NUM_FOLDER_TYPES 

Definition at line 26 of file FolderTypes.h.

Function Documentation

◆ attributeListSize()

unsigned int IOVDbNamespace::attributeListSize ( const coral::AttributeList & atrlist)

return the size (in bytes) of an AttributeList

Definition at line 72 of file IOVDbCoolFunctions.cxx.

72 {
73 unsigned int total{};
74 for (const auto & attribute:atrlist){
75 total+=IOVDbNamespace::attributeSize(attribute);
76 }
77 return total;
78 }
unsigned int attributeSize(const coral::Attribute &attribute)
return the size (in bytes) of an Attribute

◆ attributeSize()

unsigned int IOVDbNamespace::attributeSize ( const coral::Attribute & attribute)

return the size (in bytes) of an Attribute

Definition at line 57 of file IOVDbCoolFunctions.cxx.

57 {
58 const auto & spec{attribute.specification()};
59 try{
60 return sizeFunctions.at(std::type_index(spec.type()))(attribute);
61 }catch (const std::out_of_range& oor) {
62 return 0;
63 }
64 }

◆ attrList2Spec()

const coral::AttributeListSpecification & IOVDbNamespace::attrList2Spec ( const coral::AttributeList & atrlist)

return the AttributeListSpecification of an AttributeList

Definition at line 52 of file IOVDbCoolFunctions.cxx.

52 {
53 return atrlist.specification();
54 }

◆ base64Decode()

coral::Blob IOVDbNamespace::base64Decode ( const std::string & base64String)

Definition at line 26 of file Base64Codec.cxx.

26 {
27 const auto &charVec = CxxUtils::base64_decode(base64String);
28 coral::Blob blob(charVec.size());
29 memcpy(blob.startingAddress(), charVec.data(), charVec.size());
30 return blob;
31 }
std::vector< unsigned char > base64_decode(const std::string &)
Definition base64.cxx:97

◆ base64Encode()

std::string IOVDbNamespace::base64Encode ( const coral::Blob & blob)

Definition at line 18 of file Base64Codec.cxx.

18 {
19 //Blob::startingAddress returns a const void *, so cast to byte size
20 const auto *const address = static_cast<const unsigned char *>(blob.startingAddress());
21 const unsigned int nBytes = blob.size();
22 return CxxUtils::base64_encode(address, nBytes);
23 }
std::string base64_encode(const unsigned char *, unsigned int)
Definition base64.cxx:55

◆ channelList()

std::pair< std::vector< cool::ChannelId >, std::vector< std::string > > IOVDbNamespace::channelList ( IOVDbConn * pConnection,
const std::string & folderName,
const bool named )

Retrieve channel information.

Definition at line 160 of file IOVDbCoolFunctions.cxx.

160 {
161 std::vector<cool::ChannelId> channelNumbers;
162 std::vector<std::string> channelNames;
163 //
164 cool::IDatabasePtr dbPtr=pConnection->getCoolDb();
165 // get folder and read information
166 if (!dbPtr->existsFolder(folderName)) {
167 throw std::runtime_error( "Folder " + folderName + " does not exist" );
168 }
169 cool::IFolderPtr fldPtr=dbPtr->getFolder(folderName);
170 if (named) {
171 typedef std::map<cool::ChannelId,std::string> ChanMap_t;
172 const ChanMap_t & chanmap=fldPtr->listChannelsWithNames();
173 channelNumbers.reserve(chanmap.size());
174 channelNames.reserve(chanmap.size());
175 auto unzipElement = [&](const ChanMap_t::value_type & element){
176 channelNumbers.push_back(element.first);
177 channelNames.push_back(element.second);
178 };
179 std::for_each(chanmap.begin(), chanmap.end(),unzipElement);
180 } else {
181 channelNumbers=fldPtr->listChannels();
182 }
183 return std::make_pair(std::move(channelNumbers), std::move(channelNames));
184 }
cool::IDatabasePtr getCoolDb()
Definition IOVDbConn.cxx:31

◆ checkTagLock()

std::optional< bool > IOVDbNamespace::checkTagLock ( const cool::IFolderPtr & fptr,
const std::string & tag )

Check whether a tag is locked on a folder, if possible.

Definition at line 43 of file TagFunctions.cxx.

43 {
44 try {
45 return (fptr->tagLockStatus(tag)==cool::HvsTagLock::LOCKED);
46 } catch (cool::Exception& e) {
47 //dont do anything, but...
48 }
49 //...return a null object
50 return std::nullopt;
51 }
std::vector< TFile * > fptr
Definition hcg.cxx:51

◆ countSelectedChannels()

int IOVDbNamespace::countSelectedChannels ( const std::vector< cool::ChannelId > & channels,
const cool::ChannelSelection & selected )

Count the number of selected channels in a vector of channels according to cool::Channel selection.

Definition at line 81 of file IOVDbCoolFunctions.cxx.

81 {
82 auto isSelected = [& selected](cool::ChannelId id){return selected.inSelection(id);};
83 return std::count_if(channels.begin(), channels.end(),isSelected);//return type of count_if is signed
84 }

◆ deleteRegex()

std::string IOVDbNamespace::deleteRegex ( const std::string & original,
const std::string & regex )

Delete characters of a matching regex from the input string.

Definition at line 79 of file IOVDbStringFunctions.cxx.

79 {
80 const std::regex delre(regex);
81 return std::regex_replace(original,delre,"");
82 }

◆ determineFolderType() [1/5]

FolderType IOVDbNamespace::determineFolderType ( const CondAttrListCollection & attrListColl)

Determine folder typeusing the CondAttrListCollection reference.

Definition at line 74 of file FolderTypes.cxx.

74 {
75 FolderType ftype(AttrList);
76 //has a single magic channel?
77 if (attrListColl.size()==1 && attrListColl.begin()->first==0xFFFF) {
78 if (poolCompatible (attrListColl)) return PoolRef;
79 return AttrList;
80 } else {
81 ftype=AttrListColl;
82 if ( attrListColl.size()>0) {
83 if (poolCompatible(attrListColl)) return PoolRefColl;
84 }
85 }
86 return ftype;
87 }
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
size_type size() const
number of Chan/AttributeList pairs
bool poolCompatible(const cool::IRecordSpecification &rspec)
Is the folder type compatible with Pool storage type?

◆ determineFolderType() [2/5]

FolderType IOVDbNamespace::determineFolderType ( const CondAttrListCollection * pAttrListColl)

Determine folder type using the CondAttrListCollection pointer.

Definition at line 57 of file FolderTypes.cxx.

57 {
58 FolderType ftype(AttrList);
59 //has a single magic channel?
60 if (pAttrListColl->size()==1 && pAttrListColl->begin()->first==0xFFFF) {
61 if (poolCompatible (pAttrListColl)) return PoolRef;
62 return AttrList;
63 } else {
64 ftype=AttrListColl;
65 if ( pAttrListColl->size()>0) {
66 if (poolCompatible(pAttrListColl)) return PoolRefColl;
67 }
68 }
69 return ftype;
70 }

◆ determineFolderType() [3/5]

FolderType IOVDbNamespace::determineFolderType ( const cool::IFolderPtr & pFolder,
IClassIDSvc *  )

Determine folder type with optional check using clid service to check clid matches typename.

Definition at line 36 of file FolderTypes.cxx.

36 {
37 const auto & folderDescription = pFolder->description();
38 //If you find a coracool tag, it is unambiguously a coracool folder
39 if (folderDescription.find("<coracool>") != std::string::npos) return CoraCool;
40 const std::string typeName = parseTypename(folderDescription);
41 //if the type is CondAttrListVec, and yet it is not a CoraCool, it must be a CoolVector
42 if (typeName=="CondAttrListVec") return CoolVector;
43 //check if the payload spec is compatible with a pool ref/pool ref collection
44 if (poolCompatible(pFolder->payloadSpecification())){
45 const auto & chans=pFolder->listChannels();
46 const auto nchans = chans.size();
47 const bool onlyOneSpecialChannel = ((nchans == 1) and (chans[0] == 0));
48 return onlyOneSpecialChannel ? PoolRef : PoolRefColl;
49 }
50 if (typeName == "CondAttrListCollection") return AttrListColl;
51 //defaults to AttrList
52 return AttrList;
53 }
std::string parseTypename(const std::string &description)
Extract the typename from a folder description.

◆ determineFolderType() [4/5]

FolderType IOVDbNamespace::determineFolderType ( const coral::AttributeSpecification & spec)

Determine folder type using the coral::AttributeSpecification.

Definition at line 90 of file FolderTypes.cxx.

90 {
92 if (spec.name()=="PoolRef" && spec.typeName()=="string") result = PoolRef;
93 return result;
94 }

◆ determineFolderType() [5/5]

FolderType IOVDbNamespace::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.

Definition at line 17 of file FolderTypes.cxx.

17 {
18 //If you find a coracool tag, it is unambiguously a coracool folder
19 if (folderDescription.find("<coracool>") != std::string::npos) return CoraCool;
20 const std::string typeName = parseTypename(folderDescription);
21 //if the type is CondAttrListVec, and yet it is not a CoraCool, it must be a CoolVector
22 if (typeName=="CondAttrListVec") return CoolVector;
23 //check if the payload spec is compatible with a pool ref/pool ref collection
24 if (poolCompatible(spec)){
25 const auto nchans = chans.size();
26 const bool onlyOneSpecialChannel = ((nchans == 1) and (chans[0] == 0));
27 return onlyOneSpecialChannel ? PoolRef : PoolRefColl;
28 }
29 if (typeName == "CondAttrListCollection") return AttrListColl;
30 //defaults to AttrList
31 return AttrList;
32 }

◆ folderMetadata()

std::pair< bool, std::string > IOVDbNamespace::folderMetadata ( IOVDbConn * pConnection,
const std::string & folderName )

Retrieve (bool) multiversion flag and folder description.

Definition at line 136 of file IOVDbCoolFunctions.cxx.

136 {
137 bool multiversion{};
138 std::string folderdesc{};
139 // folder being read from COOL
140 // get COOL database - will wake up connection on first access
141 cool::IDatabasePtr dbPtr=pConnection->getCoolDb();
142 if (not dbPtr.get()) {
143 throw std::runtime_error( "Conditions database connection " + pConnection->name() + " cannot be opened - STOP" );
144 }
145 // get folder and read information
146 if (!dbPtr->existsFolder(folderName)) {
147 throw std::runtime_error( "Folder " + folderName + " does not exist" );
148 }
149 cool::IFolderPtr fldPtr=dbPtr->getFolder(folderName);
150 // get versiontype of folder
151 multiversion=(fldPtr->versioningMode()==cool::FolderVersioning::MULTI_VERSION);
152 // read and process description string
153 folderdesc=fldPtr->description();
154 return std::make_pair(multiversion, std::move(folderdesc));
155 }
const std::string & name() const
Definition IOVDbConn.h:70

◆ folderTypeName()

std::string IOVDbNamespace::folderTypeName ( const FolderType f)

Give a string name for the folder type.

Definition at line 135 of file FolderTypes.cxx.

135 {
136 static const std::vector<std::string> names{"AttrList", "AttrListColl", "PoolRef",
137 "PoolRefColl", "CoraCool", "CoolVector", "JSON"};
138 if (f==UNKNOWN) return "Unknown";
139 return names[f];
140 }

◆ getGeoAtlasVersion()

std::string IOVDbNamespace::getGeoAtlasVersion ( )

Get the GeoAtlas version directly from GeoModelSvc.

Definition at line 33 of file TagFunctions.cxx.

33 {
34 SmartIF<IGeoModelSvc> geomodel{Gaudi::svcLocator()->service("GeoModelSvc")};
35 if (not geomodel) {
36 throw std::runtime_error("The GeoModelSvc could not be retrieved in TagFunctions.cxx getGeoAtlasVersion()");
37 } else {
38 return geomodel->atlasVersion();
39 }
40 }

◆ getTagInfo()

std::string IOVDbNamespace::getTagInfo ( const std::string & tag,
const ITagInfoMgr * tagInfoMgr )

Retrieve the TagInfo.

Definition at line 21 of file TagFunctions.cxx.

21 {
22 std::string result{};
23 enum ResultIndices{WHOLETAG, MAJMIN, PATH1, PATH2, SIZEWITHPREFIX};
25 if (results.empty()) return result;
26 const auto & [prefix, target] = IOVDbNamespace::tag2PrefixTarget(results);
27 std::string tagval = tagInfoMgr->findTag(target);
28 if (not tagval.empty()) result=prefix+tagval;
29 return result;
30 }
virtual std::string findTag(const std::string &name) const =0
Find tag by its name, return by value - empty string if not found.
std::pair< std::string, std::string > tag2PrefixTarget(const std::vector< std::string > &tagParseResults)
Takes a vector<string> containing {"<fulltag>", "Major|Minor", "<prefix>", "<tag>"}...
std::vector< std::string > parseMagicTag(const std::string &v)
Takes a tag of form TagInfo{Major|Minor}/<tag> or TagInfo{Major|Minor}/<prefix>/<tag> and resolve it ...

◆ inRange() [1/2]

template<class NumericType>
bool IOVDbNamespace::inRange ( const NumericType & val,
const std::pair< NumericType, NumericType > & range )

Function to check whether a number is in the inclusive range, given as a pair.

Typically used with Channel ranges for COOL

Definition at line 42 of file IOVDbCoolFunctions.h.

42 {
43 return (val>=range.first && val<=range.second);
44 }

◆ inRange() [2/2]

template<class NumericType>
bool IOVDbNamespace::inRange ( const NumericType & val,
const std::vector< std::pair< NumericType, NumericType > > & ranges )

Definition at line 48 of file IOVDbCoolFunctions.h.

48 {
49 auto valueInRange=[val](const std::pair<NumericType, NumericType> & range){ return inRange(val,range); };
50 return std::any_of(ranges.begin(), ranges.end(), valueInRange);
51 }
bool inRange(const NumericType &val, const std::pair< NumericType, NumericType > &range)
Function to check whether a number is in the inclusive range, given as a pair.

◆ iovFromLumiBlockString()

unsigned long long IOVDbNamespace::iovFromLumiBlockString ( const std::string & lbString)

String representation of lumiblock just converted to LL (as in original code) and returned as a ULL.

Definition at line 45 of file IOVDbStringFunctions.cxx.

45 {
46 if (lbString.empty()) return 0LL;
47 unsigned long long lb=std::stoll(lbString.c_str());
48 return lb;
49 }
int lb
Definition globals.cxx:23

◆ iovFromRunString()

unsigned long long IOVDbNamespace::iovFromRunString ( const std::string & runString)

Take a string run number and convert it to an ULL representing run<<32.

Definition at line 38 of file IOVDbStringFunctions.cxx.

38 {
39 if (runString.empty()) return 0LL;
40 unsigned long long run=std::stoi(runString);
41 return run<<32LL;
42 }
Definition run.py:1

◆ iovFromTimeString()

unsigned long long IOVDbNamespace::iovFromTimeString ( const std::string & iovString)

Take a string integer giving a time in seconds and convert it to a ULL in nanoseconds.

Definition at line 31 of file IOVDbStringFunctions.cxx.

31 {
32 if (iovString.empty()) return 0LL;
33 unsigned long long time=std::stoi(iovString);
34 return time*1000000000LL;
35 }

◆ iovTimeFromRunLumi()

unsigned long long IOVDbNamespace::iovTimeFromRunLumi ( const unsigned long long run,
const unsigned long long lumi )

Create a long long representing the IOV from run, lumi.

Definition at line 103 of file IOVDbCoolFunctions.cxx.

103 {
104 return (run<<32) + lumi;
105 }

◆ iovTimeFromSeconds()

unsigned long long IOVDbNamespace::iovTimeFromSeconds ( const unsigned long long seconds)

Create a long long time in ns from s.

Definition at line 98 of file IOVDbCoolFunctions.cxx.

98 {
99 return seconds*1000000000LL;
100 }

◆ jsonAttribute()

std::string IOVDbNamespace::jsonAttribute ( const coral::Attribute & attr)

Produce a representation of a coral::Attribute as a json string.

Definition at line 15 of file IOVDbJsonStringFunctions.cxx.

15 {
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 const std::string sep(" : ");
22 const auto separatorPosition = native.find(sep);
23 const std::string payloadOnly=native.substr(separatorPosition+3);
24 if (stringPayload) return quote(sanitiseJsonString(payloadOnly));
25 if (blobPayload){
26 return quote(IOVDbNamespace::base64Encode(attr.data<coral::Blob>()));
27 }
28 if (payloadOnly == "NULL") {
29 return "null";
30 }
31 return payloadOnly;
32 }
std::string quote(const std::string &sentence)
Enclose a string in ".
std::string base64Encode(const coral::Blob &blob)
std::string sanitiseJsonString(const std::string &dataString)
Sanitise json string, escaping raw carriage returns.

◆ jsonAttributeList()

std::string IOVDbNamespace::jsonAttributeList ( const coral::AttributeList & atrlist)

Produce a representation of a coral::AttributeList as a json string.

Definition at line 35 of file IOVDbJsonStringFunctions.cxx.

35 {
36 std::string os("[");
37 const unsigned int nelement=atrlist.size();
38 std::string delimiter(" ");
39 for (unsigned int i(0);i!=nelement;++i){
40 if (i==1) delimiter = s_delimiterJson;
41 os+=delimiter;
42 os+=jsonAttribute(atrlist[i]);
43 }
44 os+="]";
45 return os;
46 }
static const std::string s_delimiterJson
json standard delimiter ', '
std::string jsonAttribute(const coral::Attribute &attr)
Produce a representation of a coral::Attribute as a json string.

◆ looksLikeMagicTag()

bool IOVDbNamespace::looksLikeMagicTag ( const std::string & candidateTag)

Looks like it should be magic.

Definition at line 150 of file IOVDbStringFunctions.cxx.

150 {
151 return (candidateTag.compare(0,7, "TagInfo")==0 and
152 candidateTag.find('/')!=std::string::npos);
153 }

◆ makeChannel() [1/2]

cool::ChannelId IOVDbNamespace::makeChannel ( const std::string & strval,
const cool::ChannelId defchan )

Create a ChannelId from a string; if string is empty, return the default channel number given.

Definition at line 128 of file IOVDbCoolFunctions.cxx.

128 {
129 // construct a cool channelId from the string value (numeric)
130 // if empty, use the default value
131 if (not strval.empty()) return std::stol(strval);
132 return defchan;
133 }

◆ makeChannel() [2/2]

int IOVDbNamespace::makeChannel ( const std::string & strval,
const int defchan )

Produce a channel number from the string; default to 'defchan' if empty.

Definition at line 23 of file IOVDbStringFunctions.cxx.

23 {
24 // construct a cool channelId from the string value (numeric)
25 // if empty, use the default value
26 if (!strval.empty()) return std::stoi(strval);
27 return defchan;
28 }

◆ makeEpochOrRunLumi()

IOVTime IOVDbNamespace::makeEpochOrRunLumi ( const cool::ValidityKey key,
const bool timeIsEpoch )

Create an IOVTime in ns of epoch or run-lumi (determined by the bool) from a ValidityKey.

Definition at line 87 of file IOVDbCoolFunctions.cxx.

87 {
88 IOVTime time;
89 if(timeIsEpoch){
90 time.setTimestamp(key);
91 } else {
92 time.setRETime(key);
93 }
94 return time;
95 }
Basic time unit for IOVSvc.
Definition IOVTime.h:33
time(flags, cells_name, *args, **kw)

◆ makeRange()

IOVRange IOVDbNamespace::makeRange ( const cool::ValidityKey since,
const cool::ValidityKey until,
const bool timeIsEpoch )

Make an IOVRange from two validity keys.

Definition at line 113 of file IOVDbCoolFunctions.cxx.

113 {
114 // make an IOVRange object corresponding to given interval
115 // dealing with timestamp/RunLB differences
116 IOVTime itsince,ituntil;
117 if (timeIsEpoch) {
118 itsince.setTimestamp(since);
119 ituntil.setTimestamp(until);
120 } else {
121 itsince.setRETime(since);
122 ituntil.setRETime(until);
123 }
124 return IOVRange(itsince,ituntil);
125 }
void setRETime(uint64_t time) noexcept
Definition IOVTime.cxx:84
void setTimestamp(uint64_t timestamp) noexcept
Definition IOVTime.cxx:72

◆ operator<<()

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

Definition at line 202 of file Cool2Json.cxx.

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

◆ parseChannelSpec()

template<class IntType>
std::vector< std::pair< IntType, IntType > > IOVDbNamespace::parseChannelSpec ( const std::string & chanspecString)

Parse a channel specification string of the format ":3, 65:67,100:120, 130: " into a vector of pairs.

Definition at line 34 of file IOVDbStringFunctions.h.

34 {
35 typedef std::pair<IntType, IntType> ChanRange;
36 const auto defaults=ChanRange(0,std::numeric_limits<IntType>::max());
37 //
38 std::vector<ChanRange> result;
39 std::string::size_type index;
40 std::string rangespec, chanspec(chanspecString);
41 bool first=true;
42 do {
43 index=chanspec.find(',');
44 if (index!=std::string::npos) {
45 rangespec=chanspec.substr(0,index);
46 chanspec=chanspec.substr(index+1,chanspec.size());
47 } else {
48 rangespec=chanspec;
49 }
50 if (!rangespec.empty()) {
51 // parse the range specification, look for : separator between limits
52 std::string::size_type icol=rangespec.find(':');
53 int lower,upper;
54 if (icol!=std::string::npos) {
55 lower=makeChannel(spaceStrip(rangespec.substr(0,icol)),defaults.first);
56 upper=makeChannel(spaceStrip(rangespec.substr(icol+1,rangespec.size())),defaults.second);
57 } else {
58 lower=atol(spaceStrip(rangespec).c_str());
59 upper=lower;
60 }
61 if (first) {
62 first=false;
63 }
64 result.push_back(ChanRange(lower,upper));
65 }
66 } while (index!=std::string::npos);
67 return result;
68 }
int upper(int c)
bool first
Definition DeMoScan.py:534
std::string spaceStrip(const std::string &input)
Trim leading and trailing spaces,return a new trimmed string.
cool::ChannelId makeChannel(const std::string &strval, const cool::ChannelId defchan)
Create a ChannelId from a string; if string is empty, return the default channel number given.
Definition index.py:1

◆ parseClid()

int IOVDbNamespace::parseClid ( const std::string & addrHeaderStr)

Extract the Class ID (an integer) from a string of form <addrHeader><address_header service_type="256" clid="12345" ></addrHeader>

Definition at line 59 of file IOVDbStringFunctions.cxx.

59 {
60 //string of form
61 //<addrHeader><address_header service_type="256" clid="12345" /></addrHeader>
62 std::string regex=R"delim(clid\s*=\s*"([0-9]*)")delim";
63 std::regex re(regex);
64 std::smatch clidMatch;
65 bool match=std::regex_search(addrHeaderStr, clidMatch,re);
66 return (match) ? std::stoi(clidMatch[1]) : -1;
67 }
const boost::regex re(r_e)
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:357

◆ parseLinkNames()

std::vector< std::string > IOVDbNamespace::parseLinkNames ( const std::string & linktext)

Parse string of format "A:X::B:C" to "A" , "X::B", "C".

Definition at line 177 of file IOVDbStringFunctions.cxx.

177 {
178 std::vector<std::string> v{};
179 if (linktext.empty()) return v;
180 //regex:
181 //(anything except colon, multiple times) then _possibly_ (two colons and string of anything except colons)
182 // anything except colon) then (colon or end-of-line)
183 const std::string linkRegexStr{"([^:]*(::[^:]*)?)(:|$)"};
184 std::regex linkMatchSpec(linkRegexStr);
185 //give a token iterator using the regex and returning the first substring (i.e. the
186 //bit before a single colon or line end, which would be for example "ALink" or "MyContext::AnotherLink" )
187 std::sregex_token_iterator pos(linktext.cbegin(), linktext.cend(),linkMatchSpec,{1});
188 std::sregex_token_iterator e;
189 for (;pos!=e;++pos) {
190 // the resulting text _should not_ contain spaces, but strip it to be sure.
191 if (not pos->str().empty()) v.push_back(spaceStrip(pos->str()));
192 }
193 return v;
194 }

◆ parseMagicTag()

std::vector< std::string > IOVDbNamespace::parseMagicTag ( const std::string & v)

Takes a tag of form TagInfo{Major|Minor}/<tag> or TagInfo{Major|Minor}/<prefix>/<tag> and resolve it to a string vector{"Major|Minor", <prefix>, <tag>} returns an empty vector if a match is not found.

Definition at line 163 of file IOVDbStringFunctions.cxx.

163 {
164 std::vector<std::string> result;
165 std::string regex7=R"delim(TagInfo(Major|Minor)/([^/]*)/?([^/]*)?)delim";
166 std::regex matchmagic(regex7);
167 std::smatch x;
168 bool foundmagic=std::regex_match(v,x,matchmagic);
169 if (foundmagic){
170 for (const auto & i:x)
171 if (i!="") result.push_back(i);
172 }
173 return result;
174 }
#define x

◆ parseTypename()

std::string IOVDbNamespace::parseTypename ( const std::string & description)

Extract the typename from a folder description.

Definition at line 70 of file IOVDbStringFunctions.cxx.

70 {
71 std::string regex=R"delim(<typeName>\s*([^\s]+)\s*</typeName>)delim";
72 std::regex re(regex);
73 std::smatch typeMatch;
74 bool match=std::regex_search(description, typeMatch,re);
75 return (match) ? std::string(typeMatch[1]) : std::string("");
76 }
STL class.
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:91
STL namespace.

◆ poolCompatible() [1/4]

bool IOVDbNamespace::poolCompatible ( const CondAttrListCollection & attrListColl)

Definition at line 128 of file FolderTypes.cxx.

128 {
129 const coral::AttributeList& payload1=attrListColl.begin()->second;
130 const coral::AttributeSpecification& spec=payload1[0].specification();
131 return (spec.name()=="PoolRef" && spec.typeName()=="string");
132 }

◆ poolCompatible() [2/4]

bool IOVDbNamespace::poolCompatible ( const CondAttrListCollection * pAttrListColl)

Definition at line 121 of file FolderTypes.cxx.

121 {
122 const coral::AttributeList& payload1=pAttrListColl->begin()->second;
123 const coral::AttributeSpecification& spec=payload1[0].specification();
124 return (spec.name()=="PoolRef" && spec.typeName()=="string");
125 }

◆ poolCompatible() [3/4]

bool IOVDbNamespace::poolCompatible ( const cool::IRecordSpecification & rspec)

Is the folder type compatible with Pool storage type?

Definition at line 97 of file FolderTypes.cxx.

97 {
98 return (rspec.exists("PoolRef") && rspec[0].name()=="PoolRef" &&
99 rspec[0].storageType()==cool::StorageType::String4k);
100 }

◆ poolCompatible() [4/4]

bool IOVDbNamespace::poolCompatible ( const std::string & specString)

Definition at line 103 of file FolderTypes.cxx.

103 {
104 nlohmann::json js = nlohmann::json::parse(specString);
105 if(js.is_array()){
106 int n = js.size();
107 for (int i = 0; i <= n; i++) {
108 nlohmann::json j_object = js[i];
109 for (auto& [key, val] : j_object.items()){
110 if(key=="PoolRef" && val=="String4k")
111 return true;
112 }
113 }
114 return false;
115 }
116 return (specString.find("PoolRef:String4k") != std::string::npos || specString.find("PoolRef: String4k") != std::string::npos ||
117 specString.find("PoolRef : String4k") != std::string::npos);
118 }

◆ quote()

std::string IOVDbNamespace::quote ( const std::string & sentence)

Enclose a string in ".

Definition at line 85 of file IOVDbStringFunctions.cxx.

85 {
86 std::string out;
87 out.reserve(sentence.size() + 2);
88 out += '\"';
89 out += sentence;
90 out += '\"';
91 return out;
92 }

◆ replaceNULL()

std::string IOVDbNamespace::replaceNULL ( const std::string & possibleNULL)

replace an uppercase NULL (such as returned by oracle) in string with a lowercase null (such as used in JSON)

Definition at line 126 of file IOVDbStringFunctions.cxx.

126 {
127 const std::string &original{possibleNULL};
128 const std::string regex=R"delim( NULL)delim";
129 const std::regex nullre(regex);
130 return std::regex_replace(original,nullre," null");
131 }

◆ replaceServiceType71()

bool IOVDbNamespace::replaceServiceType71 ( std::string & addrHeader)

Definition at line 211 of file IOVDbStringFunctions.cxx.

211 {
212 const std::size_t svcType = addrHeader.find("service_type=\"71\"");
213 if (svcType != std::string::npos) {
214 addrHeader.replace(svcType, 17, "service_type=\"256\"");
215 return true;
216 }
217 return false;
218 }

◆ resolveUsingTagInfo()

std::string IOVDbNamespace::resolveUsingTagInfo ( const std::string & tag,
const ITagInfoMgr * tagInfoMgr )

Definition at line 54 of file TagFunctions.cxx.

54 {
55 // tag an input tag of form TagInfo{Major|Minor}/<tag> or
56 // TagInfo(Major|Minor}/<prefix>/<tag>
57 // and resolve to value of TagInfo object tag <tag>
58 // with optional prefix
59 // <prefix>DEFAULT tags are no longer returned
60 // return true for successful resolution
61 std::string result="";
62 enum ResultIndices{WHOLETAG, MAJMIN, PATH1, PATH2, SIZEWITHPREFIX};
63 auto results=IOVDbNamespace::parseMagicTag(tag);
64 if (results.empty()) {
65 return result;
66 }
67 const auto & [prefix, target] = IOVDbNamespace::tag2PrefixTarget(results);
68 // try to get the Tag value
69 if( tagInfoMgr ) {
70 result= IOVDbNamespace::getTagInfo(tag, tagInfoMgr);
71 }
72 // if nothing found, try to get GeoAtlas directly from GeoModelSvc
73 if (result.empty() and target=="GeoAtlas") {
75 }
76 if (not result.empty()) {
77 std::string::size_type rstrip{};
78 //number of characters to strip from tag end
79 if (results[MAJMIN] == "Major") rstrip=6;
80 if (results[MAJMIN] == "Minor") rstrip=3;
81 // check if characters need to be stripped from end of tag
82 if (rstrip>0 && tag.size()>rstrip) result.erase(result.size()-rstrip);
83 } else {
84 throw std::runtime_error("Could not resolve TagInfo tag " + target );
85 }
86 return result;
87 }
std::string getGeoAtlasVersion()
Get the GeoAtlas version directly from GeoModelSvc.
std::string getTagInfo(const std::string &tag, const ITagInfoMgr *tagInfoMgr)
Retrieve the TagInfo.

◆ runLumiFromIovTime()

std::pair< unsigned long long, unsigned long long > IOVDbNamespace::runLumiFromIovTime ( const unsigned long long iovTime)

Return a [run,lumi] pair from an IOV time.

Definition at line 108 of file IOVDbCoolFunctions.cxx.

108 {
109 return std::pair<unsigned long long, unsigned long long>{iovTime>>32, iovTime&0xFFFFFFFF};
110 }

◆ sanitiseCrestTag()

std::string IOVDbNamespace::sanitiseCrestTag ( const std::string & fname)

return valid CREST tag name from folder name

Definition at line 121 of file IOVDbStringFunctions.cxx.

121 {
122 return sanitiseFilename(fname);
123 }
std::string sanitiseFilename(const std::string &fname)
Replace the '/' of a file path with '^'.

◆ sanitiseFilename()

std::string IOVDbNamespace::sanitiseFilename ( const std::string & fname)

Replace the '/' of a file path with '^'.

Definition at line 110 of file IOVDbStringFunctions.cxx.

110 {
111 std::string newName{fname};
112 auto oldEnd = newName.end();
113 auto newEnd = std::remove(newName.begin(), oldEnd, '/');
114 //keep this line for reference
115 //std::replace(newName.begin(), newName.end(), '/', '^');
116 newName.erase(newEnd, newName.end());
117 return newName;
118 }
DataModel_detail::iterator< DVL > remove(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, const T &value)
Specialization of remove for DataVector/List.

◆ sanitiseJsonString()

std::string IOVDbNamespace::sanitiseJsonString ( const std::string & dataString)

Sanitise json string, escaping raw carriage returns.

Definition at line 52 of file IOVDbStringFunctions.cxx.

52 {
53 const std::string regex="\n";
54 const std::regex lf(regex);
55 return std::regex_replace(dataString,lf,"\\n");
56 }

◆ sanitiseXml()

std::string IOVDbNamespace::sanitiseXml ( const std::string & pseudoXmlString)

for use when converting cool folder description JSON

Definition at line 134 of file IOVDbStringFunctions.cxx.

134 {
135 std::string result;
136 unsigned int strSize(pseudoXmlString.size());
137 unsigned int bufsize(strSize*1.1);
138 result.reserve(bufsize);
139 for(size_t pos = 0; pos != strSize; ++pos) {
140 switch(pseudoXmlString[pos]) {
141 case '\"': result.append("\\\""); break;
142
143 default: result.append(&pseudoXmlString[pos], 1); break;
144 }
145 }
146 return result;
147 }

◆ spaceStrip()

std::string IOVDbNamespace::spaceStrip ( const std::string & input)

Trim leading and trailing spaces,return a new trimmed string.

Definition at line 11 of file IOVDbStringFunctions.cxx.

11 {
12 // return the input string stripped of leading/trailing spaces
13 std::string::size_type idx1=input.find_first_not_of(" \n\r\t");
14 std::string::size_type idx2=input.find_last_not_of(" \n\r\t");
15 if (idx1==std::string::npos || idx2==std::string::npos) {
16 return "";
17 } else {
18 return std::string(input.substr(idx1,1+idx2-idx1));
19 }
20 }

◆ tag2PrefixTarget()

std::pair< std::string, std::string > IOVDbNamespace::tag2PrefixTarget ( const std::vector< std::string > & parseResult)

Takes a vector<string> containing {"<fulltag>", "Major|Minor", "<prefix>", "<tag>"} and returns a pair of {"<prefix>", "<tag>"}.

Note "<prefix>" is optional in the input and if missing will be an empty string on output.

Definition at line 197 of file IOVDbStringFunctions.cxx.

197 {
198 std::pair<std::string, std::string> pair;
199 std::string &prefix{pair.first};
200 std::string &target{pair.second};
201 if (tagParseResults.size() == 4){ //4 is the size of result set if there is a prefix
202 prefix = tagParseResults[2]; //index of first path
203 target = tagParseResults[3]; //index of second path
204 } else {
205 target = tagParseResults[2];
206 }
207 return pair;
208 }
STL class.

◆ tagIsMagic()

bool IOVDbNamespace::tagIsMagic ( const std::string & candidateTag)

Resolve magic tag.

Definition at line 156 of file IOVDbStringFunctions.cxx.

156 {
157 const std::string regex=R"delim(TagInfo(Major|Minor)/.*)delim";
158 const std::regex magicx(regex);
159 return std::regex_match(candidateTag, magicx);
160 }

◆ typeSizeIsKnown()

bool IOVDbNamespace::typeSizeIsKnown ( const coral::Attribute & attribute)

Return a bool indicating whether the size of a given Attribute can be determined.

Definition at line 67 of file IOVDbCoolFunctions.cxx.

67 {
68 return (sizeFunctions.find(std::type_index(attribute.specification().type())) != sizeFunctions.end());
69 }

◆ unescapeBackslash()

std::string IOVDbNamespace::unescapeBackslash ( const std::string & original)

Definition at line 102 of file IOVDbStringFunctions.cxx.

102 {
103 const std::string regex=R"delim([\\]+)delim";
104 const std::string replace=R"delim(\)delim";
105 const std::regex re(regex);
106 return std::regex_replace(original, re,replace);
107 }
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310

◆ unescapeQuotes()

std::string IOVDbNamespace::unescapeQuotes ( const std::string & original)

Definition at line 95 of file IOVDbStringFunctions.cxx.

95 {
96 const std::string regex=R"delim(\\")delim";
97 std::regex re(regex);
98 return std::regex_replace(original, re,"\"");
99 }

Variable Documentation

◆ ALL_LUMI_BLOCKS

unsigned long long IOVDbNamespace::ALL_LUMI_BLOCKS {0xFFFFFFFF}
constexpr

All the lumi blocks in one run.

Definition at line 36 of file IOVDbCoolFunctions.h.

36{0xFFFFFFFF};

◆ s_closeJson

const std::string IOVDbNamespace::s_closeJson = "}"
inlinestatic

json close tag, '}'

Definition at line 29 of file IOVDbJsonStringFunctions.h.

◆ s_delimiterJson

const std::string IOVDbNamespace::s_delimiterJson = ", "
inlinestatic

json standard delimiter ', '

Definition at line 32 of file IOVDbJsonStringFunctions.h.

◆ s_openJson

const std::string IOVDbNamespace::s_openJson = "{"
inlinestatic

json open tag, '{'

Definition at line 26 of file IOVDbJsonStringFunctions.h.