StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcMappingDb.h
1 #ifndef STAR_StEmcMappingDb
2 #define STAR_StEmcMappingDb
3 
4 // $Id: StEmcMappingDb.h,v 1.4 2009/02/01 17:34:52 kocolosk Exp $
5 
6 /*****************************************************************************
7  * @class StEmcMappingDb
8  * @author Adam Kocoloski
9  *
10  * Wrapper around b*Map tables in Calibrations_emc. Relies on St_db_Maker to
11  * choose the correct tables if the Maker is present, otherwise it calls
12  * StDbManager directly.
13  *****************************************************************************/
14 
15 #include "TObject.h"
16 #include "TDatime.h"
17 
18 #include "StEvent/StEnumerations.h"
19 
20 #include "bemcMap.h"
21 #include "bprsMap.h"
22 #include "bsmdeMap.h"
23 #include "bsmdpMap.h"
24 
25 class St_bemcMap;
26 class St_bsmdeMap;
27 class St_bsmdpMap;
28 class St_bprsMap;
29 
30 class StDbTable;
31 class StMaker;
32 
33 class StEmcMappingDb : public TObject
34 {
35 public:
36  StEmcMappingDb(int date=20330101, int time=0);
37  virtual ~StEmcMappingDb();
38 
39  static StEmcMappingDb* instance();
40 
42  void SetDateTime(int date, int time);
43  void SetFlavor(const char *flavor, const char *tablename=NULL);
44  void SetMaxEntryTime(int date, int time);
45 
46  const bemcMap_st* bemc() const;
47  const bemcMap_st& bemc(int softId) const;
48 
49  const bprsMap_st* bprs() const;
50  const bprsMap_st& bprs(int softId) const;
51 
52  const bsmdeMap_st* bsmde() const;
53  const bsmdeMap_st& bsmde(int softId) const;
54 
55  const bsmdpMap_st* bsmdp() const;
56  const bsmdpMap_st& bsmdp(int softId) const;
57 
58  int softIdFromMES(StDetectorId det, int m, int e, int s) const;
59 
60  // these are for towers
61  int softIdFromCrate(StDetectorId det, int crate, int channel) const;
62  int softIdFromDaqId(StDetectorId det, int daqId) const;
63  int softIdFromTDC(StDetectorId det, int TDC, int channel) const;
64 
65  // this is for SMD/PRS
66  int softIdFromRDO(StDetectorId det, int rdo, int channel) const;
67 
68 private:
69  static StEmcMappingDb* mInstance;
70 
71  // DB tables provided by St_db_Maker -- prefer to use these
72  mutable St_bemcMap *mBemcTTable;
73  mutable St_bprsMap *mBprsTTable;
74  mutable St_bsmdeMap *mSmdeTTable;
75  mutable St_bsmdpMap *mSmdpTTable;
76 
77  // version info from StMaker::GetValidity -- used to expire caches
78  mutable Int_t mBemcValidity;
79  mutable Int_t mBprsValidity;
80  mutable Int_t mSmdeValidity;
81  mutable Int_t mSmdpValidity;
82 
83  // DB tables provided by StDbManager in standalone mode
84  StDbTable *mBemcTable;
85  StDbTable *mBprsTable;
86  StDbTable *mSmdeTable;
87  StDbTable *mSmdpTable;
88 
89  // ensure caches expire if beginTime, flavor, or maxEntryTime changes
90  mutable bool mBemcDirty;
91  mutable bool mBprsDirty;
92  mutable bool mSmdeDirty;
93  mutable bool mSmdpDirty;
94 
95  StMaker *mChain;
96 
97  TDatime mBeginTime;
98  void maybe_reload(StDetectorId) const;
99  void reload_dbtable(StDbTable*) const;
100 
101  bool maybe_reset_cache(StDetectorId det) const;
102  void reset_bemc_cache() const;
103  void reset_bprs_cache() const;
104  void reset_smde_cache() const;
105  void reset_smdp_cache() const;
106 
107  mutable short mCacheCrate[30][160];
108  mutable short mCacheDaqId[4800];
109  mutable short mCacheTDC[30][160];
110  mutable short mCacheBprsRdo[4][4800];
111  mutable short mCacheSmdRdo[8][4800];
112 
113  ClassDef(StEmcMappingDb, 2)
114 };
115 
116 inline const bemcMap_st&
117 StEmcMappingDb::bemc(int softId) const { return bemc()[softId-1]; }
118 
119 inline const bprsMap_st&
120 StEmcMappingDb::bprs(int softId) const { return bprs()[softId-1]; }
121 
122 inline const bsmdeMap_st&
123 StEmcMappingDb::bsmde(int softId) const { return bsmde()[softId-1]; }
124 
125 inline const bsmdpMap_st&
126 StEmcMappingDb::bsmdp(int softId) const { return bsmdp()[softId-1]; }
127 
128 #endif
129 
130 /*****************************************************************************
131  * $Log: StEmcMappingDb.h,v $
132  * Revision 1.4 2009/02/01 17:34:52 kocolosk
133  * more caching and optimization.
134  *
135  * Last StEmcMapping commit was bad and left header, implementation
136  * inconsistent. This commit fixes the AutoBuild.
137  *
138  * Revision 1.1 2009/01/08 02:16:19 kocolosk
139  * move StEmcMappingDb/StEmcDecoder to StEmcUtil/database
140  *
141  * Revision 2.2 2009/01/02 03:34:34 kocolosk
142  * use default date==20330101 like St_db_Maker to suppress spurious error msgs
143  *
144  * Revision 2.1 2008/12/05 19:05:32 kocolosk
145  * new DB-backed implementation of StEmcDecoder
146  *
147  *****************************************************************************/
void SetDateTime(int date, int time)
St_db_Maker-compatible interface.