Skip to content
Snippets Groups Projects
Commit c2a0b35d authored by Shaun Roe's avatar Shaun Roe Committed by Vakhtang Tsulaia
Browse files

22.0-refactor-IOVDbSvc-2

parent 83b5e89a
No related branches found
No related tags found
No related merge requests found
......@@ -13,12 +13,9 @@ namespace IOVDbNamespace{
FolderType
determineFolderType(const cool::IFolderPtr & pFolder, IClassIDSvc* /*clidsvc*/){
const auto & folderDescription = pFolder->description();
//int clid = parseClid(folderDescription);
//If you find a coracool tag, it is unambiguously a coracool folder
std::cout<<folderDescription<<std::endl;
if (folderDescription.find("<coracool>") != std::string::npos) return CoraCool;
const std::string typeName = parseTypename(folderDescription);
std::cout<<typeName<<std::endl;
//if the type is CondAttrListVec, and yet it is not a CoraCool, it must be a CoolVector
if (typeName=="CondAttrListVec") return CoolVector;
//check if the payload spec is compatible with a pool ref/pool ref collection
......@@ -44,7 +41,24 @@ namespace IOVDbNamespace{
} else {
ftype=AttrListColl;
if ( pAttrListColl->size()>0) {
if (poolCompatible (pAttrListColl)) return PoolRefColl;
if (poolCompatible(pAttrListColl)) return PoolRefColl;
}
}
return ftype;
}
//determine folder type from CondAttrListCollection
FolderType
determineFolderType(const CondAttrListCollection & attrListColl){
FolderType ftype(AttrList);
//has a single magic channel?
if (attrListColl.size()==1 && attrListColl.begin()->first==0xFFFF) {
if (poolCompatible (attrListColl)) return PoolRef;
return AttrList;
} else {
ftype=AttrListColl;
if ( attrListColl.size()>0) {
if (poolCompatible(attrListColl)) return PoolRefColl;
}
}
return ftype;
......@@ -70,6 +84,13 @@ namespace IOVDbNamespace{
return (spec.name()=="PoolRef" && spec.typeName()=="string");
}
bool
poolCompatible(const CondAttrListCollection & attrListColl){
const coral::AttributeList& payload1=attrListColl.begin()->second;
const coral::AttributeSpecification& spec=payload1[0].specification();
return (spec.name()=="PoolRef" && spec.typeName()=="string");
}
std::string
folderTypeName(const FolderType f){
static const std::vector<std::string> names{"AttrList", "AttrListColl", "PoolRef",
......
......@@ -44,6 +44,9 @@ namespace IOVDbNamespace{
FolderType
determineFolderType(const CondAttrListCollection * pAttrListColl);
FolderType
determineFolderType(const CondAttrListCollection & pAttrListColl);
FolderType
determineFolderType(const coral::AttributeSpecification& spec);
......@@ -52,6 +55,9 @@ namespace IOVDbNamespace{
bool
poolCompatible(const CondAttrListCollection * pAttrListColl);
bool
poolCompatible(const CondAttrListCollection & pAttrListColl);
}
#endif
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
//@file IOVDbCoolFunctions.cxx
//@author Shaun Roe
#include "IOVDbCoolFunctions.h"
#include "CoralBase/Blob.h"
#include "CoralBase/Attribute.h"
#include "CoralBase/AttributeList.h"
#include "CoralBase/AttributeListSpecification.h"
//
#include "CoolKernel/ChannelSelection.h"
//
#include <unordered_map>
#include <typeinfo>
#include <typeindex>
#include <stdexcept>
namespace{
std::unordered_map<std::type_index, std::function<int(const coral::Attribute &)>>
sizeFunctions{
{std::type_index(typeid(bool)), [](const coral::Attribute & /*attr*/)->int { return 1; } },
{std::type_index(typeid(unsigned char)), [](const coral::Attribute & /*attr*/)->int { return 1; } },
{std::type_index(typeid(char)), [](const coral::Attribute & /*attr*/)->int { return 1; } },
//
{std::type_index(typeid(short)), [](const coral::Attribute & /*attr*/)->int { return 2; } },
{std::type_index(typeid(unsigned short)), [](const coral::Attribute & /*attr*/)->int { return 2; } },
{std::type_index(typeid(char)), [](const coral::Attribute & /*attr*/)->int { return 2; } },
//
{std::type_index(typeid(int)), [](const coral::Attribute & /*attr*/)->int { return 4; } },
{std::type_index(typeid(unsigned int)), [](const coral::Attribute & /*attr*/)->int { return 4; } },
{std::type_index(typeid(float)), [](const coral::Attribute & /*attr*/)->int { return 4; } },
//
{std::type_index(typeid(long long)), [](const coral::Attribute & /*attr*/)->int { return 8; } },
{std::type_index(typeid(unsigned long long)), [](const coral::Attribute & /*attr*/)->int { return 8; } },
{std::type_index(typeid(double)), [](const coral::Attribute & /*attr*/)->int { return 8; } },
//
{std::type_index(typeid(std::string)), [](const coral::Attribute & attr)->int { return attr.data<std::string>().size(); } },
{std::type_index(typeid(coral::Blob)), [](const coral::Attribute & attr)->int { return attr.data<coral::Blob>().size(); } }
};
}
namespace IOVDbNamespace{
const coral::AttributeListSpecification &
attrList2Spec(const coral::AttributeList& atrlist){
return atrlist.specification();
}
unsigned int
attributeSize(const coral::Attribute & attribute){
const auto & spec{attribute.specification()};
try{
return sizeFunctions.at(std::type_index(spec.type()))(attribute);
}catch (const std::out_of_range& oor) {
return 0;
}
}
bool
typeSizeIsKnown(const coral::Attribute & attribute){
return (sizeFunctions.find(std::type_index(attribute.specification().type())) != sizeFunctions.end());
}
unsigned int
attributeListSize(const coral::AttributeList& atrlist){
unsigned int total{};
for (const auto & attribute:atrlist){
total+=IOVDbNamespace::attributeSize(attribute);
}
return total;
}
int
countSelectedChannels(const std::vector<cool::ChannelId> & channels, const cool::ChannelSelection & selected){
auto isSelected = [& selected](cool::ChannelId id){return selected.inSelection(id);};
return std::count_if(channels.begin(), channels.end(),isSelected);//return type of count_if is signed
}
IOVTime
makeEpochOrRunLumi(const cool::ValidityKey key, const bool timeIsEpoch){
IOVTime time;
if(timeIsEpoch){
time.setTimestamp(key);
} else {
time.setRETime(key);
}
return time;
}
}
\ No newline at end of file
......@@ -4,10 +4,27 @@
//@file IOVDbCoolFunctions.h
//@brief Numeric and COOL/Coral dependent helper functions
//@author Shaun Roe
#ifndef IOVDbCoolFunctions_h
#define IOVDbCoolFunctions_h
#include "CoolKernel/ChannelId.h"
#include "CoolKernel/ValidityKey.h"
#include "AthenaKernel/IOVTime.h"
//
#include <utility>
#include <vector>
#include <algorithm>
#include <functional>
namespace coral{
class AttributeListSpecification;
class AttributeSpecification;
class AttributeList;
class Attribute;
}
namespace cool{
class ChannelSelection;
}
namespace IOVDbNamespace{
......@@ -26,5 +43,24 @@ namespace IOVDbNamespace{
return std::any_of(ranges.begin(), ranges.end(), valueInRange);
}
const coral::AttributeListSpecification &
attrList2Spec(const coral::AttributeList& atrlist);
unsigned int
attributeSize(const coral::Attribute & attribute);
bool
typeSizeIsKnown(const coral::Attribute & attribute);
unsigned int
attributeListSize(const coral::AttributeList& atrlist);
int
countSelectedChannels(const std::vector<cool::ChannelId> & channels, const cool::ChannelSelection & selected);
IOVTime
makeEpochOrRunLumi(const cool::ValidityKey key, const bool timeIsEpoch);
}
}
\ No newline at end of file
#endif
\ No newline at end of file
This diff is collapsed.
......@@ -140,13 +140,9 @@ private:
const IOVRange& range);
// - version for multichannel collection
bool addMetaAttrListColl(const CondAttrListCollection* coll);
// add type information to calculate size of attributeList
void addType(const std::string& type,const unsigned int ielm);
// setup shared AttributeListSpecification cache
void setSharedSpec(const coral::AttributeList& atrlist);
// calculate bytesize of given attributeList, using cached typeinfo
void countSize(const coral::AttributeList& atrlist);
// add this IOV to cache, including channel counting if over edge of cache
void addIOVtoCache(cool::ValidityKey since, cool::ValidityKey until);
......@@ -206,10 +202,6 @@ private:
std::string m_addrheader; // address header string from folder description
CLID m_clid; // CLID, read from folder description or ClassIDSvc
// read statistcs
typedef std::pair<unsigned int, unsigned int> VarSizePair;
std::vector<VarSizePair> m_varfields;
unsigned int m_fixedfields;
unsigned int m_ndbread; // number of times data read from DB
unsigned int m_ncacheread; // number of times data read from cache
unsigned int m_nobjread; // number of objects read from DB
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
#include "ReadFromFileMetaData.h"
#include "CoralBase/AttributeList.h"
#include "IOVDbCoolFunctions.h"
#include "IOVDbDataModel/IOVMetaDataContainer.h"
#include "IOVDbDataModel/IOVPayloadContainer.h"
#include "AthenaPoolUtilities/CondAttrListCollection.h"
#include "AthenaPoolUtilities/AthenaAttributeList.h"
using IOVDbNamespace::makeEpochOrRunLumi;
namespace IOVDbNamespace{
ReadFromFileMetaData::ReadFromFileMetaData( const IOVMetaDataContainer* container,
const IOVTime & refTime, const bool useEpochTimestamp):
m_metaContainer(container),
m_referenceTime(refTime),
m_isEpochTime(useEpochTimestamp){
m_payload = (container) ? (container->payloadContainer()) : (nullptr);
if (m_payload){
IOVPayloadContainer::const_iterator pitr=m_payload->find(m_referenceTime);
if (pitr!=m_payload->end()){
m_pptr=*pitr;
} else {
m_pptr = new CondAttrListCollection(not useEpochTimestamp);
m_newedPtr=true;
}
m_folderType=IOVDbNamespace::determineFolderType(m_pptr);
}
}
//
ReadFromFileMetaData::ReadFromFileMetaData( const IOVMetaDataContainer* container,
const cool::ValidityKey & refTimeKey, const bool useEpochTimestamp)
:ReadFromFileMetaData(container,makeEpochOrRunLumi(refTimeKey,useEpochTimestamp),useEpochTimestamp){
std::cout<<"delegated constructor"<<std::endl;//nop, we delegated the constructor
}
//
ReadFromFileMetaData::~ReadFromFileMetaData(){
if (m_newedPtr) delete m_pptr;
}
//
bool
ReadFromFileMetaData::isValid(){
return (m_metaContainer and m_payload);
}
//
IOVDbNamespace::FolderType
ReadFromFileMetaData::folderType(){
return m_folderType;
}
//
unsigned int
ReadFromFileMetaData::numberOfObjects(){
return m_pptr->size();
}
//
std::string
ReadFromFileMetaData::stringAddress(){
std::string strAddress{};
if ((m_folderType==PoolRef) or (m_folderType==AttrList)) {
const coral::AttributeList& payload1=m_pptr->begin()->second;
if (m_folderType==PoolRef) {
// single channel with PoolRef
strAddress=payload1[0].data<std::string>();
} else {
// create an AthenaAttributeList for this data
strAddress="POOLContainer_AthenaAttributeList][CLID=x";
}
}
return strAddress;
}
//
bool
ReadFromFileMetaData::poolPayloadRequested(){
return (m_folderType==PoolRef) or (m_folderType==PoolRefColl);
}
IOVRange
ReadFromFileMetaData::range(){
if ((m_folderType==PoolRef) or (m_folderType==AttrList)) {
return (m_pptr->iov_begin())->second;
} else {
return m_pptr->minRange();
}
}
CondAttrListCollection *
ReadFromFileMetaData::attrListCollection(){
if ((m_folderType!=PoolRef) and (m_folderType!=AttrList)) {
m_attrListColl=new CondAttrListCollection(*m_pptr);
}
return m_attrListColl;
}
AthenaAttributeList *
ReadFromFileMetaData::attributeList(){
if (m_folderType==AttrList) m_attrList = new AthenaAttributeList(m_pptr->begin()->second);
return m_attrList;
}
}
\ No newline at end of file
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
//@file ReadFromFileMetaData.h
//@brief Class to read from file metadata and give the results
//@author Shaun Roe
#ifndef IOVDBSVC_ReadFromFileMetaData_H
#define IOVDBSVC_ReadFromFileMetaData_H
#include "CoolKernel/ValidityKey.h"
#include "AthenaKernel/IOVTime.h"
#include "AthenaKernel/IOVRange.h"
#include <string>
#include "FolderTypes.h"
#include "IOVDbDataModel/IOVPayloadContainer.h"
//fwd declarations
class IOVMetaDataContainer;
//class IOVPayloadContainer;
class CondAttrListCollection;
class AthenaAttributeList;
namespace coral{
class AttributeList;
}
namespace IOVDbNamespace{
class ReadFromFileMetaData{
public:
ReadFromFileMetaData()=delete;
ReadFromFileMetaData(const IOVMetaDataContainer* m_metacon, const IOVTime & refTime, const bool useEpochTimestamp);
ReadFromFileMetaData(const IOVMetaDataContainer* m_metacon, const cool::ValidityKey & refTimeKey, const bool useEpochTimestamp);
~ReadFromFileMetaData();
//
//
bool isValid();
IOVDbNamespace::FolderType folderType();
CondAttrListCollection *attrListCollection();
AthenaAttributeList *attributeList();
unsigned int numberOfObjects();
std::string stringAddress();
bool poolPayloadRequested();
IOVRange range();
private:
const IOVMetaDataContainer* m_metaContainer{};
IOVTime m_referenceTime{};
const IOVPayloadContainer* m_payload{};
bool m_isEpochTime{};
CondAttrListCollection * m_pptr{};
AthenaAttributeList * m_attrList{};
CondAttrListCollection * m_attrListColl{};
IOVDbNamespace::FolderType m_folderType{UNKNOWN};
bool m_newedPtr{};
};
}//namespace
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment