source: trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc@ 8965

Last change on this file since 8965 was 8946, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 25.8 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 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2008
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MRawRunHeader
28//
29// Root storage container for the RUN HEADER information
30//
31//
32// RAW DATA FORMAT VERSION
33// =======================
34//
35// Format Version 11:
36// -----------------
37// * all variables got four bytes
38// * header sizes allow to make the format backward compatible
39// + fHeaderSizeRun
40// + fHeaderSizeEvt
41// + fHeaderSizeCrate
42// + fFileNumber
43// + fNumSamplesRemovedHead
44// + fNumSamplesRemovedTail
45//
46// Format Version 10:
47// -----------------
48// ?
49//
50// Format Version 9:
51// -----------------
52// + fNumEventsRead;
53// + fSamplingFrequency
54// - fFreqSampling
55// + fFadcResolution;
56// - fNumSignificantBits
57//
58// Format Version 8:
59// -----------------
60// + fNumBytesPerSample;
61// + fFreqSampling;
62// + fNumSignificantBits
63// * changes in MRawCrateHeader
64//
65// Format Version 7:
66// -----------------
67// - unused
68//
69// Format Version 6:
70// -----------------
71// + added CameraVersion
72// + added TelescopeNumber
73// + added ObservationMode
74// + added dummies for TelescopeRa/Dec
75//
76// Format Version 5:
77// -----------------
78// - now the sub millisecond information of the time is valid and decoded
79// which enhances the precision from 51.2us to 200ns
80//
81// Format Version 4:
82// -----------------
83// - added support for pixels with negative IDs
84//
85// Format Version 3:
86// -----------------
87// - ???
88//
89// Format Version 2:
90// -----------------
91// - removed mjd from data
92// - added start time
93// - added stop time
94//
95//
96// MRawRunHeader CLASS VERSION
97// ===========================
98//
99// Format Version 10:
100// -----------------
101// - added fHeaderSizeRun
102// - added fHeaderSizeEvt
103// - added fHeaderSizeCrate
104// - added fFileNumber
105// - increased fSourceEpochChar
106//
107// Format Version 7:
108// -----------------
109// - added fNumEventsRead;
110// * renamed fFreqSampling to fSamplingFrequency
111// * renamed fNumSignificantBits to fFadcResolution
112//
113// Format Version 6:
114// -----------------
115// - added fNumBytesPerSample;
116// - added fSamplingFrequency;
117// - added fFadcResolution;
118//
119// Class Version 5:
120// -----------------
121// - for compatibility with newer camera versions
122//
123// Class Version 4:
124// -----------------
125// - added fCameraVersion
126// - added fTelescopeNumber
127// - changed length of fProjectName to 101
128// - changed length of fSourceName to 81
129//
130// Class Version 3:
131// ----------------
132// - enhanced SourceName and ProjectName by one character, because
133// without telling us the guranteed trailing \0-character has
134// skipped
135//
136// Class Version 2:
137// ----------------
138// - removed fMJD, fYear, fMonth, fDay
139// - added fRunStart
140// - added fRunStop
141//
142// Class Version 1:
143// ----------------
144// - first implementation
145//
146////////////////////////////////////////////////////////////////////////////
147#include "MRawRunHeader.h"
148
149#include <fstream>
150#include <iomanip>
151
152#include <TArrayC.h>
153
154#include "MLog.h"
155#include "MLogManip.h"
156
157#include "MArrayS.h"
158
159ClassImp(MRawRunHeader);
160
161using namespace std;
162
163const UShort_t MRawRunHeader::kMagicNumber = 0xc0c0;
164const Byte_t MRawRunHeader::kMaxFormatVersion = 11;
165
166// --------------------------------------------------------------------------
167//
168// Default constructor. Creates array which stores the pixel assignment.
169//
170//
171MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
172{
173 fName = name ? name : "MRawRunHeader";
174 fTitle = title ? title : "Raw Run Header Information";
175
176 fPixAssignment = new MArrayS(0);
177
178 // Remark: If we read old MC data from a root file which do not
179 // yet contain one of these variable, the value given here is
180 // the default. Do not mix files with and without a value if the
181 // files with the value do not match the default!
182 fFormatVersion=0;
183 fSoftVersion=0;
184 fTelescopeNumber=1;
185 fCameraVersion=1;
186 fFadcType=1;
187 fRunType=kRTNone; // use 0xffff for invalidation, 0 means: Data run
188 fRunNumber=0;
189 fFileNumber=0;
190 memset(fProjectName, 0, 101);
191 memset(fSourceName, 0, 81);
192 memset(fObservationMode, 0, 61);
193 fSourceEpochChar[0]=0;
194 fSourceEpochDate=0;
195 fNumCrates=0;
196 fNumPixInCrate=0;
197 fNumSamplesLoGain=0;
198 fNumSamplesHiGain=0;
199 fNumEvents=0;
200 fNumBytesPerSample=1;
201 fSamplingFrequency=300;
202 fFadcResolution=8;
203}
204
205// --------------------------------------------------------------------------
206//
207// Destructor. Deletes the 'pixel-assignment-array'
208//
209MRawRunHeader::~MRawRunHeader()
210{
211 delete fPixAssignment;
212}
213
214// --------------------------------------------------------------------------
215//
216// Swap the assignment of the pixels with hardware id id0 and id1
217//
218Bool_t MRawRunHeader::SwapAssignment(Short_t id0, Short_t id1)
219{
220 const Int_t n = fPixAssignment->GetSize();
221
222 // Look-up-table
223 UShort_t *lut = fPixAssignment->GetArray();
224
225 // Search for one of the hardware indices to get exchanged
226 int i;
227 for (i=0; i<n; i++)
228 if (lut[i]==id0 || lut[i]==id1)
229 break;
230
231 // Check if one of the two pixels were found
232 if (i==n)
233 {
234 *fLog << warn << "WARNING - Assignment of pixels with hardware ID " << id0 << " and " << id1;
235 *fLog << " should be exchanged, but none were found." << endl;
236 return kTRUE;
237 }
238
239 // Store first index
240 const Int_t idx0 = i;
241
242 // Search for the other hardware indices to get exchanged
243 for (i++; i<n; i++)
244 if (lut[i]==id0 || lut[i]==id1)
245 break;
246
247 // Check if the second pixel was found
248 if (i==n)
249 {
250 *fLog << err << "ERROR - Assignment of pixels with hardware ID " << id0 << " and " << id1;
251 *fLog << " should be exchanged, but only one was found." << endl;
252 return kFALSE;
253 }
254
255 const Int_t idx1 = i;
256
257 const Short_t p0 = lut[idx0];
258 const Short_t p1 = lut[idx1];
259
260 lut[idx0] = p1;
261 lut[idx1] = p0;
262
263 *fLog << inf << "Assignment of pixels with hardware ID " << id0 << " and " << id1 << " exchanged." << endl;
264
265 return kTRUE;
266}
267
268// --------------------------------------------------------------------------
269//
270// This implements a fix of the pixel assignment before 25.9.2005
271//
272// From magic_online (the pixel numbers are hardware indices):
273// --------------------------------------------------------------------------
274// From: Florian Goebel <fgoebel@mppmu.mpg.de>
275// Date: Sun Sep 25 2005 - 05:13:19 CEST
276//
277// [...]
278// - problem 2: pixels were swaped
279// - cause: opical fibers were wrongly connected to receiver board
280// 554 <-> 559
281// 555 <-> 558
282// 556 <-> 557
283// - action: reconnect correctly
284// - result: ok now
285// - comment: I don't know when this error was introduced, so backward
286// correction of the data is difficult.
287// Fortunately the effect is not too large since the affected 6 pixels are
288// on the outermost edge of the camera
289// Since this board has special pixels the optical fibers have been
290// unplugged several times.
291// !!!!! Whenever you unplug and reconnect optical fibers make really !!!!!
292// !!!!! sure you connect them back correctly. !!!!!
293// !!!!! Always contact me before you do so and if you have any doubts !!!!!
294// !!!!! how to reconnect the fibers ask me. !!!!!
295// These swapped pixels have only been found by chance when doing the
296// flatfielding.
297// [...]
298//
299// --------------------------------------------------------------------------
300//
301// MAGIC runbook CC_2006_04_22_22_28_52.rbk
302//
303// [2006-04-22 23:14:13]
304//
305// [...]
306// Found 2 pairs of swapped pixels.
307// We corrected swapped pixels 54<->55 in the receiver boards. We probably
308// swapped today in the camera.
309// We did not correct 92<-<93 which are likely swapped. Will check and correct
310// tomorrow.
311//
312// ---
313//
314// comments:
315// - 54<->55 were corrected but have not been swapped, hence they are swapped
316// since then (run 88560 ok, run 88669 swapped; between them mostly dummy and
317// test runs)
318// - 92<->93 are never swapped, always ok.
319//
320// --------------------------------------------------------------------------
321//
322// MAGIC runbook CC_2006_08_28_19_40_18.rbk
323//
324// [2006-08-28 23:09:07]
325// While doing a flatfielding we have found out that the signals for pixels
326// 119 and 120 were swapped. We have fixed it by exchanging the corresponding
327// fibers at the input of the receivers (not before the splitters!).
328//
329// ---
330//
331// MAGIC runbook CC_2006_08_29_15_19_14.rbk
332//
333// [2006-08-29 16:43:09]
334// In the last hours we have found out and fixed a good number of pixels which
335// were swapped: 119-120, 160-161-162 and 210-263. According to Florian,
336// 160-161-162 and 210-263 were swapped since November 2005.
337//
338// ---
339//
340// mail Florian Goebel (08/30/2006 03:13 PM):
341//
342// As far as I can tell pixels 161 and 162 as well as 263 and 210 were
343// swapped in the trigger. This leads to some inefficiency of the trigger.
344// However, they were not swapped in the readout. So, you don't have to
345// correct anything in the data for these pixels.
346//
347// ---
348//
349// comments:
350// - 119-120 swapped between run 93251 (not swapped) and 93283 (swapped)
351// (only testruns between these runs)
352// corrected since run 99354 (== runbook [2006-08-28 23:09:07])
353// - 160 never swapped
354// - 161-162 were only swapped in the trigger, but nevertheless were
355// "corrected" also in the signal. Hence signal swapped since 99354
356//
357Bool_t MRawRunHeader::FixAssignment()
358{
359 if (fRunNumber>=53300 && fRunNumber<=68754)
360 {
361 if (!SwapAssignment(554, 559))
362 return kFALSE;
363 if (!SwapAssignment(555, 558))
364 return kFALSE;
365 if (!SwapAssignment(556, 557))
366 return kFALSE;
367 }
368
369 if (fRunNumber>=93283 && fRunNumber<99354)
370 {
371 if (!SwapAssignment(119, 120))
372 return kFALSE;
373 }
374
375 if (fRunNumber>=99354 && fRunNumber<=101789)
376 {
377 if (!SwapAssignment(161, 162))
378 return kFALSE;
379 if (!SwapAssignment(210, 263))
380 return kFALSE;
381 }
382
383 if (fRunNumber>=88669)
384 {
385 if (!SwapAssignment(54, 55))
386 return kFALSE;
387 }
388
389 if (fRunNumber>=200000)
390 {
391 if (!SwapAssignment(428, 429))
392 return kFALSE;
393 }
394
395 return kTRUE;
396}
397
398// --------------------------------------------------------------------------
399//
400// Reading function to read/interpret the file formats 1-10
401//
402Bool_t MRawRunHeader::ReadEvtOld(istream& fin)
403{
404 if (fFormatVersion==7)
405 {
406 *fLog << err << "ERROR - File format V7 was for testing only and is not correctly implemented!" << endl;
407 return kFALSE;
408 }
409
410 // ----- DAQ software format version -----
411 fin.read((char*)&fSoftVersion, 2); // Total=6
412
413
414 fFadcType = 1;
415 if (fFormatVersion>7)
416 fin.read((char*)&fFadcType, 2);
417
418 // ----- Camera geometry and telescope number -----
419 fCameraVersion = 1;
420 fTelescopeNumber = 1;
421 if (fFormatVersion>5)
422 {
423 fin.read((char*)&fCameraVersion, 2); // (+2)
424 fin.read((char*)&fTelescopeNumber, 2); // (+2)
425 }
426
427 // ----- Run information -----
428 fin.read((char*)&fRunType, 2); // Total=8
429
430 fin.read((char*)&fRunNumber, 4); // Total=12
431 fin.read((char*)&fProjectName, fFormatVersion>5?100:22); // Total=34 (+78)
432 fin.read((char*)&fSourceName, fFormatVersion>5? 80:12); // Total=46 (+58)
433
434 if (fFormatVersion>5)
435 fin.read((char*)fObservationMode, 60); // (+60)
436 // Maybe we should set fObservationMode to something
437 // in case of fFormatVersion<6
438
439 // ----- Source position -----
440 fin.seekg(fFormatVersion>5 ? 16 : 8, ios::cur);
441 /*
442 if (fFormatVersion>5)
443 {
444 fin.read((char*)&fSourceRa, 4); // F32 SourceRA; Total=48
445 fin.read((char*)&fSourceDec, 4); // F32 SourceDEC; Total=52
446 }
447 fin.read((char*)&fTelescopeRa, 4); // F32 TelescopeRA; (+4)
448 fin.read((char*)&fTelescopeDec, 4); // F32 TelescopeDEC; (+4)
449 */
450
451 // Maybe we should set these to something
452 // in case of fFormatVersion<6
453 fin.read((char*)&fSourceEpochChar, 2); // Total=56
454 fin.read((char*)&fSourceEpochDate, 2); // Total=58
455
456 // ----- Old Start time -----
457 if (fFormatVersion<2) // Total += 10
458 {
459 UShort_t y, m, d;
460 fin.seekg(4, ios::cur); // Former fMJD[4],
461 fin.read((char*)&y, 2); // Former fDateYear[2]
462 fin.read((char*)&m, 2); // Former fDateMonth[2]
463 fin.read((char*)&d, 2); // Former fDateDay[2]
464 fRunStart.Set(y, m, d, 0, 0, 0, 0);
465 }
466
467 // ----- Data Geometry -----
468
469 fin.read((char*)&fNumCrates, 2); // MUX: number of channels
470 fin.read((char*)&fNumPixInCrate, 2); // MUX: number of pix in channel
471 fin.read((char*)&fNumSamplesLoGain, 2); // MUX: dummy (must be 0 for MUX data)
472 fin.read((char*)&fNumSamplesHiGain, 2); // MUX: Number of samples per pixel
473
474 char dummy[16];
475 if (fFormatVersion>8)
476 fin.read(dummy, 4); // 2xU16 (NumSamplesRemovedHead and NumSamplesRemovedTail)
477
478 // ----- Number of events -----
479 fin.read((char*)&fNumEvents, 4); // Total=70
480
481 if (fFormatVersion>8)
482 {
483 fin.read((char*)&fNumEventsRead, 4); // Total=70
484 fNumEvents--;
485 fNumEventsRead--;
486 *fLog << inf << "Format V9: Stored number of events decreased by 1." << endl;
487 }
488
489 // New in general features: (should they be included in new MAGIC1 formats, too?)
490 fNumBytesPerSample = 1; // 2 for MUX DATA
491 fSamplingFrequency = 300;
492 fFadcResolution = 8;
493
494 if (fFormatVersion>7)
495 {
496 fin.read((char*)&fNumBytesPerSample, 2);
497 fin.read((char*)&fSamplingFrequency, 2); // [MHz], 2000 for MuxFadc
498 fin.read((char*)&fFadcResolution, 1); // nominal resolution [# Bits], 10 for MuxFadc
499
500 if (fNumBytesPerSample!=2)
501 {
502 *fLog << err << "ERROR - " << fNumBytesPerSample << " bytes per sample are not supported!" << endl;
503 return kFALSE;
504 }
505 }
506
507 // ----- Start/Stop time -----
508 if (fFormatVersion>1)
509 {
510 fRunStart.ReadBinary(fin); // Total += 7
511 fRunStop.ReadBinary(fin); // Total += 7
512 }
513
514 //
515 // calculate size of array, create it and fill it
516 //
517 const Int_t nPixel = fNumCrates*fNumPixInCrate;
518 fPixAssignment->Set(nPixel);
519
520 // ----- Pixel Assignement -----
521 fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
522
523 if (fFormatVersion<7)
524 fin.read(dummy, 16);
525
526 return FixAssignment();
527}
528
529// --------------------------------------------------------------------------
530//
531// Read in one run header from the binary file
532//
533Bool_t MRawRunHeader::ReadEvt(istream& fin)
534{
535 //
536 // read one RUN HEADER from the input stream
537 //
538 fMagicNumber = 0;
539
540 fin.read((char*)&fMagicNumber, 2); // Total=2
541
542 //
543 // check whether the the file has the right file type or not
544 //
545 if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
546 {
547 *fLog << err << "ERROR - Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
548 return kFALSE;
549 }
550
551 if (fMagicNumber == kMagicNumber+1)
552 *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
553
554 // ----- File format version -----
555 fin.read((char*)&fFormatVersion, 2); // Total=4
556 if (fFormatVersion==10 || fFormatVersion>kMaxFormatVersion)
557 {
558 *fLog << err << "ERROR - File format V" << fFormatVersion << " not implemented!" << endl;
559 return kFALSE;
560 }
561
562 // ----- Process old file formats -----
563 if (fFormatVersion<10)
564 return ReadEvtOld(fin);
565
566 // ----- Overwrite format version for format 11 -----
567 fin.read((char*)&fFormatVersion, 4);
568 if (fFormatVersion<11)
569 {
570 *fLog << err << "ERROR - Format Version <11." << endl;
571 return kFALSE;
572 }
573
574 // ----- Read Header by size as written in the header -----
575 fin.read((char*)&fHeaderSizeRun, 4);
576 if (fHeaderSizeRun<346)
577 {
578 *fLog << err << "ERROR - Event header too small (<388b)." << endl;
579 return kFALSE;
580 }
581
582 TArrayC h(fHeaderSizeRun-12);
583 fin.read(h.GetArray(), h.GetSize());
584 if (!fin)
585 return kFALSE;
586
587 // ----- convert -----
588 const Byte_t *Char = reinterpret_cast<Byte_t* >(h.GetArray());
589 const UInt_t *Int = reinterpret_cast<UInt_t* >(h.GetArray());
590 //const Float_t *Float = reinterpret_cast<Float_t*>(h.GetArray());
591
592 // ----- Start interpretation -----
593
594 fHeaderSizeEvt = Int[0];
595 fHeaderSizeCrate = Int[1];
596 fSoftVersion = Int[2];
597 fFadcType = Int[3];
598 fCameraVersion = Int[4];
599 fTelescopeNumber = Int[5];
600 fRunType = Int[6];
601 fRunNumber = Int[7];
602 fFileNumber = Int[8];
603
604 memcpy(fProjectName, Char+ 36, 100); // 25
605 memcpy(fSourceName, Char+136, 80); // 20
606 memcpy(fObservationMode, Char+216, 60); // 15
607
608 //F32 fSourceRA = Float[69];
609 //F32 fSourceDEC = Float[70];
610 //F32 fTelescopeRA = Float[71];
611 //F32 fTelescopeDEC = Float[72];
612
613 memcpy(fSourceEpochChar, Char+232, 4);
614
615 fSourceEpochDate = Int[74];
616 fNumCrates = Int[75];
617 fNumPixInCrate = Int[76];
618 fNumSamplesHiGain = Int[77];
619 fNumSamplesLoGain = 0;
620
621 //fNumSamplesRemovedHead = Int[78];
622 //fNumSamplesRemovedTail = Int[79];
623
624 fNumEvents = Int[80];
625 fNumEventsRead = Int[81];
626 fNumBytesPerSample = Int[82];
627 fSamplingFrequency = Int[83];
628 fFadcResolution = Int[84];
629
630 fRunStart.SetBinary(Int+85);
631 fRunStop.SetBinary(Int+91);
632
633 // ----- 388 bytes so far -----
634
635 const UInt_t n = fNumCrates*fNumPixInCrate;
636 if (fHeaderSizeRun<388+n*4)
637 {
638 *fLog << err << "ERROR - Event header too small to contain pix assignment." << endl;
639 return kFALSE;
640 }
641
642 // ----- Pixel Assignment -----
643 fPixAssignment->Set(n);
644
645 for (UInt_t i=0; i<n; i++)
646 (*fPixAssignment)[i] = Int[97+i];
647
648 return FixAssignment();
649}
650
651// --------------------------------------------------------------------------
652//
653// Return the run type as string ("Data", "Pedestal", ...), for example
654// to print it as readable text.
655//
656const char *MRawRunHeader::GetRunTypeStr() const
657{
658 switch (fRunType)
659 {
660 case kRTData:
661 return "Data";
662 case kRTPedestal:
663 return "Pedestal";
664 case kRTCalibration:
665 return "Calibration";
666 case kRTPointRun:
667 return "Point-Run";
668 case kRTMonteCarlo:
669 return "Monte Carlo";
670 case kRTNone:
671 return "<none>";
672 default:
673 return "<unknown>";
674 }
675}
676
677// --------------------------------------------------------------------------
678//
679// print run header information on *fLog. The option 'header' supresses
680// the pixel index translation table.
681//
682void MRawRunHeader::Print(Option_t *t) const
683{
684 *fLog << all << endl;
685 *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - ";
686 switch (fMagicNumber)
687 {
688 case kMagicNumber: *fLog << "OK"; break;
689 case kMagicNumber+1: *fLog << "File not closed!"; break;
690 default: *fLog << "Wrong!"; break;
691 }
692 *fLog << endl;
693 *fLog << "Versions: " << dec << "Format=" << fFormatVersion << " ";
694 *fLog << "Software=" << fSoftVersion << " ";
695 if (fFormatVersion>5)
696 *fLog << "Camera=" << fCameraVersion;
697 *fLog << endl;
698 if (fFormatVersion>10)
699 *fLog << "Header sizes: " << fHeaderSizeRun << "b (run), " << fHeaderSizeEvt << "b (evt), " << fHeaderSizeCrate << "b (crate)" << endl;
700 if (fFormatVersion>5)
701 *fLog << "Telescope: " << fTelescopeNumber << endl;
702 if (fFormatVersion>7)
703 {
704 *fLog << "FadcType: " << fFadcType << " (";
705 switch (fFadcType)
706 {
707 case 1: *fLog << "Siegen"; break;
708 case 2: *fLog << "MUX"; break;
709 default: *fLog << "unknown";
710 }
711 *fLog << ")" << endl;
712 }
713 *fLog << "RunNumber: " << fRunNumber << " (Type=" << GetRunTypeStr() << ")" << endl;
714 *fLog << "ProjectName: '" << fProjectName << "'" << endl;
715 if (fFormatVersion>5)
716 *fLog << "Observation: '" << fObservationMode << "'" << endl;
717 *fLog << "Source: '" << fSourceName << "' " << " ";
718 *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
719 *fLog << "Run Start: " << fRunStart << endl;
720 *fLog << "Run Stop: " << fRunStop << endl;
721 *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
722 *fLog << "Num Pixels: " << GetNumNormalPixels() << " (normal) + " << GetNumSpecialPixels() << " (special) = " << GetNumConnectedPixels() << " (total)" << endl;
723 if (fFormatVersion>6)
724 *fLog << "Sampling: " << fSamplingFrequency << "MHz with " << (int)fFadcResolution << " significant bits" << endl;
725 *fLog << "Samples: " << fNumSamplesHiGain << "/" << fNumSamplesLoGain << " (hi/lo) * " << fNumBytesPerSample << "B/sample = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate * fNumBytesPerSample/1000 << "kB/Evt" << endl;
726 *fLog << "Evt Counter: " << fNumEvents;
727 if (fFormatVersion>8)
728 *fLog << " (read=" << fNumEventsRead << ")";
729 *fLog << endl;
730
731 if (TString(t).Contains("header", TString::kIgnoreCase))
732 return;
733
734 *fLog << inf3 << "Assignment:" << hex << endl;
735 for (int i=0; i<GetNumPixel(); i++)
736 *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
737
738 *fLog << dec << setfill(' ') << endl;
739}
740
741// --------------------------------------------------------------------------
742//
743// Return the assigned pixel number for the given FADC channel
744//
745Short_t MRawRunHeader::GetPixAssignment(UShort_t i) const
746{
747 // FIXME: Do we need a range check here?
748 return (Short_t)(*fPixAssignment)[i];
749}
750
751// --------------------------------------------------------------------------
752//
753// Return the number of pixel which are markes as connected in the
754// pix assignment (!=0)
755//
756UShort_t MRawRunHeader::GetNumConnectedPixels() const
757{
758 const Int_t num = fPixAssignment->GetSize();
759
760 UShort_t rc = 0;
761 for (int i=0; i<num; i++)
762 {
763 if (GetPixAssignment(i)!=0)
764 rc++;
765 }
766 return rc;
767}
768
769// --------------------------------------------------------------------------
770//
771// Return the number of pixel which are markes as connected and so-called
772// 'normal' pixels in the pix assignment (>0)
773//
774UShort_t MRawRunHeader::GetNumNormalPixels() const
775{
776 const Int_t num = fPixAssignment->GetSize();
777
778 UShort_t rc = 0;
779 for (int i=0; i<num; i++)
780 {
781 if (GetPixAssignment(i)>0)
782 rc++;
783 }
784 return rc;
785}
786
787// --------------------------------------------------------------------------
788//
789// Return the number of pixel which are markes as connected and so-called
790// 'special' pixels in the pix assignment (<0)
791//
792UShort_t MRawRunHeader::GetNumSpecialPixels() const
793{
794 const Int_t num = fPixAssignment->GetSize();
795
796 UShort_t rc = 0;
797 for (int i=0; i<num; i++)
798 {
799 if (GetPixAssignment(i)<0)
800 rc++;
801 }
802 return rc;
803}
804
805// --------------------------------------------------------------------------
806//
807// Return the maximum id which exists in the pix assignment
808//
809UShort_t MRawRunHeader::GetMaxPixId() const
810{
811 const Int_t num = fPixAssignment->GetSize();
812
813 Short_t rc = 0;
814 for (int i=0; i<num; i++)
815 rc = TMath::Max(GetPixAssignment(i), rc);
816
817 return rc;
818}
819
820// --------------------------------------------------------------------------
821//
822// Return minus th minimum id which exists in the pix assignment
823//
824UShort_t MRawRunHeader::GetMinPixId() const
825{
826 const Int_t num = fPixAssignment->GetSize();
827
828 Short_t rc = 0;
829 for (int i=0; i<num; i++)
830 rc = TMath::Min(GetPixAssignment(i), rc);
831
832 return (UShort_t)-rc;
833}
834
835// --------------------------------------------------------------------------
836//
837// Return the number of pixel in this event.
838//
839// WARNING: This is the number of pixels stored in this file which is
840// a multiple of the number of pixels per crate and in general
841// a number which is larger than the camera size!
842//
843// To know the range of the pixel indices please use the geometry
844// container!
845//
846UShort_t MRawRunHeader::GetNumPixel() const
847{
848 return fPixAssignment->GetSize();
849}
850
851// --------------------------------------------------------------------------
852//
853// Returns absolute size in bytes of the run header as read from a raw file.
854// This must be done _after_ the header is read, because the header doesn't
855// have a fixed size (used in MRawSocketRead)
856//
857Int_t MRawRunHeader::GetNumTotalBytes() const
858{
859 switch (fFormatVersion)
860 {
861 case 1:
862 return 80+fNumCrates*fNumPixInCrate*2+16;
863 case 2:
864 case 3:
865 case 4:
866 case 5:
867 return 84+fNumCrates*fNumPixInCrate*2+16;
868 case 6:
869 return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8;
870 case 7:
871 return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8 +3-16;
872 }
873 return 0;
874}
Note: See TracBrowser for help on using the repository browser.