| 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 (tbretz@uni-sw.gwdg.de)
 | 
|---|
| 19 | !
 | 
|---|
| 20 | !   Copyright: MAGIC Software Development, 2000-2001
 | 
|---|
| 21 | !
 | 
|---|
| 22 | !
 | 
|---|
| 23 | \* ======================================================================== */
 | 
|---|
| 24 | 
 | 
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 26 | //
 | 
|---|
| 27 | // MRawRunHeader
 | 
|---|
| 28 | //
 | 
|---|
| 29 | // Root storage container for the RUN HEADER information
 | 
|---|
| 30 | //
 | 
|---|
| 31 | ////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 32 | 
 | 
|---|
| 33 | #include "MRawRunHeader.h"
 | 
|---|
| 34 | 
 | 
|---|
| 35 | #include <fstream.h>
 | 
|---|
| 36 | #include <iomanip.h>
 | 
|---|
| 37 | 
 | 
|---|
| 38 | #include "MLog.h"
 | 
|---|
| 39 | #include "MArrayS.h"
 | 
|---|
| 40 | 
 | 
|---|
| 41 | ClassImp(MRawRunHeader)
 | 
|---|
| 42 | 
 | 
|---|
| 43 | MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
 | 
|---|
| 44 | {
 | 
|---|
| 45 |     *fName  = name  ? name  : "MRawRunHeader";
 | 
|---|
| 46 |     *fTitle = title ? title : "Raw Run Header Information";
 | 
|---|
| 47 | 
 | 
|---|
| 48 |     fPixAssignment = new MArrayS(0);
 | 
|---|
| 49 | 
 | 
|---|
| 50 |     // This is only valid for root > 3.0
 | 
|---|
| 51 |     // IsA()->CanIgnoreTObjectStreamer();
 | 
|---|
| 52 | }
 | 
|---|
| 53 | 
 | 
|---|
| 54 | MRawRunHeader::~MRawRunHeader()
 | 
|---|
| 55 | {
 | 
|---|
| 56 |     delete fPixAssignment;
 | 
|---|
| 57 | }
 | 
|---|
| 58 | 
 | 
|---|
| 59 | void MRawRunHeader::ReadEvt(istream& fin)
 | 
|---|
| 60 | {
 | 
|---|
| 61 |     //
 | 
|---|
| 62 |     // read one RUN HEADER from the input stream
 | 
|---|
| 63 |     //
 | 
|---|
| 64 |     fin.read((Byte_t*)&fMagicNumber,       2);
 | 
|---|
| 65 | 
 | 
|---|
| 66 |     //
 | 
|---|
| 67 |     // check whether the the file has the right file type or not
 | 
|---|
| 68 |     //
 | 
|---|
| 69 |     if (fMagicNumber != kMagicNumber)
 | 
|---|
| 70 |     {
 | 
|---|
| 71 |         *fLog << "Error: Wrong Magic Number: Not a Magic File!" << endl;
 | 
|---|
| 72 |         return;
 | 
|---|
| 73 |     }
 | 
|---|
| 74 | 
 | 
|---|
| 75 |     Byte_t dummy[16];
 | 
|---|
| 76 | 
 | 
|---|
| 77 |     fin.read((Byte_t*)&fFormatVersion,    2);
 | 
|---|
| 78 |     fin.read((Byte_t*)&fSoftVersion,      2);
 | 
|---|
| 79 |     fin.read((Byte_t*)&fRunType,          2);
 | 
|---|
| 80 |     fin.read((Byte_t*)&fRunNumber,        4);
 | 
|---|
| 81 |     fin.read((Byte_t*)&fProjectName,     22);
 | 
|---|
| 82 |     fin.read((Byte_t*)&fSourceName,      12);
 | 
|---|
| 83 |     fin.read((Byte_t*)dummy,              4); // was RA
 | 
|---|
| 84 |     fin.read((Byte_t*)dummy,              4); // was DEC
 | 
|---|
| 85 |     fin.read((Byte_t*)&fSourceEpochChar,  2);
 | 
|---|
| 86 |     fin.read((Byte_t*)&fSourceEpochDate,  2);
 | 
|---|
| 87 |     fin.read((Byte_t*)&fMJD,              4);
 | 
|---|
| 88 |     fin.read((Byte_t*)&fDateYear,         2);
 | 
|---|
| 89 |     fin.read((Byte_t*)&fDateMonth,        2);
 | 
|---|
| 90 |     fin.read((Byte_t*)&fDateDay,          2);
 | 
|---|
| 91 |     fin.read((Byte_t*)&fNumCrates,        2);
 | 
|---|
| 92 |     fin.read((Byte_t*)&fNumPixInCrate,    2);
 | 
|---|
| 93 |     fin.read((Byte_t*)&fNumSamplesLoGain, 2);
 | 
|---|
| 94 |     fin.read((Byte_t*)&fNumSamplesHiGain, 2);
 | 
|---|
| 95 |     fin.read((Byte_t*)&fNumEvents,        4);
 | 
|---|
| 96 | 
 | 
|---|
| 97 | 
 | 
|---|
| 98 |     //
 | 
|---|
| 99 |     // calculate size of array, create it and fill it
 | 
|---|
| 100 |     //
 | 
|---|
| 101 |     Int_t nPixel = fNumCrates*fNumPixInCrate;
 | 
|---|
| 102 |     fPixAssignment->Set(nPixel);
 | 
|---|
| 103 | 
 | 
|---|
| 104 |     fin.read((Byte_t*)fPixAssignment->GetArray(), nPixel*2);
 | 
|---|
| 105 |     fin.read((Byte_t*)&dummy, 16);
 | 
|---|
| 106 | }
 | 
