source: trunk/Mars/mreport/MReportTrigger.cc@ 13233

Last change on this file since 13233 was 7388, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 13.1 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! Author(s): Antonio Stamerra, 05/2004 <mailto:antonio.stamerra@pi.infn.it>
20!
21! Copyright: MAGIC Software Development, 2000-2004
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 9 sections:
37// - the name of the Table (1 field)
38// - the cell rates (32 fields)
39// - L1 and L2 table name ( 2 fields)
40// - prescaling factors (2x8 fields)
41// - livetime and deadtime (5x4 fields)
42// - L2 output bit rates (20 integers)
43// - global rates (before/after presc.) (2 floats)
44// - 18 dummy fields (18 fields)
45// - IPR (325 hexs + 397 integers)
46//
47// *Output:
48//
49// The values read from the report string are used to fill the following
50// containers:
51// - MTriggerIPR (Individual Pixel Rates)
52// - MTriggerCell (Rate of trigger cells)
53// - MTriggerBit (Output Bits from prescaler (before and after presc.)
54// - MTriggerPrescFact (Prescaling factors for each bit)
55// - MTriggerLiveTime (Values of counters for dead/livetime)
56//
57//////////////////////////////////////////////////////////////////////////////
58#include "MReportTrigger.h"
59
60#include "MParList.h"
61
62#include "MLogManip.h"
63
64#include "MTriggerIPR.h"
65#include "MTriggerCell.h"
66#include "MTriggerBit.h"
67#include "MTriggerPrescFact.h"
68#include "MTriggerLiveTime.h"
69
70#include "MReportFileRead.h"
71
72ClassImp(MReportTrigger);
73
74using namespace std;
75
76// --------------------------------------------------------------------------
77//
78// Default construtor. Initialize identifier to "TRIGGER-REPORT"
79//
80MReportTrigger::MReportTrigger() : MReport("TRIGGER-REPORT")
81{
82 fName = "MReportTrigger";
83 fTitle = "Class for TRIGGER-REPORT information";
84}
85
86// --------------------------------------------------------------------------
87//
88// FindCreate the following objects:
89// - MTriggerIPR
90// - MTriggerCell
91// - MTriggerBit
92// - MTriggerPrescFact
93// - MTriggerLiveTime
94//
95Bool_t MReportTrigger::SetupReading(MParList &plist)
96{
97 fIPR = (MTriggerIPR*)plist.FindCreateObj("MTriggerIPR");
98 if (!fIPR)
99 return kFALSE;
100
101 fCell = (MTriggerCell*)plist.FindCreateObj("MTriggerCell");
102 if (!fCell)
103 return kFALSE;
104
105 fBit = (MTriggerBit*)plist.FindCreateObj("MTriggerBit");
106 if (!fBit)
107 return kFALSE;
108
109 fPrescFactor = (MTriggerPrescFact*)plist.FindCreateObj("MTriggerPrescFact");
110 if (!fPrescFactor)
111 return kFALSE;
112
113 fLiveTime = (MTriggerLiveTime*)plist.FindCreateObj("MTriggerLiveTime");
114 if (!fLiveTime)
115 return kFALSE;
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 str.Remove(0, ws);
168
169 n = sscanf(str.Data(), " %li %n", &fPrescFactor->fPrescFact[i], &len);
170 if (n!=1)
171 {
172 *fLog << warn << "WARNING - prescaler factor " << i << " missing." << endl;
173 return kCONTINUE;
174 }
175 str.Remove(0, len); // Remove Prescal. factors from report string
176 }
177 str=str.Strip(TString::kLeading);
178
179 return kTRUE;
180}
181
182// --------------------------------------------------------------------------
183//
184// Interprete the Scalers with Live-Deadtime section of the report
185// Read 4x5 integers separated with a blank
186// There are 5 scalers,each one with the live and deadtime.
187// Live and deadtimes have two fields, with the most significant
188// and less significant bits.
189//
190Bool_t MReportTrigger::InterpreteLiveTime(TString &str)
191{
192 Int_t len, n, i=0;
193 Int_t gsNScalers=5;
194 Int_t dLSB, dMSB,lLSB, lMSB;
195
196 for (i=0;i<gsNScalers;i++)
197 {
198 n = sscanf(str.Data(), " %d %d %d %d %n", &lLSB, &lMSB,&dLSB, &dMSB, &len);
199 if (n!=4)
200 {
201 *fLog << warn << "WARNING - Live-Deadtime Scaler Value #" << i << " missing." << endl;
202 return kCONTINUE;
203 }
204
205 str.Remove(0, len); // Remove Live-Deadtimes from string
206
207 //convert to seconds and fill container
208 // (FIXME! only the MSB (seconds is now considered)
209 (fLiveTime->fLiveTime)[i] = lMSB;
210 (fLiveTime->fDeadTime)[i] = dMSB;
211 }
212
213 str=str.Strip(TString::kLeading);
214
215 return kTRUE;
216}
217
218// --------------------------------------------------------------------------
219//
220// Interprete the Bit rates section of the report
221// 20 integers. First and last two are not used
222//
223Bool_t MReportTrigger::InterpreteBit(TString &str)
224{
225 Int_t len, n, i=0;
226 Int_t gsNBits=20;
227
228 for (i=0;i<gsNBits;i++)
229 {
230 n = sscanf(str.Data(), " %f %n", &fBit->fBit[i], &len);
231 if (n!=1)
232 {
233 *fLog << warn << "WARNING - Bit rate #" << i << " missing." << endl;
234 return kCONTINUE;
235 }
236 str.Remove(0, len); // Remove output bit rates from string
237 }
238
239 str=str.Strip(TString::kLeading);
240
241 return kTRUE;
242}
243
244// --------------------------------------------------------------------------
245//
246// Interprete the L1 and L2 table names
247// 1String + 1Int +1 String
248//
249Bool_t MReportTrigger::InterpreteL1L2Table(TString &str)
250{
251 const Int_t wsL1 = str.First(' ');
252
253 if (wsL1<=0)
254 {
255 *fLog << warn << "WARNING - Cannot determine name of L1 trigger table." << endl;
256 return kCONTINUE;
257 }
258
259 fL1Tablename = str(0, wsL1);
260 str.Remove(0, wsL1);
261
262 // remove an integer between names
263 Int_t len;
264 Int_t mi;
265 Int_t n=sscanf(str.Data(), "%d %n", &mi, &len);
266 if (n!=1)
267 {
268 *fLog << warn << "WARNING - Not enough arguments." << endl;
269 return kCONTINUE;
270 }
271 str.Remove(0, len);
272
273 // L2 tablename
274 const Int_t wsL2 = str.First(' ');
275
276 if (wsL2<=0)
277 {
278 *fLog << warn << "WARNING - Cannot determine name of L2 trigger table." << endl;
279 return kCONTINUE;
280 }
281 fL2Tablename = str(0, wsL2);
282 str.Remove(0,wsL2);
283 str.Strip(TString::kBoth);
284
285 return kTRUE;
286}
287
288// --------------------------------------------------------------------------
289//
290// Interprete an unused section of the report
291// 18 integers
292//
293Bool_t MReportTrigger::InterpreteDummy(TString &str)
294{
295 Int_t len, n, i=0;
296 Int_t gsNDummies=18;
297 Int_t dummy;
298
299 for (i=0;i<gsNDummies;i++)
300 {
301 n = sscanf(str.Data(), " %d %n", &dummy, &len);
302 if (n!=1)
303 {
304 *fLog << warn << "WARNING - Dummy #" << i << " missing." << endl;
305 return kCONTINUE;
306 }
307 str.Remove(0, len); // Remove dummies from report string
308
309 }
310
311 str=str.Strip(TString::kLeading);
312
313
314 return kTRUE;
315}
316
317// --------------------------------------------------------------------------
318//
319// Interprete the IPR section of the report
320// sep-04
321// The IPR are saved as 340 (=number of pixs in trigger area) hex numbers
322// and as 397 (= #pixs in inner region) dec numbers.
323// Only the dec numbers are now saved in the MTriggerIPR container.
324//
325
326Bool_t MReportTrigger::InterpreteIPR(TString &str)
327{
328
329 Int_t gsNhexIPR=340; //number of IPR saved in hex format
330 Int_t gsNdecIPR=397; //number of IPR saved in dec format
331
332 // Read Individual pixel rates in hex format
333 const char *pos = str.Data();
334 const char *end = str.Data() + gsNhexIPR*8;
335
336 Int_t i=0,n,len;
337 short dummy;
338 while (pos < end)
339 {
340 const Char_t hex[9] = { pos[0], pos[1], pos[2], pos[3],pos[4],pos[5],pos[6],pos[7],0 };
341 n = sscanf(hex, "%hx", &dummy);
342 pos+=8;
343 if (n!=1)
344 {
345 *fLog << warn << "WARNING - Rate #" << i << " missing." << endl;
346 return kFALSE;
347 }
348 }
349
350 str.Remove(0, end-str.Data()); // Remove IPR hex from report string
351 str.Strip(TString::kBoth);
352
353 // ------
354 // Read Individual pixel rates in dec format
355 // and save them in the MTriggerIPR container
356
357 for (i=0;i<gsNdecIPR;i++)
358 {
359 n = sscanf(str.Data(), " %ld %n", &fIPR->fIPR[i], &len);
360 if (n!=1)
361 {
362 *fLog << warn << "WARNING - IPR dec #" << i << " missing." << endl;
363 return kCONTINUE;
364 }
365 str.Remove(0, len); // Remove IPR dec from report string
366 }
367
368 str=str.Strip(TString::kLeading);
369
370 return kTRUE;
371}
372
373
374// --------------------------------------------------------------------------
375//
376// Interprete the body of the TRIGGER-REPORT string
377// Read comments for details
378//
379Int_t MReportTrigger::InterpreteBody(TString &str, Int_t ver )
380{
381
382 str = str.Strip(TString::kLeading);
383
384 // Extract trigger table name
385 const Int_t ws = str.First(' ');
386
387 if (ws<=0)
388 {
389 *fLog << warn << "WARNING - Cannot determine name of trigger table." << endl;
390 return kCONTINUE;
391 }
392
393 fTablename = str(0, ws);
394 str.Remove(0, ws);
395
396 // Check the Version of CC file, and takes care of the differences
397 // introduced in the format of the report (on May 2004).
398
399 if (ver < 200405050)
400 {
401 *fLog << warn << " WARNING - This is an old TRIGGER-REPORT without IPRs" <<endl;
402 return InterpreteOldBody(str);
403 }
404
405 // Read the cell rates (32 fields)
406 if (!InterpreteCell(str))
407 return kCONTINUE;
408
409 // Read L1 and L2 table name (2 fields)
410 if (!InterpreteL1L2Table(str))
411 return kCONTINUE;
412
413 // Read prescaling factors (2x8 fields)
414 if (!InterpretePrescFact(str))
415 return kCONTINUE;
416
417 // Read livetime and deadtime (5x4 fields)
418 if (!InterpreteLiveTime(str))
419 return kCONTINUE;
420
421 // Read L2 outout bit rates
422 if (!InterpreteBit(str))
423 return kCONTINUE;
424
425 // Read global rates (before and after prescaling)
426 Int_t len, n;
427 n = sscanf(str.Data(), " %f %f %n", &fL2BeforePrescaler, &fL2AfterPrescaler, &len);
428 if (n!=2)
429 {
430 *fLog << warn << "WARNING - Couldn't read Trigger rates." << endl;
431 return kFALSE;
432 }
433 str.Remove(0,len);
434 str.Strip(TString::kBoth);
435
436 // Read 18 dummy fields
437 if (!InterpreteDummy(str))
438 return kCONTINUE;
439
440 // Read IPR
441 if (!InterpreteIPR(str))
442 return kCONTINUE;
443
444 return str==(TString)"OVER" ? kTRUE : kCONTINUE;
445}
446
447
448// --------------------------------------------------------------------------
449//
450// Interprete the body of the TRIGGER-REPORT string
451// for OLD runs (older than may-04)
452//
453Bool_t MReportTrigger::InterpreteOldBody(TString &str)
454{
455
456 Int_t len, n;
457 Float_t fPrescalerRates[100];
458
459 const char *pos = str.Data();
460 for (int i=0; i<19; i++)
461 {
462 n = sscanf(pos, " %f %n", &fPrescalerRates[i], &len);
463 if (n!=1)
464 {
465 *fLog << warn << "WARNING - Scaler Value #" << i << " missing." << endl;
466 return kCONTINUE;
467 }
468 pos += len;
469 }
470
471 n = sscanf(pos, " %f %f %n", &fL2BeforePrescaler, &fL2AfterPrescaler, &len);
472 if (n!=2)
473 {
474 *fLog << warn << "WARNING - Couldn't read Trigger rates." << endl;
475 return kFALSE;
476 }
477 pos += len;
478 for (int i=0; i<11; i++)
479 {
480 Float_t dummy;
481 n = sscanf(pos, " %f %n", &dummy/*fRates[i]*/, &len);
482 if (n!=1)
483 {
484 *fLog << warn << "WARNING - Rate #" << i << " missing." << endl;
485 return kFALSE;
486 }
487 pos += len;
488 }
489 str.Remove(0, pos-str.Data());
490 str.Strip(TString::kBoth);
491
492 return str==(TString)"OVER" ? kTRUE : kCONTINUE;
493}
Note: See TracBrowser for help on using the repository browser.