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

Last change on this file since 5138 was 4919, checked in by stamerra, 20 years ago
*** empty log message ***
File size: 13.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 fIPR = (MTriggerIPR*)plist.FindCreateObj("MTriggerIPR");
97 if (!fIPR)
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
310 str=str.Strip(TString::kLeading);
311
312
313 return kTRUE;
314}
315
316// --------------------------------------------------------------------------
317//
318// Interprete the IPR section of the report
319// sep-04
320// The IPR are saved as 340 (=number of pixs in trigger area) hex numbers
321// and as 397 (= #pixs in inner region) dec numbers.
322// Only the dec numbers are now saved in the MTriggerIPR container.
323//
324
325Bool_t MReportTrigger::InterpreteIPR(TString &str)
326{
327
328 Int_t gsNhexIPR=340; //number of IPR saved in hex format
329 Int_t gsNdecIPR=397; //number of IPR saved in dec format
330
331 // Read Individual pixel rates in hex format
332 const char *pos = str.Data();
333 const char *end = str.Data() + gsNhexIPR*8;
334
335 Int_t i=0,n,len;
336 short dummy;
337 while (pos < end)
338 {
339 const Char_t hex[9] = { pos[0], pos[1], pos[2], pos[3],pos[4],pos[5],pos[6],pos[7],0 };
340 n = sscanf(hex, "%hx", &dummy);
341 pos+=8;
342 if (n!=1)
343 {
344 *fLog << warn << "WARNING - Rate #" << i << " missing." << endl;
345 return kFALSE;
346 }
347 }
348
349 str.Remove(0, end-str.Data()); // Remove IPR hex from report string
350 str.Strip(TString::kBoth);
351
352 // ------
353 // Read Individual pixel rates in dec format
354 // and save them in the MTriggerIPR container
355
356 for (i=0;i<gsNdecIPR;i++)
357 {
358 n = sscanf(str.Data(), " %ld %n", &fIPR->fIPR[i], &len);
359 if (n!=1)
360 {
361 *fLog << warn << "WARNING - IPR dec #" << i << " missing." << endl;
362 return kCONTINUE;
363 }
364 str.Remove(0, len); // Remove IPR dec from report string
365 }
366
367 str=str.Strip(TString::kLeading);
368
369 return kTRUE;
370}
371
372
373// --------------------------------------------------------------------------
374//
375// Interprete the body of the TRIGGER-REPORT string
376// Read comments for details
377//
378Int_t MReportTrigger::InterpreteBody(TString &str, Int_t ver )
379{
380
381 str = str.Strip(TString::kLeading);
382
383 // Extract trigger table name
384 const Int_t ws = str.First(' ');
385
386 if (ws<=0)
387 {
388 *fLog << warn << "WARNING - Cannot determine name of trigger table." << endl;
389 return kCONTINUE;
390 }
391
392 TString tablename = str(0, ws);
393 str.Remove(0, ws);
394
395 // Check the Version of CC file, and takes care of the differences
396 // introduced in the format of the report.
397
398 //if (ver<)....
399
400 // Check the length of the report to take care of the differences
401 // introduced in the format of the report (!Preliminary! the
402 // Version number of the CC file should be used instead)
403
404 if (str.Length() < 1000)
405 {
406 *fLog << warn << " TRIGGER-REPORT: old report without IPRs" <<endl;
407 return InterpreteOldBody(str);
408 }
409
410 // Read the cell rates (32 fields)
411 if (!InterpreteCell(str))
412 return kCONTINUE;
413
414 // Read L1 and L2 table name (2 fields)
415 if (!InterpreteL1L2Table(str))
416 return kCONTINUE;
417
418 // Read prescaling factors (2x8 fields)
419 if (!InterpretePrescFact(str))
420 return kCONTINUE;
421
422 // Read livetime and deadtime (5x4 fields)
423 if (!InterpreteLiveTime(str))
424 return kCONTINUE;
425
426 // Read L2 outout bit rates
427 if (!InterpreteBit(str))
428 return kCONTINUE;
429
430 // Read global rates (before and after prescaling)
431 Int_t len, n;
432 n = sscanf(str.Data(), " %f %f %n", &fL2BeforePrescaler, &fL2AfterPrescaler, &len);
433 if (n!=2)
434 {
435 *fLog << warn << "WARNING - Couldn't read Trigger rates." << endl;
436 return kFALSE;
437 }
438 str.Remove(0,len);
439 str.Strip(TString::kBoth);
440
441 // Read 18 dummy fields
442 if (!InterpreteDummy(str))
443 return kCONTINUE;
444
445 // Read IPR
446 if (!InterpreteIPR(str))
447 return kCONTINUE;
448
449
450
451 // str.Remove(0,len);
452 // str.Strip(TString::kBoth);
453
454 //*fLog << warn << " str=" << str << endl;
455
456 return str==(TString)"OVER" ? kTRUE : kCONTINUE;
457}
458
459
460// --------------------------------------------------------------------------
461//
462// Interprete the body of the TRIGGER-REPORT string
463// for OLD runs (older than may-04)
464//
465Bool_t MReportTrigger::InterpreteOldBody(TString &str)
466{
467
468 Int_t len, n;
469 Float_t fPrescalerRates[100];
470
471 const char *pos = str.Data();
472 for (int i=0; i<19; i++)
473 {
474 n = sscanf(pos, " %f %n", &fPrescalerRates[i], &len);
475 if (n!=1)
476 {
477 *fLog << warn << "WARNING - Scaler Value #" << i << " missing." << endl;
478 return kCONTINUE;
479 }
480 pos += len;
481 }
482
483 n = sscanf(pos, " %f %f %n", &fL2BeforePrescaler, &fL2AfterPrescaler, &len); if (n!=2)
484 {
485 *fLog << warn << "WARNING - Couldn't read Trigger rates." << endl;
486 return kFALSE;
487 }
488 pos += len;
489 for (int i=0; i<11; i++)
490 {
491 Float_t dummy;
492 n = sscanf(pos, " %f %n", &dummy/*fRates[i]*/, &len);
493 if (n!=1)
494 {
495 *fLog << warn << "WARNING - Rate #" << i << " missing." << endl;
496 return kFALSE;
497 }
498 pos += len;
499 }
500 str.Remove(0, pos-str.Data());
501 str.Strip(TString::kBoth);
502
503 return str==(TString)"OVER" ? kTRUE : kCONTINUE;
504}
Note: See TracBrowser for help on using the repository browser.