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},
33 {
"Float", cool::StorageType::Float},
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){
187 if(
tag.getObjectType()==
"crest-json-multi-iov")
190 std::vector< std::pair<std::string,std::string> >
spec=
info.getPayloadSpec().getColumns();
191 for (
auto &
p :
spec){
200 std::pair<uint64_t,uint64_t>
207 gLog << MSG::ERROR <<
"Wrong since/until."<<
endmsg;
208 return std::make_pair(0,0);
210 const std::size_t
N =
v.size();
226 return std::make_pair(new_since,new_until);
229 std::pair<uint64_t,uint64_t>
231 Crest::IovSetDto dto =
m_crestCl->selectGroups(
tag, 0, 10000, 0,
"id.since:ASC");
232 std::vector<uint64_t>
v = dto.getListSince();
233 v.push_back(cool::ValidityKeyMax);
240 std::vector<std::pair<cool::ValidityKey,std::string>>
res;
241 Crest::IovSetDto dto;
242 if(iovNumber <=1000){
250 if (s_time == 0 && u_time == 0){
257 for (
auto &
p : dto.getResources()){
258 res.push_back(std::make_pair((cool::ValidityKey)
p.getSince(),
p.getPayloadHash()));
271 gLog << MSG::ERROR << __FILE__<<
":"<<__LINE__<<
": "<<
e.what()<<
" while trying to find the payload"<<
endmsg;
272 throw std::runtime_error(
e.what());
281 gLog << MSG::ERROR <<
"LoadPayloadForHash:"<<
e.what()<<
" while trying to parse the payload. Since="<<
since<<
", hash="<<
hash<<
endmsg;
282 throw std::runtime_error(
e.what());
290 std::stringstream
res;
292 std::vector<std::string> chIds =
m_crest_cont.value().channelIds();
295 for (
auto &
ch : chIds){
297 res<<IOVDbNamespace::s_openJson<<
"\""<<
ch<<
"\" : ";
304 for (
const auto & vitr:attr){
306 if (sep2.empty()) sep2 =IOVDbNamespace::s_delimiterJson;
322 std::ostringstream
os;
323 attr[0].toOutputStream(
os);
325 const std::string del(
" : ");
326 const auto separatorPosition =
str.find(del);
327 const std::string payloadOnly=
str.substr(separatorPosition+3);
328 res<<
"\""<<payloadOnly<<
"\"";
335 res<<
" a_data_value";
338 res<<IOVDbNamespace::s_closeJson;
351 std::vector<coral::AttributeList>
res;
353 for (
auto &
p : vecJ){
371 unsigned int s=attr.size();
373 json::const_iterator
it = j.begin();
374 for (
unsigned int i(0);
i!=
s;++
i){
377 auto & att =
const_cast<coral::Attribute&
>(attr[
i]);
381 const auto thisVal =
it.value();
385 if (thisVal.is_null()){
390 for(
auto &
p : tSpec){
391 if(
p.first.compare(att.specification().name())==0){
392 auto pElement = Crest::s_typeToString.find(
p.second);
393 if (pElement == Crest::s_typeToString.
end()){
394 throw std::runtime_error(
"CoralCrestManager::createAttributeList: name not found.");
396 std::string str_spec = pElement ->second;
399 throw std::runtime_error(
"CoralCrestManager::createAttributeList: typespec not found.");
401 typespec=pTypespec->second;
406 if(strVal.size()>2&& strVal[0]==
'"'&& strVal[strVal.size()-1]==
'"')
407 strVal=strVal.substr(1,strVal.size()-2);
409 if((strVal.compare(
"NULL")==0||strVal.compare(
"null")==0)&&
410 (typespec==cool::StorageType::Bool || typespec==cool::StorageType::Int16 || typespec==cool::StorageType::UInt16
411 || typespec==cool::StorageType::Int32 || typespec==cool::StorageType::UInt32
412 || typespec==cool::StorageType::Int64 || typespec==cool::StorageType::UInt63
413 || typespec==cool::StorageType::Float || typespec==cool::StorageType::Double)){
418 case cool::StorageType::Bool:
420 const bool newVal=(strVal ==
"true");
421 att.setValue<
bool>(newVal);
424 case cool::StorageType::UChar:
426 const unsigned char newVal=std::stoul(strVal);
427 att.setValue<
unsigned char>(newVal);
430 case cool::StorageType::Int16:
432 const short newVal=std::stol(strVal);
433 att.setValue<
short>(newVal);
436 case cool::StorageType::UInt16:
438 const unsigned short newVal=std::stoul(strVal);
439 att.setValue<
unsigned short>(newVal);
442 case cool::StorageType::Int32:
444 const int newVal=std::stoi(strVal);
445 att.setValue<
int>(newVal);
448 case cool::StorageType::UInt32:
450 const unsigned int newVal=std::stoull(strVal);
451 att.setValue<
unsigned int>(newVal);
454 case cool::StorageType::UInt63:
456 const unsigned long long newVal=std::stoull(strVal);
457 att.setValue<
unsigned long long>(newVal);
460 case cool::StorageType::Int64:
462 const long long newVal=std::stoll(strVal);
463 att.setValue<
long long>(newVal);
466 case cool::StorageType::Float:
468 const float newVal=std::stof(strVal);
469 att.setValue<
float>(newVal);
472 case cool::StorageType::Double:
474 const double newVal=std::stod(strVal);
475 att.setValue<
double>(newVal);
478 case cool::StorageType::String255:
479 case cool::StorageType::String4k:
480 case cool::StorageType::String64k:
481 case cool::StorageType::String16M:
482 case cool::StorageType::String128M:
484 att.setValue<std::string>(thisVal.get<std::string>());
487 case cool::StorageType::Blob128M:
488 case cool::StorageType::Blob16M:
489 case cool::StorageType::Blob64k:
493 memcpy(
blob.startingAddress(), charVec.data(), charVec.size());
499 std::string errorMessage(
"UNTREATED TYPE! " +
std::to_string(typespec));
501 gLog << MSG::ERROR <<
"LoadPayloadForHash:" <<errorMessage<<
endmsg;
502 throw std::runtime_error(errorMessage);
508 gLog << MSG::ERROR <<
"Error CoralCrestManager::createAttributeList: "<<
e.what()<<
endmsg;
509 throw std::runtime_error(
e.what());