Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PoolCollectionConverter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include "PoolSvc/IPoolSvc.h"
13 
14 // Pool
15 #include "CoralBase/AttributeList.h"
16 #include "CoralBase/Attribute.h"
17 
23 
24 // Gaudi
25 #include "GaudiKernel/StatusCode.h"
26 
27 #include <assert.h>
28 #include <exception>
29 
30 //______________________________________________________________________________
31 PoolCollectionConverter::PoolCollectionConverter(const std::string& collectionType,
32  const std::string& inputCollection,
33  unsigned int contextId,
34  const IPoolSvc* svc) :
35  m_collectionType(),
36  m_connection(),
37  m_inputCollection(inputCollection),
38  m_contextId(contextId),
39  m_poolSvc(svc),
40  m_poolCollection(nullptr),
41  m_collectionQuery(nullptr),
42  m_inputContainer() {
43  // Find out if the user specified a container
44  std::string::size_type p_colon = collectionType.rfind(':');
45  if (p_colon != std::string::npos) {
46  m_inputContainer = collectionType.substr(p_colon + 1);
47  m_collectionType = collectionType.substr(0, p_colon);
48  } else {
49  // The user didn't specify any container. Using the default one.
50  m_inputContainer = "POOLContainer";
51  m_collectionType = collectionType;
52  }
53  std::string::size_type p_slash = m_inputContainer.find('/');
54  if (p_slash != std::string::npos) {
55  m_inputContainer.resize(p_slash);
56  }
57 }
58 //______________________________________________________________________________
60  if (m_poolCollection) {
62  delete m_collectionQuery; m_collectionQuery = nullptr;
63  delete m_poolCollection; m_poolCollection = nullptr;
64  }
65 }
66 //______________________________________________________________________________
68  std::string collectionTypeString;
69  if (m_collectionType == "ExplicitROOT") {
70  collectionTypeString = "RootCollection";
71  } else if (m_collectionType == "ImplicitROOT") {
72  collectionTypeString = "ImplicitCollection";
73  } else {
74  return(StatusCode::FAILURE);
75  }
76  if (collectionTypeString == "ImplicitCollection") {
77  // Check if already prefixed
78  if (m_inputCollection.starts_with( "PFN:")
79  || m_inputCollection.starts_with( "LFN:")
80  || m_inputCollection.starts_with( "FID:")) {
81  // Aready prefixed
83  } else {
84  // Prefix with PFN:
86  }
87  try {
89  } catch (std::exception &e) {
90  m_poolCollection = nullptr;
91  }
92  if (m_poolCollection == nullptr) {
93  // Now set where to look in the implicit file
94  m_inputCollection = m_inputContainer + "(DataHeader)";
95  }
96  }
97  try {
98  if (m_poolCollection == nullptr) {
100  }
101  if (m_poolCollection == nullptr && collectionTypeString == "ImplicitCollection") {
102  m_inputCollection = m_inputContainer + "_DataHeader";
104  }
105  } catch (std::exception &e) {
106  return(StatusCode::RECOVERABLE);
107  }
108  return(StatusCode::SUCCESS);
109 }
110 //______________________________________________________________________________
112  if (m_poolCollection == nullptr) {
113  return(StatusCode::SUCCESS);
114  }
115  if (m_poolCollection->description().type() == "ImplicitCollection") {
117  }
118  return(StatusCode::SUCCESS);
119 }
120 //______________________________________________________________________________
122  return(m_poolCollection != nullptr ? StatusCode::SUCCESS : StatusCode::FAILURE);
123 }
124 //______________________________________________________________________________
126  assert(m_poolCollection);
127  delete m_collectionQuery; m_collectionQuery = nullptr;
130  m_collectionQuery->setRowCacheSize(100); //MN: FIXME - just an arbitrary number
131  return(m_collectionQuery->execute());
132 }
133 //______________________________________________________________________________
135  const std::string& refName) const {
136 // Retrieve the DataHeader Token from POOL.
137 // If header name is non-zero, then search the attibute list for
138 // the corresponding ref. Otherwise, use the main token
139  std::string tokenStr;
140  if (!refName.empty()) {
141  std::string attrName = refName + "_ref";
142  try {
143  tokenStr = cursor->currentRow().tokenList()[attrName].toString();
144  } catch (...) {
145  // check also in attributes, for backward compatibility
146  try {
147  tokenStr = cursor->currentRow().attributeList()[attrName].data<std::string>();
148  } catch (std::exception& e) {
149  return("");
150  }
151  }
152  } else {
153  tokenStr = cursor->eventRef().toString();
154  }
155  return(tokenStr);
156 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
IPoolSvc
This class provides the interface to the LCG POOL persistency software.
Definition: IPoolSvc.h:35
PoolCollectionConverter::m_contextId
unsigned int m_contextId
Definition: PoolCollectionConverter.h:64
PoolCollectionConverter::m_connection
std::string m_connection
Definition: PoolCollectionConverter.h:62
PoolCollectionConverter.h
This file contains the class definition for the PoolCollectionConverter class.
ICollectionCursor.h
pool::ICollectionQuery::execute
virtual pool::ICollectionCursor & execute()=0
Processes the query and returns a cursor over the query result.
PoolCollectionConverter::selectAll
pool::ICollectionCursor & selectAll()
Definition: PoolCollectionConverter.cxx:125
pool::ICollection::close
virtual void close()=0
Closes the collection and terminates any database connections.
PoolCollectionConverter::m_collectionType
std::string m_collectionType
Definition: PoolCollectionConverter.h:61
pool::ICollectionDescription::type
virtual const std::string & type() const =0
Returns the storage technology type of the collection.
pool::ICollectionQuery::selectAll
virtual void selectAll()=0
Adds all Token and Attribute columns to the query select list.
PoolCollectionConverter::m_inputCollection
std::string m_inputCollection
Definition: PoolCollectionConverter.h:63
PoolCollectionConverter::m_inputContainer
std::string m_inputContainer
Definition: PoolCollectionConverter.h:68
pool::ICollection::newQuery
virtual ICollectionQuery * newQuery()=0
Returns an object used to query the collection.
PoolCollectionConverter::isValid
StatusCode isValid() const
Check whether has valid pool::ICollection*.
Definition: PoolCollectionConverter.cxx:121
CollectionRowBuffer.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PoolCollectionConverter::m_poolSvc
const IPoolSvc * m_poolSvc
Definition: PoolCollectionConverter.h:65
calibdata.exception
exception
Definition: calibdata.py:496
ICollection.h
pool::ICollection::description
virtual const ICollectionDescription & description() const =0
Returns an object used to describe the collection properties.
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
pool::ICollectionCursor
Definition: ICollectionCursor.h:21
PoolCollectionConverter::PoolCollectionConverter
PoolCollectionConverter(const std::string &collectionType, const std::string &inputCollection, unsigned int contextId, const IPoolSvc *svc)
Constructor.
Definition: PoolCollectionConverter.cxx:31
PoolCollectionConverter::retrieveToken
std::string retrieveToken(const pool::ICollectionCursor *cursor, const std::string &refName) const
Definition: PoolCollectionConverter.cxx:134
PoolCollectionConverter::m_collectionQuery
pool::ICollectionQuery * m_collectionQuery
Definition: PoolCollectionConverter.h:67
IPoolSvc.h
This file contains the class definition for the IPoolSvc interface class.
PoolCollectionConverter::disconnectDb
StatusCode disconnectDb()
Disconnect Database.
Definition: PoolCollectionConverter.cxx:111
PoolCollectionConverter::initialize
StatusCode initialize()
Required by all Gaudi Services.
Definition: PoolCollectionConverter.cxx:67
PoolCollectionConverter::m_poolCollection
pool::ICollection * m_poolCollection
Definition: PoolCollectionConverter.h:66
python.PoolAttributeHelper.attrName
attrName
Definition: PoolAttributeHelper.py:100
query_example.cursor
cursor
Definition: query_example.py:21
IPoolSvc::disconnectDb
virtual StatusCode disconnectDb(const std::string &connection, unsigned int contextId=IPoolSvc::kInputStream) const =0
Disconnect single Database.
ICollectionQuery.h
pool::ICollectionQuery::setRowCacheSize
virtual void setRowCacheSize(int rowCacheSize)=0
Sets the cache size used to store the query result.
PoolCollectionConverter::~PoolCollectionConverter
virtual ~PoolCollectionConverter()
Destructor.
Definition: PoolCollectionConverter.cxx:59
ICollectionDescription.h
Token.h
This file contains the class definition for the Token class (migrated from POOL).
IPoolSvc::createCollection
virtual pool::ICollection * createCollection(const std::string &collectionType, const std::string &connection, const std::string &collectionName, unsigned int contextId=IPoolSvc::kInputStream) const =0