FACT++  1.0
int StateMachineRateScan::HandleTriggerRates ( const EventImp evt)
inlineprivate

Definition at line 99 of file ratescan.cc.

References data, FTM::DimTriggerRates::fBoardRate, FTM::DimTriggerRates::fElapsedTime, FTM::DimTriggerRates::fOnTime, FTM::DimTriggerRates::fPatchRate, fThreshold, FTM::DimTriggerRates::fTriggerRate, EventImp::GetData(), i, if(), RateScan::State::kConnected, RateScan::State::kInProgress, RateScan::State::kPaused, Dim::SendCommandNB(), DimDescribedService::setData(), DimService::setQuality(), time, and DimDescribedService::Update().

Referenced by StateMachineRateScan().

100  {
101  if (!CheckEventSize(evt, sizeof(FTM::DimTriggerRates)))
102  return GetCurrentState();
103 
105  return GetCurrentState();
106 
107  const FTM::DimTriggerRates &sdata = *static_cast<const FTM::DimTriggerRates*>(evt.GetData());
108 
109  if (++fCounter<0)
110  return GetCurrentState();
111 
113  fCounter=0;
114 
115  if (fCounter==0)
116  {
117  fRate = 0;
118 
119  memset(fRateBoard, 0, 40*sizeof(double));
120  memset(fRatePatch, 0, 160*sizeof(double));
121 
122  fOnTime = 0;
123  return GetCurrentState();
124  }
125 /*
126  if (sdata.fTriggerRate==0)
127  {
128  Message("Rate scan stopped due zero trigger rate.");
129  fThreshold = -1;
130  return;
131  }
132 */
133 
134  fRate += sdata.fTriggerRate;
135  for (int i=0; i<40; i++)
136  fRateBoard[i] += sdata.fBoardRate[i];
137  for (int i=0; i<160; i++)
138  fRatePatch[i] += sdata.fPatchRate[i];
139 
140  double reference = fRate;
141  if (fReference==kBoard)
142  reference = fRateBoard[fReferenceIdx];
143  if (fReference==kPatch)
144  reference = fRatePatch[fReferenceIdx];
145 
146  fOnTime += sdata.fOnTime;
147 
148  reference *= sdata.fElapsedTime;
149 
150  if ((reference==0 || sqrt(reference)>fResolution*reference) && fCounter<fCounterMax)
151  {
152  ostringstream out;
153  out << "Triggers so far: " << reference;
154  if (reference>0)
155  out << " (" << sqrt(reference)/reference << ")";
156  Info(out);
157 
158  return GetCurrentState();
159  }
160 
161  const double time = sdata.fElapsedTime*fCounter;
162  const uint32_t th = fThreshold;
163 
164  float data[2+3+1+40+160];
165  memcpy(data, &fStartTime, 8);
166  memcpy(data+2, &th, 4);
167  data[3] = time; // total elapsed time
168  data[4] = fOnTime/time; // relative on time
169  data[5] = fRate/fCounter;
170  for (int i=0; i<40; i++)
171  data[i+6] = fRateBoard[i]/fCounter;
172  for (int i=0; i<160; i++)
173  data[i+46] = fRatePatch[i]/fCounter;
174 
175  ostringstream sout1, sout2, sout3;
176 
177  sout1 << th << " " << data[5];
178  for (int i=0; i<200; i++)
179  sout2 << " " << data[i+6];
180  sout3 << " " << data[3] << " " << data[4];
181 
182  Info(sout1.str());
183 
184  //ofstream fout("ratescan.txt", ios::app);
185  //fout << sout1.str() << sout2.str() << sout3.str() << endl;
186 
187  fDimData.setQuality(fCommand=="FTM_CONTROL/SET_THRESHOLD");
188  fDimData.setData(data, sizeof(data));
189  fDimData.Update();
190 
192 
193  if (fCounter>=fCounterMax)
194  {
195  Message("Rate scan stopped due to timeout.");
196  //Dim::SendCommandNB("FTM_CONTROL/RESET_CONFIGURE");
198  }
199 
201  {
202  Message("Rate scan finished.");
203  //Dim::SendCommandNB("FTM_CONTROL/RESET_CONFIGURE");
205  }
206 
207  // Does this need to be shifted upwards?
208  if (fCounter>1 && fThresholdStepDyn>0)
209  {
210  //const double scale = fCounter/reference/fResolution/fResolution;
211  //const double step = floor(scale*fThresholdStepDyn);
212 
214  }
215 
216  //fCounter = -2; // FIXME: In principle one missed report is enough
217  fCounter = -1;
218 
219  const int32_t cmd[2] = { -1, fThreshold };
220  Dim::SendCommandNB(fCommand.c_str(), cmd);
221 
222  return GetCurrentState();
223  }
uint64_t fStartTime
Definition: ratescan.cc:63
int GetCurrentState() const
return the current state of the machine
int i
Definition: db_dim_client.c:21
void setQuality(int quality)
Definition: discpp.cxx:1256
float fBoardRate[40]
Definition: HeadersFTM.h:589
reference_t fReference
Definition: ratescan.cc:74
DimDescribedService fDimData
Definition: ratescan.cc:43
double fRateBoard[40]
Definition: ratescan.cc:58
void setData(const void *ptr, size_t sz)
void SendCommandNB(const std::string &command)
Definition: Dim.h:30
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
float data[4 *1440]
uint16_t fReferenceIdx
Definition: ratescan.cc:75
int Info(const std::string &str)
Definition: MessageImp.h:47
if(extraDns) new Dns
int Message(const std::string &str)
Definition: MessageImp.h:46
bool CheckEventSize(const EventImp &evt, size_t size)
Definition: ratescan.cc:85
virtual const void * GetData() const
Definition: EventImp.h:54
double fRatePatch[160]
Definition: ratescan.cc:59
float fPatchRate[160]
Definition: HeadersFTM.h:590

+ Here is the call graph for this function:

+ Here is the caller graph for this function: