RawTriggerMaskV0.cpp
Go to the documentation of this file.
1 #include "DAQDataFormats/RawTriggerMaskV0.h"
2 #include "DAQDataFormats/DataFormatException.h"
3 #include <boost/format.hpp>
4 
5 /// It is requred to
6 /// 1. include DAQDataFormats/DataFormatFirst.inc
7 /// 2. define CURRENT_CLASS
8 /// 3. define CURRENT_CLASS_VERSION for version of the class
9 /// OR define LAST_CLASS_VERSION for the main structure of the class
10 /// 4. (optional) define CURRENT_FIELDS_SUB_NAMESPACE
11 /// 5. include DAQDataFormats/DataFormatLast.inc
12 /// before the declaration of the DataFormat version class in the header.
13 #include "DAQDataFormats/DataFormatFirst.inc"
14 #define CURRENT_CLASS RawTriggerMask
15 #define CURRENT_CLASS_VERSION 0
16 #define CURRENT_FIELDS_SUB_NAMESPACE triggermask
17 #include "DAQDataFormats/DataFormatLast.inc"
18 
19 namespace daqdataformats{
20 namespace VERSION_NAMESPACE{
21 
22 //------------------------Constructors------------------------------------------
24  PREVIOUS_VERSION_CLASS_NAME(version)
25  ,ZEROOUT_GET_AND_SET(Version )
26  ,ZEROOUT_GET_AND_SET(MonteCarloFlag)
27  ,ZEROOUT_GET_AND_SET(TrigMod )
28  ,ZEROOUT_GET_AND_SET(TrigMask_Low )
29  ,ZEROOUT_GET_AND_SET(TrigMask_High )
30  ,ZEROOUT_GET_AND_SET(TrigMask_High2)
31  ,ZEROOUT_GET_AND_SET(Prescale )
33 {}
34 
35 //------------------------------------------------------------------------------
37  PREVIOUS_VERSION_CLASS_NAME(copyin)
38  ,DEEPCOPY_GET_AND_SET(Version )
39  ,DEEPCOPY_GET_AND_SET(MonteCarloFlag)
40  ,DEEPCOPY_GET_AND_SET(TrigMod )
41  ,DEEPCOPY_GET_AND_SET(TrigMask_Low )
42  ,DEEPCOPY_GET_AND_SET(TrigMask_High )
43  ,DEEPCOPY_GET_AND_SET(TrigMask_High2)
44  ,DEEPCOPY_GET_AND_SET(Prescale )
46 {}
47 
48 //------------------------------------------------------------------------------
50 
51 //------------------------------------------------------------------------------
52 // General Initialization
54  EXECUTE_FUNCTION(setVersion)(_version);
55 }
56 
57 //------------------------------------------------------------------------------
58 uint32_t RawTriggerMask::getTriggerMask() const{
59 
60 
61 #ifdef USE_DENIS_96BIT_TRIGGER_CODE
62  /********************************************************
63  * Original Math is wrong. We have 88 primary trigger *
64  * bits. The low word provides 24 of these, the others *
65  * provide 32 each *
66  ********************************************************/
67 
68  if (EXECUTE_FUNCTION(getTrigMask_Low)()){
69  uint32_t number = EXECUTE_FUNCTION(getTrigMask_Low)();
70  for(uint32_t ishift = 0; ishift < 32; ++ishift){
71  if(number & 0x1 )return ishift;
72  number = number >> 1;
73  }
74  std::string msg("Something is wrong in RawTriggerMask::getTriggerMask()");
76  return 0;
77  }
78  else if(EXECUTE_FUNCTION(getTrigMask_High)()){
79  uint32_t number = EXECUTE_FUNCTION(getTrigMask_High)();
80  for(uint32_t ishift = 0; ishift < 32; ++ishift){
81  if(number & 0x1)return ishift + 32;
82  number = number >> 1;
83  }
84  std::string msg("Something is wrong in RawTriggerMask::getTriggerMask()");
86  return 0;
87  }
88  else if(EXECUTE_FUNCTION(getTrigMask_High2)()){
89  uint32_t number = EXECUTE_FUNCTION(getTrigMask_High2)();
90  for(uint32_t ishift = 0; ishift < 32; ++ishift){
91  if(number & 0x1)return ishift + 64;
92  number = number >> 1;
93  }
94  std::string msg("Something is wrong in RawTriggerMask::getTriggerMask()");
96  return 0;
97  }
98 #endif // USE_DENIS_96BIT_TRIGGER_CODE
99 
100  // TMOD is used as the "page" for the triggers. This is just a multiplication of the
101  // trigger bit by the TMOD value
102 
103  uint8_t tmod = (uint8_t)(EXECUTE_FUNCTION(getTrigMod)() & 0xFF);
104 
105  if (EXECUTE_FUNCTION(getTrigMask_Low)()){
106  uint32_t number = EXECUTE_FUNCTION(getTrigMask_Low)();
107  for(uint32_t ishift = 0; ishift < 24; ++ishift){
108  if(number & 0x1 ){
109  return ishift * (tmod+1);
110  }
111  number = number >> 1;
112  } // endfor
113  std::string msg("Something is wrong in RawTriggerMask::getTriggerMask()");
115  return 0;
116  }
117  else if(EXECUTE_FUNCTION(getTrigMask_High)()){
118  uint32_t number = EXECUTE_FUNCTION(getTrigMask_High)();
119  for(uint32_t ishift = 0; ishift < 32; ++ishift){
120  if(number & 0x1){
121  return (ishift + 24)*(tmod+1);
122  }
123  number = number >> 1;
124  }
125  std::string msg("Something is wrong in RawTriggerMask::getTriggerMask()");
127  return 0;
128  }
129  else if(EXECUTE_FUNCTION(getTrigMask_High2)()){
130  uint32_t number = EXECUTE_FUNCTION(getTrigMask_High2)();
131  for(uint32_t ishift = 0; ishift < 32; ++ishift){
132  if(number & 0x1){
133  return (ishift + 56)*(tmod+1);
134  }
135  number = number >> 1;
136  }
137  std::string msg("Something is wrong in RawTriggerMask::getTriggerMask()");
139  return 0;
140  }
141 
142 
143  //std::string msg("From RawTriggerMask::getTriggerMask(). TriggerMask is not set");
144  //GENERATE_DATAFORMAT_EXCEPTION(msg);
145  return 0;
146 }
147 
148 //------------------------------------------------------------------------------
149 bool RawTriggerMask::setTriggerMask(const uint32_t mask){
150 
151  uint32_t mask_copy = mask;
152  uint8_t tmod;
153 
154  // Calculate the trigger page that we should be on
155  // This is the bit number div the size of the pages (88 bits)
156  if(mask_copy > 88){
157  tmod = (mask_copy / 88); // bit div page size
158  EXECUTE_FUNCTION(setTrigMod)(tmod); // Set the page value
159  mask_copy = mask_copy - (tmod * 88); // Subtract off the page offsets
160  }
161 
162 
163  if (mask_copy > 88){
164  std::string msg("The mask is too high");
166  return false;
167  }
168 
169  if(mask_copy < 24){
170  uint32_t number = 0x1;
171  for(uint32_t ishift = 0; ishift < mask_copy; ++ishift){
172  number = number << 1;
173  }
174  RETURN_FUNCTION(setTrigMask_Low)(number & 0x00FFFFFF);
175  }
176  else if(mask_copy < 56){
177  mask_copy -= 24;
178  uint32_t number = 0x1;
179  for(uint32_t ishift = 0; ishift < mask_copy; ++ishift){
180  number = number << 1;
181  }
182  RETURN_FUNCTION(setTrigMask_High)(number);
183  }
184 
185 
186  mask_copy -= 56;
187  uint32_t number = 0x1;
188  for(uint32_t ishift = 0; ishift < mask_copy; ++ishift){
189  number = number << 1;
190  }
191  RETURN_FUNCTION(setTrigMask_High2)(number);
192 }
193 
194 //------------------------------------------------------------------------------
195 void RawTriggerMask::print(std::ostream& os) const{
196 
197  os<<"++++ Trigger Mask ++++\n";
198  os<<boost::format("Trigger Mask Version:\t%u\n") % EXECUTE_FUNCTION(getVersion)();
199  os<<boost::format("Monte Carlo:\t\t%s\n" ) %(EXECUTE_FUNCTION(getMonteCarloFlag)()? "True" : "False");
200  os<<boost::format("Trigger Modification:\t0x%02x\n") % EXECUTE_FUNCTION(getTrigMod)();
201  os<<boost::format("Trigger Types low:\t0x%08x\n" ) % EXECUTE_FUNCTION(getTrigMask_Low)();
202  os<<boost::format("Trigger Types mid:\t0x%08x\n" ) % EXECUTE_FUNCTION(getTrigMask_High)();
203  os<<boost::format("Trigger Types high:\t0x%08x\n" ) % EXECUTE_FUNCTION(getTrigMask_High2)();
204  os<<boost::format("Trigger Type:\t\t%u\n" ) % EXECUTE_FUNCTION(getTriggerMask)();
205  os<<boost::format("Trigger prescale:\t%u\n" ) % EXECUTE_FUNCTION(getPrescale)();
206  PRINT_ON_DEBUG("Buffer is set to "<<_Buffer);
207 }
208 
209 
210 }}
#define EXECUTE_FUNCTION(FULLFUNCTIONNAME)
Execute and return the delegate.
Definition: Macros.h:54
#define DEEPCOPY_GET_AND_SET(FUNC)
Definition: FunctionBind.h:44
#define GENERATE_DATAFORMAT_EXCEPTION(msg)
Class to hold the data corresponding to the trigger mask.
#define VERSION_NAMESPACE
Float_t x1[n_points_granero]
Definition: compare.C:5
#define ZEROOUT_GET_AND_SET(FUNC)
Definition: FunctionBind.h:56
#define RETURN_FUNCTION(FULLFUNCTIONNAME)
Definition: Macros.h:57
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
const XML_Char * version
Definition: expat.h:187
int32_t version_t
Definition: RawDAQData.h:72
#define PRINT_ON_DEBUG(x)
Definition: RawDAQData.h:35
Class to hold the data from the FEBs in correct formats.
RawTriggerMask(const version_t)
The default constructor.
void print(std::ostream &os=std::cout) const
enum BeamMode string