CMS 3D CMS Logo

EDProductGetter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     EDProduct
00004 // Class  :     EDProductGetter
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Tue Nov  1 15:06:41 EST 2005
00011 // $Id: EDProductGetter.cc,v 1.4 2008/05/29 21:13:15 wmtan Exp $
00012 //
00013 
00014 // system include files
00015 #include "boost/thread/tss.hpp"
00016 
00017 // user include files
00018 #include "DataFormats/Common/interface/EDProductGetter.h"
00019 #include "FWCore/Utilities/interface/EDMException.h"
00020 
00021 namespace edm {
00022   //
00023   // constants, enums and typedefs
00024   //
00025   
00026   //
00027   // static data member definitions
00028   //
00029   
00030   //
00031   // constructors and destructor
00032   //
00033   EDProductGetter::EDProductGetter()
00034   {
00035   }
00036   
00037   // EDProductGetter::EDProductGetter(const EDProductGetter& rhs)
00038   // {
00039   //    // do actual copying here;
00040   // }
00041   
00042   EDProductGetter::~EDProductGetter()
00043   {
00044   }
00045   
00046   //
00047   // assignment operators
00048   //
00049   // const EDProductGetter& EDProductGetter::operator=(const EDProductGetter& rhs)
00050   // {
00051   //   //An exception safe implementation is
00052   //   EDProductGetter temp(rhs);
00053   //   swap(rhs);
00054   //
00055   //   return *this;
00056   // }
00057   
00058   //
00059   // member functions
00060   //
00061   
00062   //
00063   // const member functions
00064   //
00065   
00066   //
00067   // static member functions
00068   //
00069   
00070   namespace {
00071      struct Holder {
00072         Holder(): held_(0) {}
00073         edm::EDProductGetter const* held_;
00074      };
00075   }
00076   EDProductGetter const* 
00077   EDProductGetter::set(EDProductGetter const* iGetter)
00078   {
00079      //NOTE: I use a Holder so that when s_registry goes away it will not delete the last EDProductGetter it saw
00080      static boost::thread_specific_ptr<Holder> s_registry;
00081      if(0 == s_registry.get()){
00082         s_registry.reset(new Holder);
00083      }
00084      EDProductGetter const* previous = s_registry->held_;
00085      s_registry->held_= iGetter;
00086      return previous;
00087   }
00088   
00089   EDProductGetter const*
00090   EDProductGetter::instance()
00091   {
00092      EDProductGetter const* returnValue = EDProductGetter::set(0);
00093      EDProductGetter::set(returnValue);
00094      return returnValue;
00095   }
00096   
00097   EDProductGetter const*
00098   mustBeNonZero(EDProductGetter const* prodGetter, std::string refType, ProductID const& productID) {
00099     if (prodGetter != 0) return prodGetter;
00100         throw Exception(errors::InvalidReference, refType)
00101         << "Attempt to construct a " << refType << " with ProductID " << productID << "\n"
00102         << "but with a null pointer to a product getter.\n"
00103         << "The product getter pointer passed to the constructor must refer\n"
00104         << "to a real getter, such as an EventPrincipal.\n";
00105   }
00106 }

Generated on Tue Jun 9 17:30:40 2009 for CMSSW by  doxygen 1.5.4