ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/ObjectService/interface/ObjectService.h
(Generate patch)

Comparing UserCode/MitProd/ObjectService/interface/ObjectService.h (file contents):
Revision 1.1 by loizides, Wed Jul 30 09:04:39 2008 UTC vs.
Revision 1.2 by loizides, Wed Jul 30 11:24:43 2008 UTC

# Line 3 | Line 3
3   //
4   // ObjectService
5   //
6 < // This service can be used in the config files to provide access to the TreeWriter,
7 < // for example:
8 < //
9 < //   service = ObjectService {
10 < //
11 < //   }
6 > // This service can be used in the config files to provide a simple interface to
7 > // exchange objects accross fillers and in principle also across modules.
8 > // Usage in config files is:
9 > //   service = ObjectService { }
10   //
11   // Authors: C.Loizides
14 //
12   //--------------------------------------------------------------------------------------------------
13  
14   #ifndef MITPROD_OBJECTSERVICE_H
# Line 21 | Line 18
18   #include "DataFormats/Provenance/interface/Timestamp.h"
19   #include "FWCore/Framework/interface/Event.h"
20   #include "FWCore/Framework/interface/EventSetup.h"
21 <
22 < #include <TObjArray.h>
21 > #include "FWCore/MessageLogger/interface/MessageLogger.h"
22 > #include "MitProd/ObjectService/interface/NamedObject.h"
23 > #include <THashTable.h>
24  
25   namespace edm
26   {
# Line 38 | Line 36 | namespace mithep
36        ObjectService(const edm::ParameterSet &cfg, edm::ActivityRegistry &ar);
37        ~ObjectService();
38  
39 < //      TreeWriter *get(const char *name=0);
39 >      template<class T> bool add(const T *obj, const char *name);
40 >      template<class T> bool addObjEvt(const T *obj, const char *name);
41 >      template<class T> const T *get(const char *name) const;
42 >      template<class T> const T *getObjEvt(const char *name) const;
43  
44      private:
44 #if 0
45        void preEventProcessing(const edm::EventID &id, const edm::Timestamp &t);
46 <      void postEventProcessing(const edm::Event& e, const edm::EventSetup& es);
46 >      void postEventProcessing(const edm::Event &e, const edm::EventSetup &es);
47        void postBeginJob();
48        void postEndJob();
49 #endif
50      TObjArray obs_; //array holding the hash table
49  
50 <      // parameters for service
51 <      std::vector<std::string> hashNames_;   //hash names
50 >      THashTable obs_;    //hash table holding the objects
51 >      THashTable obsEvt_; //hash table holding the objects per event
52    };
53   }
54 +
55 + //--------------------------------------------------------------------------------------------------
56 + template<class T>
57 + bool mithep::ObjectService::add(const T *obj, const char *name)
58 + {
59 +  // Add object with given name.
60 +
61 +  if (obs_.FindObject(name)) {
62 +    edm::LogError("ObjectService") << "Cannot add object with name " << name
63 +                                   << "since name is already used."
64 +                                   << std::endl;
65 +    return 0;
66 +  }
67 +      
68 +  NamedObject<T> *no = new NamedObject<T>(obj, name);
69 +  obs_.Add(no);
70 +  return 1;
71 + }
72 +
73 + //--------------------------------------------------------------------------------------------------
74 + template<class T>
75 + bool mithep::ObjectService::addObjEvt(const T *obj, const char *name)
76 + {
77 +  // Add object with given name for the current event.
78 +
79 +  if (obsEvt_.FindObject(name)) {
80 +    edm::LogError("ObjectService") << "Cannot add object with name " << name
81 +                                   << "to event since name is already used."
82 +                                   << std::endl;
83 +    return 0;
84 +  }
85 +      
86 +  NamedObject<T> *no = new NamedObject<T>(obj, name);
87 +  obsEvt_.Add(no);
88 +  return 1;
89 + }
90 +
91 + //--------------------------------------------------------------------------------------------------
92 + template<class T>
93 + const T *mithep::ObjectService::get(const char *name) const
94 + {
95 +  // Retrieve object with given name.
96 +
97 +  TObject *o = obs_.FindObject(name);
98 +  if (!o)
99 +    return 0;
100 +
101 +  const NamedObject<T> *no = dynamic_cast<const NamedObject<T>* >(o);
102 +  if (!no)
103 +    return 0;
104 +
105 +  return no->Get();
106 + }
107 +
108 + //--------------------------------------------------------------------------------------------------
109 + template<class T>
110 + const T *mithep::ObjectService::getObjEvt(const char *name) const
111 + {
112 +  // Retrieve object for the current event with given name.
113 +
114 +  TObject *o = obsEvt_.FindObject(name);
115 +  if (!o)
116 +    return 0;
117 +
118 +  const NamedObject<T> *no = dynamic_cast<const NamedObject<T>* >(o);
119 +  if (!no)
120 +    return 0;
121 +
122 +  return no->Get();
123 + }
124   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines