ATLAS Offline Software
BasicFolder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "BasicFolder.h"
5 #include <iostream>
6 #include "FolderTypes.h"
7 #include "IOVDbStringFunctions.h"
9 #include "CoralBase/AttributeList.h"
10 #include "CoralBase/AttributeListSpecification.h"
11 #include "CoralBase/Attribute.h"
12 
13 namespace IOVDbNamespace{
14 
15 static const std::pair<cool::ValidityKey, cool::ValidityKey> infiniteIov(0,cool::ValidityKeyMax);
16 static const coral::AttributeList invalidPayload{};
17 static const std::vector<coral::AttributeList> invalidVectorPayload{};
18 
19 
21  m_payload{},
22  m_vectorPayload{},
23  m_name2Channel{},
24  m_channel2Name{},
25  m_isVectorPayload{},
26  m_channels{},
27  m_iov{infiniteIov} {
28 
29  }
30  bool
32  return m_channels.empty();
33  }
34 
35  void
38  }
39 
40  bool
42  return m_isVectorPayload;
43  }
44  //
45  void
46  BasicFolder::setIov(const std::pair<cool::ValidityKey, cool::ValidityKey> & iov){
47  m_iov=iov;
48  }
49 
50  //add attributeList
51  void
52  BasicFolder::addChannelPayload(const cool::ChannelId & channelId, const std::string & name, const coral::AttributeList & payload){
56  }
57 
58  void
60 
61  m_channels.push_back(channelId);
63  }
64 
65  //add vector payload
66  void
67  BasicFolder::addChannelPayload(const cool::ChannelId & channelId, const std::string & name, const std::vector<coral::AttributeList> & payload){
71  }
72 
73  void
74  BasicFolder::addChannelPayload(const cool::ChannelId & channelId, const std::vector<coral::AttributeList> & payload){
75  m_channels.push_back(channelId);
77  }
78 
79  //
81  BasicFolder::getPayload(const cool::ChannelId & channelId){
82  return m_payload.find(channelId)->second;
83  }
84 
86  BasicFolder::getPayload(const std::string & channelName){
87  if (m_isVectorPayload) return invalidPayload;
88  const auto chanPtr= m_name2Channel.find(channelName);
89  bool nameExists = (chanPtr != m_name2Channel.end());
90  if (not nameExists) return invalidPayload;
91  const cool::ChannelId channel=chanPtr->second;
92  return getPayload(channel);
93  }
94 
95  std::vector<coral::AttributeList>
96  BasicFolder::getVectorPayload(const cool::ChannelId & channelId){
97  return m_vectorPayload.find(channelId)->second;
98  }
99 
100  std::vector<coral::AttributeList>
101  BasicFolder::getVectorPayload(const std::string & channelName){
102  if (not m_isVectorPayload) return invalidVectorPayload;
103  const auto chanPtr= m_name2Channel.find(channelName);
104  bool nameExists = (chanPtr != m_name2Channel.end());
105  if (not nameExists) return invalidVectorPayload;
106  const cool::ChannelId channel=chanPtr->second;
107  return getVectorPayload(channel);
108  }
109 
110  const std::vector<cool::ChannelId>&
112  return m_channels;
113  }
114 
115  std::pair<cool::ValidityKey, cool::ValidityKey>
117  return m_iov;
118  }
119  std::string BasicFolder::jsonPayload(const std::string & folderDescription, const std::string & spec){
121  std::string sep="";
122  std::string result("\"data_array\" : [");
123  std::sort(m_channels.begin(), m_channels.end());
124  for (auto &chId : m_channels){
125  result+=sep;
126  result+=s_openJson+quote(std::to_string(chId))+" : ";
127  switch (ftype){
129  {
130  const std::vector<coral::AttributeList>& vAtt = getVectorPayload(chId);
131  std::string os="";
132  std::string sep="";
133  os+='[';//vector of vectors
134  for (auto &att : vAtt){
135  os+=sep;
136  os+=jsonAttributeList(att);
137  if (sep.empty()) sep =s_delimiterJson;
138  }
139  os+=']';
140  result+=os;
141  break;
142  }
146  {
147  const coral::AttributeList& att = getPayload(chId);
148  result +=jsonAttributeList(att);
149  break;
150  }
152  {
153  const coral::AttributeList& att = getPayload(chId);
154  std::ostringstream os;
155  att[0].toOutputStream(os);
156  auto res=os.str();
157  const std::string sep(" : ");
158  const auto separatorPosition = res.find(sep);
159  const std::string payloadOnly=res.substr(separatorPosition+3);
160  result += quote(payloadOnly);
161  break;
162  }
164  {
165  result += " CoraCool";
166  break;
167  }
168  default:
169  result+=" a_data_value";
170  }
171  if (sep.empty()) sep=",";
172  result+=s_closeJson;
173  }
174  result+=']';
175  return result;
176  }
177 
178 
179  }//namespace end
180 
IOVDbNamespace::BasicFolder::isVectorPayload
bool isVectorPayload() const
Definition: BasicFolder.cxx:41
get_generator_info.result
result
Definition: get_generator_info.py:21
dqt_zlumi_alleff_HIST.iov
iov
Definition: dqt_zlumi_alleff_HIST.py:119
IOVDbNamespace::BasicFolder::getPayload
coral::AttributeList getPayload(const cool::ChannelId &channelId)
Definition: BasicFolder.cxx:81
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
IOVDbNamespace::BasicFolder::m_channels
std::vector< cool::ChannelId > m_channels
Definition: BasicFolder.h:54
IOVDbNamespace::PoolRefColl
@ PoolRefColl
Definition: FolderTypes.h:31
IOVDbNamespace::BasicFolder::m_iov
std::pair< cool::ValidityKey, cool::ValidityKey > m_iov
Definition: BasicFolder.h:55
IOVDbNamespace::PoolRef
@ PoolRef
Definition: FolderTypes.h:30
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
IOVDbStringFunctions.h
IOVDbJsonStringFunctions.h
IOVDbNamespace::BasicFolder::m_isVectorPayload
bool m_isVectorPayload
Definition: BasicFolder.h:53
IOVDbNamespace::BasicFolder::m_name2Channel
std::map< std::string, int > m_name2Channel
Definition: BasicFolder.h:50
master.flag
bool flag
Definition: master.py:29
IOVDbNamespace::BasicFolder::m_payload
std::map< int, coral::AttributeList > m_payload
Definition: BasicFolder.h:47
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
IOVDbNamespace::CoolVector
@ CoolVector
Definition: FolderTypes.h:33
IOVDbNamespace::CoraCool
@ CoraCool
Definition: FolderTypes.h:32
IOVDbNamespace::BasicFolder::empty
bool empty() const
Definition: BasicFolder.cxx:31
IOVDbNamespace::AttrListColl
@ AttrListColl
Definition: FolderTypes.h:29
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
grepfile.sep
sep
Definition: grepfile.py:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
IOVDbNamespace::jsonAttributeList
std::string jsonAttributeList(const coral::AttributeList &atrlist)
Produce a representation of a coral::AttributeList as a json string.
Definition: IOVDbJsonStringFunctions.cxx:40
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
IOVDbNamespace::BasicFolder::addChannelPayload
void addChannelPayload(const cool::ChannelId &channelId, const std::string &name, const coral::AttributeList &payload)
Definition: BasicFolder.cxx:52
IOVDbNamespace::BasicFolder::BasicFolder
BasicFolder()
Definition: BasicFolder.cxx:20
IOVDbNamespace::BasicFolder::iov
std::pair< cool::ValidityKey, cool::ValidityKey > iov()
Definition: BasicFolder.cxx:116
IOVDbNamespace::BasicFolder::channelIds
const std::vector< cool::ChannelId > & channelIds()
Definition: BasicFolder.cxx:111
IOVDbNamespace::AttrList
@ AttrList
Definition: FolderTypes.h:28
IOVDbNamespace::BasicFolder::m_channel2Name
std::map< int, std::string > m_channel2Name
Definition: BasicFolder.h:51
FolderTypes.h
BasicFolder.h
IOVDbNamespace::BasicFolder::setVectorPayloadFlag
void setVectorPayloadFlag(const bool flag)
Definition: BasicFolder.cxx:36
IOVDbNamespace::determineFolderType
FolderType determineFolderType(const std::string &folderDescription, const std::string &spec, const std::vector< cool::ChannelId > &chans)
Determine folder type with optional check using clid service to check clid matches typename.
Definition: FolderTypes.cxx:17
IOVDbNamespace::BasicFolder::getVectorPayload
std::vector< coral::AttributeList > getVectorPayload(const cool::ChannelId &channelId)
Definition: BasicFolder.cxx:96
IOVDbNamespace::quote
std::string quote(const std::string &sentence)
Enclose a string in ".
Definition: IOVDbStringFunctions.cxx:85
IOVDbNamespace::BasicFolder::m_vectorPayload
std::map< int, std::vector< coral::AttributeList > > m_vectorPayload
Definition: BasicFolder.h:48
IOVDbNamespace::BasicFolder::jsonPayload
std::string jsonPayload(const std::string &folderDescription, const std::string &spec)
Definition: BasicFolder.cxx:119
IOVDbNamespace::BasicFolder::setIov
void setIov(const std::pair< cool::ValidityKey, cool::ValidityKey > &iov)
Definition: BasicFolder.cxx:46
IOVDbNamespace::FolderType
FolderType
Definition: FolderTypes.h:26
IOVDbNamespace
Definition: Base64Codec.cxx:16