ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
IOVDbNamespace::CrestFunctions Class Reference

#include <CrestFunctions.h>

Collaboration diagram for IOVDbNamespace::CrestFunctions:

Public Member Functions

 CrestFunctions (const std::string &crest_path)
 
const std::string & getURLBase ()
 
void setURLBase (const std::string &crest_path)
 
std::string extractHashFromJson (const std::string &jsonReply)
 
std::vector< IovHashPairgetIovsForTag (const std::string &tag, uint64_t since, uint64_t until)
 
std::string getLastHashForTag (const std::string &tag)
 
std::string getPayloadForHash (const std::string &hash)
 
std::string folderDescriptionForTag (const std::string &tag)
 
std::string extractDescriptionFromJson (const std::string &jsonReply)
 
std::map< std::string, std::string > getGlobalTagMap (const std::string &globaltag)
 
nlohmann::json getTagInfo (const std::string &tag)
 
nlohmann::json getTagProperties (const std::string &tag)
 
std::string getTagInfoElement (nlohmann::json tag_info, const std::string &key)
 
std::pair< std::vector< cool::ChannelId >, std::vector< std::string > > extractChannelListFromString (const std::string &chanString)
 
std::vector< uint64_t > getIovGroups (const std::string &tag)
 
std::pair< uint64_t, uint64_t > getSinceUntilPair (const std::vector< uint64_t > &v, const uint64_t since, const uint64_t until)
 
int getTagSize (const std::string &tagname)
 
std::pair< uint64_t, uint64_t > getIovInterval (const std::string &tag, const uint64_t since, const uint64_t until)
 

Private Member Functions

nlohmann::json getResources (nlohmann::json &js)
 

Private Attributes

std::unique_ptr< Crest::CrestApiBasem_crestCl
 
std::string m_CREST_PATH = ""
 

Detailed Description

Definition at line 30 of file CrestFunctions.h.

Constructor & Destructor Documentation

◆ CrestFunctions()

IOVDbNamespace::CrestFunctions::CrestFunctions ( const std::string &  crest_path)

Definition at line 22 of file CrestFunctions.cxx.

22  {
23  setURLBase(crest_path);
24 
25  const std::string prefix1 = "http://";
26  const std::string prefix2 = "https://";
27  if (crest_path.starts_with(prefix1) || crest_path.starts_with(prefix2)){
28  m_crestCl = std::unique_ptr<Crest::CrestClient>(new Crest::CrestClient(getURLBase()));
29  }
30  else{
31  m_crestCl = std::unique_ptr<Crest::CrestFsClient>(new Crest::CrestFsClient(true,getURLBase()));
32  }
33  }

Member Function Documentation

◆ extractChannelListFromString()

std::pair< std::vector< cool::ChannelId >, std::vector< std::string > > IOVDbNamespace::CrestFunctions::extractChannelListFromString ( const std::string &  chanString)

Definition at line 199 of file CrestFunctions.cxx.

199  {
200  std::vector<cool::ChannelId> list;
201  std::vector<std::string> names;
202  nlohmann::json js = nlohmann::json::parse(chanString);
203  int n = js.size();
204 
205  for (int i = 0; i <= n; i++) {
206  nlohmann::json j_object = js[i];
207  for (auto& [key, val] : j_object.items()){
208  list.push_back(std::stoll(key));
209  names.push_back(val);
210  }
211  }
212 
213  // if all the names are empty, these are unnamed channels, and can just return an empty vector for the names
214  auto isEmpty=[](const std::string & s){return s.empty();};
215  if ( std::all_of(names.begin(), names.end(), isEmpty)) names.clear();
216  return std::make_pair(std::move(list), std::move(names));
217  }

◆ extractDescriptionFromJson()

std::string IOVDbNamespace::CrestFunctions::extractDescriptionFromJson ( const std::string &  jsonReply)

Definition at line 101 of file CrestFunctions.cxx.

101  {
102  std::string description{};
103  try{
104  const std::string_view signature="node_description\\\":\\\"";
105  const auto signaturePosition = jsonReply.find(signature);
106  if (signaturePosition == std::string::npos) throw std::runtime_error("signature "+std::string(signature)+" not found");
107  const auto startOfDescription= signaturePosition + signature.size();
108  const std::string_view endSignature = "\\\",\\\"payload_spec";
109  const auto endOfDescription=jsonReply.find(endSignature);
110  if (endOfDescription == std::string::npos) throw std::runtime_error("end signature "+std::string(endSignature)+" not found");
111  const auto len=endOfDescription-startOfDescription;
112  description=jsonReply.substr(startOfDescription, len);
113  } catch (std::exception & e){
114  std::cerr<<__FILE__<<":"<<__LINE__<< ": "<<e.what()<<" while trying to find the description in "<<jsonReply<<std::endl;
115  }
116 
118  }

◆ extractHashFromJson()

std::string IOVDbNamespace::CrestFunctions::extractHashFromJson ( const std::string &  jsonReply)

Definition at line 47 of file CrestFunctions.cxx.

47  {
48  std::string hash{};
49  try{
50  std::string_view signature="payloadHash\":\"";
51  auto signaturePosition=jsonReply.rfind(signature);
52  if (signaturePosition == std::string::npos) throw std::runtime_error("signature "+std::string(signature)+" not found");
53  auto startOfHash=signaturePosition + signature.size();
54  auto endOfHash=jsonReply.find('\"',startOfHash);
55  auto len=endOfHash-startOfHash;
56  if (startOfHash > jsonReply.size()) throw std::runtime_error("Hash start is beyond end of string");
57  hash=jsonReply.substr(startOfHash, len);
58  } catch (std::exception & e){
59  std::cerr<<__FILE__<<":"<<__LINE__<< ": "<<e.what()<<" while trying to find the hash in "<<jsonReply<<std::endl;
60  }
61  return hash;
62  }

◆ folderDescriptionForTag()

std::string IOVDbNamespace::CrestFunctions::folderDescriptionForTag ( const std::string &  tag)

Definition at line 122 of file CrestFunctions.cxx.

122  {
123 
124  std::string jsonReply = "";
125 
126  TagMetaDto dto = m_crestCl->findTagMeta(tag);
127  jsonReply = dto.tagInfo.getFolderDescription();
128  return jsonReply;
129  }

◆ getGlobalTagMap()

std::map< std::string, std::string > IOVDbNamespace::CrestFunctions::getGlobalTagMap ( const std::string &  globaltag)

Definition at line 133 of file CrestFunctions.cxx.

133  {
134  std::map<std::string, std::string> tagmap;
135  try{
136  GlobalTagMapSetDto dto = m_crestCl->findGlobalTagMap(globaltag,"Trace");
137  nlohmann::json globaltag_map_data = dto.to_json();
138  nlohmann::json j = getResources(globaltag_map_data);
139  int n = j.size();
140  for (int i = 0; i < n; i++ ){
141  nlohmann::json j_item = j[i];
142  if (j_item.contains("label") && j_item.contains("tagName") ){
143  tagmap[j_item["label"]] = j_item["tagName"];
144  }
145  }
146  } catch (std::exception & e){
147  std::cerr<<__FILE__<<":"<<__LINE__<< ": " << e.what() << " Cannot get a global tag map for " << globaltag << std::endl;
148  }
149 
150  return tagmap;
151  }

◆ getIovGroups()

std::vector< uint64_t > IOVDbNamespace::CrestFunctions::getIovGroups ( const std::string &  tag)

Definition at line 227 of file CrestFunctions.cxx.

227  {
228  std::vector<uint64_t> v;
229  try{
230  IovSetDto dto = m_crestCl->selectGroups(tag, 0, 10000, 0, "id.since:ASC");
231  const std::vector<IovDto> & res = dto.resources;
232  for (const IovDto & item_iov: res){
233  v.emplace_back(item_iov.since);
234  }
235  } catch (std::exception & e){
236  std::cerr<<__FILE__<<":"<<__LINE__<< ": "<<e.what()<<" while trying to find the IOVs"<<std::endl;
237  return {};
238  }
239  return v;
240  }

