ATLAS Offline Software
Loading...
Searching...
No Matches
pool::Collection Class Reference

Read-only collection implementation. More...

#include <Collection.h>

Inheritance diagram for pool::Collection:
Collaboration diagram for pool::Collection:

Public Member Functions

 Collection (FileDescriptor &fileDescr)
 Construct from an already-connected file descriptor.
 ~Collection ()
 Defined out of line because CollectionColumn is incomplete here.
std::unique_ptr< CollectionCursor > cursor ()
 Returns a cursor for the collection.
bool msgLvl (const MSG::Level lvl) const
 Test the output level.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.
void setLevel (MSG::Level lvl)
 Change the current logging level.

Private Member Functions

 Collection (const Collection &)=delete
Collection & operator= (const Collection &)=delete
void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

std::vector< CollectionColumn > m_attributeColumns
std::map< std::string, DbContainer > m_containerMap
 Map of container names to container handles for all EventTag attributes in the file.
DbContainer m_dhCont
 The DataHeader container, if present, in the file.
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels).
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging).

Detailed Description

Read-only collection implementation.

  • Supports a single Token plus meta data attributes

Definition at line 26 of file Collection.h.

Constructor & Destructor Documentation

◆ Collection() [1/2]

pool::Collection::Collection ( FileDescriptor & fileDescr)
explicit

Construct from an already-connected file descriptor.

Definition at line 30 of file Collection.cxx.

31 : APRMessaging( "Collection")
32 {
33 if( !fileDescr.dbc() ) {
34 throw std::runtime_error( "Collection: file must already be connected: " + fileDescr.PFN() );
35 }
36
37 // all errors are thrown as exceptions
38 ATH_MSG_VERBOSE( "Opening collection '" << fileDescr.PFN() << "' in READ mode" );
39
40 std::vector<const Token*> containerTokens;
41 DbDatabase db( fileDescr.dbc()->handle() );
42 if( !db.containers(containerTokens, false).isSuccess() ) {
43 throw std::runtime_error( "Collection: error reading " + fileDescr.PFN() );
44 }
45 const std::string containerPrefix = APRDefaults::ReadConfig::getEventTagName( fileDescr.FID() );
46 const std::string dhName = APRDefaults::ReadConfig::getDataHeaderName( fileDescr.FID() );
47 const std::string newDHContName = std::format("{}({})", dhName, APRDefaults::DataHeaderTypeName);
48 const std::string oldDHContName = std::format("{}_{}", dhName, APRDefaults::DataHeaderTypeName);
49 ATH_MSG_DEBUG("Opening Collection '" << fileDescr.PFN() << "' using container prefix: " << containerPrefix );
50 std::string tagContName = containerPrefix + "(";
51 // it seems merged files report multiple instances of the same container - avoid trying to process duplicates
52 std::set<std::string> seenContainers;
53 for( const Token *t : containerTokens ) {
54 Token token(t); // need a non-const Token
55 const std::string& contName = db.cntName(token);
56 const DbTypeInfo* typ_info = db.objectShape( token.classID() );
57 if( contName.starts_with( tagContName ) and !seenContainers.contains( contName ) ) {
58 seenContainers.insert( contName );
59 const std::string& attrName = contName.substr( tagContName.size(), contName.size() - tagContName.size() - 1 );
60 ATH_MSG_DEBUG(" :container " << contName << " with attribute " << attrName << " of type: " << typ_info->clazz().Name());
61 DbContainer cnt( db.type() );
62 if( cnt.open( db, contName, typ_info, token.technology(), db.openMode() ).isSuccess() ) {
63 if( attrName != CollectionColumn::tokenColumn().name() ) {
64 const auto duplicate = std::find_if(
66 [&attrName]( const CollectionColumn& column ) {
67 return column.name() == attrName;
68 } );
69 if( duplicate != m_attributeColumns.end() ) {
70 throw std::runtime_error( "Column with name `" + attrName + "' already exists." );
71 }
72 m_attributeColumns.emplace_back( attrName, typ_info->clazz().Name() );
73 }
74 m_containerMap.emplace( attrName, std::move(cnt) );
75 } else {
76 ATH_MSG_WARNING("EventTag container " << contName << " could not be opened");
77 }
78 } else if( contName == newDHContName || contName == oldDHContName ) {
79 ATH_MSG_DEBUG(" :container " << contName << " is the DataHeader container");
80 DbContainer cnt( db.type() );
81 if( cnt.open( db, contName, typ_info, token.technology(), db.openMode() ).isSuccess() ) {
82 m_dhCont = std::move(cnt);
83 } else {
84 ATH_MSG_WARNING("EventTag container " << contName << " could not be opened");
85 }
86 }
87 }
88 }
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
APRMessaging(const std::string &name)
static const CollectionColumn & tokenColumn()
std::vector< CollectionColumn > m_attributeColumns
Definition Collection.h:42
std::map< std::string, DbContainer > m_containerMap
Map of container names to container handles for all EventTag attributes in the file.
Definition Collection.h:45
DbContainer m_dhCont
The DataHeader container, if present, in the file.
Definition Collection.h:47
std::string getDataHeaderName(std::string_view databaseName)
std::string getEventTagName(std::string_view databaseName)
static constexpr const char * DataHeaderTypeName