|---|
| 107 | 
 | 
|---|
| 108 | void MRawRunHeader::Print(Option_t *t)
 | 
|---|
| 109 | {
 | 
|---|
| 110 |     //
 | 
|---|
| 111 |     // print run header information on screen
 | 
|---|
| 112 |     //
 | 
|---|
| 113 |     *fLog << endl;
 | 
|---|
| 114 |     *fLog << "MagicNumber:  0x" << hex << fMagicNumber << " - " << (fMagicNumber==kMagicNumber?"OK":"Wrong!") << endl;
 | 
|---|
| 115 |     *fLog << "Version:      " << dec << "Format=" << fFormatVersion << "  ";
 | 
|---|
| 116 |     *fLog << "Software=" << fSoftVersion << endl;
 | 
|---|
| 117 |     *fLog << "RunNumber:    " << fRunNumber << " (Type=";
 | 
|---|
| 118 |     switch (fRunType)
 | 
|---|
| 119 |     {
 | 
|---|
| 120 |     case 0:
 | 
|---|
| 121 |         *fLog << "Data";
 | 
|---|
| 122 |         break;
 | 
|---|
| 123 |     case 1:
 | 
|---|
| 124 |         *fLog << "Pedestal";
 | 
|---|
| 125 |         break;
 | 
|---|
| 126 |     case 2:
 | 
|---|
| 127 |         *fLog << "Calibration";
 | 
|---|
| 128 |         break;
 | 
|---|
| 129 |     }
 | 
|---|
| 130 |     *fLog << ")" << endl;
 | 
|---|
| 131 |     *fLog << "ProjectName: '" << fProjectName << "'" << endl;
 | 
|---|
| 132 |     *fLog << "Source:      '" << fSourceName << "' " << "  ";
 | 
|---|
| 133 |     *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
 | 
|---|
| 134 |     *fLog << "Date:         " << setprecision(1) << setiosflags(ios::fixed) << fMJD << " (MJD)  " << fDateYear << "/" << fDateMonth << "/" << fDateDay << endl;
 | 
|---|
| 135 |     *fLog << "Crates:       " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
 | 
|---|
| 136 |     *fLog << "Samples:      " << fNumSamplesLoGain << "/" << fNumSamplesHiGain << " (lo/hi) = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate /1024 << "kB/Evt" << endl;
 | 
|---|
| 137 |     *fLog << "Evt Counter:  " << fNumEvents << endl;
 | 
|---|
| 138 | 
 | 
|---|
| 139 |     *fLog << hex;
 | 
|---|
| 140 |     for (int i=0; i<GetNumPixel(); i++)
 | 
|---|
| 141 |         *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
 | 
|---|
| 142 |     *fLog << hex << endl;
 | 
|---|
| 143 | 
 | 
|---|
| 144 |     *fLog << endl;
 | 
|---|
| 145 | }
 | 
|---|
| 146 | 
 | 
|---|
| 147 | UShort_t MRawRunHeader::GetPixAssignment(UShort_t i) const
 | 
|---|
| 148 | {
 | 
|---|
| 149 |     // FIXME: Do we need a range check here?
 | 
|---|
| 150 |     return (*fPixAssignment)[i];
 | 
|---|
| 151 | }
 | 
|---|
| 152 | 
 | 
|---|
| 153 | UShort_t MRawRunHeader::GetNumPixel() const
 | 
|---|
| 154 | {
 | 
|---|
| 155 |     return fPixAssignment->GetSize();
 | 
|---|
| 156 | }
 | 
|---|