◆ getIovInterval()

std::pair< uint64_t, uint64_t > IOVDbNamespace::CrestFunctions::getIovInterval ( const std::string &  tag,
const uint64_t  since,
const uint64_t  until 
)

Definition at line 285 of file CrestFunctions.cxx.

285  {
286  std::vector<uint64_t> v = getIovGroups(tag);
287  v.push_back(std::numeric_limits<uint64_t>::max()); // added "infinity" as the last item
288  return getSinceUntilPair(std::move(v), since, until);
289  }

◆ getIovsForTag()

std::vector< IovHashPair > IOVDbNamespace::CrestFunctions::getIovsForTag ( const std::string &  tag,
uint64_t  since,
uint64_t  until 
)

Definition at line 293 of file CrestFunctions.cxx.

293  {
294  std::vector<IovHashPair> iovHashPairs;
295  int iovNumber = getTagSize(tag);
296  try{
297  IovSetDto dto;
298  if (iovNumber <=1000) {
299  dto = m_crestCl->selectIovs(tag, 0, -1, 0, 10000, 0, "id.since:ASC");
300  } else {
301  const auto &[s_time, u_time] = getIovInterval(tag, since, until);
302  if (s_time == 0 && u_time == 0){ // data out of range
303  return iovHashPairs;
304  } else {
305  dto = m_crestCl->selectIovs(tag, s_time, u_time, 0, 10000, 0, "id.since:ASC");
306  }
307  }
308  std::vector<IovDto> res = dto.resources;
309  std::map<uint64_t, std::string> hashmap;
310  for (const IovDto & item: res) {
311  hashmap[item.since] = item.payloadHash;
312  }
313  for (auto& t : hashmap){
314  iovHashPairs.emplace_back(std::to_string(t.first),t.second);
315  }
316  } catch (std::exception & e){
317  std::cerr<<__FILE__<<":"<<__LINE__<< ": "<<e.what()<<" while trying to find the IOVs"<<std::endl;
318  return {};
319  }
320  return iovHashPairs;
321  }

◆ getLastHashForTag()

std::string IOVDbNamespace::CrestFunctions::getLastHashForTag ( const std::string &  tag)

Definition at line 66 of file CrestFunctions.cxx.

66  {
67  char tu[] = "";
68  strfry(tu);
69  std::string reply = "";
70 
71  try{
72  IovSetDto dto = m_crestCl->selectIovs(tag, 0, -1, 0, 10000, 0, "id.since:ASC");
73 
74  nlohmann::json iov_data = dto.to_json();
75  nlohmann::json iov_list = getResources(iov_data);
76  reply = iov_list.dump();
77  } catch (std::exception & e){
78  std::cerr<<__FILE__<<":"<<__LINE__<< ": "<<e.what()<<" while trying to find the IOVs"<<std::endl;
79  return "";
80  }
81 
82  return extractHashFromJson(reply);
83  }

◆ getPayloadForHash()

std::string IOVDbNamespace::CrestFunctions::getPayloadForHash ( const std::string &  hash)

Definition at line 86 of file CrestFunctions.cxx.

86  {
87  std::string reply = "";
88 
89  try{
90  reply = m_crestCl->getPayload(hash);
91  } catch (std::exception & e){
92  std::cerr<<__FILE__<<":"<<__LINE__<< ": "<<e.what()<<" while trying to find the payload"<<std::endl;
93  return "";
94  }
95 
96  return reply;
97  }

◆ getResources()

nlohmann::json IOVDbNamespace::CrestFunctions::getResources ( nlohmann::json js)
private

Definition at line 220 of file CrestFunctions.cxx.

220  {
221  nlohmann::json js2 = json::array();
222  nlohmann::json result = js.value("resources", js2);
223  return result;
224  }

◆ getSinceUntilPair()

std::pair< uint64_t, uint64_t > IOVDbNamespace::CrestFunctions::getSinceUntilPair ( const std::vector< uint64_t > &  v,
const uint64_t  since,
const uint64_t  until 
)