◆ ~Collection()

pool::Collection::~Collection ( )
default

Defined out of line because CollectionColumn is incomplete here.

◆ Collection() [2/2]

pool::Collection::Collection ( const Collection & )
privatedelete

Member Function Documentation

◆ cursor()

std::unique_ptr< CollectionCursor > pool::Collection::cursor ( )

Returns a cursor for the collection.

Definition at line 91 of file Collection.cxx.

91 {
92 if( m_containerMap.empty() ) {
94 }
95 pool::CollectionRowBuffer collectionRowBuffer;
96 coral::AttributeList attributeList;
97 for( const auto& attrCol : m_attributeColumns ) {
98 attributeList.extend( attrCol.name(), attrCol.type() );
99 }
100 collectionRowBuffer.setAttributeList( attributeList );
101 return std::make_unique<CollectionCursor>( collectionRowBuffer, m_containerMap);
102 }
void setAttributeList(const coral::AttributeList &attributeList)
Sets the Attribute list schema.
static constexpr const char * TokenTypeName

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)
int outputLevel(const IMessageSvc *ims, const std::string &source)

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 167 of file AthMessaging.h.

168{
169 MsgStream* ms = m_msg_tls.get();
170 if (!ms) {
171 if (!m_initialized.test_and_set()) initMessaging();
172 ms = new MsgStream(m_imsg,m_nm);
173 m_msg_tls.reset( ms );
174 }
175
176 ms->setLevel (m_lvl);
177 return *ms;
178}
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels).
void initMessaging() const
Initialize our message level and MessageSvc.

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 182 of file AthMessaging.h.

183{ return msg() << lvl; }
MsgStream & msg() const
The standard message stream.

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152{
153 // If user did not set explicit message level we have to initialize
154 // the messaging and retrieve the default via the MessageSvc.
155 if (m_lvl==MSG::NIL && !m_initialized.test_and_set()) initMessaging();
156
157 if (m_lvl <= lvl) {
158 msg() << lvl;
159 return true;
160 } else {
161 return false;
162 }
163}

◆ operator=()

Collection & pool::Collection::operator= ( const Collection & )
privatedelete

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging).

Definition at line 141 of file AthMessaging.h.

◆ m_attributeColumns

std::vector<CollectionColumn> pool::Collection::m_attributeColumns
private

Definition at line 42 of file Collection.h.

◆ m_containerMap

std::map<std::string, DbContainer> pool::Collection::m_containerMap
private

Map of container names to container handles for all EventTag attributes in the file.

Definition at line 45 of file Collection.h.

◆ m_dhCont

DbContainer pool::Collection::m_dhCont
private

The DataHeader container, if present, in the file.

Definition at line 47 of file Collection.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels).

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.


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