CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenericObjectOwner.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Framework
4 // Class : GenericObjectOwner
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Feb 7 17:21:22 EST 2008
11 //
12 
13 // system include files
14 
15 // user include files
19 
20 namespace edm {
21 //
22 // constants, enums and typedefs
23 //
24 
25 //
26 // static data member definitions
27 //
28 
29 //
30 // constructors and destructor
31 //
32 //GenericObjectOwner::GenericObjectOwner()
33 //{
34 //}
35 
36 // GenericObjectOwner::GenericObjectOwner(const GenericObjectOwner& rhs)
37 // {
38 // // do actual copying here;
39 // }
40 
42 {
43  if(m_ownData) {
44  m_object.Destruct();
45  }
46 }
47 
48 //
49 // assignment operators
50 //
51 // const GenericObjectOwner& GenericObjectOwner::operator=(const GenericObjectOwner& rhs)
52 // {
53 // //An exception safe implementation is
54 // GenericObjectOwner temp(rhs);
55 // swap(rhs);
56 //
57 // return *this;
58 // }
59 
60 //
61 // member functions
62 //
63 void
65  Reflex::Object old(m_object);
66  m_object = iOther.m_object;
67  iOther.m_object = m_object;
68 }
69 
70 //
71 // const member functions
72 //
73 Reflex::Object
75  return m_object;
76 }
77 
78 //
79 // static member functions
80 //
81 
82 template <>
84 Event::put<GenericObjectOwner>(std::auto_ptr<GenericObjectOwner> product, std::string const& productInstanceName)
85 {
86  if(product.get() == 0) { // null pointer is illegal
88  << "Event::put: A null auto_ptr was passed to 'put'.\n"
89  << "The pointer is of type " << "GenericObjectOwner" << ".\n"
90  << "The specified productInstanceName was '" << productInstanceName << "'.\n";
91  }
92 
93  // The following will call post_insert if T has such a function,
94  // and do nothing if T has no such function.
95  /*
96  typename boost::mpl::if_c<detail::has_postinsert<PROD>::value,
97  DoPostInsert<PROD>,
98  DoNotPostInsert<PROD> >::type maybe_inserter;
99  maybe_inserter(product.get());
100  */
101  ConstBranchDescription const& desc =
102  provRecorder_.getBranchDescription(TypeID(product->object().TypeOf().TypeInfo()), productInstanceName);
103 
104  Reflex::Type const wrapperType = Reflex::Type::ByName(wrappedClassName(desc.fullClassName()));
105  if(wrapperType == Reflex::Type()) {
106  throw edm::Exception(errors::DictionaryNotFound, "NoWrapperDictionary")
107  << "Event::put: the class type '" << desc.fullClassName()
108  << "' was passed to put but the Reflex dictionary for the required class '"
109  << wrappedClassName(desc.fullClassName()) << "' could not be found./n"
110  << "Please change the C++ package which contains the description of '" << desc.fullClassName()
111  << "' so that the required class also has a dictionary autogenerated.";
112  }
113  std::vector<void*> args;
114  args.reserve(1);
115  args.push_back(product->object().Address());
116  //generate the signature of the function we want to call
117  std::string s("void(");
118  s += desc.fullClassName();
119  s += "*)";
120  Reflex::Type ptrT = Reflex::Type::ByName(s);
121  Reflex::Object oWrapper(wrapperType.Construct(ptrT,args));
122  //ownership was transfered to the wrapper
123  product.release();
124 
125  //static Reflex::Type s_edproductType(Reflex::Type::ByTypeInfo(typeid(EDProduct)));
126  WrapperOwningHolder wp(oWrapper.Address(), desc.getInterface());
127  putProducts().push_back(std::make_pair(wp, &desc));
128 
129  // product.release(); // The object has been copied into the Wrapper.
130  // The old copy must be deleted, so we cannot release ownership.
131 
132  return(OrphanHandle<GenericObjectOwner>(oWrapper.Get("obj"), eventPrincipal().branchIDToProductID(desc.branchID())));
133 }
134 }
135 
void swap(GenericObjectOwner &)
Reflex::Object object() const
BranchID const & branchID() const
WrapperInterfaceBase const * getInterface() const
std::string const & fullClassName() const
std::string wrappedClassName(std::string const &iFullName)
dictionary args