ICP  1
detector_card.h
Go to the documentation of this file.
1 #ifndef DETECTOR_CARD
2 #define DETECTOR_CARD
3 
4 #include "dae2_card.h"
5 
6 template <class DetCardPolicy> class DetectorCard;
7 
8 class DetectorCardIntf;
9 
10 struct Addmap {
12  unsigned long dae2add;
13  unsigned long dae1add;
14  int spec;
15  int card;
16  int len;
17 };
18 
20 template <class DetCardPolicy>
21 struct EventModeRegister : public DAE2Register<DetCardPolicy>
22 {
23  enum Mask
24  {
25  EventMode = (1 << 0),
26  EventSize64 = (1 << 1),
27  HeaderType = ((1<<8) + (1<<9) + (1<<10) + (1<<11)),
28  StoreVetoedData = (1 << 12),
29  AllVetosInHeader = (1 << 13)
30  };
32  {
34  };
35  EventModeRegister(DAE2Card<DetCardPolicy>* card) : DAE2Register(card, DetCardPolicy::DCEVNTMD) { }
36  int eventMode(DAEstatus& status) { return (read(status) & 0x1); }
37  int eventMode(bool choice, DAEstatus& status) { return enable(choice, EventMode, status); }
38  int enable32bitEvents(DAEstatus& status) { return clearBits(EventSize64, status); }
39  int enable64bitEvents(DAEstatus& status) { return setBits(EventSize64, true, status); }
40  int storeVetodData(bool choice, DAEstatus& status) { return enable(choice, StoreVetoedData, status); }
41  int allVetoesInHeader(bool choice, DAEstatus& status) { return enable(choice, AllVetosInHeader, status); }
42  unsigned setHeaderType(unsigned val, DAEstatus& status) { return (setBits((val & 0x0f) << 8, true, status)); }
43  unsigned getHeaderType(DAEstatus& status) { return ((read(status) >> 8) & 0x0f); }
44 };
45 
46 template <class DetCardPolicy>
48 {
51 };
52 
54 {
55  public: // len is the number of 32 bit words to write
56  enum DetectorCardMode { ModeUnknown=0x0, ModeNeutronData=0x1, ModeSEData=0x2 };
57  virtual int readHistogramMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status) = 0;
58  virtual bool readHistogramMemoryWrapped(unsigned long start, isisU32_t* buffer, uint32_t len, DAEstatus& status) = 0;
59  virtual int writeHistogramMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status) = 0;
60  virtual isisU32_t sumHistogramMemory(DAEstatus& status) = 0;
61  virtual int clearHistogramMemoryStart(DAEstatus& status) = 0;
62  virtual bool isClearHistogramMemoryComplete(DAEstatus& status) = 0;
63  virtual int readPOSLUTMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status) = 0;
64  virtual int writePOSLUTMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status) = 0;
65  virtual int clearPOSLUTMemory(DAEstatus& status, unsigned long start = 0, int len = 65536) = 0;
66  virtual int readTCGLUTMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status) = 0;
67  virtual int writeTCGLUTMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status) = 0;
68  virtual int readDescriptorTimeBinLimitRegister(isisU32_t* value, DAEstatus& status) = 0;
69  virtual int writeDescriptorTimeBinLimitRegister(isisU32_t value, DAEstatus& status) = 0;
70  virtual int readTCGTimeBinLimitRegister(isisU32_t* value, DAEstatus& status) = 0;
71  virtual int writeTCGTimeBinLimitRegister(isisU32_t value, DAEstatus& status) = 0;
73  virtual int getNTimeChannels(isisU32_t* ntc, DAEstatus& status) = 0; // ntc
74  virtual int setNTimeChannels(isisU32_t ntc, DAEstatus& status) = 0; // ntc
75  virtual int getSpectrumSize(isisU32_t* value, DAEstatus& status) = 0; // ntc+1
76  virtual int readSpectrum(int spec, isisU32_t* buffer, int nbuffer, DAEstatus& status) = 0;
77  virtual int readDAE1Spectrum(int dae1_spec, isisU32_t* buffer, int nbuffer, DAEstatus& status) = 0;
78  virtual int readDAE1Spectra(isisU32_t* buffer, int nbuffer, const int spec_to_crpt_offset[], int spec_start, int nspec, int period, int persize, DAEstatus& status) = 0;
79  virtual int setTimeChannels(isisU32_t* tcb, int ntc, DAEstatus& status) = 0;
80  virtual int getTimeChannels(isisU32_t* tcb, int ntc, DAEstatus& status) = 0;
81  virtual ~DetectorCardIntf() { }
82  virtual int programDAE1POSLUT(int crat[], int modn[], int mpos[],
83  int spec[], int ndet, int nperiods, int dae1persize, DAEstatus& status) = 0;
84  virtual int findDAE1Spectrum(int dae1_spectrum, DAEstatus& ) const = 0; // returns DAE2 spectrum number for DAE1 number or NOSPECTRUM
85  virtual int findDAE2Spectrum(int dae2_spectrum, DAEstatus& ) const = 0;
86  virtual const int* getDAE2SpecMap() = 0;
87  virtual int readAllDAE1Spectra(isisU32_t* buffer, int nbuffer, const int spec_to_crpt_offset[], int persize, DAEstatus& status) = 0;
88  virtual int programPOSLUT(int cards[], int dims[], int pos_start[],
89  int npos[], int spec[], int spec_step[], int nblocks,
90  int nperiods, int dae1persize, DAEstatus& status) = 0;
91  virtual int fillAddmap(Addmap* addmap, int len, DAEstatus& status) = 0;
92  virtual void printStatus(std::ostream& os, DAEstatus& status) = 0;
93  virtual void printSpecmap(std::ostream& os) = 0;
94  virtual void printTimeChannels(std::ostream& os, int start = 0, int end = -1) = 0;
95  virtual void printPOSLUT(std::ostream& os, DAEstatus& status) = 0;
96  virtual int readPOSLUT(DAEstatus& status) = 0;
97  virtual unsigned long memorySize() = 0;
98  virtual int loadDAE2SpecmapFromArray(int* array, int len, DAEstatus& status) = 0;
99  virtual int saveDAE2SpecmapToArray(int* array, int offset, int len, DAEstatus& status) = 0;
100  virtual int changePeriod(int period, DAEstatus& status) = 0;
101  virtual int changeNumberOfPeriods(int nperiod, DAEstatus& status) = 0;
102  virtual int setPeriodType(bool hardware_periods, bool single_daq_period, DAEstatus& status) = 0;
103  virtual int enableDIMVetos(isisU16_t dim_mask, DAEstatus& status) = 0; // set bit 0 for dim0 etc
104  virtual int getDIMVetos(isisU16_t* dim_mask, DAEstatus& status) = 0; // set bit 0 for dim0 etc
105  virtual int disableDIMVetos(DAEstatus& status) = 0;
106  virtual int clearVetoOccurredFlag(DAEstatus& status) = 0;
107  virtual int readDIMVetoOccurredFlag(isisU16_t* dim_mask, DAEstatus& status) = 0; // bit 0 set for dim 0 etc
108  virtual int getCurrentHardwarePeriod(isisU32_t* period, DAEstatus& status) = 0;
109  virtual int getTotalCounts(isisU32_t* counts, DAEstatus& status) = 0;
110  virtual int clearTotalCountsRegister(DAEstatus& status) = 0;
111  virtual int getFrameSyncDelay(isisU32_t* value, DAEstatus& status) = 0;
112  virtual int setFrameSyncDelay(isisU32_t value, DAEstatus& status) = 0;
113  virtual int fillWithTestPattern(unsigned long pattern, DAEstatus& status) = 0;
114  virtual int checkTestPattern(unsigned long pattern, DAEstatus& status) = 0;
115  virtual int whichVeto(std::ostream& os, DAEstatus& status) = 0;
116 
117  virtual int setEventCollectionMode(bool enable, DAEstatus& status) = 0;
118 // int setEventModeOptions(bool event_size32, bool store_vetoed_events, all_vetos_in_headers, DAEstatus& status)
119 
120  virtual uint32_t getNewEvents(isisU32_t* buffer, uint32_t maxlen, uint64_t& num_unread,
121  bool& run_ended, DAEstatus& status) = 0;
122  virtual uint64_t nNewEventWords(DAEstatus& status) = 0;
123  virtual void updateDAEEventLastRead(DAEstatus& status) = 0;
124  virtual isisU32_t getLastAddressRead() = 0;
125  virtual void setLastAddressRead(isisU32_t addr) = 0;
126  virtual int eventSourceID() const = 0;
127  virtual int highspec() const = 0;
128  static const int NOSPECTRUM;
129  static const int SPECTRUM_PLACEHOLDER;
130 
131  enum DetectorCardVeto { FrameOverflowVeto=0x1, MemoryFullVeto=0x2, FIFOLateVeto=0x4 }; // see #DAEEventHeaderInfo
132  virtual int enableVeto(DetectorCardVeto veto, DAEstatus& status) = 0;
133  virtual int disableVeto(DetectorCardVeto veto, DAEstatus& status) = 0;
134  virtual bool isVetoEnabled(DetectorCardVeto veto, DAEstatus& status) = 0;
135  virtual bool hasVetoOccurred(DetectorCardVeto veto, DAEstatus& status) = 0;
136  virtual int printVetoStatus(std::ostream& os, bool triggered_only, DAEstatus& status) = 0;
137  virtual int resetCardState(DAEstatus& status) = 0;
138  virtual void setCardMode(DetectorCardMode mode) = 0;
139 };
140 
141 template <class DetCardPolicy>
142 class DetectorCard : public DAE2Card<DetCardPolicy>, public DetectorCardIntf
143 {
144 public:
145 protected:
146  unsigned long m_memsize;
148  std::vector<int> m_dae1specmap;
149  std::vector<int> m_dae2specmap;
150 // int* m_dae1specmap; ///< dae2spec = m_dae1specmap[dae1spec]
151 // int* m_dae2specmap; ///< dae1spec = m_dae2specmap[dae2spec]
157  enum DetectorCardOptions { None=0x0, HardwarePeriods=0x1, VetoLogging=0x2, TotalCounts=0x4,
158  DelayedFrameSync=0x8, EventMode=0x10, Muon32Channel=0x20 };
159  DetectorCardMode m_mode;
161  CRITICAL_SECTION m_critical;
166 
167 public: // len is the number of 32 bit words to write
168  int readHistogramMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status);
169  bool readHistogramMemoryWrapped(unsigned long start, isisU32_t* buffer, uint32_t len, DAEstatus& status);
170  int writeHistogramMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status);
171  isisU32_t sumHistogramMemory(DAEstatus& status);
172  int clearHistogramMemoryStart(DAEstatus& status);
173  bool isClearHistogramMemoryComplete(DAEstatus& status);
174  int readPOSLUTMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status);
175  int writePOSLUTMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status);
176  int clearPOSLUTMemory(DAEstatus& status, unsigned long start = 0, int len = 65536);
177  int readTCGLUTMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status);
178  int writeTCGLUTMemory(unsigned long start, isisU32_t* buffer, int len, DAEstatus& status);
179  int readDescriptorTimeBinLimitRegister(isisU32_t* value, DAEstatus& status);
180  int writeDescriptorTimeBinLimitRegister(isisU32_t value, DAEstatus& status);
181  int readTCGTimeBinLimitRegister(isisU32_t* value, DAEstatus& status);
182  int writeTCGTimeBinLimitRegister(isisU32_t value, DAEstatus& status);
183  DetectorCard(int position, ISISVME* vme, int* specmap_array, int specmap_len, DAEstatus& status);
184  virtual int getNTimeChannels(isisU32_t* ntc, DAEstatus& status); // ntc
185  virtual int setNTimeChannels(isisU32_t ntc, DAEstatus& status); // ntc
186  int getSpectrumSize(isisU32_t* value, DAEstatus& status); // ntc+1
187  int readSpectrum(int spec, isisU32_t* buffer, int nbuffer, DAEstatus& status);
188  int readDAE1Spectrum(int dae1_spec, isisU32_t* buffer, int nbuffer, DAEstatus& status);
189  int readDAE1Spectra(isisU32_t* buffer, int nbuffer, const int spec_to_crpt_offset[], int spec_start, int nspec, int period, int persize, DAEstatus& status);
190  virtual int setTimeChannels(isisU32_t* tcb, int ntc, DAEstatus& status);
191  virtual int getTimeChannels(isisU32_t* tcb, int ntc, DAEstatus& status);
192  virtual ~DetectorCard();
193  virtual int programDAE1POSLUT(int crat[], int modn[], int mpos[],
194  int spec[], int ndet, int nperiods, int dae1persize, DAEstatus& status);
195  int findDAE1Spectrum(int dae1_spectrum, DAEstatus& ) const { return m_dae1specmap[dae1_spectrum]; } // returns DAE2 spectrum number for DAE1 number or NOSPECTRUM
196  int findDAE2Spectrum(int dae2_spectrum, DAEstatus& ) const { return m_dae2specmap[dae2_spectrum]; }
197  const int* getDAE2SpecMap() { return &(m_dae2specmap.front()); }
198  int readAllDAE1Spectra(isisU32_t* buffer, int nbuffer, const int spec_to_crpt_offset[], int persize, DAEstatus& status);
199  virtual int programPOSLUT(int cards[], int dims[], int pos_start[],
200  int npos[], int spec[], int spec_step[], int nblocks,
201  int nperiods, int dae1persize, DAEstatus& status);
202  int fillAddmap(Addmap* addmap, int len, DAEstatus& status);
203  virtual void printStatus(std::ostream& os, DAEstatus& status);
204  void printSpecmap(std::ostream& os);
205  void printTimeChannels(std::ostream& os, int start = 0, int end = -1);
206  void printPOSLUT(std::ostream& os, DAEstatus& status);
207  virtual int readPOSLUT(DAEstatus& status);
208  unsigned long memorySize() { return m_memsize; }
209  int loadDAE2SpecmapFromArray(int* array, int len, DAEstatus& status);
210  int saveDAE2SpecmapToArray(int* array, int offset, int len, DAEstatus& status);
211  virtual int changePeriod(int period, DAEstatus& status);
212  virtual int changeNumberOfPeriods(int nperiod, DAEstatus& status);
213  virtual int setPeriodType(bool hardware_periods, bool single_daq_period, DAEstatus& status);
214  int enableDIMVetos(isisU16_t dim_mask, DAEstatus& status); // set bit 0 for dim0 etc
215  int getDIMVetos(isisU16_t* dim_mask, DAEstatus& status); // set bit 0 for dim0 etc
216  int disableDIMVetos(DAEstatus& status);
217  int clearVetoOccurredFlag(DAEstatus& status);
218  int readDIMVetoOccurredFlag(isisU16_t* dim_mask, DAEstatus& status); // bit 0 set for dim 0 etc
219  int getCurrentHardwarePeriod(isisU32_t* period, DAEstatus& status);
220  int getTotalCounts(isisU32_t* counts, DAEstatus& status);
221  int clearTotalCountsRegister(DAEstatus& status);
222  int getFrameSyncDelay(isisU32_t* value, DAEstatus& status);
223  int setFrameSyncDelay(isisU32_t value, DAEstatus& status);
224  int fillWithTestPattern(unsigned long pattern, DAEstatus& status);
225  int checkTestPattern(unsigned long pattern, DAEstatus& status);
226  int whichVeto(std::ostream& os, DAEstatus& status);
227 
228  int setEventCollectionMode(bool enable, DAEstatus& status);
229 // int setEventModeOptions(bool event_size32, bool store_vetoed_events, all_vetos_in_headers, DAEstatus& status)
230 
231  uint32_t getNewEvents(isisU32_t* buffer, uint32_t maxlen, uint64_t& num_unread,
232  bool& run_ended, DAEstatus& status);
233  uint64_t nNewEventWords(DAEstatus& status);
234  void updateDAEEventLastRead(DAEstatus& status);
235  isisU32_t getLastAddressRead() { return m_last_address_read; }
236  void setLastAddressRead(isisU32_t addr) { m_last_address_read = addr; }
237  int eventSourceID() const { return position(); }
238  int highspec() const { return m_highspec; }
239 // static const int NOSPECTRUM;
240 // static const int SPECTRUM_PLACEHOLDER;
241 
242  int enableVeto(DetectorCardVeto veto, DAEstatus& status);
243  int disableVeto(DetectorCardVeto veto, DAEstatus& status);
244  bool isVetoEnabled(DetectorCardVeto veto, DAEstatus& status);
245  bool hasVetoOccurred(DetectorCardVeto veto, DAEstatus& status);
246  int printVetoStatus(std::ostream& os, bool triggered_only, DAEstatus& status);
247  virtual int resetCardState(DAEstatus& status);
248  void setCardMode(DetectorCardMode mode);
249 
250  int position() const { return DAE2Card<DetCardPolicy>::position(); }
251  std::string daeDevice() const { return DAE2Card<DetCardPolicy>::daeDevice(); }
252 
253 protected:
254  int printVetoStatus(DetectorCardVeto veto, std::ostream& os, bool triggered_only, DAEstatus& status);
255  uint32_t getVetoMask(DetectorCardVeto veto);
256  const char* getVetoName(DetectorCardVeto veto);
257  int setTCGAccessRegister(isisU32_t mask, DAEstatus& status);
258  int readTCGAccessRegister(isisU32_t *value, DAEstatus& status);
259  int setAndClearTCGAccessRegister(isisU32_t mask, DAEstatus& status);
260  int recreateDAE1Specmap(DAEstatus& status);
261  int setPeriodSize(int per_size, DAEstatus& status); // in 32 bit words
262  int setPeriodCounter(int period, DAEstatus& status);
263 // Poco::ActiveMethod<int, uint32_t, DetectorCard> flushEvents;
264 // int flushEventsImpl(const uint32_t last_address_read);
265 // int readEventWords(isisU32_t* buffer, uint32_t maxlen, uint32_t& num_unread, uint32_t start, uint32_t end, DAEstatus& status);
266  bool isEventMode(DAEstatus& status);
267  virtual int programDAE1POSLUTDataDae(DAEstatus& status);
268 };
269 
270 #endif /* DETECTOR_CARD */
int findDAE1Spectrum(int dae1_spectrum, DAEstatus &) const
DetectorCardRegisters< DetCardPolicy > m_reg
int enable(bool choice, isisU32_t mask, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.h:233
unsigned long m_memsize
histogram memory in bytes
set for event mode, clear for histogram mode
Definition: detector_card.h:25
isisU32_t getLastAddressRead()
int findDAE2Spectrum(int dae2_spectrum, DAEstatus &) const
std::string daeDevice() const
int allVetoesInHeader(bool choice, DAEstatus &status)
Definition: detector_card.h:41
unsigned long dae1add
Definition: detector_card.h:13
int position() const
unsigned long isisU32_t
Definition: isisvme_types.h:8
CRITICAL_SECTION m_critical
std::vector< int > m_dae1specmap
dae2spec = m_dae1specmap[dae1spec]
EventModeRegister(DAE2Card< DetCardPolicy > *card)
Definition: detector_card.h:35
int spec
Definition: detector_card.h:14
int m_nperiods
number of software/DAQ periods
int m_highspec
highest DAE2 spectrum used
void setLastAddressRead(isisU32_t addr)
isisU16_t m_wrap_counter
number of times memory wrapped in event mode
unsigned getHeaderType(DAEstatus &status)
Definition: detector_card.h:43
int CardOptions
Definition: dae2_card.h:25
unsigned setHeaderType(unsigned val, DAEstatus &status)
Definition: detector_card.h:42
int eventMode(DAEstatus &status)
Definition: detector_card.h:36
int setBits(isisU32_t mask, bool preserve, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.h:225
isisU32_t read(DAEstatus &status, bool little_endian=false, bool retry=true)
Definition: dae2_card.h:237
int m_dae1persize
number of dae1 spectra in a period
int storeVetodData(bool choice, DAEstatus &status)
Definition: detector_card.h:40
bit assignmments for DAE2DetCardPolicy::DCEVNTMD
Definition: detector_card.h:21
set to store events for all frames, clear to only store events for good frames
Definition: detector_card.h:28
DetectorCard< DetCardPolicy > MyDetectorCard
unsigned short isisU16_t
Definition: isisvme_types.h:7
DetectorCardIntf * dc
Definition: detector_card.h:11
int eventSourceID() const
DetectorCardMode m_mode
isisU32_t m_last_address_read
last memory addess read in event mode
int m_dae2persize
number of spectra in a dae2 period
int enable64bitEvents(DAEstatus &status)
Definition: detector_card.h:39
int clearBits(isisU32_t mask, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.h:229
std::string daeDevice() const
Definition: dae2_card.cpp:13
int m_hardware_periods
are we using hardware periods?
static const int NOSPECTRUM
unsigned long dae2add
Definition: detector_card.h:12
DetectorCardRegisters(DAE2Card< DetCardPolicy > *dc)
Definition: detector_card.h:50
int position() const
Definition: dae2_card.h:72
EventModeRegister< DetCardPolicy > event_reg
Definition: detector_card.h:49
static const int SPECTRUM_PLACEHOLDER
int highspec() const
unsigned long memorySize()
isisU32_t * m_poslut
temp workspace for POSLUT programming
int card
dae2 spectrum;
Definition: detector_card.h:15
std::vector< int > m_dae2specmap
dae1spec = m_dae2specmap[dae2spec]
const int * getDAE2SpecMap()
CardOptions m_options
set to enable 64bit events, clear to enable 32 bit events
Definition: detector_card.h:26
int eventMode(bool choice, DAEstatus &status)
Definition: detector_card.h:37
set to store all received vetos in header, clear to only store enabled vetos in header ...
Definition: detector_card.h:29
int enable32bitEvents(DAEstatus &status)
Definition: detector_card.h:38
virtual ~DetectorCardIntf()
Definition: detector_card.h:81