test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ObjectStreamer.cc
Go to the documentation of this file.
2 #include "ObjectStreamer.h"
3 #include "DataElement.h"
4 #include "MappingElement.h"
5 #include "ClassUtils.h"
6 #include "MappingRules.h"
7 // externals
8 #include "Reflex/Base.h"
9 #include "Reflex/Member.h"
10 
11 namespace ora {
12 
13  bool isLoosePersistencyDataMember( const Reflex::Member& dataMember ){
14  std::string persistencyType("");
15  Reflex::PropertyList memberProps = dataMember.Properties();
16  if( memberProps.HasProperty(ora::MappingRules::persistencyPropertyNameInDictionary())){
17  persistencyType = memberProps.PropertyAsString(ora::MappingRules::persistencyPropertyNameInDictionary());
18  }
19  return ora::MappingRules::isLooseOnWriting( persistencyType ) || ora::MappingRules::isLooseOnReading( persistencyType ) ;
20  }
21 
22 }
23 
25  MappingElement& mapping,
26  ContainerSchema& contSchema ):
27  m_streamerFactory( contSchema ),
28  m_objectType( objectType ),
29  m_mapping( mapping ){
30 }
31 
33 }
34 
36  IRelationalData& relationalData,
37  const Reflex::Type& objType,
38  RelationalBuffer* operationBuffer ){
39 
40  for ( unsigned int i=0;i<objType.BaseSize();i++){
41  Reflex::Base base = objType.BaseAt(i);
42  Reflex::Type baseType = ClassUtils::resolvedType( base.ToType() );
43  buildBaseDataMembers( dataElement, relationalData, baseType, operationBuffer );
44  for ( unsigned int j=0;j<baseType.DataMemberSize();j++){
45  Reflex::Member dataMember = baseType.DataMemberAt(j);
46  DataElement& dataMemberElement = dataElement.addChild( dataMember.Offset(), base.OffsetFP() );
47  // Ignore the transients and the statics (how to deal with non-const statics?)
48  if ( dataMember.IsTransient() || dataMember.IsStatic() ) continue;
49  // Get the member type and resolve possible typedef chains
50  Reflex::Type dataMemberType = ClassUtils::resolvedType( dataMember.TypeOf() );
51  if ( ! dataMemberType ) {
52  throwException( "Missing dictionary information for data member \"" +
53  dataMember.Name() + "\" of class \"" +
54  baseType.Name(Reflex::SCOPED|Reflex::FINAL) + "\"",
55  "ObjectStreamerBase::buildBaseDataMembers" );
56  }
57 
58  // check if the member is from a class in the inheritance tree
59  Reflex::Type declaringType = ClassUtils::resolvedType( dataMember.DeclaringType());
60  std::string scope = declaringType.Name(Reflex::SCOPED|Reflex::FINAL);
61  // Get the data member name
62  std::string dataMemberName = MappingRules::scopedVariableName( dataMember.Name(), scope );
63  // Retrieve the relevant mapping element
64  MappingElement::iterator iDataMemberMapping = m_mapping.find( dataMemberName );
65  if ( iDataMemberMapping != m_mapping.end() ) {
66  MappingElement& dataMemberMapping = iDataMemberMapping->second;
67  if( !ClassUtils::checkMappedType(dataMemberType,dataMemberMapping.variableType()) ){
68  throwException( "Data member \""+dataMemberName +"\" type \"" + dataMemberType.Name(Reflex::SCOPED|Reflex::FINAL) +
69  "\" does not match with the expected type in the mapping \""+dataMemberMapping.variableType()+"\".",
70  "ObjectStreamerBase::buildBaseDataMembers" );
71  }
72  processDataMember( dataMemberElement, relationalData, dataMemberType, dataMemberMapping, operationBuffer );
73  } else {
74  if( !isLoosePersistencyDataMember( dataMember ) ){
75  throwException( "Data member \"" + dataMemberName +
76  "\" not found in the mapping element of variable \""+m_mapping.variableName()+"\".",
77  "ObjectStreamerBase::buildBaseDataMembers" );
78  }
79  }
80  }
81  }
82 
83 }
84 
86  IRelationalData& relationalData,
87  RelationalBuffer* operationBuffer ){
88  buildBaseDataMembers( dataElement, relationalData, m_objectType, operationBuffer );
89  // Loop over the data members of the class.
90  for ( unsigned int i=0;i<m_objectType.DataMemberSize();i++){
91 
92  Reflex::Member dataMember = m_objectType.DataMemberAt(i);
93  DataElement& dataMemberElement = dataElement.addChild( dataMember.Offset(), 0 );
94 
95  Reflex::Type declaringType = ClassUtils::resolvedType( dataMember.DeclaringType());
96  if( declaringType != m_objectType ){
97  continue;
98  }
99 
100  // Ignore the transients and the statics (how to deal with non-const statics?)
101  if ( dataMember.IsTransient() || dataMember.IsStatic() ) continue;
102 
103  // Get the member type and resolve possible typedef chains
104  Reflex::Type dataMemberType = ClassUtils::resolvedType( dataMember.TypeOf() );
105  if ( ! dataMemberType ) {
106  throwException( "Missing dictionary information for data member \"" +
107  dataMember.Name() + "\" of class \"" +
108  m_objectType.Name(Reflex::SCOPED|Reflex::FINAL) + "\"",
109  "ObjectStreamerBase::buildDataMembers" );
110  }
111 
112  // check if the member is from a class in the inheritance tree
113  std::string scope("");
114  // Get the data member name
115  std::string dataMemberName = MappingRules::scopedVariableName( dataMember.Name(), scope );
116 
117  // Retrieve the relevant mapping element
118  MappingElement::iterator idataMemberMapping = m_mapping.find( dataMemberName );
119  if ( idataMemberMapping != m_mapping.end() ) {
120  MappingElement& dataMemberMapping = idataMemberMapping->second;
121  if( !ClassUtils::checkMappedType(dataMemberType,dataMemberMapping.variableType())){
122  throwException( "Data member \""+dataMemberName +"\" type \"" + dataMemberType.Name(Reflex::SCOPED|Reflex::FINAL) +
123  "\" does not match with the expected type in the mapping \""+dataMemberMapping.variableType()+"\".",
124  "ObjectStreamerBase::buildDataMembers" );
125  }
126  processDataMember( dataMemberElement, relationalData, dataMemberType, dataMemberMapping, operationBuffer );
127  } else {
128  if(!isLoosePersistencyDataMember( dataMember ) ){
129  throwException( "Data member \"" + dataMemberName +
130  "\" not found in the mapping element of variable \""+m_mapping.variableName()+"\".",
131  "ObjectStreamerBase::buildDataMembers" );
132  }
133  }
134  }
135  return true;
136 }
137 
139  MappingElement& mapping,
140  ContainerSchema& contSchema ):
141  ObjectStreamerBase( objectType, mapping, contSchema ),
142  m_writers(){
143 }
144 
146  for( std::vector< IRelationalWriter* >::iterator iW = m_writers.begin();
147  iW != m_writers.end(); ++iW ){
148  delete *iW;
149  }
150  m_writers.clear();
151 }
152 
154  IRelationalData& relationalData,
155  RelationalBuffer& operationBuffer){
156  return buildDataMembers( dataElement, relationalData, &operationBuffer );
157 }
158 
159 void ora::ObjectWriter::setRecordId( const std::vector<int>& identity ){
160  for( std::vector< IRelationalWriter* >::iterator iW = m_writers.begin();
161  iW != m_writers.end(); ++iW ){
162  (*iW)->setRecordId( identity );
163  }
164 }
165 
168  const void* data ){
169  for( std::vector< IRelationalWriter* >::iterator iW = m_writers.begin();
170  iW != m_writers.end(); ++iW ){
171  (*iW)->write( oid, data );
172  }
173 }
174 
176  IRelationalData& relationalData,
177  Reflex::Type& dataMemberType,
178  MappingElement& dataMemberMapping,
179  RelationalBuffer* operationBuffer ){
180  IRelationalWriter* dataMemberWriter = m_streamerFactory.newWriter( dataMemberType, dataMemberMapping );
181  m_writers.push_back( dataMemberWriter );
182  dataMemberWriter->build( dataMemberElement, relationalData, *operationBuffer );
183 }
184 
185 
187  MappingElement& mapping,
188  ContainerSchema& contSchema ):
189  ObjectStreamerBase( objectType, mapping, contSchema ),
190  m_updaters(){
191 }
192 
194  for( std::vector< IRelationalUpdater* >::iterator iU = m_updaters.begin();
195  iU != m_updaters.end(); ++iU ){
196  delete *iU;
197  }
198  m_updaters.clear();
199 }
200 
202  IRelationalData& relationalData,
203  RelationalBuffer& operationBuffer){
204  return buildDataMembers( dataElement, relationalData, &operationBuffer );
205 }
206 
207 void ora::ObjectUpdater::setRecordId( const std::vector<int>& identity ){
208  for( std::vector< IRelationalUpdater* >::iterator iU = m_updaters.begin();
209  iU != m_updaters.end(); ++iU){
210  (*iU)->setRecordId( identity );
211  }
212 }
213 
216  const void* data ){
217  for( std::vector< IRelationalUpdater* >::iterator iU = m_updaters.begin();
218  iU != m_updaters.end(); ++iU ){
219  (*iU)->update( oid, data );
220  }
221 }
222 
224  IRelationalData& relationalData,
225  Reflex::Type& dataMemberType,
226  MappingElement& dataMemberMapping,
227  RelationalBuffer* operationBuffer ){
228  IRelationalUpdater* dataMemberUpdater = m_streamerFactory.newUpdater( dataMemberType, dataMemberMapping );
229  m_updaters.push_back( dataMemberUpdater );
230  dataMemberUpdater->build( dataMemberElement, relationalData, *operationBuffer );
231 }
232 
234  MappingElement& mapping,
235  ContainerSchema& contSchema ):
236  ObjectStreamerBase( objectType, mapping, contSchema ),
237  m_readers(){
238 }
239 
241  for( std::vector< IRelationalReader* >::iterator iStr = m_readers.begin();
242  iStr != m_readers.end(); ++iStr ){
243  delete *iStr;
244  }
245  m_readers.clear();
246 }
247 
249  IRelationalData& relationalData){
250  return buildDataMembers( dataElement, relationalData, 0 );
251 }
252 
254  for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
255  iDepReader != m_readers.end(); ++iDepReader ){
256  (*iDepReader)->select( oid );
257  }
258 }
259 
260 void ora::ObjectReader::setRecordId( const std::vector<int>& identity ){
261  for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
262  iDepReader != m_readers.end(); ++iDepReader ){
263  (*iDepReader)->setRecordId( identity );
264  }
265 }
266 
269  for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
270  iDepReader != m_readers.end(); ++iDepReader ){
271  (*iDepReader)->read( data );
272  }
273 }
274 
276  for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
277  iDepReader != m_readers.end(); ++iDepReader ){
278  (*iDepReader)->clear();
279  }
280 }
281 
283  IRelationalData& relationalData,
284  Reflex::Type& dataMemberType,
285  MappingElement& dataMemberMapping,
287  IRelationalReader* dataMemberReader = m_streamerFactory.newReader( dataMemberType, dataMemberMapping );
288  m_readers.push_back( dataMemberReader );
289  dataMemberReader->build( dataMemberElement, relationalData );
290 }
291 
292 
294  MappingElement& mapping,
295  ContainerSchema& contSchema ):
296  m_objectType( objectType ),
297  m_mapping( mapping ),
298  m_schema( contSchema ){
299 }
300 
302 }
303 
305  return new ObjectWriter( m_objectType, m_mapping, m_schema );
306 }
307 
309  return new ObjectUpdater( m_objectType, m_mapping, m_schema );
310 }
311 
313  return new ObjectReader( m_objectType, m_mapping, m_schema );
314 }
315 
tuple base
Main Program
Definition: newFWLiteAna.py:92
void processDataMember(DataElement &dataElement, IRelationalData &relationalData, Reflex::Type &dataMemberType, MappingElement &dataMemberMapping, RelationalBuffer *operationBuffer)
int i
Definition: DBlmapReader.cc:9
void setRecordId(const std::vector< int > &identity)
ObjectStreamer(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
bool build(DataElement &offset, IRelationalData &relationalData)
void processDataMember(DataElement &dataElement, IRelationalData &relationalData, Reflex::Type &dataMemberType, MappingElement &dataMemberMapping, RelationalBuffer *operationBuffer)
static std::string scopedVariableName(const std::string &variableName, const std::string &scope)
variable name manipulation
void update(int oid, const void *data)
Updates a data element.
static std::string persistencyPropertyNameInDictionary()
Definition: MappingRules.cc:47
virtual bool build(DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)=0
IRelationalWriter * newWriter()
DataElement & addChild(size_t declaringScopeOffset, Reflex::OffsetFunction offsetFunction)
Definition: DataElement.cc:26
bool isLoosePersistencyDataMember(const Reflex::Member &dataMember)
IRelationalUpdater * newUpdater()
void setRecordId(const std::vector< int > &identity)
void read(void *destination)
Reads a data element.
ObjectReader(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
bool checkMappedType(const Reflex::Type &type, const std::string &mappedTypeName)
Definition: ClassUtils.cc:54
ObjectWriter(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
void setRecordId(const std::vector< int > &identity)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
virtual bool build(DataElement &offset, IRelationalData &relationalData)=0
bool buildDataMembers(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer *operationBuffer)
int j
Definition: DBlmapReader.cc:9
void buildBaseDataMembers(DataElement &dataElement, IRelationalData &relationalData, const Reflex::Type &objType, RelationalBuffer *operationBuffer)
static bool isLooseOnReading(const std::string &persistencyProperty)
Definition: MappingRules.cc:53
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
void processDataMember(DataElement &dataElement, IRelationalData &relationalData, Reflex::Type &dataMemberType, MappingElement &dataMemberMapping, RelationalBuffer *operationBuffer)
Reflex::Type resolvedType(const Reflex::Type &typ)
Definition: ClassUtils.cc:404
static bool isLooseOnWriting(const std::string &persistencyProperty)
Definition: MappingRules.cc:58
ObjectStreamerBase(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
ObjectUpdater(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
const std::string & variableType() const
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
virtual bool build(DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)=0
IRelationalReader * newReader()
void select(int oid)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
void write(int oid, const void *data)
Writes a data element.