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