9#include "CoralBase/Blob.h"
10#include "CoralBase/Attribute.h"
11#include "CoralBase/AttributeList.h"
12#include "CoralBase/AttributeListSpecification.h"
14#include "CoolKernel/ChannelSelection.h"
15#include "CoolKernel/IDatabase.h"
16#include "CoolKernel/IFolder.h"
19#include <unordered_map>
25 const std::unordered_map<std::type_index, std::function<int(
const coral::Attribute &)>>
27 {std::type_index(
typeid(
bool)), [](
const coral::Attribute & )->
int {
return 1; } },
28 {std::type_index(
typeid(
unsigned char)), [](
const coral::Attribute & )->
int {
return 1; } },
29 {std::type_index(
typeid(
char)), [](
const coral::Attribute & )->
int {
return 1; } },
31 {std::type_index(
typeid(
short)), [](
const coral::Attribute & )->
int {
return 2; } },
32 {std::type_index(
typeid(
unsigned short)), [](
const coral::Attribute & )->
int {
return 2; } },
33 {std::type_index(
typeid(
char)), [](
const coral::Attribute & )->
int {
return 2; } },
35 {std::type_index(
typeid(
int)), [](
const coral::Attribute & )->
int {
return 4; } },
36 {std::type_index(
typeid(
unsigned int)), [](
const coral::Attribute & )->
int {
return 4; } },
37 {std::type_index(
typeid(
float)), [](
const coral::Attribute & )->
int {
return 4; } },
39 {std::type_index(
typeid(
long long)), [](
const coral::Attribute & )->
int {
return 8; } },
40 {std::type_index(
typeid(
unsigned long long)), [](
const coral::Attribute & )->
int {
return 8; } },
41 {std::type_index(
typeid(
double)), [](
const coral::Attribute & )->
int {
return 8; } },
43 {std::type_index(
typeid(std::string)), [](
const coral::Attribute & attr)->
int {
return attr.data<std::string>().size(); } },
44 {std::type_index(
typeid(coral::Blob)), [](
const coral::Attribute & attr)->
int {
return attr.data<coral::Blob>().size(); } }
51 const coral::AttributeListSpecification &
53 return atrlist.specification();
58 const auto & spec{attribute.specification()};
60 return sizeFunctions.at(std::type_index(spec.type()))(attribute);
61 }
catch (
const std::out_of_range& oor) {
68 return (sizeFunctions.find(std::type_index(attribute.specification().type())) != sizeFunctions.end());
74 for (
const auto & attribute:atrlist){
82 auto isSelected = [& selected](cool::ChannelId id){
return selected.inSelection(
id);};
83 return std::count_if(channels.begin(), channels.end(),isSelected);
90 time.setTimestamp(key);
99 return seconds*1000000000LL;
104 return (
run<<32) + lumi;
107 std::pair<unsigned long long, unsigned long long>
109 return std::pair<unsigned long long, unsigned long long>{iovTime>>32, iovTime&0xFFFFFFFF};
113 makeRange(
const cool::ValidityKey since,
const cool::ValidityKey until,
const bool timeIsEpoch) {
128 makeChannel(
const std::string& strval,
const cool::ChannelId defchan) {
131 if (not strval.empty())
return std::stol(strval);
135 std::pair<bool, std::string>
138 std::string folderdesc{};
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" );
146 if (!dbPtr->existsFolder(folderName)) {
147 throw std::runtime_error(
"Folder " + folderName +
" does not exist" );
149 cool::IFolderPtr fldPtr=dbPtr->getFolder(folderName);
151 multiversion=(fldPtr->versioningMode()==cool::FolderVersioning::MULTI_VERSION);
153 folderdesc=fldPtr->description();
154 return std::make_pair(multiversion, std::move(folderdesc));
159 std::pair<std::vector<cool::ChannelId>, std::vector<std::string>>
161 std::vector<cool::ChannelId> channelNumbers;
162 std::vector<std::string> channelNames;
164 cool::IDatabasePtr dbPtr=pConnection->
getCoolDb();
166 if (!dbPtr->existsFolder(folderName)) {
167 throw std::runtime_error(
"Folder " + folderName +
" does not exist" );
169 cool::IFolderPtr fldPtr=dbPtr->getFolder(folderName);
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);
179 std::for_each(chanmap.begin(), chanmap.end(),unzipElement);
181 channelNumbers=fldPtr->listChannels();
183 return std::make_pair(std::move(channelNumbers), std::move(channelNames));
const std::string & name() const
cool::IDatabasePtr getCoolDb()
Basic time unit for IOVSvc.
void setRETime(uint64_t time) noexcept
void setTimestamp(uint64_t timestamp) noexcept
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.
unsigned int attributeListSize(const coral::AttributeList &atrlist)
return the size (in bytes) of an AttributeList
unsigned int attributeSize(const coral::Attribute &attribute)
return the size (in bytes) of an Attribute
std::pair< unsigned long long, unsigned long long > runLumiFromIovTime(const unsigned long long iovTime)
Return a [run,lumi] pair from an IOV time.
bool typeSizeIsKnown(const coral::Attribute &attribute)
Return a bool indicating whether the size of a given Attribute can be determined.
std::pair< bool, std::string > folderMetadata(IOVDbConn *pConnection, const std::string &folderName)
Retrieve (bool) multiversion flag and folder description.
const coral::AttributeListSpecification & attrList2Spec(const coral::AttributeList &atrlist)
return the AttributeListSpecification of an AttributeList
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.
std::pair< std::vector< cool::ChannelId >, std::vector< std::string > > channelList(IOVDbConn *pConnection, const std::string &folderName, const bool named)
Retrieve channel information.
unsigned long long iovTimeFromSeconds(const unsigned long long seconds)
Create a long long time in ns from s.
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.
unsigned long long iovTimeFromRunLumi(const unsigned long long run, const unsigned long long lumi)
Create a long long representing the IOV from run, lumi.
IOVRange makeRange(const cool::ValidityKey since, const cool::ValidityKey until, const bool timeIsEpoch)
Make an IOVRange from two validity keys.