ATLAS Offline Software
Loading...
Searching...
No Matches
RDBVersionAccessor Class Reference

RDBVersionAccessor is a helper class navigating HVS tree and getting child node tag by the tag of one of its parents. More...

#include <RDBVersionAccessor.h>

Collaboration diagram for RDBVersionAccessor:

Public Member Functions

 RDBVersionAccessor (const std::string &childNode, const std::string &parentNode, const std::string &parentTag, coral::ISessionProxy *session, MsgStream &stream)
 Constructor.
void getChildTagData ()
 Constructs SQL query and retrieves child tag ID and Name from DB.
const std::string & getNodeName () const
const std::string & getTagName () const
const std::string & getTagID () const
bool isLeaf () const

Private Member Functions

 RDBVersionAccessor ()
 Default constructor.
std::string attribute2String (const coral::AttributeList &attList, const std::string &fieldName)

Private Attributes

coral::ISessionProxy * m_session
std::string m_childNode
std::string m_parentNode
std::string m_parentTag
std::string m_tagName
std::string m_tagID
bool m_isChildLeaf
MsgStream & m_msgStream

Detailed Description

RDBVersionAccessor is a helper class navigating HVS tree and getting child node tag by the tag of one of its parents.

Definition at line 36 of file RDBVersionAccessor.h.

Constructor & Destructor Documentation

◆ RDBVersionAccessor() [1/2]

RDBVersionAccessor::RDBVersionAccessor ( const std::string & childNode,
const std::string & parentNode,
const std::string & parentTag,
coral::ISessionProxy * session,
MsgStream & stream )

Constructor.

Parameters
childNode[IN] child node name
parentNode[IN] parent node name
parentTag[IN] parent tag name
session[IN] active relational session

Definition at line 41 of file RDBVersionAccessor.cxx.

46 : m_session(session)
47 , m_childNode(childNode)
48 , m_parentNode(parentNode)
49 , m_parentTag(parentTag)
50 , m_tagName("")
51 , m_tagID("")
52 , m_isChildLeaf(false)
53 , m_msgStream(msgStream)
54{
55}
coral::ISessionProxy * m_session

◆ RDBVersionAccessor() [2/2]

RDBVersionAccessor::RDBVersionAccessor ( )
private

Default constructor.

Member Function Documentation

◆ attribute2String()

std::string RDBVersionAccessor::attribute2String ( const coral::AttributeList & attList,
const std::string & fieldName )
private

Definition at line 338 of file RDBVersionAccessor.cxx.

340{
341 std::ostringstream streamValue;
342 attList[fieldName].toOutputStream(streamValue);
343 std::string stringValue = streamValue.str();
344 unsigned int position = stringValue.find(") :");
345 return stringValue.substr(position+4);
346}
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.

◆ getChildTagData()

void RDBVersionAccessor::getChildTagData ( )

Constructs SQL query and retrieves child tag ID and Name from DB.

Definition at line 57 of file RDBVersionAccessor.cxx.

