| 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-2004
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MRawRunHeader
|
|---|
| 28 | //
|
|---|
| 29 | // Root storage container for the RUN HEADER information
|
|---|
| 30 | //
|
|---|
| 31 | // Format Version 4:
|
|---|
| 32 | // -----------------
|
|---|
| 33 | // - added support for pixels with negative IDs
|
|---|
| 34 | //
|
|---|
| 35 | // Format Version 3:
|
|---|
| 36 | // -----------------
|
|---|
| 37 | // - ???
|
|---|
| 38 | //
|
|---|
| 39 | // Format Version 2:
|
|---|
| 40 | // -----------------
|
|---|
| 41 | // - removed mjd from data
|
|---|
| 42 | // - added start time
|
|---|
| 43 | // - added stop time
|
|---|
| 44 | //
|
|---|
| 45 | // Class Version 2:
|
|---|
| 46 | // ----------------
|
|---|
| 47 | // - removed fMJD, fYear, fMonth, fDay
|
|---|
| 48 | // - added fRunStart
|
|---|
| 49 | // - added fRunStop
|
|---|
| 50 | //
|
|---|
| 51 | // Class Version 1:
|
|---|
| 52 | // ----------------
|
|---|
| 53 | // - first implementation
|
|---|
| 54 | //
|
|---|
| 55 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 56 |
|
|---|
| 57 | #include "MRawRunHeader.h"
|
|---|
| 58 |
|
|---|
| 59 | #include <fstream>
|
|---|
| 60 | #include <iomanip>
|
|---|
| 61 |
|
|---|
| 62 | #include "MLog.h"
|
|---|
| 63 | #include "MLogManip.h"
|
|---|
| 64 |
|
|---|
| 65 | #include "MArrayS.h"
|
|---|
| 66 |
|
|---|
| 67 | ClassImp(MRawRunHeader);
|
|---|
| 68 |
|
|---|
| 69 | using namespace std;
|
|---|
| 70 |
|
|---|
| 71 | const UShort_t MRawRunHeader::kMagicNumber = 0xc0c0;
|
|---|
| 72 | const Byte_t MRawRunHeader::kMaxFormatVersion = 4;
|
|---|
| 73 |
|
|---|
| 74 | // --------------------------------------------------------------------------
|
|---|
| 75 | //
|
|---|
| 76 | // Default constructor. Creates array which stores the pixel assignment.
|
|---|
| 77 | //
|
|---|
| 78 | //
|
|---|
| 79 | MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
|
|---|
| 80 | {
|
|---|
| 81 | fName = name ? name : "MRawRunHeader";
|
|---|
| 82 | fTitle = title ? title : "Raw Run Header Information";
|
|---|
| 83 |
|
|---|
| 84 | fPixAssignment = new MArrayS(0);
|
|---|
| 85 |
|
|---|
| 86 | fFormatVersion=0;
|
|---|
| 87 | fSoftVersion=0;
|
|---|
| 88 | fRunType=kRTNone; // use 0xffff for invalidation, 0 means: Data run
|
|---|
| 89 | fRunNumber=0;
|
|---|
| 90 | fProjectName[0]=0;
|
|---|
| 91 | fSourceName[0]=0;
|
|---|
| 92 | fSourceEpochChar[0]=0;
|
|---|
| 93 | fSourceEpochDate=0;
|
|---|
| 94 | fNumCrates=0;
|
|---|
| 95 | fNumPixInCrate=0;
|
|---|
| 96 | fNumSamplesLoGain=0;
|
|---|
| 97 | fNumSamplesHiGain=0;
|
|---|
| 98 | fNumEvents=0;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | // --------------------------------------------------------------------------
|
|---|
| 102 | //
|
|---|
| 103 | // Destructor. Deletes the 'pixel-assignment-array'
|
|---|
| 104 | //
|
|---|
| 105 | MRawRunHeader::~MRawRunHeader()
|
|---|
| 106 | {
|
|---|
| 107 | delete fPixAssignment;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | // --------------------------------------------------------------------------
|
|---|
| 111 | //
|
|---|
| 112 | // Read in one run header from the binary file
|
|---|
| 113 | //
|
|---|
| 114 | Bool_t MRawRunHeader::ReadEvt(istream& fin)
|
|---|
| 115 | {
|
|---|
| 116 | //
|
|---|
| 117 | // read one RUN HEADER from the input stream
|
|---|
| 118 | //
|
|---|
| 119 | fMagicNumber = 0;
|
|---|
| 120 |
|
|---|
| 121 | fin.read((char*)&fMagicNumber, 2); // Total=2
|
|---|
| 122 |
|
|---|
| 123 | //
|
|---|
| 124 | // check whether the the file has the right file type or not
|
|---|
| 125 | //
|
|---|
| 126 | if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
|
|---|
| 127 | {
|
|---|
| 128 | *fLog << err << "Error: Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
|
|---|
| 129 | return kFALSE;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | if (fMagicNumber == kMagicNumber+1)
|
|---|
| 133 | *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
|
|---|
| 134 |
|
|---|
| 135 | Byte_t dummy[16];
|
|---|
| 136 |
|
|---|
| 137 | fin.read((char*)&fFormatVersion, 2); // Total=4
|
|---|
| 138 | if (fFormatVersion>kMaxFormatVersion)
|
|---|
| 139 | {
|
|---|
| 140 | *fLog << err << "WARNING - File vormat V" << fFormatVersion << " not implemented!" << endl;
|
|---|
| 141 | return kFALSE;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | fin.read((char*)&fSoftVersion, 2); // Total=6
|
|---|
| 145 | fin.read((char*)&fRunType, 2); // Total=8
|
|---|
| 146 | fin.read((char*)&fRunNumber, 4); // Total=12
|
|---|
| 147 | fin.read((char*)&fProjectName, 22); // Total=34
|
|---|
| 148 | fin.read((char*)&fSourceName, 12); // Total=46
|
|---|
| 149 | fin.read((char*)dummy, 4); // was RA (moved to tracking system)
|
|---|
| 150 | fin.read((char*)dummy, 4); // was DEC (moved to tracking system)
|
|---|
| 151 | fin.read((char*)&fSourceEpochChar, 2); // Total=56
|
|---|
| 152 | fin.read((char*)&fSourceEpochDate, 2); // Total=58
|
|---|
| 153 | if (fFormatVersion<2) // Total += 10
|
|---|
| 154 | {
|
|---|
| 155 | UShort_t y, m, d;
|
|---|
| 156 | fin.read((char*)dummy, 4); // Former fMJD[4],
|
|---|
| 157 | fin.read((char*)&y, 2); // Former fDateYear[2]
|
|---|
| 158 | fin.read((char*)&m, 2); // Former fDateMonth[2]
|
|---|
| 159 | fin.read((char*)&d, 2); // Former fDateDay[2]
|
|---|
| 160 | fRunStart.Set(y, m, d, 0, 0, 0, 0);
|
|---|
| 161 | }
|
|---|
| 162 | fin.read((char*)&fNumCrates, 2); // Total=60
|
|---|
| 163 | fin.read((char*)&fNumPixInCrate, 2); // Total=62
|
|---|
| 164 | fin.read((char*)&fNumSamplesLoGain, 2); // Total=64
|
|---|
| 165 | fin.read((char*)&fNumSamplesHiGain, 2); // Total=66
|
|---|
| 166 | fin.read((char*)&fNumEvents, 4); // Total=70
|
|---|
| 167 | if (fFormatVersion>1)
|
|---|
| 168 | {
|
|---|
| 169 | fRunStart.ReadBinary(fin); // Total += 7
|
|---|
| 170 | fRunStop.ReadBinary(fin); // Total += 7
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | //
|
|---|
| 174 | // calculate size of array, create it and fill it
|
|---|
| 175 | //
|
|---|
| 176 | Int_t nPixel = fNumCrates*fNumPixInCrate;
|
|---|
| 177 | fPixAssignment->Set(nPixel);
|
|---|
| 178 |
|
|---|
| 179 | fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
|
|---|
| 180 | fin.read((char*)&dummy, 16);
|
|---|
| 181 |
|
|---|
| 182 | return kTRUE;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | // --------------------------------------------------------------------------
|
|---|
| 186 | //
|
|---|
| 187 | // Return the run type as string ("Data", "Pedestal", ...), for example
|
|---|
| 188 | // to print it as readable text.
|
|---|
| 189 | //
|
|---|
| 190 | const char *MRawRunHeader::GetRunTypeStr() const
|
|---|
| 191 | {
|
|---|
| 192 | switch (fRunType)
|
|---|
| 193 | {
|
|---|
| 194 | case kRTData:
|
|---|
| 195 | return "Data";
|
|---|
| 196 | case kRTPedestal:
|
|---|
| 197 | return "Pedestal";
|
|---|
| 198 | case kRTCalibration:
|
|---|
| 199 | return "Calibration";
|
|---|
| 200 | case kRTPointRun:
|
|---|
| 201 | return "Point-Run";
|
|---|
| 202 | case kRTMonteCarlo:
|
|---|
| 203 | return "Monte Carlo";
|
|---|
| 204 | case kRTNone:
|
|---|
| 205 | return "<none>";
|
|---|
| 206 | default:
|
|---|
| 207 | return "<unknown>";
|
|---|
| 208 | }
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | // --------------------------------------------------------------------------
|
|---|
| 212 | //
|
|---|
| 213 | // print run header information on *fLog. The option 'header' supresses
|
|---|
| 214 | // the pixel index translation table.
|
|---|
| 215 | //
|
|---|
| 216 | void MRawRunHeader::Print(Option_t *t) const
|
|---|
| 217 | {
|
|---|
| 218 | *fLog << all << endl;
|
|---|
| 219 | *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - ";
|
|---|
| 220 | switch (fMagicNumber)
|
|---|
| 221 | {
|
|---|
| 222 | case kMagicNumber: *fLog << "OK"; break;
|
|---|
| 223 | case kMagicNumber+1: *fLog << "File not closed!"; break;
|
|---|
| 224 | default: *fLog << "Wrong!"; break;
|
|---|
| 225 | }
|
|---|
| 226 | *fLog << endl;
|
|---|
| 227 | *fLog << "Version: " << dec << "Format=" << fFormatVersion << " ";
|
|---|
| 228 | *fLog << "Software=" << fSoftVersion << endl;
|
|---|
| 229 | *fLog << "RunNumber: " << fRunNumber << " (Type=" << GetRunTypeStr() << ")" << endl;
|
|---|
| 230 | *fLog << "ProjectName: '" << fProjectName << "'" << endl;
|
|---|
| 231 | *fLog << "Source: '" << fSourceName << "' " << " ";
|
|---|
| 232 | *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
|
|---|
| 233 | *fLog << "Run Start: " << fRunStart << endl;
|
|---|
| 234 | *fLog << "Run Stop: " << fRunStop << endl;
|
|---|
| 235 | *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
|
|---|
| 236 | *fLog << "Samples: " << fNumSamplesLoGain << "/" << fNumSamplesHiGain << " (lo/hi) = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate /1024 << "kB/Evt" << endl;
|
|---|
| 237 | *fLog << "Evt Counter: " << fNumEvents << endl;
|
|---|
| 238 |
|
|---|
| 239 | if (TString(t).Contains("header", TString::kIgnoreCase))
|
|---|
| 240 | return;
|
|---|
| 241 |
|
|---|
| 242 | *fLog << inf << hex;
|
|---|
| 243 | for (int i=0; i<GetNumPixel(); i++)
|
|---|
| 244 | *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
|
|---|
| 245 |
|
|---|
| 246 | *fLog << endl;
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | // --------------------------------------------------------------------------
|
|---|
| 250 | //
|
|---|
| 251 | // Return the assigned pixel number for the given FADC channel
|
|---|
| 252 | //
|
|---|
| 253 | Short_t MRawRunHeader::GetPixAssignment(UShort_t i) const
|
|---|
| 254 | {
|
|---|
| 255 | // FIXME: Do we need a range check here?
|
|---|
| 256 | return (Short_t)(*fPixAssignment)[i];
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | // --------------------------------------------------------------------------
|
|---|
| 260 | //
|
|---|
| 261 | // Return the number of pixel which are markes as connected in the
|
|---|
| 262 | // pix assignment (!=0)
|
|---|
| 263 | //
|
|---|
| 264 | UShort_t MRawRunHeader::GetNumConnectedPixels() const
|
|---|
| 265 | {
|
|---|
| 266 | const Int_t num = fPixAssignment->GetSize();
|
|---|
| 267 |
|
|---|
| 268 | UShort_t rc = 0;
|
|---|
| 269 | for (int i=0; i<num; i++)
|
|---|
| 270 | {
|
|---|
| 271 | if (GetPixAssignment(i)!=0)
|
|---|
| 272 | rc++;
|
|---|
| 273 | }
|
|---|
| 274 | return rc;
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | // --------------------------------------------------------------------------
|
|---|
| 278 | //
|
|---|
| 279 | // Return the number of pixel which are markes as connected and so-called
|
|---|
| 280 | // 'normal' pixels in the pix assignment (>0)
|
|---|
| 281 | //
|
|---|
| 282 | UShort_t MRawRunHeader::GetNumNormalPixels() const
|
|---|
| 283 | {
|
|---|
| 284 | const Int_t num = fPixAssignment->GetSize();
|
|---|
| 285 |
|
|---|
| 286 | UShort_t rc = 0;
|
|---|
| 287 | for (int i=0; i<num; i++)
|
|---|
| 288 | {
|
|---|
| 289 | if (GetPixAssignment(i)>0)
|
|---|
| 290 | rc++;
|
|---|
| 291 | }
|
|---|
| 292 | return rc;
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | // --------------------------------------------------------------------------
|
|---|
| 296 | //
|
|---|
| 297 | // Return the number of pixel which are markes as connected and so-called
|
|---|
| 298 | // 'special' pixels in the pix assignment (<0)
|
|---|
| 299 | //
|
|---|
| 300 | UShort_t MRawRunHeader::GetNumSpecialPixels() const
|
|---|
| 301 | {
|
|---|
| 302 | const Int_t num = fPixAssignment->GetSize();
|
|---|
| 303 |
|
|---|
| 304 | UShort_t rc = 0;
|
|---|
| 305 | for (int i=0; i<num; i++)
|
|---|
| 306 | {
|
|---|
| 307 | if (GetPixAssignment(i)<0)
|
|---|
| 308 | rc++;
|
|---|
| 309 | }
|
|---|
| 310 | return rc;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | // --------------------------------------------------------------------------
|
|---|
| 314 | //
|
|---|
| 315 | // Return the maximum id which exists in the pix assignment
|
|---|
| 316 | //
|
|---|
| 317 | UShort_t MRawRunHeader::GetMaxPixId() const
|
|---|
| 318 | {
|
|---|
| 319 | const Int_t num = fPixAssignment->GetSize();
|
|---|
| 320 |
|
|---|
| 321 | Short_t rc = 0;
|
|---|
| 322 | for (int i=0; i<num; i++)
|
|---|
| 323 | rc = TMath::Max(GetPixAssignment(i), rc);
|
|---|
| 324 |
|
|---|
| 325 | return rc;
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | // --------------------------------------------------------------------------
|
|---|
| 329 | //
|
|---|
| 330 | // Return minus th minimum id which exists in the pix assignment
|
|---|
| 331 | //
|
|---|
| 332 | UShort_t MRawRunHeader::GetMinPixId() const
|
|---|
| 333 | {
|
|---|
| 334 | const Int_t num = fPixAssignment->GetSize();
|
|---|
| 335 |
|
|---|
| 336 | Short_t rc = 0;
|
|---|
| 337 | for (int i=0; i<num; i++)
|
|---|
| 338 | rc = TMath::Min(GetPixAssignment(i), rc);
|
|---|
| 339 |
|
|---|
| 340 | return (UShort_t)-rc;
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | // --------------------------------------------------------------------------
|
|---|
| 344 | //
|
|---|
| 345 | // Return the number of pixel in this event.
|
|---|
| 346 | //
|
|---|
| 347 | // WARNING: This is the number of pixels stored in this file which is
|
|---|
| 348 | // a multiple of the number of pixels per crate and in general
|
|---|
| 349 | // a number which is larger than the camera size!
|
|---|
| 350 | //
|
|---|
| 351 | // To know the range of the pixel indices please use the geometry
|
|---|
| 352 | // container!
|
|---|
| 353 | //
|
|---|
| 354 | UShort_t MRawRunHeader::GetNumPixel() const
|
|---|
| 355 | {
|
|---|
| 356 | return fPixAssignment->GetSize();
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | // --------------------------------------------------------------------------
|
|---|
| 360 | //
|
|---|
| 361 | // Returns absolute size in bytes of the run header as read from a raw file.
|
|---|
| 362 | // This must be done _after_ the header is read, because the header doesn't
|
|---|
| 363 | // have a fixed size (used in MRawSocketRead)
|
|---|
| 364 | //
|
|---|
| 365 | Int_t MRawRunHeader::GetNumTotalBytes() const
|
|---|
| 366 | {
|
|---|
| 367 | switch (fFormatVersion)
|
|---|
| 368 | {
|
|---|
| 369 | case 1:
|
|---|
| 370 | return 80+fNumCrates*fNumPixInCrate*2+16;
|
|---|
| 371 | case 2:
|
|---|
| 372 | return 84+fNumCrates*fNumPixInCrate*2+16;
|
|---|
| 373 | }
|
|---|
| 374 | return 0;
|
|---|
| 375 | }
|
|---|