ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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. More...
 
void getChildTagData ()
 Constructs SQL query and retrieves child tag ID and Name from DB. More...
 
std::string getNodeName () const
 
std::string getTagName () const
 
std::string getTagID () const
 
bool isLeaf () const
 

Private Member Functions

 RDBVersionAccessor ()
 Default constructor. More...
 
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 34 of file RDBVersionAccessor.cxx.

39  : m_session(session)
40  , m_childNode(childNode)
41  , m_parentNode(parentNode)
42  , m_parentTag(parentTag)
43  , m_tagName("")
44  , m_tagID("")
45  , m_isChildLeaf(false)
46  , m_msgStream(msgStream)
47 {
48 }

◆ 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 331 of file RDBVersionAccessor.cxx.

333 {
334  std::ostringstream streamValue;
335  attList[fieldName].toOutputStream(streamValue);
336  std::string stringValue = streamValue.str();
337  unsigned int position = stringValue.find(") :");
338  return stringValue.substr(position+4);
339 }

◆ getChildTagData()

void RDBVersionAccessor::getChildTagData ( )

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

Definition at line 50 of file RDBVersionAccessor.cxx.

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

◆ getNodeName()

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

Definition at line 54 of file RDBVersionAccessor.h.

54 {return m_childNode;}

◆ getTagID()

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

Definition at line 61 of file RDBVersionAccessor.h.

61 {return m_tagID;}

◆ getTagName()

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:
query_example.row
row
Definition: query_example.py:24
RDBVersionAccessor::m_parentNode
std::string m_parentNode
Definition: RDBVersionAccessor.h:77
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
keylayer_zslicemap.se
se
Definition: keylayer_zslicemap.py:194
RDBVersionAccessor::m_msgStream
MsgStream & m_msgStream
Definition: RDBVersionAccessor.h:84
RDBVersionAccessor::m_isChildLeaf
bool m_isChildLeaf
Definition: RDBVersionAccessor.h:82
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
taskman.fieldName
fieldName
Definition: taskman.py:492
calibdata.exception
exception
Definition: calibdata.py:496
RDBVersionAccessor::m_tagID
std::string m_tagID
Definition: RDBVersionAccessor.h:81
RDBVersionAccessor::m_childNode
std::string m_childNode
Definition: RDBVersionAccessor.h:76
RDBVersionAccessor::m_session
coral::ISessionProxy * m_session
Definition: RDBVersionAccessor.h:74
RDBVersionAccessor::m_tagName
std::string m_tagName
Definition: RDBVersionAccessor.h:80
RDBVersionAccessor::m_parentTag
std::string m_parentTag
Definition: RDBVersionAccessor.h:78
python.selection.stringValue
stringValue
Definition: selection.py:30
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
RDBVersionAccessor::attribute2String
std::string attribute2String(const coral::AttributeList &attList, const std::string &fieldName)
Definition: RDBVersionAccessor.cxx:331
DEBUG
#define DEBUG
Definition: page_access.h:11
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
checkFileSG.ind
list ind
Definition: checkFileSG.py:118