58{
59 std::string parentNodeId, childNodeId, parentTagId;
60 int nRows{};
61
62 if(!m_session) {
63 RDB_MSG_ERROR ("VersionAccessor: No connection to database!");
64 return;
65 }
66
67 try {
68 RDB_MSG_VERBOSE("VersionAccessor: Version accessor for \n"
69 "ChildNode = {} ParentNode = {} ParentTag = {}",
71
72 coral::ITable& tableTag2Node = m_session->nominalSchema().tableHandle("HVS_TAG2NODE");
73 coral::ITable& tableNode = m_session->nominalSchema().tableHandle("HVS_NODE");
74 coral::ITable& tableLtag2Ltag = m_session->nominalSchema().tableHandle("HVS_LTAG2LTAG");
75
76 //
77 // STEP 1. Get TagId for parentTag
78 //
79 // Query: "SELECT TAG_ID FROM HVS_TAG2NODE WHERE TAG_NAME='m_parentTag'"
80 //
81 coral::IQuery *queryTag2Node = tableTag2Node.newQuery();
82 queryTag2Node->addToOutputList("TAG_ID");
83 queryTag2Node->setMemoryCacheSize(1);
84 coral::AttributeList bindsTag2Node ATLAS_THREAD_SAFE;
85 bindsTag2Node.extend<std::string>("tagN");
86 queryTag2Node->setCondition("TAG_NAME=:tagN", bindsTag2Node);
87 bindsTag2Node[0].data<std::string>() = m_parentTag;
88
89 coral::ICursor& cursorTag2Node = queryTag2Node->execute();
90 nRows = 0;
91 while(cursorTag2Node.next()) {
92 if(++nRows>1) {
93 delete queryTag2Node;
94 RDB_MSG_DEBUG("The tag {} is not unique in HVS_TAG2NODE table!",
96 return;
97 }
98
99 const coral::AttributeList& row = cursorTag2Node.currentRow();
100 parentTagId = attribute2String(row,"TAG_ID");
101
102 }
103 if(nRows==0) {
104 delete queryTag2Node;
105 RDB_MSG_DEBUG("The tag {} not found in HVS_TAG2NODE table!",
107 return;
108 }
109
110 delete queryTag2Node;
111 RDB_MSG_VERBOSE("VersionAccessor: Parent Tag Id = {}", parentTagId);
112
113 //
114 // STEP 2. Get NodeIDs for parentNode and child
115 //
116 // Query: "SELECT NODE_NAME, NODE_ID, BRANCH_FLAG FROM HVS_NODE
117 // WHERE NODE_NAME='m_parentNode' OR NODE_NAME='m_childNode'"
118 //
119
120 coral::IQuery* queryNodeIDs = tableNode.newQuery();
121
122 queryNodeIDs->addToOutputList("NODE_NAME");
123 queryNodeIDs->addToOutputList("NODE_ID");
124 queryNodeIDs->addToOutputList("BRANCH_FLAG");
125 queryNodeIDs->setMemoryCacheSize(2);
126
127 coral::AttributeList bindsNodeIDs ATLAS_THREAD_SAFE;
128 bindsNodeIDs.extend<std::string>("parentN");
129 bindsNodeIDs.extend<std::string>("childN");
130
131 queryNodeIDs->setCondition( "NODE_NAME=:parentN OR NODE_NAME=:childN", bindsNodeIDs);
132
133 bindsNodeIDs[0].data<std::string>() = m_parentNode;
134 bindsNodeIDs[1].data<std::string>() = m_childNode;
135
136 coral::ICursor& cursorNodeIDs = queryNodeIDs->execute();
137
138 nRows = 0;
139 while(cursorNodeIDs.next()) {
140 if(++nRows>2) {
141 break;
142 }
143 const coral::AttributeList& row = cursorNodeIDs.currentRow();
144
145 if(attribute2String(row,"NODE_NAME")==m_childNode) {
146 childNodeId = attribute2String(row,"NODE_ID");
147 m_isChildLeaf = (attribute2String(row,"BRANCH_FLAG")=="0");
148 }
149 else {
150 parentNodeId = attribute2String(row,"NODE_ID");
151 }
152 }
153 if(nRows!=2 && m_childNode!=m_parentNode) {
154 delete queryNodeIDs;
155 RDB_MSG_DEBUG("Error processing HVS_NODE, Number of fetched records !=2");
156 return;
157 }
158
159 RDB_MSG_VERBOSE("VersionAccessor: Child Node Id = {}", childNodeId);
160 RDB_MSG_VERBOSE("VersionAccessor: Parent Node Id = {}", parentNodeId);
161
162 delete queryNodeIDs;
163
166 m_tagID = std::move(parentTagId);
167 return;
168 }
169
170 //
171 // STEP 3.
172 //
173 // *********************** THIS IS A TEMPORARY SOLUTION ************************
174 // *** ***
175 // *** 1. First we determine a path from childNode to parentNode querying ***
176 // *** HVS_NODE few times ***
177 // *** 2. Then we query HVS_LTAG2LTAG few times to get tag of childNode ***
178 // *** of childNode ***
179 // *** ***
180 // *********** ************ ********** ************* ************ **************
181
182 std::vector<std::string> path;
183 path.push_back(childNodeId);
184 std::string currentParrent = childNodeId;
185 std::string currentChild = std::move(childNodeId);
186
187 coral::AttributeList bindsNode ATLAS_THREAD_SAFE;
188 bindsNode.extend<std::string>("nodeId");
189 const std::string parentIdStr{"PARENT_ID"};
190 const std::string conditionStr{"NODE_ID=:nodeId"};
191 while(currentParrent != parentNodeId) {
192 //
193 // Query: "SELECT PARENT_ID FROM HVS_NODE WHERE NODE_ID='currentChild'"
194 //
195 coral::IQuery* queryNode(tableNode.newQuery());
196
197 queryNode->addToOutputList(parentIdStr);
198 queryNode->setMemoryCacheSize(1);
199
200 queryNode->setCondition(conditionStr, bindsNode);
201 bindsNode[0].data<std::string>()=currentChild;
202
203 coral::ICursor& cursorNode = queryNode->execute();
204
205 nRows = 0;
206
207 // Process Query results
208 while(cursorNode.next()) {
209 if(++nRows>1) {
210 delete queryNode;
211 RDB_MSG_DEBUG("The node {} has more than one parent!", currentChild);
212 return;
213 }
214
215 const coral::AttributeList& row = cursorNode.currentRow();
216
217 if(row[0].isNull()) {
218 delete queryNode;
219 RDB_MSG_DEBUG("The requested child and parent nodes are not on the same branch!");
220 return;
221 }
222
223 currentParrent = attribute2String(row,parentIdStr);
224 currentChild = currentParrent;
225 path.push_back(currentParrent);
226 }
227 if(nRows==0) {
228 delete queryNode;
229 RDB_MSG_DEBUG("The node {} has no parent!", currentChild);
230 return;
231 }
232
233 delete queryNode;
234 RDB_MSG_VERBOSE("VersionAccessor: Current Child = {}", currentChild);
235 RDB_MSG_VERBOSE("VersionAccessor: Current Parrent = {}", currentParrent);
236 }
237
238 coral::AttributeList bindsLtag2Ltag ATLAS_THREAD_SAFE;
239 bindsLtag2Ltag.extend<std::string>("childN");
240 bindsLtag2Ltag.extend<std::string>("parentT");
241 bindsLtag2Ltag.extend<std::string>("parentN");
242
243 const std::string childTagString{"CHILD_TAG"};
244 const std::string childConditionStr = "CHILD_NODE =:childN AND PARENT_TAG =:parentT AND PARENT_NODE =:parentN";
245 for(unsigned int ind=1; ind<path.size(); ind++) {
246 // Query: "SELECT CHILD_TAG FROM HVS_LTAG2LTAG WHERE
247 // CHILD_NODE = 'path[path.size()-ind-1]' AND
248 // PARENT_TAG = 'parentTagId' AND
249 // PARENT_NODE = 'path[path.size()-ind]'
250 coral::IQuery* queryLtag2Ltag(tableLtag2Ltag.newQuery());
251
252 queryLtag2Ltag->addToOutputList(childTagString);
253 queryLtag2Ltag->setMemoryCacheSize(1);
254
255 queryLtag2Ltag->setCondition(childConditionStr, bindsLtag2Ltag);
256
257 bindsLtag2Ltag[0].data<std::string>() = path[path.size()-ind-1];
258 bindsLtag2Ltag[1].data<std::string>() = parentTagId;
259 bindsLtag2Ltag[2].data<std::string>() = path[path.size()-ind];
260
261 coral::ICursor& cursorLtag2Ltag = queryLtag2Ltag->execute();
262
263 nRows = 0;
264 // Process Query results
265 while(cursorLtag2Ltag.next()) {
266 if(++nRows>1) {
267 delete queryLtag2Ltag;
268 RDB_MSG_DEBUG("Version {} has more than one child of type {}!",
269 parentTagId, path[path.size()-ind-1]);
270 return;
271 }
272
273 const coral::AttributeList& row = cursorLtag2Ltag.currentRow();
274 parentTagId = attribute2String(row,childTagString);
275 }
276 if(nRows==0) {
277 delete queryLtag2Ltag;
278 RDB_MSG_DEBUG("Version {} has no child of type {}!",
279 parentTagId, path[path.size()-ind-1]);
280 return;
281 }
282
283 delete queryLtag2Ltag;
284
285 RDB_MSG_VERBOSE("VersionAccessor: Parent Tag Id = {}", parentTagId);
286 }
287
288 //
289 // STEP 4. Get tag name for obtained TAG_ID
290 //
291 // Query: "SELECT TAG_NAME from HVS_TAG2NODE WHERE TAG_ID='parentTagId'"
292 //
293 coral::IQuery* queryTagName(tableTag2Node.newQuery());
294 const std::string tagNameStr{"TAG_NAME"};
295 queryTagName->addToOutputList(tagNameStr);
296 queryTagName->setMemoryCacheSize(1);
297
298 coral::AttributeList bindsTagName ATLAS_THREAD_SAFE;
299 bindsTagName.extend<std::string>("tagId");
300
301 queryTagName->setCondition("TAG_ID=:tagId", bindsTagName);
302 bindsTagName[0].data<std::string>() = parentTagId;
303
304 coral::ICursor& cursorTagName = queryTagName->execute();
305
306 nRows = 0;
307 while(cursorTagName.next()) {
308 if(++nRows>1) {
309 delete queryTagName;
310 RDB_MSG_DEBUG("More than one record retrieved when getting tag name for given ID");
311 return;
312 }
313
314 const coral::AttributeList& row = cursorTagName.currentRow();
315
316 m_tagName =attribute2String(row,tagNameStr);
317 m_tagID = parentTagId;
318
319 RDB_MSG_VERBOSE("VersionAccessor: Child Tag Name = {}", m_tagName);
320 }
321 delete queryTagName;
322
323 }
324 catch(coral::SchemaException& se)
325 {
326 RDB_MSG_ERROR("VersionAccessor: Schema Exception : {}", se.what());
327 }
328 catch(std::exception& e)
329 {
330 RDB_MSG_DEBUG("{}", e.what());
331 }
332 catch(...)
333 {
334 RDB_MSG_ERROR("VersionAccessor: Exception caught(...)");
335 }
336}
#define RDB_MSG_ERROR(fmt,...)
#define RDB_MSG_DEBUG(fmt,...)
#define RDB_MSG_VERBOSE(fmt,...)
#define ATLAS_THREAD_SAFE
std::string attribute2String(const coral::AttributeList &attList, const std::string &fieldName)
row
Appending html table to final .html summary file.
unsigned int constexpr nRows
Definition RPDUtils.h:24
path
python interpreter configuration --------------------------------------—
Definition athena.py:130

◆ getNodeName()

const std::string & RDBVersionAccessor::getNodeName ( ) const
inline
Returns
node name

Definition at line 54 of file RDBVersionAccessor.h.

54{return m_childNode;}

◆ getTagID()

const std::string & RDBVersionAccessor::getTagID ( ) const
inline
Returns
stringified tag ID

Definition at line 61 of file RDBVersionAccessor.h.

61{return m_tagID;}

◆ getTagName()

const std::string & RDBVersionAccessor::getTagName ( ) const
inline
Returns
tag name for the child node

Definition at line 58 of file RDBVersionAccessor.h.

58{return m_tagName;}

◆ isLeaf()

bool RDBVersionAccessor::isLeaf ( ) const
inline
Returns
branch flag for the child node returns false if the data has not been fetched yet

Definition at line 65 of file RDBVersionAccessor.h.

65{return m_isChildLeaf;}

Member Data Documentation

◆ m_childNode

std::string RDBVersionAccessor::m_childNode
private

Definition at line 76 of file RDBVersionAccessor.h.

◆ m_isChildLeaf

bool RDBVersionAccessor::m_isChildLeaf
private

Definition at line 82 of file RDBVersionAccessor.h.

◆ m_msgStream

MsgStream& RDBVersionAccessor::m_msgStream
private

Definition at line 84 of file RDBVersionAccessor.h.

◆ m_parentNode

std::string RDBVersionAccessor::m_parentNode
private

Definition at line 77 of file RDBVersionAccessor.h.

◆ m_parentTag

std::string RDBVersionAccessor::m_parentTag
private

Definition at line 78 of file RDBVersionAccessor.h.

◆ m_session

coral::ISessionProxy* RDBVersionAccessor::m_session
private

Definition at line 74 of file RDBVersionAccessor.h.

◆ m_tagID

std::string RDBVersionAccessor::m_tagID
private

Definition at line 81 of file RDBVersionAccessor.h.

◆ m_tagName

std::string RDBVersionAccessor::m_tagName
private

Definition at line 80 of file RDBVersionAccessor.h.


The documentation for this class was generated from the following files: