10 #include "CrestApi/CrestApi.h"
11 #include "CrestApi/CrestApiFs.h"
12 #include "CoralBase/AttributeList.h"
13 #include "CoralBase/Attribute.h"
14 #include "CoolKernel/StorageType.h"
15 #include "CoolKernel/RecordSpecification.h"
16 #include "CoolKernel/Record.h"
21 #include "GaudiKernel/MsgStream.h"
22 #include "GaudiKernel/SystemOfUnits.h"
25 {
"Bool", cool::StorageType::Bool},
26 {
"UChar",cool::StorageType::UChar},
27 {
"Int16", cool::StorageType::Int16},
28 {
"UInt16", cool::StorageType::UInt16},
29 {
"Int32", cool::StorageType::Int32},
30 {
"UInt32", cool::StorageType::UInt32},
31 {
"UInt63",cool::StorageType::UInt63},
32 {
"Int64", cool::StorageType::Int64},
34 {
"Double", cool::StorageType::Double},
35 {
"String255", cool::StorageType::String255},
36 {
"String4k", cool::StorageType::String4k},
37 {
"String64k", cool::StorageType::String64k},
38 {
"String16M", cool::StorageType::String16M},
39 {
"String128M", cool::StorageType::String128M},
40 {
"Blob64k", cool::StorageType::Blob64k},
41 {
"Blob16M", cool::StorageType::Blob16M},
42 {
"Blob128M", cool::StorageType::Blob128M}
46 if(crest_path.length()==0)
49 m_crestCl = std::make_unique<Crest::CrestApi>(Crest::CrestApi(crest_path));
52 m_crestCl = std::make_unique<Crest::CrestApiFs>(Crest::CrestApiFs(
true,crest_path));
58 Crest::CrestApiBase* crestCl=NULL;
60 crestCl =
new Crest::CrestApi(crest_path);
63 crestCl =
new Crest::CrestApiFs(
true,crest_path);
65 std::map<std::string, std::string> tagmap;
67 Crest::GlobalTagMapSetDto dto = crestCl->findGlobalTagMap(
globaltag,
"Trace");
68 for (
const auto &tagMapDto : dto.getResources()){
69 tagmap[tagMapDto.getLabel()]=tagMapDto.getTagName();
73 gLog << MSG::ERROR << __FILE__<<
":"<<__LINE__<<
": " <<
e.what() <<
" Cannot get a global tag map for " <<
globaltag<<
endmsg;
83 std::string
regex=R
"delim(<typeName>\s*([^\s]+)\s*</typeName>)delim";
85 std::smatch typeMatch;
87 return (
match) ? std::string(typeMatch[1]) : std::string(
"");
92 std::string folderDescription =
info.getFolderDescription();
100 std::vector< std::pair<std::string,std::string> >
spec=
info.getPayloadSpec().getColumns();
101 std::vector< std::pair<std::string,std::string> > chs =
info.getChannels().getChannels();
102 for (
auto &
p :
spec){
103 if(
p.first==
"PoolRef" &&
p.second==
"String4k"){
104 int id=std::stoll(chs[0].
first);
105 if(chs.size()==1 &&
id==0)
130 gLog << MSG::ERROR << __FILE__<<
":"<<__LINE__<<
": " <<
e.what() <<
" Cannot get a tag meta info " <<
m_crestTag<<
endmsg;
138 return m_TagMeta.value().getTagInfoDto();
142 if(!
m_Tag.has_value()){
145 return m_Tag.value();
154 return info.getFolderDescription();
161 std::vector<cool::ChannelId>
list;
162 std::vector<std::string>
names;
163 std::vector< std::pair<std::string,std::string> >
res =
info.getChannels().getChannels();
165 list.push_back(std::stoll(
p.first));
166 names.push_back(
p.second);
168 return std::make_pair(std::move(
list), std::move(
names));
173 std::vector< std::pair<std::string,std::string> > spec_vec=
info.getPayloadSpec().getColumns();
174 auto *
spec =
new coral::AttributeListSpecification();
175 for (
auto &
p : spec_vec){
178 spec->extend(
p.first,cool::StorageType::storageType(
it->second).cppType());
190 if(
tag.getObjectType()==
"crest-json-multi-iov")
193 std::vector< std::pair<std::string,std::string> >
spec=
info.getPayloadSpec().getColumns();
194 for (
auto &
p :
spec){
203 std::pair<uint64_t,uint64_t>
210 gLog << MSG::ERROR <<
"Wrong since/until."<<
endmsg;
211 return std::make_pair(0,0);
213 const std::size_t
N =
v.size();
229 return std::make_pair(new_since,new_until);
232 std::pair<uint64_t,uint64_t>
234 Crest::IovSetDto dto =
m_crestCl->selectGroups(
tag, 0, 10000, 0,
"id.since:ASC");
235 std::vector<uint64_t>
v = dto.getListSince();
236 v.push_back(cool::ValidityKeyMax);
243 std::vector<std::pair<cool::ValidityKey,std::string>>
res;
244 Crest::IovSetDto dto;
245 if(iovNumber <=1000){
253 if (s_time == 0 && u_time == 0){
260 for (
auto &
p : dto.getResources()){
261 res.push_back(std::make_pair((cool::ValidityKey)
p.getSince(),
p.getPayloadHash()));
274 gLog << MSG::ERROR << __FILE__<<
":"<<__LINE__<<
": "<<
e.what()<<
" while trying to find the payload"<<
endmsg;
275 throw std::runtime_error(
e.what());
284 gLog << MSG::ERROR <<
"LoadPayloadForHash:"<<
e.what()<<
" while trying to parse the payload. Since="<<
since<<
", hash="<<
hash<<
endmsg;
285 throw std::runtime_error(
e.what());
293 std::stringstream
res;
295 std::vector<std::string> chIds =
m_crest_cont.value().channelIds();
298 for (
auto &
ch : chIds){
300 res<<IOVDbNamespace::s_openJson<<
"\""<<
ch<<
"\" : ";
307 for (
const auto & vitr:attr){
309 if (sep2.empty()) sep2 =IOVDbNamespace::s_delimiterJson;
325 std::ostringstream
os;
326 attr[0].toOutputStream(
os);
328 const std::string del(
" : ");
329 const auto separatorPosition =
str.find(del);
330 const std::string payloadOnly=
str.substr(separatorPosition+3);
331 res<<
"\""<<payloadOnly<<
"\"";
338 res<<
" a_data_value";
341 res<<IOVDbNamespace::s_closeJson;
354 std::vector<coral::AttributeList>
res;
356 for (
auto &
p : vecJ){
374 unsigned int s=attr.size();
376 json::const_iterator
it = j.begin();
377 for (
unsigned int i(0);
i!=
s;++
i){
380 auto & att =
const_cast<coral::Attribute&
>(attr[
i]);
384 const auto thisVal =
it.value();
388 if (thisVal.is_null()){
393 for(
auto &
p : tSpec){
394 if(
p.first.compare(att.specification().name())==0){
395 auto pElement = Crest::s_typeToString.find(
p.second);
396 if (pElement == Crest::s_typeToString.
end()){
397 throw std::runtime_error(
"CoralCrestManager::createAttributeList: name not found.");
399 std::string str_spec = pElement ->second;
402 throw std::runtime_error(
"CoralCrestManager::createAttributeList: typespec not found.");
404 typespec=pTypespec->second;
409 if(strVal.size()>2&& strVal[0]==
'"'&& strVal[strVal.size()-1]==
'"')
410 strVal=strVal.substr(1,strVal.size()-2);
412 if((strVal.compare(
"NULL")==0||strVal.compare(
"null")==0)&&
413 (typespec==cool::StorageType::Bool || typespec==cool::StorageType::Int16 || typespec==cool::StorageType::UInt16
414 || typespec==cool::StorageType::Int32 || typespec==cool::StorageType::UInt32
415 || typespec==cool::StorageType::Int64 || typespec==cool::StorageType::UInt63
421 case cool::StorageType::Bool:
423 const bool newVal=(strVal ==
"true");
424 att.setValue<
bool>(newVal);
427 case cool::StorageType::UChar:
429 const unsigned char newVal=std::stoul(strVal);
430 att.setValue<
unsigned char>(newVal);
433 case cool::StorageType::Int16:
435 const short newVal=std::stol(strVal);
436 att.setValue<
short>(newVal);
439 case cool::StorageType::UInt16:
441 const unsigned short newVal=std::stoul(strVal);
442 att.setValue<
unsigned short>(newVal);
445 case cool::StorageType::Int32:
447 const int newVal=std::stoi(strVal);
448 att.setValue<
int>(newVal);
451 case cool::StorageType::UInt32:
453 const unsigned int newVal=std::stoull(strVal);
454 att.setValue<
unsigned int>(newVal);
457 case cool::StorageType::UInt63:
459 const unsigned long long newVal=std::stoull(strVal);
460 att.setValue<
unsigned long long>(newVal);
463 case cool::StorageType::Int64:
465 const long long newVal=std::stoll(strVal);
466 att.setValue<
long long>(newVal);
471 const float newVal=std::stof(strVal);
472 att.setValue<
float>(newVal);
475 case cool::StorageType::Double:
477 const double newVal=std::stod(strVal);
478 att.setValue<
double>(newVal);
481 case cool::StorageType::String255:
482 case cool::StorageType::String4k:
483 case cool::StorageType::String64k:
484 case cool::StorageType::String16M:
485 case cool::StorageType::String128M:
487 att.setValue<std::string>(thisVal.get<std::string>());
490 case cool::StorageType::Blob128M:
491 case cool::StorageType::Blob16M:
492 case cool::StorageType::Blob64k:
496 memcpy(
blob.startingAddress(), charVec.data(), charVec.size());
502 std::string errorMessage(
"UNTREATED TYPE! " +
std::to_string(typespec));
504 gLog << MSG::ERROR <<
"LoadPayloadForHash:" <<errorMessage<<
endmsg;
505 throw std::runtime_error(errorMessage);
511 gLog << MSG::ERROR <<
"Error CoralCrestManager::createAttributeList: "<<
e.what()<<
endmsg;
512 throw std::runtime_error(
e.what());