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
10 
11 namespace ora {
12 
15  return ora::MappingRules::isLooseOnWriting( persistencyType ) || ora::MappingRules::isLooseOnReading( persistencyType ) ;
16  }
17 
18 }
19 
21  MappingElement& mapping,
22  ContainerSchema& contSchema ):
23  m_streamerFactory( contSchema ),
24  m_objectType( objectType ),
25  m_mapping( mapping ){
26 }
27 
29 }
30 
31 
33  IRelationalData& relationalData,
34  const edm::TypeWithDict& objType,
35  RelationalBuffer* operationBuffer ){
36 
37  // Don't look for base classes of std:: stuff
38  if(objType.name().substr(0,5) == "std::") {
39  return;
40  }
41  edm::TypeBases bases(objType);
42  for (auto const & b : bases) {
45  buildBaseDataMembers( dataElement, relationalData, baseType, operationBuffer );
46  edm::TypeDataMembers members(baseType);
47  for (auto const & member : members) {
48  edm::MemberWithDict dataMember(member);
49  DataElement& dataMemberElement = dataElement.addChild( dataMember.offset(), /*base.offsetFP()*/ base.offset() );
50  // Ignore the transients and the statics (how to deal with non-const statics?)
51  if ( dataMember.isTransient() || dataMember.isStatic() ) continue;
52  // Get the member type and resolve possible typedef chains
53  edm::TypeWithDict dataMemberType = ClassUtils::resolvedType( dataMember.typeOf() );
54  if ( ! dataMemberType ) {
55  throwException( "Missing dictionary information for data member \"" +
56  dataMember.name() + "\" of class \"" +
57  baseType.cppName() + "\"",
58  "ObjectStreamerBase::buildBaseDataMembers" );
59  }
60 
61  // check if the member is from a class in the inheritance tree
62  edm::TypeWithDict declaringType = ClassUtils::resolvedType( dataMember.declaringType());
63  std::string scope = declaringType.cppName();
64  // Get the data member name
65  std::string dataMemberName = MappingRules::scopedVariableName( dataMember.name(), scope );
66  // Retrieve the relevant mapping element
67  MappingElement::iterator iDataMemberMapping = m_mapping.find( dataMemberName );
68  if ( iDataMemberMapping != m_mapping.end() ) {
69  MappingElement& dataMemberMapping = iDataMemberMapping->second;
70  if( !ClassUtils::checkMappedType(dataMemberType,dataMemberMapping.variableType()) ){
71  throwException( "Data member \""+dataMemberName +"\" type \"" + dataMemberType.cppName() +
72  "\" does not match with the expected type in the mapping \""+dataMemberMapping.variableType()+"\".",
73  "ObjectStreamerBase::buildBaseDataMembers" );
74  }
75  processDataMember( dataMemberElement, relationalData, dataMemberType, dataMemberMapping, operationBuffer );
76  } else {
77  if( !isLoosePersistencyDataMember( dataMember ) ){
78  throwException( "Data member \"" + dataMemberName +
79  "\" not found in the mapping element of variable \""+m_mapping.variableName()+"\".",
80  "ObjectStreamerBase::buildBaseDataMembers" );
81  }
82  }
83  }
84  }
85 
86 }
87 
89  IRelationalData& relationalData,
90  RelationalBuffer* operationBuffer ){
91  buildBaseDataMembers( dataElement, relationalData, m_objectType, operationBuffer );
92  // Loop over the data members of the class.
93  edm::TypeDataMembers members(m_objectType);
94  for (auto const & member : members) {
95  edm::MemberWithDict dataMember(member);
96  DataElement& dataMemberElement = dataElement.addChild( dataMember.offset(), 0 );
97 
98  edm::TypeWithDict declaringType = ClassUtils::resolvedType( dataMember.declaringType());
99  if( declaringType != m_objectType ){
100  continue;
101  }
102 
103  // Ignore the transients and the statics (how to deal with non-const statics?)
104  if ( dataMember.isTransient() || dataMember.isStatic() ) continue;
105 
106  // Get the member type and resolve possible typedef chains
107  edm::TypeWithDict dataMemberType = ClassUtils::resolvedType( dataMember.typeOf() );
108  if ( ! dataMemberType ) {
109  throwException( "Missing dictionary information for data member \"" +
110  dataMember.name() + "\" of class \"" +
111  m_objectType.cppName() + "\"",
112  "ObjectStreamerBase::buildDataMembers" );
113  }
114 
115  // check if the member is from a class in the inheritance tree
116  std::string scope("");
117  // Get the data member name
118  std::string dataMemberName = MappingRules::scopedVariableName( dataMember.name(), scope );
119 
120  // Retrieve the relevant mapping element
121  MappingElement::iterator idataMemberMapping = m_mapping.find( dataMemberName );
122  if ( idataMemberMapping != m_mapping.end() ) {
123  MappingElement& dataMemberMapping = idataMemberMapping->second;
124  if( !ClassUtils::checkMappedType(dataMemberType,dataMemberMapping.variableType())){
125  throwException( "Data member \""+dataMemberName +"\" type \"" + dataMemberType.cppName() +
126  "\" does not match with the expected type in the mapping \""+dataMemberMapping.variableType()+"\".",
127  "ObjectStreamerBase::buildDataMembers" );
128  }
129  processDataMember( dataMemberElement, relationalData, dataMemberType, dataMemberMapping, operationBuffer );
130  } else {
131  if(!isLoosePersistencyDataMember( dataMember ) ){
132  throwException( "Data member \"" + dataMemberName +
133  "\" not found in the mapping element of variable \""+m_mapping.variableName()+"\".",
134  "ObjectStreamerBase::buildDataMembers" );
135  }
136  }
137  }
138  return true;
139 }
140 
142  MappingElement& mapping,
143  ContainerSchema& contSchema ):
144  ObjectStreamerBase( objectType, mapping, contSchema ),
145  m_writers(){
146 }
147 
149  for( std::vector< IRelationalWriter* >::iterator iW = m_writers.begin();
150  iW != m_writers.end(); ++iW ){
151  delete *iW;
152  }
153  m_writers.clear();
154 }
155 
157  IRelationalData& relationalData,
158  RelationalBuffer& operationBuffer){
159  return buildDataMembers( dataElement, relationalData, &operationBuffer );
160 }
161 
162 void ora::ObjectWriter::setRecordId( const std::vector<int>& identity ){
163  for( std::vector< IRelationalWriter* >::iterator iW = m_writers.begin();
164  iW != m_writers.end(); ++iW ){
165  (*iW)->setRecordId( identity );
166  }
167 }
168 
171  const void* data ){
172  for( std::vector< IRelationalWriter* >::iterator iW = m_writers.begin();
173  iW != m_writers.end(); ++iW ){
174  (*iW)->write( oid, data );
175  }
176 }
177 
179  IRelationalData& relationalData,
180  edm::TypeWithDict& dataMemberType,
181  MappingElement& dataMemberMapping,
182  RelationalBuffer* operationBuffer ){
183  IRelationalWriter* dataMemberWriter = m_streamerFactory.newWriter( dataMemberType, dataMemberMapping );
184  m_writers.push_back( dataMemberWriter );
185  dataMemberWriter->build( dataMemberElement, relationalData, *operationBuffer );
186 }
187 
188 
190  MappingElement& mapping,
191  ContainerSchema& contSchema ):
192  ObjectStreamerBase( objectType, mapping, contSchema ),
193  m_updaters(){
194 }
195 
197  for( std::vector< IRelationalUpdater* >::iterator iU = m_updaters.begin();
198  iU != m_updaters.end(); ++iU ){
199  delete *iU;
200  }
201  m_updaters.clear();
202 }
203 
205  IRelationalData& relationalData,
206  RelationalBuffer& operationBuffer){
207  return buildDataMembers( dataElement, relationalData, &operationBuffer );
208 }
209 
210 void ora::ObjectUpdater::setRecordId( const std::vector<int>& identity ){
211  for( std::vector< IRelationalUpdater* >::iterator iU = m_updaters.begin();
212  iU != m_updaters.end(); ++iU){
213  (*iU)->setRecordId( identity );
214  }
215 }
216 
219  const void* data ){
220  for( std::vector< IRelationalUpdater* >::iterator iU = m_updaters.begin();
221  iU != m_updaters.end(); ++iU ){
222  (*iU)->update( oid, data );
223  }
224 }
225 
227  IRelationalData& relationalData,
228  edm::TypeWithDict& dataMemberType,
229  MappingElement& dataMemberMapping,
230  RelationalBuffer* operationBuffer ){
231  IRelationalUpdater* dataMemberUpdater = m_streamerFactory.newUpdater( dataMemberType, dataMemberMapping );
232  m_updaters.push_back( dataMemberUpdater );
233  dataMemberUpdater->build( dataMemberElement, relationalData, *operationBuffer );
234 }
235 
237  MappingElement& mapping,
238  ContainerSchema& contSchema ):
239  ObjectStreamerBase( objectType, mapping, contSchema ),
240  m_readers(){
241 }
242 
244  for( std::vector< IRelationalReader* >::iterator iStr = m_readers.begin();
245  iStr != m_readers.end(); ++iStr ){
246  delete *iStr;
247  }
248  m_readers.clear();
249 }
250 
252  IRelationalData& relationalData){
253  return buildDataMembers( dataElement, relationalData, 0 );
254 }
255 
257  for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
258  iDepReader != m_readers.end(); ++iDepReader ){
259  (*iDepReader)->select( oid );
260  }
261 }
262 
263 void ora::ObjectReader::setRecordId( const std::vector<int>& identity ){
264  for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
265  iDepReader != m_readers.end(); ++iDepReader ){
266  (*iDepReader)->setRecordId( identity );
267  }
268 }
269 
272  for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
273  iDepReader != m_readers.end(); ++iDepReader ){
274  (*iDepReader)->read( data );
275  }
276 }
277 
279  for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
280  iDepReader != m_readers.end(); ++iDepReader ){
281  (*iDepReader)->clear();
282  }
283 }
284 
286  IRelationalData& relationalData,
287  edm::TypeWithDict& dataMemberType,
288  MappingElement& dataMemberMapping,
290  IRelationalReader* dataMemberReader = m_streamerFactory.newReader( dataMemberType, dataMemberMapping );
291  m_readers.push_back( dataMemberReader );
292  dataMemberReader->build( dataMemberElement, relationalData );
293 }
294 
295 
297  MappingElement& mapping,
298  ContainerSchema& contSchema ):
299  m_objectType( objectType ),
300  m_mapping( mapping ),
301  m_schema( contSchema ){
302 }
303 
305 }
306 
308  return new ObjectWriter( m_objectType, m_mapping, m_schema );
309 }
310 
312  return new ObjectUpdater( m_objectType, m_mapping, m_schema );
313 }
314 
316  return new ObjectReader( m_objectType, m_mapping, m_schema );
317 }
318 
ObjectWriter(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
tuple base
Main Program
Definition: newFWLiteAna.py:92
void setRecordId(const std::vector< int > &identity)
bool build(DataElement &offset, IRelationalData &relationalData)
edm::TypeWithDict resolvedType(const edm::TypeWithDict &typ)
Definition: ClassUtils.cc:486
bool isLoosePersistencyDataMember(const edm::MemberWithDict &dataMember)
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:48
bool isStatic() const
virtual bool build(DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)=0
size_t offset() const
IRelationalWriter * newWriter()
void processDataMember(DataElement &dataElement, IRelationalData &relationalData, edm::TypeWithDict &dataMemberType, MappingElement &dataMemberMapping, RelationalBuffer *operationBuffer)
ObjectReader(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
IRelationalUpdater * newUpdater()
void setRecordId(const std::vector< int > &identity)
void read(void *destination)
Reads a data element.
TypeWithDict toType() const
ObjectStreamer(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
size_t offset() const
Definition: BaseWithDict.cc:31
TypeWithDict declaringType() const
void setRecordId(const std::vector< int > &identity)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
std::string name() const
ObjectUpdater(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
std::string cppName() const
ObjectStreamerBase(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
virtual bool build(DataElement &offset, IRelationalData &relationalData)=0
bool buildDataMembers(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer *operationBuffer)
std::string name() const
void processDataMember(DataElement &dataElement, IRelationalData &relationalData, edm::TypeWithDict &dataMemberType, MappingElement &dataMemberMapping, RelationalBuffer *operationBuffer)
TypeWithDict typeOf() const
bool checkMappedType(const edm::TypeWithDict &type, const std::string &mappedTypeName)
Definition: ClassUtils.cc:114
static bool isLooseOnReading(const std::string &persistencyProperty)
Definition: MappingRules.cc:54
TypeWithDict typeOf() const
Definition: BaseWithDict.cc:26
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
DataElement & addChild(size_t declaringScopeOffset, size_toffset)
Definition: DataElement.cc:27
void processDataMember(DataElement &dataElement, IRelationalData &relationalData, edm::TypeWithDict &dataMemberType, MappingElement &dataMemberMapping, RelationalBuffer *operationBuffer)
static bool isLooseOnWriting(const std::string &persistencyProperty)
Definition: MappingRules.cc:59
void buildBaseDataMembers(DataElement &dataElement, IRelationalData &relationalData, const edm::TypeWithDict &objType, RelationalBuffer *operationBuffer)
double b
Definition: hdecay.h:120
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
bool isTransient() const
IRelationalReader * newReader()
void select(int oid)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
std::string getDataMemberProperty(const std::string &propertyName, const edm::MemberWithDict &dataMember)
Definition: ClassUtils.cc:513
void write(int oid, const void *data)
Writes a data element.