Definition at line 244 of file CrestFunctions.cxx.

244  {
245  uint64_t new_since = 0;
246  uint64_t new_until = 0;
247  std::pair<uint64_t,uint64_t> answer = std::make_pair(0,0);
248 
249  if (until < since){
250  std::cerr << "Wrong since/until." << std::endl;
251  return answer;
252  }
253 
254  int N = v.size();
255  for (int i = 0; i < N; i++) {
256  if(v[i] <= since && since < v[i+1]){
257  new_since = v[i];
258  break;
259  }
260  }
261 
262  for (int i = 0; i < N; i++) {
263  if(v[i] < until && until <= v[i+1]){
264  new_until = v[i+1];
265  break;
266  }
267  }
268 
269  answer = std::make_pair(new_since,new_until);
270  return answer;
271  }

◆ getTagInfo()

nlohmann::json IOVDbNamespace::CrestFunctions::getTagInfo ( const std::string &  tag)

Definition at line 154 of file CrestFunctions.cxx.

154  {
155  try{
156  TagMetaDto dto = m_crestCl->findTagMeta(tag);
157  nlohmann::json meta_info = dto.to_json();
158 
159  if (meta_info.contains("tagInfo")){
160  std::string metainf = meta_info["tagInfo"];
162  return js;
163  }
164 
165  } catch (std::exception & e){
166  std::cerr<<__FILE__<<":"<<__LINE__<< ": " << e.what() << " Cannot get a tag meta info " << tag << std::endl;
167  }
168  return nullptr;
169  }

◆ getTagInfoElement()

std::string IOVDbNamespace::CrestFunctions::getTagInfoElement ( nlohmann::json  tag_info,
const std::string &  key 
)

Definition at line 183 of file CrestFunctions.cxx.

183  {
184  if (tag_info.contains(key)){
185  if (key == "channel_list"){
186  return tag_info[key].dump();
187  } else if (key== "node_description"){
188  std::string v;
189  tag_info[key].get_to(v);
190  return v;
191  } else{
192  return nlohmann::to_string(tag_info[key]);
193  }
194  }
195  return "";
196  }

◆ getTagProperties()

nlohmann::json IOVDbNamespace::CrestFunctions::getTagProperties ( const std::string &  tag)

Definition at line 172 of file CrestFunctions.cxx.

172  {
173  try{
174  TagDto dto = m_crestCl->findTag(tag);
175  return dto.to_json();
176  } catch (std::exception & e){
177  std::cerr<<__FILE__<<":"<<__LINE__<< ": " << e.what() << " Cannot get a tag Properties of " << tag << std::endl;
178  }
179  return nullptr;
180  }

◆ getTagSize()

int IOVDbNamespace::CrestFunctions::getTagSize ( const std::string &  tagname)

Definition at line 274 of file CrestFunctions.cxx.

274  {
275  int res = 0;
276  try{
277  res = m_crestCl->getSize(tagname);
278  } catch (std::exception & e){
279  std::cerr<<__FILE__<<":"<<__LINE__<< ": " << e.what() << " Cannot get the tag size for " << tagname << std::endl;
280  }
281  return res;
282  }

◆ getURLBase()

const std::string & IOVDbNamespace::CrestFunctions::getURLBase ( )

Definition at line 36 of file CrestFunctions.cxx.

36  {
37  return m_CREST_PATH;
38  }

◆ setURLBase()

void IOVDbNamespace::CrestFunctions::setURLBase ( const std::string &  crest_path)

Definition at line 41 of file CrestFunctions.cxx.

41  {
42  m_CREST_PATH = crest_path;
43  }

Member Data Documentation

◆ m_CREST_PATH

std::string IOVDbNamespace::CrestFunctions::m_CREST_PATH = ""
private

Definition at line 88 of file CrestFunctions.h.

◆ m_crestCl

std::unique_ptr<Crest::CrestApiBase> IOVDbNamespace::CrestFunctions::m_crestCl
private

