source: trunk/MagicSoft/Mars/mtemp/mpisa/classes/MReportTrigger.cc@ 4905

Last change on this file since 4905 was 4890, checked in by stamerra, 20 years ago
*** empty log message ***
File size: 12.3 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Antonio Stamerra, 05/2004 <mailto:antonio.stamerra@pi.infn.it>
20!
21! Copyright: MAGIC Software Development, 2000-2003
22!
23!
24\* ======================================================================== */
25
26//////////////////////////////////////////////////////////////////////////////
27//
28// MReportTrigger
29//
30// This is the class interpreting and storing the TRIGGER-REPORT information.
31// Updated to add IPR; data format follows TDAS 00-07 ver.6.3 jul-04
32// http://hegra1.mppmu.mpg.de/MAGIC/private/software/doc/control/tdas0007_v6.3.ps.gz
33//
34// *Input:
35//
36// The report is divided into 8 sections:
37// - the cell rates (32 fields)
38// - L1 and L2 table name ( 2 fields)
39// - prescaling factors (2x8 fields)
40// - livetime and deadtime (5x4 fields)
41// - L2 output bit rates (20 integers)
42// - global rates (before/after presc.) (2 floats)
43// - 18 dummy fields (18 fields)
44// - IPR (325 hexs + 397 integers)
45//
46// *Output:
47//
48// The values read from the report string are used to fill the following
49// containers:
50// - MTriggerIPR (Individual Pixel Rates)
51// - MTriggerCell (Rate of trigger cells)
52// - MTriggerBit (Output Bits from prescaler (before and after presc.)
53// - MTriggerPrescFact (Prescaling factors for each bit)
54// - MTriggerLiveTime (Values of counters for dead/livetime)
55//
56//////////////////////////////////////////////////////////////////////////////
57#include "MReportTrigger.h"
58
59#include "MParList.h"
60
61#include "MLogManip.h"
62
63#include "MTriggerIPR.h"
64#include "MTriggerCell.h"
65#include "MTriggerBit.h"
66#include "MTriggerPrescFact.h"
67#include "MTriggerLiveTime.h"
68
69#include "MReportFileRead.h"
70
71ClassImp(MReportTrigger);
72
73using namespace std;
74
75// --------------------------------------------------------------------------
76//
77// Default construtor. Initialize identifier to "TRIGGER-REPORT"
78//
79MReportTrigger::MReportTrigger() : MReport("TRIGGER-REPORT")
80{
81 fName = "MReportTrigger";
82 fTitle = "Class for TRIGGER-REPORT information";
83}
84
85// --------------------------------------------------------------------------
86//
87// FindCreate the following objects:
88// - MTriggerIPR
89// - MTriggerCell
90// - MTriggerBit
91// - MTriggerPrescFact
92// - MTriggerLiveTime
93//
94Bool_t MReportTrigger::SetupReading(MParList &plist)
95{
96 fPixel = (MTriggerIPR*)plist.FindCreateObj("MTriggerIPR");
97 if (!fPixel)
98 return kFALSE;
99
100 fCell = (MTriggerCell*)plist.FindCreateObj("MTriggerCell");
101 if (!fCell)
102 return kFALSE;
103
104 fBit = (MTriggerBit*)plist.FindCreateObj("MTriggerBit");
105 if (!fBit)
106 return kFALSE;
107
108 fPrescFactor = (MTriggerPrescFact*)plist.FindCreateObj("MTriggerPrescFact");
109 if (!fPrescFactor)
110 return kFALSE;
111
112 fLiveTime = (MTriggerLiveTime*)plist.FindCreateObj("MTriggerLiveTime");
113 if (!fLiveTime)
114 return kFALSE;
115
116
117 return MReport::SetupReading(plist);
118}
119
120
121// --------------------------------------------------------------------------
122//
123// Interprete the Cell rates section of the report
124// Read 32 floats separated with a blank
125//
126Bool_t MReportTrigger::InterpreteCell(TString &str)
127{
128 Int_t len=0, n, i=0;
129 Int_t gsNCells=32;
130
131 for (i=0;i<gsNCells;i++)
132 {
133 n = sscanf(str.Data(), " %f %n", &fCell->fCellRate[i], &len);
134 if (n!=1)
135 {
136 *fLog << warn << "WARNING - Cell Scaler Value #" << i << " missing." << endl;
137 return kCONTINUE;
138 }
139 str.Remove(0, len); // Remove cell rates from report string
140 }
141
142 str=str.Strip(TString::kLeading);
143
144 return kTRUE;
145}
146
147// --------------------------------------------------------------------------
148//
149// Interprete the Prescaling factors section of the report
150//
151Bool_t MReportTrigger::InterpretePrescFact(TString &str)
152{
153 Int_t len=0, n, i=0;
154 Int_t gsNPrescFacts=8;
155
156 str.Remove(0, 1);
157
158 for (i=0;i<gsNPrescFacts;i++)
159 {
160 const Int_t ws = str.First(' ');
161 if (ws<=0)
162 {
163 *fLog << warn << "WARNING - Cannot determine Prescaling factor #" << i << " descriptor" << endl;
164 return kCONTINUE;
165 }
166 TString descriptor = str(0, ws);
167 *fLog << descriptor <<endl;
168 str.Remove(0, ws);
169
170 n = sscanf(str.Data(), " %li %n", &fPrescFactor->fPrescFact[i], &len);
171 if (n!=1)
172 {
173 *fLog << warn << "WARNING - prescaler factor " << i << " missing." << endl;
174 return kCONTINUE;
175 }
176 str.Remove(0, len); // Remove Prescal. factors from report string
177 *fLog << warn << fPrescFactor->fPrescFact[i]<<endl;
178 }
179 str=str.Strip(TString::kLeading);
180
181 return kTRUE;
182}
183
184// --------------------------------------------------------------------------
185//
186// Interprete the Scaler with Live-Deadtime section of the report
187// Read 4x5 integers separated with a blank
188//
189Bool_t MReportTrigger::InterpreteLiveTime(TString &str)
190{
191 Int_t len, n, i=0;
192 Int_t gsNScalers=5;
193 Int_t dLSB, dMSB,lLSB, lMSB;
194
195 for (i=0;i<gsNScalers;i++)
196 {
197 n = sscanf(str.Data(), " %d %d %d %d %n", &lLSB, &lMSB,&dLSB, &dMSB, &len);
198 if (n!=4)
199 {
200 *fLog << warn << "WARNING - Live-Deadtime Scaler Value #" << i << " missing." << endl;
201 return kCONTINUE;
202 }
203
204 str.Remove(0, len); // Remove Live-Deadtimes from string
205
206 //convert to seconds and fill container
207 // (FIXME! only the MSB (seconds is now considered)
208 (fLiveTime->fLiveTime)[i] = lMSB;
209 (fLiveTime->fDeadTime)[i] = dMSB;
210 }
211
212 str=str.Strip(TString::kLeading);
213
214 return kTRUE;
215}
216
217// --------------------------------------------------------------------------
218//
219// Interprete the Bit rates section of the report
220// 20 integers. First and last two are not used
221//
222Bool_t MReportTrigger::InterpreteBit(TString &str)
223{
224 Int_t len, n, i=0;
225 Int_t gsNBits=20;
226
227 for (i=0;i<gsNBits;i++)
228 {
229 n = sscanf(str.Data(), " %f %n", &fBit->fBit[i], &len);
230 if (n!=1)
231 {
232 *fLog << warn << "WARNING - Bit rate #" << i << " missing." << endl;
233 return kCONTINUE;
234 }
235 str.Remove(0, len); // Remove output bit rates from string
236 }
237
238 str=str.Strip(TString::kLeading);
239
240 return kTRUE;
241}
242
243// --------------------------------------------------------------------------
244//
245// Interprete the L1 and L2 table names
246// 1String + 1Int +1 String
247//
248Bool_t MReportTrigger::InterpreteL1L2Table(TString &str)
249{
250 const Int_t wsL1 = str.First(' ');
251
252 if (wsL1<=0)
253 {
254 *fLog << warn << "WARNING - Cannot determine name of L1 trigger table." << endl;
255 return kCONTINUE;
256 }
257
258 TString L1tablename = str(0, wsL1);
259 str.Remove(0, wsL1);
260
261 // remove an integer between names
262 Int_t len;
263 Int_t mi;
264 Int_t n=sscanf(str.Data(), "%d %n", &mi, &len);
265 if (n!=1)
266 {
267 *fLog << warn << "WARNING - Not enough arguments." << endl;
268 return kCONTINUE;
269 }
270 str.Remove(0, len);
271
272 // L2 tablename
273 const Int_t wsL2 = str.First(' ');
274
275 if (wsL2<=0)
276 {
277 *fLog << warn << "WARNING - Cannot determine name of L2 trigger table." << endl;
278 return kCONTINUE;
279 }
280 TString L2tablename = str(0, wsL2);
281 str.Remove(0,wsL2);
282 str.Strip(TString::kBoth);
283
284 return kTRUE;
285}
286
287// --------------------------------------------------------------------------
288//
289// Interprete an unused section of the report
290// 18 integers
291//
292Bool_t MReportTrigger::InterpreteDummy(TString &str)
293{
294 Int_t len, n, i=0;
295 Int_t gsNDummies=18;
296 Int_t dummy;
297
298 for (i=0;i<gsNDummies;i++)
299 {
300 n = sscanf(str.Data(), " %d %n", &dummy, &len);
301 if (n!=1)
302 {
303 *fLog << warn << "WARNING - Dummy #" << i << " missing." << endl;
304 return kCONTINUE;
305 }
306 str.Remove(0, len); // Remove dummies from report string
307 }
308
309 str=str.Strip(TString::kLeading);
310
311
312 return kTRUE;
313}
314
315// --------------------------------------------------------------------------
316//
317// Interprete the IPR section of the report
318//
319Bool_t MReportTrigger::InterpreteIPR(TString &str)
320{
321
322
323 *fLog << warn << "IPR ok!" <<endl;
324 return kTRUE;
325}
326
327
328// --------------------------------------------------------------------------
329//
330// Interprete the body of the TRIGGER-REPORT string
331// Read comments for details
332//
333Int_t MReportTrigger::InterpreteBody(TString &str, Int_t ver )
334{
335
336 str = str.Strip(TString::kLeading);
337
338 // Extract trigger table name
339 const Int_t ws = str.First(' ');
340
341 if (ws<=0)
342 {
343 *fLog << warn << "WARNING - Cannot determine name of trigger table." << endl;
344 return kCONTINUE;
345 }
346
347 TString tablename = str(0, ws);
348 str.Remove(0, ws);
349
350 // Check the Version of CC file, and takes care of the differences
351 // introduced in the format of the report.
352
353 //if (ver<)....
354
355 // Check the length of the report to take care of the differences
356 // introduced in the format of the report (!Preliminary! the
357 // Version number of the CC file should be used instead)
358
359 if (str.Length() < 1000)
360 {
361 *fLog << warn << " TRIGGER-REPORT: old report without IPRs" <<endl;
362 return InterpreteOldBody(str);
363 }
364
365 // Read the cell rates (32 fields)
366 if (!InterpreteCell(str))
367 return kCONTINUE;
368
369 // Read L1 and L2 table name (2 fields)
370 if (!InterpreteL1L2Table(str))
371 return kCONTINUE;
372
373 // Read prescaling factors (2x8 fields)
374 if (!InterpretePrescFact(str))
375 return kCONTINUE;
376
377 // Read livetime and deadtime (5x4 fields)
378 if (!InterpreteLiveTime(str))
379 return kCONTINUE;
380
381 // Read L2 outout bit rates
382 if (!InterpreteBit(str))
383 return kCONTINUE;
384
385 // Read global rates (before and after prescaling)
386 Int_t len, n;
387 n = sscanf(str.Data(), " %f %f %n", &fL2BeforePrescaler, &fL2AfterPrescaler, &len);
388 if (n!=2)
389 {
390 *fLog << warn << "WARNING - Couldn't read Trigger rates." << endl;
391 return kFALSE;
392 }
393 str.Remove(0,len);
394 str.Strip(TString::kBoth);
395
396 // Read 18 dummy fields
397 if (!InterpreteDummy(str))
398 return kCONTINUE;
399
400 // Read IPR
401 if (!InterpreteIPR(str))
402 return kCONTINUE;
403
404 /*
405
406 // Read Individual pixel rates
407 pos = str.Data();
408 end = str.Data() + 344;
409
410 Int_t i=0;
411 while (pos < end)
412 {
413 const Char_t hex[4] = { pos[0], pos[1], pos[2], 0 };
414 n = sscanf(hex, "%hx", &fRates->fRates[i++]);
415 pos++;
416 if (n!=1)
417 {
418 *fLog << warn << "WARNING - Rate #" << i << " missing." << endl;
419 return kFALSE;
420 }
421 }
422
423 */
424
425 str.Remove(0,len);
426 str.Strip(TString::kBoth);
427
428 return str==(TString)"OVER" ? kTRUE : kCONTINUE;
429}
430
431
432// --------------------------------------------------------------------------
433//
434// Interprete the body of the TRIGGER-REPORT string
435// for OLD runs (older than may-04)
436//
437Bool_t MReportTrigger::InterpreteOldBody(TString &str)
438{
439
440 Int_t len, n;
441 Float_t fPrescalerRates[100];
442
443 const char *pos = str.Data();
444 for (int i=0; i<19; i++)
445 {
446 n = sscanf(pos, " %f %n", &fPrescalerRates[i], &len);
447 if (n!=1)
448 {
449 *fLog << warn << "WARNING - Scaler Value #" << i << " missing." << endl;
450 return kCONTINUE;
451 }
452 pos += len;
453 }
454
455 n = sscanf(pos, " %f %f %n", &fL2BeforePrescaler, &fL2AfterPrescaler, &len); if (n!=2)
456 {
457 *fLog << warn << "WARNING - Couldn't read Trigger rates." << endl;
458 return kFALSE;
459 }
460 pos += len;
461 for (int i=0; i<11; i++)
462 {
463 Float_t dummy;
464 n = sscanf(pos, " %f %n", &dummy/*fRates[i]*/, &len);
465 if (n!=1)
466 {
467 *fLog << warn << "WARNING - Rate #" << i << " missing." << endl;
468 return kFALSE;
469 }
470 pos += len;
471 }
472 str.Remove(0, pos-str.Data());
473 str.Strip(TString::kBoth);
474
475 return str==(TString)"OVER" ? kTRUE : kCONTINUE;
476}
Note: See TracBrowser for help on using the repository browser.