Belle II Software  release-05-02-19
TRGGDL.h
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : TRGGDL.h
5 // Section : TRG GDL
6 // Owner : Yoshihito Iwasaki, Chunhua Li
7 // Email : yoshihito.iwasaki@kek.jp, chunhua.li@unimelb.edu.au
8 //-----------------------------------------------------------------------------
9 // Description : A class to represent GDL.
10 //-----------------------------------------------------------------------------
11 // $Log$
12 //-----------------------------------------------------------------------------
13 
14 #ifndef TRGGDL_FLAG_
15 #define TRGGDL_FLAG_
16 
17 #define TRGGDL_UNDEFINED 999999
18 
19 #include <fstream>
20 #include <vector>
21 #include "trg/trg/Clock.h"
22 #include "trg/trg/SignalVector.h"
23 #include "trg/trg/SignalBundle.h"
24 
25 #include <framework/database/DBObjPtr.h>
26 #include <mdst/dbobjects/TRGGDLDBInputBits.h>
27 #include <mdst/dbobjects/TRGGDLDBFTDLBits.h>
28 #include <mdst/dbobjects/TRGGDLDBPrescales.h>
29 #include <trg/gdl/dbobjects/TRGGDLDBAlgs.h>
30 
31 #include <TH1I.h>
32 
33 namespace Belle2 {
39  class TRGClock;
40  class TRGLink;
41 
47 
48  class TRGGDL {
49 
50  public:
51 
53  static TRGGDL* getTRGGDL(const std::string& configFile,
54  unsigned simulationMode = 0,
55  unsigned fastSimulationMode = 0,
56  unsigned firmwareSimulationMode = 0,
57  const std::string& Phase = "Phase",
58  bool algFromDB = true,
59  const std::string& algFilePath = "ftd.alg",
60  int debugLevel = 0);
61 
64  static TRGGDL* getTRGGDL(void);
65 
66  private:
67 
69  TRGGDL(const std::string& configFile,
70  unsigned simulationMode,
71  unsigned fastSimulationMode,
72  unsigned firmwareSimulationMode,
73  const std::string& Phase,
74  bool algFromDB = true,
75  const std::string& algFilePath = "ftd.alg",
76  int debugLevel = 0);
77 
79  virtual ~TRGGDL();
80 
82  void initialize(void);
83 
85  void configure(void);
86 
88  void simulate(void);
89 
91  void terminate(void);
92 
93  public:// Selectors
94 
96  std::string name(void) const;
97 
99  std::string version(void) const;
100 
102  std::string configFile(void) const;
103 
105  unsigned mode(void) const;
106 
108  unsigned mode(unsigned);
109 
111  unsigned firmwareSimulationMode(void) const;
112 
114  void dump(const std::string& message) const;
115 
117  int debugLevel(void) const;
118 
120  int debugLevel(int) const;
121 
122  public:// Event by event information.
123 
125  void clear(void);
126 
128  void fastClear(void);
129 
131  void update(bool mcAnalysis = true);
132 
133  public:
134 
136  const TRGClock& systemClock(void) const;
137 
139  double systemOffsetMC(void) const;
140 
142  static TRGState decision(const TRGState& input);
143 
145  static void (* _ftd)(bool* out, bool* in);
146 
148  static TRGState timingDecision(const TRGState& input,
149  TRGState& registers,
150  bool& logicStillActive);
151  bool doprescale(int f);
152 
153  bool isFiredFTDL(std::vector<bool> input, std::string alg);
154 
155  std::vector<bool> getInpBits(void) {return _inpBits;}
156 
157  std::vector<bool> getFtdBits(void) {return _ftdBits;}
158 
159  std::vector<bool> getPsnBits(void) {return _psnBits;}
160 
161  private:
162 
164  void updateMC(void);
165 
167  void fastSimulation(void);
168 
170  void firmwareSimulation(void);
171 
173  void dataSimulation(void);
174 
176  void getInput(std::ifstream& ifs);
177 
179  void getOutput(std::ifstream& ifs);
180 
182  void getAlgorithm(std::ifstream& ifs);
183 
185  void accumulateInp(TH1I*);
186 
188  void accumulateFtd(TH1I*);
189 
191  void accumulatePsn(TH1I*);
192 
194  bool isFiredInput(int n) {return _inpBits[n];}
195 
197  bool isFiredFtdl(int n) {return _ftdBits[n];}
198 
200  bool isFiredPsnm(int n) {return _psnBits[n];}
201 
202  private:
203 
205  static TRGGDL* _gdl;
206 
208  mutable int _debugLevel;
209 
211  std::string _configFilename;
212 
214  unsigned _simulationMode;
215 
218 
221 
222  //Phase
223  std::string _Phase;
224 
225  // Path to algorithm file
226  std::string _algFilePath;
227 
229  const TRGClock& _clock;
230 
232  const double _offset;
233 
235  std::vector<TRGLink*> _links;
236 
238  std::vector<std::string> _input;
239 
241  std::vector<std::string> _output;
242 
244  std::vector<std::string> _algorithm;
245 
248 
251 
254 
257 
260  DBObjPtr<TRGGDLDBFTDLBits> m_FTDLBitsDB;
261  DBObjPtr<TRGGDLDBPrescales> m_PrescalesDB;
262  DBObjPtr<TRGGDLDBAlgs> db_algs;
263 
265  std::vector<bool> _inpBits;
266  std::vector<bool> _ftdBits;
267  std::vector<bool> _psnBits;
268  std::vector<std::string> _inpBitNames;
269  std::vector<std::string> _oupBitNames;
270 
271  int getNbitsOup(void) {return _oupBitNames.size();}
272  int getNbitsInp(void) {return _inpBitNames.size();}
273 
274  bool _algFromDB;
275 
276  friend class TRGGDLModule;
277  };
278 
279 //-----------------------------------------------------------------------------
280 
281  inline
282  int
283  TRGGDL::debugLevel(void) const
284  {
285  return _debugLevel;
286  }
287 
288  inline
289  int
290  TRGGDL::debugLevel(int a) const
291  {
292  return _debugLevel = a;
293  }
294 
295  inline
296  const TRGClock&
298  {
299  return _clock;
300  }
301 
302  inline
303  double
305  {
306  return _offset;
307  }
308 
309  inline
310  unsigned
312  {
314  }
315 
316  inline
317  std::string
318  TRGGDL::configFile(void) const
319  {
320  return _configFilename;
321  }
322 
323 
325 } // namespace Belle2
326 
327 #endif /* TRGGDL_FLAG_ */
Belle2::TRGGDL::getInput
void getInput(std::ifstream &ifs)
Read input data definition.
Definition: TRGGDL.cc:719
Belle2::TRGGDL::isFiredFtdl
bool isFiredFtdl(int n)
Returns fired/not for ftdl bits.
Definition: TRGGDL.h:197
Belle2::TRGGDL::firmwareSimulationMode
unsigned firmwareSimulationMode(void) const
returns firmware simulation mode.
Definition: TRGGDL.h:311
Belle2::TRGGDL::getAlgorithm
void getAlgorithm(std::ifstream &ifs)
Read algorithm data definition.
Definition: TRGGDL.cc:774
Belle2::TRGGDL::_firmwareSimulationMode
unsigned _firmwareSimulationMode
Firmware simulation mode.
Definition: TRGGDL.h:220
Belle2::TRGGDL::configFile
std::string configFile(void) const
returns configuration file name.
Definition: TRGGDL.h:318
Belle2::TRGGDL::_input
std::vector< std::string > _input
Input names.
Definition: TRGGDL.h:238
Belle2::TRGGDL::decision
static TRGState decision(const TRGState &input)
Makes bit pattern(state) using input bit pattern(state).
Definition: TRGGDL.cc:806
Belle2::TRGGDL::firmwareSimulation
void firmwareSimulation(void)
Firmware simulation.
Definition: TRGGDL.cc:544
Belle2::TRGGDL::systemOffsetMC
double systemOffsetMC(void) const
returns the system offset in MC.
Definition: TRGGDL.h:304
Belle2::TRGGDL::getOutput
void getOutput(std::ifstream &ifs)
Read output data definition.
Definition: TRGGDL.cc:746
Belle2::TRGGDL::accumulatePsn
void accumulatePsn(TH1I *)
Accumulate bit info in histogram.
Definition: TRGGDL.cc:970
Belle2::TRGGDL::accumulateInp
void accumulateInp(TH1I *)
Accumulate bit info in histogram.
Definition: TRGGDL.cc:954
Belle2::TRGGDL::_configFilename
std::string _configFilename
GDL configuration filename.
Definition: TRGGDL.h:211
Belle2::TRGGDL::dataSimulation
void dataSimulation(void)
Data simulation.
Definition: TRGGDL.cc:323
Belle2::TRGGDL::_fastSimulationMode
unsigned _fastSimulationMode
Fast simulation mode.
Definition: TRGGDL.h:217
Belle2::TRGGDL::dump
void dump(const std::string &message) const
dumps debug information.
Definition: TRGGDL.cc:179
Belle2::TRGGDL::simulate
void simulate(void)
fast trigger simulation.
Definition: TRGGDL.cc:222
Belle2::TRGGDL::mode
unsigned mode(void) const
returns simulation mode.
Belle2::TRGGDL::fastClear
void fastClear(void)
clears TRGGDL information.
Definition: TRGGDL.cc:199
Belle2::TRGState
A class to represent a state of multi bits.
Definition: State.h:29
Belle2::TRGGDL::_tsb
TRGSignalBundle * _tsb
Timing input signal bundle.
Definition: TRGGDL.h:253
Belle2::TRGGDL
The instance of TRGGDL is a singleton.
Definition: TRGGDL.h:48
Belle2::TRGGDL::name
std::string name(void) const
returns name.
Definition: TRGGDL.cc:57
Belle2::TRGGDL::_ftd
static void(* _ftd)(bool *out, bool *in)
Function to simulate final trigger decision.
Definition: TRGGDL.h:145
Belle2::TRGGDL::_algorithm
std::vector< std::string > _algorithm
Algorithm.
Definition: TRGGDL.h:244
Belle2::TRGSignalBundle
A class to represent a bundle of SignalVectors.
Definition: SignalBundle.h:31
Belle2::TRGGDL::_output
std::vector< std::string > _output
Output names.
Definition: TRGGDL.h:241
Belle2::TRGGDL::_osb
TRGSignalBundle * _osb
Output signal bundle.
Definition: TRGGDL.h:250
Belle2::TRGGDL::~TRGGDL
virtual ~TRGGDL()
Destructor.
Definition: TRGGDL.cc:216
Belle2::TRGGDL::updateMC
void updateMC(void)
updates TRGGDL information for MC.
Belle2::DBObjPtr
Class for accessing objects in the database.
Definition: DBObjPtr.h:31
Belle2::TRGGDL::debugLevel
int debugLevel(void) const
returns debug level.
Definition: TRGGDL.h:283
Belle2::TRGGDL::update
void update(bool mcAnalysis=true)
updates TRGGDL information.
Definition: TRGGDL.cc:204
Belle2::TRGGDL::timingDecision
static TRGState timingDecision(const TRGState &input, TRGState &registers, bool &logicStillActive)
Makes timing decision.
Definition: TRGGDL.cc:846
Belle2::TRGGDL::_debugLevel
int _debugLevel
Debug level.
Definition: TRGGDL.h:208
Belle2::TRGGDL::_links
std::vector< TRGLink * > _links
All serial links.
Definition: TRGGDL.h:235
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TRGGDL::systemClock
const TRGClock & systemClock(void) const
returns the system clock.
Definition: TRGGDL.h:297
Belle2::TRGGDL::_offset
const double _offset
Timing offset of GDL.
Definition: TRGGDL.h:232
Belle2::TRGGDL::_clock
const TRGClock & _clock
GDL trigger system clock.
Definition: TRGGDL.h:229
Belle2::TRGGDL::version
std::string version(void) const
returns version.
Definition: TRGGDL.cc:63
Belle2::TRGGDL::_gdl
static TRGGDL * _gdl
GDL singleton.
Definition: TRGGDL.h:205
Belle2::TRGGDL::TRGGDL
TRGGDL(const std::string &configFile, unsigned simulationMode, unsigned fastSimulationMode, unsigned firmwareSimulationMode, const std::string &Phase, bool algFromDB=true, const std::string &algFilePath="ftd.alg", int debugLevel=0)
Constructor.
Definition: TRGGDL.cc:109
Belle2::TRGGDL::_tosb
TRGSignalBundle * _tosb
Timing output signal bundle.
Definition: TRGGDL.h:256
Belle2::TRGGDL::getTRGGDL
static TRGGDL * getTRGGDL(void)
returns TRGGDL object.
Definition: TRGGDL.cc:102
Belle2::TRGGDL::accumulateFtd
void accumulateFtd(TH1I *)
Accumulate bit info in histogram.
Definition: TRGGDL.cc:962
Belle2::TRGGDL::clear
void clear(void)
clears all TRGGDL information.
Definition: TRGGDL.cc:194
Belle2::TRGGDL::fastSimulation
void fastSimulation(void)
Fast simulation.
Definition: TRGGDL.cc:236
Belle2::TRGGDL::terminate
void terminate(void)
terminates when run is finished
Definition: TRGGDL.cc:174
Belle2::TRGGDL::_simulationMode
unsigned _simulationMode
Simulation mode.
Definition: TRGGDL.h:214
Belle2::TRGGDL::isFiredInput
bool isFiredInput(int n)
Returns fired/not for input bits.
Definition: TRGGDL.h:194
Belle2::TRGGDL::configure
void configure(void)
configures trigger modules for firmware simulation.
Definition: TRGGDL.cc:662
Belle2::TRGGDL::m_InputBitsDB
DBObjPtr< TRGGDLDBInputBits > m_InputBitsDB
Data base of GDL input bits.
Definition: TRGGDL.h:259
Belle2::TRGGDL::_isb
TRGSignalBundle * _isb
Input signal bundle.
Definition: TRGGDL.h:247
Belle2::TRGClock
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:43
Belle2::TRGGDL::isFiredPsnm
bool isFiredPsnm(int n)
Returns fired/not for psnm bits.
Definition: TRGGDL.h:200
Belle2::TRGGDL::initialize
void initialize(void)
initializes GDL.
Definition: TRGGDL.cc:155