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::STLContainerWriter Class Reference

#include <STLContainerStreamer.h>

Inheritance diagram for ora::STLContainerWriter:
ora::IRelationalWriter

Public Member Functions

IArrayHandlerarrayHandler ()
 
bool build (DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
 
DataElementdataElement ()
 
MappingElementmapping ()
 
void setRecordId (const std::vector< int > &identity)
 
 STLContainerWriter (const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
 Constructor. More...
 
void write (int oid, const void *data)
 Writes a data element. More...
 
virtual ~STLContainerWriter ()
 
- Public Member Functions inherited from ora::IRelationalWriter
virtual ~IRelationalWriter ()
 Destructor. More...
 

Private Attributes

std::auto_ptr< IArrayHandlerm_arrayHandler
 
bool m_associative
 
std::auto_ptr< IRelationalWriterm_dataWriter
 
MultiRecordInsertOperationm_insertOperation
 
std::auto_ptr< IRelationalWriterm_keyWriter
 
DataElement m_localElement
 
MappingElementm_mappingElement
 
edm::TypeWithDict m_objectType
 
DataElementm_offset
 
std::vector< int > m_recordId
 
ContainerSchemam_schema
 

Detailed Description

Definition at line 21 of file STLContainerStreamer.h.

Constructor & Destructor Documentation

ora::STLContainerWriter::STLContainerWriter ( const edm::TypeWithDict objectType,
MappingElement mapping,
ContainerSchema contSchema 
)

Constructor.

Definition at line 19 of file STLContainerStreamer.cc.

21  :
22  m_objectType( objectType ),
24  m_schema( contSchema ),
25  m_recordId(),
28  m_offset( 0 ),
29  m_insertOperation( 0 ),
31  m_keyWriter(),
32  m_dataWriter(){
33 }
std::vector< int > m_recordId
std::auto_ptr< IRelationalWriter > m_keyWriter
MultiRecordInsertOperation * m_insertOperation
std::auto_ptr< IRelationalWriter > m_dataWriter
edm::TypeWithDict m_objectType
bool isTypeAssociativeContainer(const edm::TypeWithDict &typ)
Definition: ClassUtils.cc:286
MappingElement & m_mappingElement
std::auto_ptr< IArrayHandler > m_arrayHandler
ora::STLContainerWriter::~STLContainerWriter ( )
virtual

Definition at line 35 of file STLContainerStreamer.cc.

35  {
36 }

Member Function Documentation

ora::IArrayHandler * ora::STLContainerWriter::arrayHandler ( )
inline

Definition at line 151 of file STLContainerStreamer.h.

151  {
152  return m_arrayHandler.get();
153 }
std::auto_ptr< IArrayHandler > m_arrayHandler
bool ora::STLContainerWriter::build ( DataElement offset,
IRelationalData relationalData,
RelationalBuffer operationBuffer 
)
virtual

Implements ora::IRelationalWriter.

Definition at line 38 of file STLContainerStreamer.cc.

References ora::ClassUtils::containerDataType(), ora::ClassUtils::containerKeyType(), ora::ClassUtils::containerValueType(), i, ora::ArrayHandlerFactory::newArrayHandler(), ora::RelationalBuffer::newMultiRecordInsert(), ora::RelationalStreamerFactory::newWriter(), hltrates_dqm_sourceclient-live_cfg::offset, ora::ClassUtils::resolvedType(), AlCaHLTBitMon_QueryRunRegistry::string, ora::throwException(), and edm::TypeWithDict::unscopedName().

Referenced by psClasses.BuildThread::run().

40  {
41  if( !m_objectType ){
42  throwException( "Missing dictionary information for the type of the container \"" +
43  m_objectType.cppName() + "\"",
44  "STLContainerWriter::build" );
45  }
47  m_recordId.clear();
48  // allocate for the index...
49  m_recordId.push_back(0);
50 
51  RelationalStreamerFactory streamerFactory( m_schema );
52 
53  // first open the insert on the extra table...
54  m_insertOperation = &operationBuffer.newMultiRecordInsert( m_mappingElement.tableName() );
55  const std::vector<std::string>& columns = m_mappingElement.columnNames();
56  if( !columns.size() ){
57  throwException( "Id columns not found in the mapping.",
58  "STLContainerWriter::build");
59  }
60  for( size_t i=0; i<columns.size(); i++ ){
61  m_insertOperation->addId( columns[ i ] );
62  }
63 
64  m_offset = &offset;
65 
67 
68  edm::TypeWithDict valueType;
69  if ( m_associative ){
70 
72  edm::TypeWithDict keyResolvedType = ClassUtils::resolvedType(keyType);
73  if ( ! keyType || !keyResolvedType ) {
74  throwException( "Missing dictionary information for the key type of the container \"" +
75  m_objectType.cppName() + "\"",
76  "STLContainerWriter::build" );
77  }
78  std::string keyName("key_type");
79  // Retrieve the relevant mapping element
81  if ( iMe == m_mappingElement.end() ) {
82  throwException( "Item for \"" + keyName + "\" not found in the mapping element",
83  "STLContainerWriter::build" );
84  }
85 
86  m_keyWriter.reset( streamerFactory.newWriter( keyResolvedType, iMe->second ) );
87  m_keyWriter->build( m_localElement, *m_insertOperation, operationBuffer );
89  } else {
91  }
92 
93  edm::TypeWithDict valueResolvedType = ClassUtils::resolvedType(valueType);
94  // Check the component type
95  if ( ! valueType || !valueResolvedType ) {
96  throwException( "Missing dictionary information for the content type of the container \"" +
97  m_objectType.cppName() + "\"",
98  "STLContainerWriter::build" );
99  }
100 
101  std::string valueName(m_associative ? "mapped_type" : "value_type");
102  // Retrieve the relevant mapping element
104  if ( iMe == m_mappingElement.end() ) {
105  // Try again with the name of a possible typedef
106  std::string valueName2 = valueType.unscopedName();
107  iMe = m_mappingElement.find( valueName2 );
108  if ( iMe == m_mappingElement.end() ) {
109  throwException( "Item for \"" + valueName + "\" not found in the mapping element",
110  "STLContainerWriter::build" );
111  }
112  }
113 
114  m_dataWriter.reset( streamerFactory.newWriter( valueResolvedType, iMe->second ) );
115  m_dataWriter->build( m_localElement, *m_insertOperation, operationBuffer );
116  //operationBuffer.addToExecutionBuffer( *m_insertOperation );
117  return true;
118 }
int i
Definition: DBlmapReader.cc:9
edm::TypeWithDict resolvedType(const edm::TypeWithDict &typ)
Definition: ClassUtils.cc:486
std::vector< int > m_recordId
std::auto_ptr< IRelationalWriter > m_keyWriter
std::string unscopedName() const
std::string cppName() const
MultiRecordInsertOperation * m_insertOperation
static IArrayHandler * newArrayHandler(const edm::TypeWithDict &arrayType)
std::auto_ptr< IRelationalWriter > m_dataWriter
iterator find(const std::string &key)
Retrieves a sub-element.
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
const std::vector< std::string > & columnNames() const
edm::TypeWithDict m_objectType
edm::TypeWithDict containerKeyType(const edm::TypeWithDict &typ)
Definition: ClassUtils.cc:429
edm::TypeWithDict containerDataType(const edm::TypeWithDict &typ)
Definition: ClassUtils.cc:449
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
iterator end()
Returns an iterator in the end of the sequence.
edm::TypeWithDict containerValueType(const edm::TypeWithDict &typ)
Definition: ClassUtils.cc:410
const std::string & tableName() const
MappingElement & m_mappingElement
std::auto_ptr< IArrayHandler > m_arrayHandler
int addId(const std::string &columnName)
ora::DataElement * ora::STLContainerWriter::dataElement ( )
inline

Definition at line 145 of file STLContainerStreamer.h.

145  {
146  return m_offset;
147 }
ora::MappingElement & ora::STLContainerWriter::mapping ( )
inline

Definition at line 139 of file STLContainerStreamer.h.

References m_mappingElement.

139  {
140  return m_mappingElement;
141 }
MappingElement & m_mappingElement
void ora::STLContainerWriter::setRecordId ( const std::vector< int > &  identity)
virtual

Implements ora::IRelationalWriter.

Definition at line 120 of file STLContainerStreamer.cc.

References i.

120  {
121  m_recordId.clear();
122  for(size_t i=0;i<identity.size();i++) {
123  m_recordId.push_back( identity[i] );
124  }
125  m_recordId.push_back( 0 );
126 }
int i
Definition: DBlmapReader.cc:9
std::vector< int > m_recordId
void ora::STLContainerWriter::write ( int  oid,
const void *  data 
)
virtual

Writes a data element.

Implements ora::IRelationalWriter.

Definition at line 128 of file STLContainerStreamer.cc.

References edm::TypeWithDict::cppName(), data, edm::TypeWithDict::dataMemberByName(), i, edm::MemberWithDict::offset(), edm::TypeWithDict::templateArgumentAt(), and ora::throwException().

Referenced by pkg.AbstractPkg::generate(), and querying.connection::write_and_commit().

129  {
130 
131  if(!m_offset){
132  throwException("The streamer has not been built.",
133  "STLContainerWriter::write");
134  }
135 
136  const std::vector<std::string>& columns = m_mappingElement.columnNames();
137  if( columns.size() != m_recordId.size()+1){
138  throwException( "Object id elements provided are not matching with the mapped id columns.",
139  "STLContainerWriter::write");
140  }
141 
142  const edm::TypeWithDict& iteratorReturnType = m_arrayHandler->iteratorReturnType();
143  // Retrieve the container type
144  edm::TypeWithDict keyType;
145  if ( m_associative ) keyType = m_objectType.templateArgumentAt(0);
146  edm::MemberWithDict firstMember;
147  edm::MemberWithDict secondMember;
148  if( keyType ){
149  firstMember = iteratorReturnType.dataMemberByName( "first" );
150  if ( ! firstMember ) {
151  throwException( "Could not find the data member \"first\" for the class \"" +
152  iteratorReturnType.cppName() + "\"",
153  "STLContainerWriter::write" );
154  }
155  secondMember = iteratorReturnType.dataMemberByName( "second" );
156  if ( ! secondMember ) {
157  throwException( "Could not retrieve the data member \"second\" for the class \"" +
158  iteratorReturnType.cppName() + "\"",
159  "STLContainerWriter::write" );
160  }
161  }
162 
163  void* data = m_offset->address( inputData );
164 
165  // Use the iterator to loop over the elements of the container.
166  size_t containerSize = m_arrayHandler->size( data );
167 
168  if ( containerSize == 0 ) return;
169 
170  size_t startElementIndex = m_arrayHandler->startElementIndex( data );
171  std::auto_ptr<IArrayIteratorHandler> iteratorHandler( m_arrayHandler->iterate( data ) );
172 
173  InsertCache& bulkInsert = m_insertOperation->setUp( containerSize-startElementIndex+1 );
174 
175  for ( size_t iIndex = startElementIndex; iIndex < containerSize; ++iIndex ) {
176 
177  m_recordId[m_recordId.size()-1] = iIndex;
178  coral::AttributeList& dataBuff = m_insertOperation->data();
179 
180  dataBuff[ columns[0] ].data<int>() = oid;
181  for( size_t i = 1;i < columns.size(); i++ ){
182  dataBuff[ columns[i] ].data<int>() = m_recordId[i-1];
183  }
184 
185  void* objectReference = iteratorHandler->object();
186  void* componentData = objectReference;
187 
188  if ( keyType ) { // treat the key object first
189  void* keyData = static_cast< char* >( objectReference ) + firstMember.offset();
190  m_keyWriter->setRecordId( m_recordId );
191  m_keyWriter->write( oid, keyData );
192 
193  componentData = static_cast< char* >( objectReference ) + secondMember.offset();
194  }
195  m_dataWriter->setRecordId( m_recordId );
196 
197  m_dataWriter->write( oid, componentData );
198  bulkInsert.processNextIteration();
199 
200  // Increment the iterator
201  iteratorHandler->increment();
202  }
203 
204  // execute the insert...
205  m_arrayHandler->finalize( const_cast<void*>( data ) );
206 
207 }
int i
Definition: DBlmapReader.cc:9
void * address(const void *topLevelAddress) const
Definition: DataElement.cc:49
std::vector< int > m_recordId
size_t offset() const
std::auto_ptr< IRelationalWriter > m_keyWriter
TypeWithDict templateArgumentAt(size_t index) const
MemberWithDict dataMemberByName(std::string const &) const
std::string cppName() const
MultiRecordInsertOperation * m_insertOperation
std::auto_ptr< IRelationalWriter > m_dataWriter
const std::vector< std::string > & columnNames() const
edm::TypeWithDict m_objectType
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
InsertCache & setUp(int rowCacheSize)
MappingElement & m_mappingElement
std::auto_ptr< IArrayHandler > m_arrayHandler
tuple inputData
Definition: idDealer.py:72

Member Data Documentation

std::auto_ptr<IArrayHandler> ora::STLContainerWriter::m_arrayHandler
private

Definition at line 52 of file STLContainerStreamer.h.

bool ora::STLContainerWriter::m_associative
private

Definition at line 49 of file STLContainerStreamer.h.

std::auto_ptr<IRelationalWriter> ora::STLContainerWriter::m_dataWriter
private

Definition at line 54 of file STLContainerStreamer.h.

MultiRecordInsertOperation* ora::STLContainerWriter::m_insertOperation
private

Definition at line 51 of file STLContainerStreamer.h.

std::auto_ptr<IRelationalWriter> ora::STLContainerWriter::m_keyWriter
private

Definition at line 53 of file STLContainerStreamer.h.

DataElement ora::STLContainerWriter::m_localElement
private

Definition at line 46 of file STLContainerStreamer.h.

MappingElement& ora::STLContainerWriter::m_mappingElement
private

Definition at line 43 of file STLContainerStreamer.h.

Referenced by mapping().

edm::TypeWithDict ora::STLContainerWriter::m_objectType
private

Definition at line 42 of file STLContainerStreamer.h.

DataElement* ora::STLContainerWriter::m_offset
private

Definition at line 50 of file STLContainerStreamer.h.

std::vector<int> ora::STLContainerWriter::m_recordId
private

Definition at line 45 of file STLContainerStreamer.h.

ContainerSchema& ora::STLContainerWriter::m_schema
private

Definition at line 44 of file STLContainerStreamer.h.