AttenCache.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief Helper for AttenCurve
3 /// \author bckhouse@caltech.edu
4 /// \date
5 ////////////////////////////////////////////////////////////////////////
6 #ifndef CALIB_ATTENCACHE_H
7 #define CALIB_ATTENCACHE_H
8 
9 #include <map>
10 #include <set>
11 #include <string>
12 
13 #include "NovaDAQConventions/DAQConventions.h"
15 
16 namespace geo{class GeometryBase; class PlaneGeo;}
17 
18 namespace calib
19 {
20  class AttenCurve;
21 
22  class AttenCache
23  {
24  public:
25  AttenCache( bool is_data, int brightness_bin );
26  virtual ~AttenCache();
27 
28  /// Return an AttenCurve object matching your parameters, or NULL
29  /// if there isn't one in the database. Do not delete the resulting object,
30  /// they are cached internally.
31  const AttenCurve* ForData(const geo::GeometryBase* geom,
33  const AttenCurve* ForMC(const geo::GeometryBase* geom,
34  geo::OfflineChan chan, bool maskUncalibratedChannels);
35 
36  void SetCSVSource(const std::string& path){ fCSVSourceDir = path; }
37 
38  void UseCSVsFromUPS(bool use = true) {fUseCSVsFromUPS = use;}
39 
40  void SetTag(const std::string& tag) {fTag = tag;}
41 
42  std::string GetTag() {return fTag;}
43 
44  void SetUseEpochs(bool b) { fUseEpochs = b; }
45 
46  bool UseEpochs() {return fUseEpochs;}
47 
48  void SetEpoch(const std::string& epoch) {fEpoch = epoch;}
49  void SetEpochTag( const std::string& tag) {fEpochTag = tag;}
50 
51  std::string Epoch() {return fEpoch;}
52  std::string EpochTag() { return fEpochTag; }
53  void GetEpochFromDB(int idet, bool forceData = false);
54 
55  void ReadEpochsFromCSV(bool readEpochs=true) {fReadEpochsFromCSV=readEpochs;}
56 
57 
58  void SetRun(int run) { fRun = run; }
59  int Run() { return fRun; }
60 
61  void SetGainSetting(int g) {fGainSetting = g;}
62  int GainSetting() {return fGainSetting;}
63 
64  void Reinit();
65 
66  protected:
67  // Loading curves from the database as required is too slow (latency).
68  // Instead, just read the whole detector in and cache it.
69 
70  void Add(AttenCurve* res);
71 
72  class Key_t
73  {
74  public:
75  Key_t(int d, geo::OfflineChan chan) : fDet(d), fChan(chan) {}
76  bool operator<(const Key_t& rhs) const;
77  protected:
78  int fDet;
80  };
81 
82  /// NULL if entry isn't in the cache. Do not delete the returned pointer.
83  const AttenCurve* Get(Key_t key) const;
84 
85  std::string GetCSVPath(novadaq::cnv::DetId det, bool points, bool forceData = false);
86 
87  void LoadFromDatabase(const geo::GeometryBase* geom);
88 
89  void LoadFromDatabaseUncalibratedMask(const geo::GeometryBase* geom);
90 
91  /// Deal with averaged constants etc
92  Key_t TranslateChannelData(geo::OfflineChan chan,
93  const geo::GeometryBase* geom) const;
94  /// Deal with merged views, muon catcher, etc
95  Key_t TranslateChannelMC(geo::OfflineChan chan,
96  const geo::GeometryBase* geom) const;
97 
98  /// Get the view for the current combination of view and plane (x,y,mux, or muy)
99  int GetView(int plane, const geo::GeometryBase* geom) const;
100 
101  const geo::PlaneGeo* RepresentativePlane(const geo::GeometryBase* geom,
102  int view,
103  bool& inMuonCatcher) const;
104 
108  int fRun;
112 
113  bool fReadEpochsFromCSV; //Needs to have fRun set
114 
115  // Whether we have (attempted to) read from db or csv yet
119 
122 
123  bool fIsData; ///< this is a cache for data calibrations or not
124 
125  std::map<Key_t, AttenCurve*> fMapData;
126  std::map<Key_t, AttenCurve*> fMapMC;
127  std::set<Key_t> fMapUncalibratedMask;
128 
129  std::set<int> fDiblocks; ///< Diblocks with calibrations
130  };
131 
132 } // end namespace calib
133 
134 #endif
135 ////////////////////////////////////////////////////////////////////////
void ReadEpochsFromCSV(bool readEpochs=true)
Definition: AttenCache.h:55
std::string fEpoch
Definition: AttenCache.h:110
void SetGainSetting(int g)
Definition: AttenCache.h:61
void UseCSVsFromUPS(bool use=true)
Definition: AttenCache.h:38
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
std::set< Key_t > fMapUncalibratedMask
Definition: AttenCache.h:127
std::string fTag
Definition: AttenCache.h:109
bool fIsData
this is a cache for data calibrations or not
Definition: AttenCache.h:123
CDPStorage service.
std::string GetTag()
Definition: AttenCache.h:42
bool fInitializedUncalibratedMask
Definition: AttenCache.h:118
std::set< int > fDiblocks
Diblocks with calibrations.
Definition: AttenCache.h:129
void SetEpochTag(const std::string &tag)
Definition: AttenCache.h:49
std::string Epoch()
Definition: AttenCache.h:51
Geometry information for a single readout plane.
Definition: PlaneGeo.h:36
bool operator<(StanConfig::Verbosity a, StanConfig::Verbosity b)
Allow for comparing them, since kQuiet is definitely "less" verbose than kVerbose.
Definition: StanConfig.h:95
std::string fEpochTag
Definition: AttenCache.h:111
Float_t d
Definition: plot.C:236
void SetRun(int run)
Definition: AttenCache.h:58
std::string EpochTag()
Definition: AttenCache.h:52
std::map< Key_t, AttenCurve * > fMapMC
Definition: AttenCache.h:126
Definition: run.py:1
std::string fCSVSourceDir
Definition: AttenCache.h:105
const std::string path
Definition: plot_BEN.C:43
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void SetEpoch(const std::string &epoch)
Definition: AttenCache.h:48
A (plane, cell) pair.
Definition: OfflineChan.h:17
void geom(int which=0)
Definition: geom.C:163
const hit & b
Definition: hits.cxx:21
The geometry of one entire detector (near, far, ipnd)
Definition: GeometryBase.h:49
void SetCSVSource(const std::string &path)
Definition: AttenCache.h:36
Helper for AttenCurve.
Definition: Path.h:10
void SetTag(const std::string &tag)
Definition: AttenCache.h:40
geo::OfflineChan fChan
Definition: AttenCache.h:79
Simple object representing a (plane, cell) pair.
Key_t(int d, geo::OfflineChan chan)
Definition: AttenCache.h:75
std::map< Key_t, AttenCurve * > fMapData
Definition: AttenCache.h:125
void SetUseEpochs(bool b)
Definition: AttenCache.h:44