Definition at line 86 of file CrestFunctions.h.


The documentation for this class was generated from the following files:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
TagMetaDto::tagInfo
TagInfoDto tagInfo
Definition: CrestModel.h:243
IOVDbNamespace::CrestFunctions::m_CREST_PATH
std::string m_CREST_PATH
Definition: CrestFunctions.h:88
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
get_generator_info.result
result
Definition: get_generator_info.py:21
IovSetDto::resources
std::vector< IovDto > resources
Definition: CrestModel.h:289
IOVDbNamespace::CrestFunctions::getIovInterval
std::pair< uint64_t, uint64_t > getIovInterval(const std::string &tag, const uint64_t since, const uint64_t until)
Definition: CrestFunctions.cxx:285
IOVDbNamespace::CrestFunctions::m_crestCl
std::unique_ptr< Crest::CrestApiBase > m_crestCl
Definition: CrestFunctions.h:86
json
nlohmann::json json
Definition: HistogramDef.cxx:9
IOVDbNamespace::CrestFunctions::getSinceUntilPair
std::pair< uint64_t, uint64_t > getSinceUntilPair(const std::vector< uint64_t > &v, const uint64_t since, const uint64_t until)
Definition: CrestFunctions.cxx:244
TagDto::to_json
json to_json() const
Definition: CrestModel.cxx:172
IovDto
Definition: CrestModel.h:268
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
IOVDbNamespace::CrestFunctions::setURLBase
void setURLBase(const std::string &crest_path)
Definition: CrestFunctions.cxx:41
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
TagMetaDto::to_json
json to_json() const
Definition: CrestModel.cxx:389
TagMetaDto
Definition: CrestModel.h:238
IOVDbNamespace::CrestFunctions::extractHashFromJson
std::string extractHashFromJson(const std::string &jsonReply)
Definition: CrestFunctions.cxx:47
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
dq_defect_copy_defect_database.until
def until
Definition: dq_defect_copy_defect_database.py:55
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
python.subdetectors.mmg.names
names
Definition: mmg.py:8
TagDto
The TagDto class It contains all fields of the TagDto class from the CREST API.
Definition: CrestModel.h:98
calibdata.exception
exception
Definition: calibdata.py:496
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
GlobalTagMapSetDto
Definition: CrestModel.h:160
GlobalTagMapSetDto::to_json
json to_json() const
Definition: CrestModel.cxx:253
CheckTagAssociation.globaltag
globaltag
Definition: CheckTagAssociation.py:18
lumiFormat.array
array
Definition: lumiFormat.py:91
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
IOVDbNamespace::unescapeBackslash
std::string unescapeBackslash(const std::string &original)
Definition: IOVDbStringFunctions.cxx:102
item
Definition: ItemListSvc.h:43
Crest::CrestFsClient
Definition: CrestApiFs.h:32
python.PyAthena.v
v
Definition: PyAthena.py:154
IOVDbNamespace::CrestFunctions::getResources
nlohmann::json getResources(nlohmann::json &js)
Definition: CrestFunctions.cxx:220
IOVDbNamespace::CrestFunctions::getURLBase
const std::string & getURLBase()
Definition: CrestFunctions.cxx:36
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
IOVDbNamespace::CrestFunctions::getIovGroups
std::vector< uint64_t > getIovGroups(const std::string &tag)
Definition: CrestFunctions.cxx:227
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
IovSetDto
Definition: CrestModel.h:287
IOVDbNamespace::unescapeQuotes
std::string unescapeQuotes(const std::string &original)
Definition: IOVDbStringFunctions.cxx:95
TagInfoDto::getFolderDescription
const std::string & getFolderDescription()
Definition: CrestModel.h:228
Crest::CrestClient
Definition: CrestApi.h:33
tagname
Definition: tagname.h:29
IOVDbNamespace::CrestFunctions::getTagSize
int getTagSize(const std::string &tagname)
Definition: CrestFunctions.cxx:274
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
IovSetDto::to_json
json to_json() const
Definition: CrestModel.cxx:497
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37