CMS 3D CMS Logo

DTBufferTree.h
Go to the documentation of this file.
1 #ifndef DTBufferTree_H
2 #define DTBufferTree_H
3 
11 #include <map>
12 #include <memory>
13 #include <vector>
14 
15 // This trait template defines the type of the output argument
16 // in the find function. Usually the output type is just the
17 // content type, but in the special case where the content is
18 // a unique_ptr the the output type is a bare pointer. The
19 // functions in the trait template make that output type work
20 // in both cases.
21 template <typename T>
23 public:
26 
27  static T getOutputValue(T const& t) { return t; }
28  static T getDefault() { return 0; }
29 };
30 
31 template <typename T>
32 class DTBufferTreeTrait<std::unique_ptr<T> > {
33 public:
34  typedef T const* outputTypeOfConstFind;
36 
37  static T* getOutputValue(std::unique_ptr<T> const& t) { return t.get(); }
38  static T* getDefault() { return nullptr; }
39 };
40 
41 template <class Key, class Content>
42 class DTBufferTree {
43 
44 public:
45 
46  typedef typename std::vector<Key>::const_iterator ElementKey;
47 
48  DTBufferTree();
49  virtual ~DTBufferTree();
50 
51  void clear();
52 
53  int insert(ElementKey fKey, ElementKey lKey, Content cont );
54  int insert(const Key& k, Content cont );
55  int find(ElementKey fKey, ElementKey lKey, typename DTBufferTreeTrait<Content>::outputTypeOfConstFind& cont ) const;
56  int find(const Key& k, typename DTBufferTreeTrait<Content>::outputTypeOfConstFind& cont ) const;
57  int find(ElementKey fKey, ElementKey lKey, typename DTBufferTreeTrait<Content>::outputTypeOfNonConstFind& cont );
59 
60 private:
61 
62  DTBufferTree(DTBufferTree const&) = delete;
63  DTBufferTree& operator=(DTBufferTree const&) = delete;
64 
66  typedef typename std::map<Key,DTBufferTree<Key,Content>*> map_cont;
67  typedef typename std::map<Key,DTBufferTree<Key,Content>*>::const_iterator map_iter;
68 
69  Content bufferContent;
70  map_cont bufferMap;
71 };
72 
73 #include "CondFormats/DTObjects/interface/DTBufferTree.icc"
74 
75 // This class is defined because it is easier to forward declare
76 // it than the template. Then unique_ptr is not exposed. When
77 // we stop using GCCXML (which does not recognize C++11's unique_ptr)
78 // this will not be as important, although it will still keep
79 // #include <memory> out of the header file of the class using
80 // DTBufferTree.
81 class DTBufferTreeUniquePtr : public DTBufferTree<int, std::unique_ptr<std::vector<int> > > {
82 };
83 
84 #endif // DTBufferTree_H
static T getOutputValue(T const &t)
Definition: DTBufferTree.h:27
std::map< Key, DTBufferTree< Key, Content > * >::const_iterator map_iter
Definition: DTBufferTree.h:67
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
Content bufferContent
Definition: DTBufferTree.h:69
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
static T getDefault()
Definition: DTBufferTree.h:28
map_cont bufferMap
Definition: DTBufferTree.h:70
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:50
int k[5][pyjets_maxn]
static T * getOutputValue(std::unique_ptr< T > const &t)
Definition: DTBufferTree.h:37
std::map< Key, DTBufferTree< Key, Content > * > map_cont
Definition: DTBufferTree.h:66
std::vector< Key >::const_iterator ElementKey
Definition: DTBufferTree.h:46
DTBufferTree< Key, Content > map_node
Definition: DTBufferTree.h:65
long double T