CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
ora::NamedReferenceStreamerBase Class Reference

#include <NamedRefStreamer.h>

Inheritance diagram for ora::NamedReferenceStreamerBase:
ora::NamedRefReader ora::NamedRefUpdater ora::NamedRefWriter

Public Member Functions

void bindDataForRead (void *data)
 
void bindDataForUpdate (const void *data)
 
bool buildDataElement (DataElement &dataElement, IRelationalData &relationalData)
 
 NamedReferenceStreamerBase (const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
 
virtual ~NamedReferenceStreamerBase ()
 

Private Attributes

const std::vector< std::string > & m_columns
 
DataElementm_dataElement
 
DataElementm_flagDataElement
 
Reflex::Type m_objectType
 
DataElementm_ptrDataElement
 
DataElementm_refNameDataElement
 
IRelationalDatam_relationalData
 
ContainerSchemam_schema
 

Detailed Description

Definition at line 20 of file NamedRefStreamer.h.

Constructor & Destructor Documentation

ora::NamedReferenceStreamerBase::NamedReferenceStreamerBase ( const Reflex::Type &  objectType,
MappingElement mapping,
ContainerSchema schema 
)
explicit

Definition at line 19 of file NamedRefStreamer.cc.

21  :
22  m_objectType( objectType ),
23  m_columns( mapping.columnNames() ),
24  m_schema( schema ),
25  m_dataElement( 0 ),
27  m_ptrDataElement( 0 ),
28  m_flagDataElement( 0 ),
29  m_relationalData( 0 ){
30 }
const std::vector< std::string > & m_columns
ora::NamedReferenceStreamerBase::~NamedReferenceStreamerBase ( )
virtual

Definition at line 32 of file NamedRefStreamer.cc.

32  {
33 }

Member Function Documentation

void ora::NamedReferenceStreamerBase::bindDataForRead ( void *  data)

Definition at line 81 of file NamedRefStreamer.cc.

References AlCaRecoCosmics_cfg::name, ora::namedRefNullLabel(), and ora::throwException().

81  {
82  if(!m_relationalData){
83  throwException("The streamer has not been built.",
84  "NamedReferenceStreamerBase::bindDataForRead");
85  }
86  void* refNameAddress = m_refNameDataElement->address( data );
87  void* ptrAddress = m_ptrDataElement->address( data );
88  void* flagAddress = m_flagDataElement->address( data );
89  coral::Attribute& refNameAttr = m_relationalData->data()[ m_columns[0] ];
90  std::string name = refNameAttr.data<std::string>();
91  if( name == namedRefNullLabel() ){
92  name = std::string("");
93  }
94  if(!name.empty()){
95  Reflex::Type namedRefType = m_objectType.TemplateArgumentAt(0);
96  boost::shared_ptr<void> ptr = m_schema.dbSession().fetchTypedObjectByName( name, namedRefType );
97  *static_cast<boost::shared_ptr<void>*>(ptrAddress) = ptr;
98  *static_cast<bool*>(flagAddress) = true;
99  }
100  *static_cast<std::string*>(refNameAddress) = name;
101 }
std::string namedRefNullLabel()
void * address(const void *topLevelAddress) const
Definition: DataElement.cc:48
boost::shared_ptr< void > fetchTypedObjectByName(const std::string &name, const Reflex::Type &asType)
DatabaseSession & dbSession()
virtual coral::AttributeList & data()=0
const std::vector< std::string > & m_columns
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::NamedReferenceStreamerBase::bindDataForUpdate ( const void *  data)

Definition at line 68 of file NamedRefStreamer.cc.

References AlCaRecoCosmics_cfg::name, ora::namedRefNullLabel(), and ora::throwException().

68  {
69  if(!m_relationalData){
70  throwException("The streamer has not been built.",
71  "NamedReferenceStreamerBase::bindDataForUpdate");
72  }
73 
74  void* refNameAddress = m_refNameDataElement->address( data );
75  coral::Attribute& refNameAttr = m_relationalData->data()[ m_columns[0] ];
76  std::string name = *static_cast<std::string*>(refNameAddress);
77  if( name.empty() ) name = namedRefNullLabel();
78  refNameAttr.data<std::string>()= name;
79 }
std::string namedRefNullLabel()
void * address(const void *topLevelAddress) const
Definition: DataElement.cc:48
virtual coral::AttributeList & data()=0
const std::vector< std::string > & m_columns
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
bool ora::NamedReferenceStreamerBase::buildDataElement ( DataElement dataElement,
IRelationalData relationalData 
)

Definition at line 36 of file NamedRefStreamer.cc.

References ora::DataElement::addChild(), ora::IRelationalData::addData(), and ora::throwException().

37  {
38  m_dataElement = &dataElement;
39  m_objectType.UpdateMembers();
40  Reflex::Member nameMember = m_objectType.DataMemberByName("m_name");
41  if( !nameMember ){
42  throwException("Data member \"m_name\" not found in class \""+m_objectType.Name()+"\".",
43  "NamedReferenceStreamerBase::buildDataElement");
44  }
45  m_refNameDataElement = &dataElement.addChild( nameMember.Offset(), 0 );
46  Reflex::Member ptrMember = m_objectType.DataMemberByName("m_ptr");
47  if( !ptrMember ){
48  throwException("Data member \"m_ptr\" not found in class \""+m_objectType.Name()+"\".",
49  "NamedReferenceStreamerBase::buildDataElement");
50  }
51  m_ptrDataElement = &dataElement.addChild( ptrMember.Offset(), 0 );
52  Reflex::Member flagMember = m_objectType.DataMemberByName("m_isPersistent");
53  if( !flagMember ){
54  throwException("Data member \"m_isPersistent\" not found in class \""+m_objectType.Name()+"\".",
55  "NamedReferenceStreamerBase::buildDataElement");
56  }
57  m_flagDataElement = &dataElement.addChild( flagMember.Offset(), 0 );
58  // then book the column in the data attribute...
59  if( m_columns.size()==0 ){
60  throwException("No columns found in the mapping element",
61  "NamedReferenceStreamerBase::buildDataElement");
62  }
63  relationalData.addData( m_columns[0], typeid(std::string) );
64  m_relationalData = &relationalData;
65  return true;
66 }
DataElement & addChild(size_t declaringScopeOffset, Reflex::OffsetFunction offsetFunction)
Definition: DataElement.cc:26
const std::vector< std::string > & m_columns
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10

Member Data Documentation

const std::vector<std::string>& ora::NamedReferenceStreamerBase::m_columns
private

Definition at line 37 of file NamedRefStreamer.h.

DataElement* ora::NamedReferenceStreamerBase::m_dataElement
private

Definition at line 39 of file NamedRefStreamer.h.

DataElement* ora::NamedReferenceStreamerBase::m_flagDataElement
private

Definition at line 42 of file NamedRefStreamer.h.

Reflex::Type ora::NamedReferenceStreamerBase::m_objectType
private

Definition at line 36 of file NamedRefStreamer.h.

DataElement* ora::NamedReferenceStreamerBase::m_ptrDataElement
private

Definition at line 41 of file NamedRefStreamer.h.

DataElement* ora::NamedReferenceStreamerBase::m_refNameDataElement
private

Definition at line 40 of file NamedRefStreamer.h.

IRelationalData* ora::NamedReferenceStreamerBase::m_relationalData
private

Definition at line 43 of file NamedRefStreamer.h.

ContainerSchema& ora::NamedReferenceStreamerBase::m_schema
private

Definition at line 38 of file NamedRefStreamer.h.