| 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 | #include "MString.h"
|
|---|
| 159 |
|
|---|
| 160 | ClassImp(MRawRunHeader);
|
|---|
| 161 |
|
|---|
| 162 | using namespace std;
|
|---|
| 163 |
|
|---|
| 164 | const UShort_t MRawRunHeader::kMagicNumber = 0xc0c0;
|
|---|
| 165 | const Byte_t MRawRunHeader::kMaxFormatVersion = 11;
|
|---|
| 166 |
|
|---|
| 167 | // --------------------------------------------------------------------------
|
|---|
| 168 | //
|
|---|
| 169 | // Default constructor. Creates array which stores the pixel assignment.
|
|---|
| 170 | //
|
|---|
| 171 | //
|
|---|
| 172 | MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
|
|---|
| 173 | {
|
|---|
| 174 | fName = name ? name : "MRawRunHeader";
|
|---|
| 175 | fTitle = title ? title : "Raw Run Header Information";
|
|---|
| 176 |
|
|---|
| 177 | fPixAssignment = new MArrayS(0);
|
|---|
| 178 |
|
|---|
| 179 | // Remark: If we read old MC data from a root file which do not
|
|---|
| 180 | // yet contain one of these variable, the value given here is
|
|---|
| 181 | // the default. Do not mix files with and without a value if the
|
|---|
| 182 | // files with the value do not match the default!
|
|---|
| 183 | fFormatVersion=11;
|
|---|
| 184 | fSoftVersion=0;
|
|---|
| 185 | fTelescopeNumber=1;
|
|---|
| 186 | fCameraVersion=1;
|
|---|
| 187 | fFadcType=1;
|
|---|
| 188 | fRunType=kRTNone; // use 0xffff for invalidation, 0 means: Data run
|
|---|
| 189 | fRunNumber=0;
|
|---|
| 190 | fFileNumber=0;
|
|---|
| 191 | memset(fProjectName, 0, 101);
|
|---|
| 192 | memset(fSourceName, 0, 81);
|
|---|
| 193 | memset(fObservationMode, 0, 61);
|
|---|
| 194 | fSourceEpochChar[0]=0;
|
|---|
| 195 | fSourceEpochDate=0;
|
|---|
| 196 | fNumCrates=0;
|
|---|
| 197 | fNumPixInCrate=0;
|
|---|
| 198 | fNumSamplesLoGain=0;
|
|---|
| 199 | fNumSamplesHiGain=0;
|
|---|
| 200 | fNumEvents=0;
|
|---|
| 201 | fNumBytesPerSample=1;
|
|---|
| 202 | fSamplingFrequency=300;
|
|---|
| 203 | fFadcResolution=8;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | // --------------------------------------------------------------------------
|
|---|
| 207 | //
|
|---|
| 208 | // Destructor. Deletes the 'pixel-assignment-array'
|
|---|
| 209 | //
|
|---|
| 210 | MRawRunHeader::~MRawRunHeader()
|
|---|
| 211 | {
|
|---|
| 212 | delete fPixAssignment;
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | // --------------------------------------------------------------------------
|
|---|
| 216 | //
|
|---|
| 217 | // Swap the assignment of the pixels with hardware id id0 and id1
|
|---|
| 218 | //
|
|---|
| 219 | Bool_t MRawRunHeader::SwapAssignment(Short_t id0, Short_t id1)
|
|---|
| 220 | {
|
|---|
| 221 | const Int_t n = fPixAssignment->GetSize();
|
|---|
| 222 |
|
|---|
| 223 | // Look-up-table
|
|---|
| 224 | UShort_t *lut = fPixAssignment->GetArray();
|
|---|
| 225 |
|
|---|
| 226 | // Search for one of the hardware indices to get exchanged
|
|---|
| 227 | int i;
|
|---|
| 228 | for (i=0; i<n; i++)
|
|---|
| 229 | if (lut[i]==id0 || lut[i]==id1)
|
|---|
| 230 | break;
|
|---|
| 231 |
|
|---|
| 232 | // Check if one of the two pixels were found
|
|---|
| 233 | if (i==n)
|
|---|
| 234 | {
|
|---|
| 235 | *fLog << warn << "WARNING - Assignment of pixels with hardware ID " << id0 << " and " << id1;
|
|---|
| 236 | *fLog << " should be exchanged, but none were found." << endl;
|
|---|
| 237 | return kTRUE;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | // Store first index
|
|---|
| 241 | const Int_t idx0 = i;
|
|---|
| 242 |
|
|---|
| 243 | // Search for the other hardware indices to get exchanged
|
|---|
| 244 | for (i++; i<n; i++)
|
|---|
| 245 | if (lut[i]==id0 || lut[i]==id1)
|
|---|
| 246 | break;
|
|---|
| 247 |
|
|---|
| 248 | // Check if the second pixel was found
|
|---|
| 249 | if (i==n)
|
|---|
| 250 | {
|
|---|
| 251 | *fLog << err << "ERROR - Assignment of pixels with hardware ID " << id0 << " and " << id1;
|
|---|
| 252 | *fLog << " should be exchanged, but only one was found." << endl;
|
|---|
| 253 | return kFALSE;
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 | const Int_t idx1 = i;
|
|---|
| 257 |
|
|---|
| 258 | const Short_t p0 = lut[idx0];
|
|---|
| 259 | const Short_t p1 = lut[idx1];
|
|---|
| 260 |
|
|---|
| 261 | lut[idx0] = p1;
|
|---|
| 262 | lut[idx1] = p0;
|
|---|
| 263 |
|
|---|
| 264 | *fLog << inf << "Assignment of pixels with hardware ID " << id0 << " and " << id1 << " exchanged." << endl;
|
|---|
| 265 |
|
|---|
| 266 | return kTRUE;
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | // --------------------------------------------------------------------------
|
|---|
| 270 | //
|
|---|
| 271 | // Return Telescope number, runnumber and filenumber on the form:
|
|---|
| 272 | // run
|
|---|
| 273 | // as string for runnumber<1000000 and
|
|---|
| 274 | // telescope:run/file
|
|---|
| 275 | // otherwise.
|
|---|
| 276 | //
|
|---|
| 277 | TString MRawRunHeader::GetStringID() const
|
|---|
| 278 | {
|
|---|
| 279 | return fRunNumber<1000000?MString::Format("%d", fRunNumber):MString::Format("%d:%d/%d", fTelescopeNumber, fRunNumber, fFileNumber);
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | // --------------------------------------------------------------------------
|
|---|
| 283 | //
|
|---|
| 284 | // Consistency checks. See code for detils.
|
|---|
| 285 | //
|
|---|
| 286 | Bool_t MRawRunHeader::IsConsistent() const
|
|---|
| 287 | {
|
|---|
| 288 | // FIXME: Match first digits of run-number with telescope number
|
|---|
| 289 |
|
|---|
| 290 | if (fFormatVersion>10)
|
|---|
| 291 | {
|
|---|
| 292 | if (GetTypeID()!=fTelescopeNumber &&
|
|---|
| 293 | GetTypeID()!=fTelescopeNumber*10U &&
|
|---|
| 294 | GetTypeID()!=fTelescopeNumber*10U+5U)
|
|---|
| 295 | {
|
|---|
| 296 | *fLog << err << "ERROR - Telscope number " << fTelescopeNumber << " doesn't match the first two digits of the run number " << fRunNumber << "." << endl;
|
|---|
| 297 | return kFALSE;
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | // Old formats can not contain a run number larger 999999
|
|---|
| 301 | if (fRunNumber<1000000)
|
|---|
| 302 | {
|
|---|
| 303 | *fLog << err << "ERROR - Run number " << fRunNumber << " smaller than 1000000." << endl;
|
|---|
| 304 | return kFALSE;
|
|---|
| 305 | }
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | // Check for correct number of bytes in data stream
|
|---|
| 309 | if (fFormatVersion>7 && fNumBytesPerSample!=2)
|
|---|
| 310 | {
|
|---|
| 311 | *fLog << err << "ERROR - " << fNumBytesPerSample << " bytes per sample are not supported!" << endl;
|
|---|
| 312 | return kFALSE;
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | // If we have a vlid stop time check its consistency with the start time
|
|---|
| 316 | if (fRunStop!=MTime() && fRunStop<fRunStart)
|
|---|
| 317 | {
|
|---|
| 318 | *fLog << err << "ERROR - Stop time smaller than start time." << endl;
|
|---|
| 319 | return kFALSE;
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 | // No file numbers larger than 999 allowed in general
|
|---|
| 323 | if (fFileNumber>999)
|
|---|
| 324 | {
|
|---|
| 325 | *fLog << err << "ERROR - File number " << fFileNumber << " larger than 999." << endl;
|
|---|
| 326 | return kFALSE;
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | // Old formats can not contain a run number larger 0
|
|---|
| 330 | if (fFormatVersion<11 && fFileNumber>0)
|
|---|
| 331 | {
|
|---|
| 332 | *fLog << err << "ERROR - File number " << fFileNumber << " larger than 0." << endl;
|
|---|
| 333 | return kFALSE;
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | if (fFormatVersion>1)
|
|---|
| 337 | {
|
|---|
| 338 | // For most of the formats the start time must be valid
|
|---|
| 339 | if (fRunStart==MTime())
|
|---|
| 340 | {
|
|---|
| 341 | *fLog << err << "ERROR - Start time invalid." << endl;
|
|---|
| 342 | return kFALSE;
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | // For most of the formats an invalid stop time cannot happen if file closed
|
|---|
| 346 | if (fMagicNumber==kMagicNumber && fRunStop==MTime())
|
|---|
| 347 | {
|
|---|
| 348 | *fLog << err << "ERROR - File closed but stop time invalid." << endl;
|
|---|
| 349 | return kFALSE;
|
|---|
| 350 | }
|
|---|
| 351 | }
|
|---|
| 352 | return kTRUE;
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 | void MRawRunHeader::FixRunNumbers()
|
|---|
| 356 | {
|
|---|
| 357 | if (fFormatVersion<11 || fTelescopeNumber!=1)
|
|---|
| 358 | return;
|
|---|
| 359 |
|
|---|
| 360 | // Map 1:1001349 to 47:1001395
|
|---|
| 361 | if (fRunNumber<48 &&
|
|---|
| 362 | fRunStart.GetMjd()>54674.5 && fRunStart.GetMjd()<56476.5)
|
|---|
| 363 | {
|
|---|
| 364 | fRunNumber += 1001348;
|
|---|
| 365 | *fLog << warn << "Format >V10: Wrong run number increased by 1001348 to " << fRunNumber << "." << endl;
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | // Map 1001916:1001922 to 1002349:1002355
|
|---|
| 369 | if (fRunNumber>1001915 && fRunNumber<1001923 &&
|
|---|
| 370 | fRunStart.GetMjd()>54710.5 && fRunStart.GetMjd()<54711.5)
|
|---|
| 371 | {
|
|---|
| 372 | fRunNumber += 433;
|
|---|
| 373 | *fLog << warn << "Format >V10: Wrong run number increased by 434 to " << fRunNumber << "." << endl;
|
|---|
| 374 | }
|
|---|
| 375 |
|
|---|
| 376 | // Map 10000342:1000343 to 10000351:1000351
|
|---|
| 377 | if (fRunNumber>10000342 && fRunNumber<10000352 &&
|
|---|
| 378 | fRunStart.GetMjd()>54254.5 && fRunStart.GetMjd()<54255.5)
|
|---|
| 379 | {
|
|---|
| 380 | fRunNumber -= 9000000;
|
|---|
| 381 | *fLog << warn << "Format >V10: Wrong run number decreased by 9000000 to " << fRunNumber << "." << endl;
|
|---|
| 382 | }
|
|---|
| 383 |
|
|---|
| 384 | if (fRunNumber==1000382 &&
|
|---|
| 385 | fRunStart.GetMjd()>54256.5 && fRunStart.GetMjd()<54257.5 &&
|
|---|
| 386 | !strcmp(fSourceName, "GRB080605-2347"))
|
|---|
| 387 | {
|
|---|
| 388 | fFileNumber += 99;
|
|---|
| 389 | *fLog << warn << "Format >V10: Ambiguous file number increased by 99 to " << fFileNumber << "." << endl;
|
|---|
| 390 | }
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | // --------------------------------------------------------------------------
|
|---|
| 394 | //
|
|---|
| 395 | // This implements a fix of the pixel assignment before 25.9.2005
|
|---|
| 396 | //
|
|---|
| 397 | // From magic_online (the pixel numbers are hardware indices):
|
|---|
| 398 | // --------------------------------------------------------------------------
|
|---|
| 399 | // From: Florian Goebel <fgoebel@mppmu.mpg.de>
|
|---|
| 400 | // Date: Sun Sep 25 2005 - 05:13:19 CEST
|
|---|
| 401 | //
|
|---|
| 402 | // [...]
|
|---|
| 403 | // - problem 2: pixels were swaped
|
|---|
| 404 | // - cause: opical fibers were wrongly connected to receiver board
|
|---|
| 405 | // 554 <-> 559
|
|---|
| 406 | // 555 <-> 558
|
|---|
| 407 | // 556 <-> 557
|
|---|
| 408 | // - action: reconnect correctly
|
|---|
| 409 | // - result: ok now
|
|---|
| 410 | // - comment: I don't know when this error was introduced, so backward
|
|---|
| 411 | // correction of the data is difficult.
|
|---|
| 412 | // Fortunately the effect is not too large since the affected 6 pixels are
|
|---|
| 413 | // on the outermost edge of the camera
|
|---|
| 414 | // Since this board has special pixels the optical fibers have been
|
|---|
| 415 | // unplugged several times.
|
|---|
| 416 | // !!!!! Whenever you unplug and reconnect optical fibers make really !!!!!
|
|---|
| 417 | // !!!!! sure you connect them back correctly. !!!!!
|
|---|
| 418 | // !!!!! Always contact me before you do so and if you have any doubts !!!!!
|
|---|
| 419 | // !!!!! how to reconnect the fibers ask me. !!!!!
|
|---|
| 420 | // These swapped pixels have only been found by chance when doing the
|
|---|
| 421 | // flatfielding.
|
|---|
| 422 | // [...]
|
|---|
| 423 | //
|
|---|
| 424 | // --------------------------------------------------------------------------
|
|---|
| 425 | //
|
|---|
| 426 | // MAGIC runbook CC_2006_04_22_22_28_52.rbk
|
|---|
| 427 | //
|
|---|
| 428 | // [2006-04-22 23:14:13]
|
|---|
| 429 | //
|
|---|
| 430 | // [...]
|
|---|
| 431 | // Found 2 pairs of swapped pixels.
|
|---|
| 432 | // We corrected swapped pixels 54<->55 in the receiver boards. We probably
|
|---|
| 433 | // swapped today in the camera.
|
|---|
| 434 | // We did not correct 92<-<93 which are likely swapped. Will check and correct
|
|---|
| 435 | // tomorrow.
|
|---|
| 436 | //
|
|---|
| 437 | // ---
|
|---|
| 438 | //
|
|---|
| 439 | // comments:
|
|---|
| 440 | // - 54<->55 were corrected but have not been swapped, hence they are swapped
|
|---|
| 441 | // since then (run 88560 ok, run 88669 swapped; between them mostly dummy and
|
|---|
| 442 | // test runs)
|
|---|
| 443 | // - 92<->93 are never swapped, always ok.
|
|---|
| 444 | //
|
|---|
| 445 | // --------------------------------------------------------------------------
|
|---|
| 446 | //
|
|---|
| 447 | // MAGIC runbook CC_2006_08_28_19_40_18.rbk
|
|---|
| 448 | //
|
|---|
| 449 | // [2006-08-28 23:09:07]
|
|---|
| 450 | // While doing a flatfielding we have found out that the signals for pixels
|
|---|
| 451 | // 119 and 120 were swapped. We have fixed it by exchanging the corresponding
|
|---|
| 452 | // fibers at the input of the receivers (not before the splitters!).
|
|---|
| 453 | //
|
|---|
| 454 | // ---
|
|---|
| 455 | //
|
|---|
| 456 | // MAGIC runbook CC_2006_08_29_15_19_14.rbk
|
|---|
| 457 | //
|
|---|
| 458 | // [2006-08-29 16:43:09]
|
|---|
| 459 | // In the last hours we have found out and fixed a good number of pixels which
|
|---|
| 460 | // were swapped: 119-120, 160-161-162 and 210-263. According to Florian,
|
|---|
| 461 | // 160-161-162 and 210-263 were swapped since November 2005.
|
|---|
| 462 | //
|
|---|
| 463 | // ---
|
|---|
| 464 | //
|
|---|
| 465 | // mail Florian Goebel (08/30/2006 03:13 PM):
|
|---|
| 466 | //
|
|---|
| 467 | // As far as I can tell pixels 161 and 162 as well as 263 and 210 were
|
|---|
| 468 | // swapped in the trigger. This leads to some inefficiency of the trigger.
|
|---|
| 469 | // However, they were not swapped in the readout. So, you don't have to
|
|---|
| 470 | // correct anything in the data for these pixels.
|
|---|
| 471 | //
|
|---|
| 472 | // ---
|
|---|
| 473 | //
|
|---|
| 474 | // comments:
|
|---|
| 475 | // - 119-120 swapped between run 93251 (not swapped) and 93283 (swapped)
|
|---|
| 476 | // (only testruns between these runs)
|
|---|
| 477 | // corrected since run 99354 (== runbook [2006-08-28 23:09:07])
|
|---|
| 478 | // - 160 never swapped
|
|---|
| 479 | // - 161-162 were only swapped in the trigger, but nevertheless were
|
|---|
| 480 | // "corrected" also in the signal. Hence signal swapped since 99354
|
|---|
| 481 | //
|
|---|
| 482 | Bool_t MRawRunHeader::FixAssignment()
|
|---|
| 483 | {
|
|---|
| 484 | if (!fTelescopeNumber==1)
|
|---|
| 485 | return kTRUE;
|
|---|
| 486 |
|
|---|
| 487 | if (fRunNumber>=53300 && fRunNumber<=68754)
|
|---|
| 488 | {
|
|---|
| 489 | if (!SwapAssignment(554, 559))
|
|---|
| 490 | return kFALSE;
|
|---|
| 491 | if (!SwapAssignment(555, 558))
|
|---|
| 492 | return kFALSE;
|
|---|
| 493 | if (!SwapAssignment(556, 557))
|
|---|
| 494 | return kFALSE;
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | if (fRunNumber>=93283 && fRunNumber<99354)
|
|---|
| 498 | {
|
|---|
| 499 | if (!SwapAssignment(119, 120))
|
|---|
| 500 | return kFALSE;
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 | if (fRunNumber>=99354 && fRunNumber<=101789)
|
|---|
| 504 | {
|
|---|
| 505 | if (!SwapAssignment(161, 162))
|
|---|
| 506 | return kFALSE;
|
|---|
| 507 | if (!SwapAssignment(210, 263))
|
|---|
| 508 | return kFALSE;
|
|---|
| 509 | }
|
|---|
| 510 |
|
|---|
| 511 | if (fRunNumber>=88669)
|
|---|
| 512 | {
|
|---|
| 513 | if (!SwapAssignment(54, 55))
|
|---|
| 514 | return kFALSE;
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 | if (fRunNumber>=200000)
|
|---|
| 518 | {
|
|---|
| 519 | if (!SwapAssignment(428, 429))
|
|---|
| 520 | return kFALSE;
|
|---|
| 521 | }
|
|---|
| 522 |
|
|---|
| 523 | return kTRUE;
|
|---|
| 524 | }
|
|---|
| 525 |
|
|---|
| 526 | // --------------------------------------------------------------------------
|
|---|
| 527 | //
|
|---|
| 528 | // Fixes to fix bugs in the run header
|
|---|
| 529 | //
|
|---|
| 530 | Bool_t MRawRunHeader::Fixes()
|
|---|
| 531 | {
|
|---|
| 532 | FixRunNumbers();
|
|---|
| 533 |
|
|---|
| 534 | if (fFormatVersion>8 && fRunNumber>326152 && fTelescopeNumber==1)
|
|---|
| 535 | {
|
|---|
| 536 | fNumEvents--;
|
|---|
| 537 | fNumEventsRead--;
|
|---|
| 538 | *fLog << inf << "Format >V8 and Run>M1:326152: Stored number of events decreased by 1." << endl;
|
|---|
| 539 | }
|
|---|
| 540 |
|
|---|
| 541 | return FixAssignment();
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | // --------------------------------------------------------------------------
|
|---|
| 545 | //
|
|---|
| 546 | // Reading function to read/interpret the file formats 1-10
|
|---|
| 547 | //
|
|---|
| 548 | Bool_t MRawRunHeader::ReadEvtOld(istream& fin)
|
|---|
| 549 | {
|
|---|
| 550 | if (fFormatVersion==7)
|
|---|
| 551 | {
|
|---|
| 552 | *fLog << err << "ERROR - File format V7 was for testing only and is not correctly implemented!" << endl;
|
|---|
| 553 | return kFALSE;
|
|---|
| 554 | }
|
|---|
| 555 |
|
|---|
| 556 | // ----- DAQ software format version -----
|
|---|
| 557 | fin.read((char*)&fSoftVersion, 2); // Total=6
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 | fFadcType = 1;
|
|---|
| 561 | if (fFormatVersion>7)
|
|---|
| 562 | fin.read((char*)&fFadcType, 2);
|
|---|
| 563 |
|
|---|
| 564 | // ----- Camera geometry and telescope number -----
|
|---|
| 565 | fCameraVersion = 1;
|
|---|
| 566 | fTelescopeNumber = 1;
|
|---|
| 567 | if (fFormatVersion>5)
|
|---|
| 568 | {
|
|---|
| 569 | fin.read((char*)&fCameraVersion, 2); // (+2)
|
|---|
| 570 | fin.read((char*)&fTelescopeNumber, 2); // (+2)
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | // ----- Run information -----
|
|---|
| 574 | fin.read((char*)&fRunType, 2); // Total=8
|
|---|
| 575 |
|
|---|
| 576 | fin.read((char*)&fRunNumber, 4); // Total=12
|
|---|
| 577 | fin.read((char*)&fProjectName, fFormatVersion>5?100:22); // Total=34 (+78)
|
|---|
| 578 | fin.read((char*)&fSourceName, fFormatVersion>5? 80:12); // Total=46 (+58)
|
|---|
| 579 |
|
|---|
| 580 | if (fFormatVersion>5)
|
|---|
| 581 | fin.read((char*)fObservationMode, 60); // (+60)
|
|---|
| 582 | // Maybe we should set fObservationMode to something
|
|---|
| 583 | // in case of fFormatVersion<6
|
|---|
| 584 |
|
|---|
| 585 | // ----- Source position -----
|
|---|
| 586 | fin.seekg(fFormatVersion>5 ? 16 : 8, ios::cur);
|
|---|
| 587 | /*
|
|---|
| 588 | if (fFormatVersion>5)
|
|---|
| 589 | {
|
|---|
| 590 | fin.read((char*)&fSourceRa, 4); // F32 SourceRA; Total=48
|
|---|
| 591 | fin.read((char*)&fSourceDec, 4); // F32 SourceDEC; Total=52
|
|---|
| 592 | }
|
|---|
| 593 | fin.read((char*)&fTelescopeRa, 4); // F32 TelescopeRA; (+4)
|
|---|
| 594 | fin.read((char*)&fTelescopeDec, 4); // F32 TelescopeDEC; (+4)
|
|---|
| 595 | */
|
|---|
| 596 |
|
|---|
| 597 | // Maybe we should set these to something
|
|---|
| 598 | // in case of fFormatVersion<6
|
|---|
| 599 | fin.read((char*)&fSourceEpochChar, 2); // Total=56
|
|---|
| 600 | fin.read((char*)&fSourceEpochDate, 2); // Total=58
|
|---|
| 601 |
|
|---|
| 602 | // ----- Old Start time -----
|
|---|
| 603 | if (fFormatVersion<2) // Total += 10
|
|---|
| 604 | {
|
|---|
| 605 | UShort_t y, m, d;
|
|---|
| 606 | fin.seekg(4, ios::cur); // Former fMJD[4],
|
|---|
| 607 | fin.read((char*)&y, 2); // Former fDateYear[2]
|
|---|
| 608 | fin.read((char*)&m, 2); // Former fDateMonth[2]
|
|---|
| 609 | fin.read((char*)&d, 2); // Former fDateDay[2]
|
|---|
| 610 | fRunStart.Set(y, m, d, 0, 0, 0, 0);
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | // ----- Data Geometry -----
|
|---|
| 614 |
|
|---|
| 615 | fin.read((char*)&fNumCrates, 2); // MUX: number of channels
|
|---|
| 616 | fin.read((char*)&fNumPixInCrate, 2); // MUX: number of pix in channel
|
|---|
| 617 | fin.read((char*)&fNumSamplesLoGain, 2); // MUX: dummy (must be 0 for MUX data)
|
|---|
| 618 | fin.read((char*)&fNumSamplesHiGain, 2); // MUX: Number of samples per pixel
|
|---|
| 619 |
|
|---|
| 620 | char dummy[16];
|
|---|
| 621 | if (fFormatVersion>8)
|
|---|
| 622 | fin.read(dummy, 4); // 2xU16 (NumSamplesRemovedHead and NumSamplesRemovedTail)
|
|---|
| 623 |
|
|---|
| 624 | // ----- Number of events -----
|
|---|
| 625 | fin.read((char*)&fNumEvents, 4); // Total=70
|
|---|
| 626 |
|
|---|
| 627 | if (fFormatVersion>8)
|
|---|
| 628 | fin.read((char*)&fNumEventsRead, 4);
|
|---|
| 629 |
|
|---|
| 630 | // New in general features: (should they be included in new MAGIC1 formats, too?)
|
|---|
| 631 | fNumBytesPerSample = 1; // 2 for MUX DATA
|
|---|
| 632 | fSamplingFrequency = 300;
|
|---|
| 633 | fFadcResolution = 8;
|
|---|
| 634 |
|
|---|
| 635 | if (fFormatVersion>7)
|
|---|
| 636 | {
|
|---|
| 637 | fin.read((char*)&fNumBytesPerSample, 2);
|
|---|
| 638 | fin.read((char*)&fSamplingFrequency, 2); // [MHz], 2000 for MuxFadc
|
|---|
| 639 | fin.read((char*)&fFadcResolution, 1); // nominal resolution [# Bits], 10 for MuxFadc
|
|---|
| 640 | }
|
|---|
| 641 |
|
|---|
| 642 | // ----- Start/Stop time -----
|
|---|
| 643 | if (fFormatVersion>1)
|
|---|
| 644 | {
|
|---|
| 645 | fRunStart.ReadBinary(fin); // Total += 7
|
|---|
| 646 | fRunStop.ReadBinary(fin); // Total += 7
|
|---|
| 647 | }
|
|---|
| 648 |
|
|---|
| 649 | //
|
|---|
| 650 | // calculate size of array, create it and fill it
|
|---|
| 651 | //
|
|---|
| 652 | const Int_t nPixel = fNumCrates*fNumPixInCrate;
|
|---|
| 653 | fPixAssignment->Set(nPixel);
|
|---|
| 654 |
|
|---|
| 655 | // ----- Pixel Assignement -----
|
|---|
| 656 | fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
|
|---|
| 657 |
|
|---|
| 658 | if (fFormatVersion<7)
|
|---|
| 659 | fin.read(dummy, 16);
|
|---|
| 660 |
|
|---|
| 661 | // ----- Fixes for broken files or contents -----
|
|---|
| 662 | if (!Fixes())
|
|---|
| 663 | return kFALSE;
|
|---|
| 664 |
|
|---|
| 665 | // ----- Consistency checks -----
|
|---|
| 666 | return IsConsistent();
|
|---|
| 667 | }
|
|---|
| 668 |
|
|---|
| 669 | // --------------------------------------------------------------------------
|
|---|
| 670 | //
|
|---|
| 671 | // Read in one run header from the binary file
|
|---|
| 672 | //
|
|---|
| 673 | Bool_t MRawRunHeader::ReadEvt(istream& fin)
|
|---|
| 674 | {
|
|---|
| 675 | //
|
|---|
| 676 | // read one RUN HEADER from the input stream
|
|---|
| 677 | //
|
|---|
| 678 | fMagicNumber = 0;
|
|---|
| 679 |
|
|---|
| 680 | fin.read((char*)&fMagicNumber, 2); // Total=2
|
|---|
| 681 |
|
|---|
| 682 | //
|
|---|
| 683 | // check whether the the file has the right file type or not
|
|---|
| 684 | //
|
|---|
| 685 | if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
|
|---|
| 686 | {
|
|---|
| 687 | *fLog << err << "ERROR - Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
|
|---|
| 688 | return kFALSE;
|
|---|
| 689 | }
|
|---|
| 690 |
|
|---|
| 691 | if (fMagicNumber == kMagicNumber+1)
|
|---|
| 692 | *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
|
|---|
| 693 |
|
|---|
| 694 | // ----- File format version -----
|
|---|
| 695 | fin.read((char*)&fFormatVersion, 2); // Total=4
|
|---|
| 696 | if (fFormatVersion==10 || fFormatVersion>kMaxFormatVersion)
|
|---|
| 697 | {
|
|---|
| 698 | *fLog << err << "ERROR - File format V" << fFormatVersion << " not implemented!" << endl;
|
|---|
| 699 | return kFALSE;
|
|---|
| 700 | }
|
|---|
| 701 |
|
|---|
| 702 | // ----- Process old file formats -----
|
|---|
| 703 | if (fFormatVersion<10)
|
|---|
| 704 | return ReadEvtOld(fin);
|
|---|
| 705 |
|
|---|
| 706 | // ----- Overwrite format version for format 11 -----
|
|---|
| 707 | fin.read((char*)&fFormatVersion, 4);
|
|---|
| 708 | if (fFormatVersion<11)
|
|---|
| 709 | {
|
|---|
| 710 | *fLog << err << "ERROR - Format Version <11." << endl;
|
|---|
| 711 | return kFALSE;
|
|---|
| 712 | }
|
|---|
| 713 |
|
|---|
| 714 | // ----- Read Header by size as written in the header -----
|
|---|
| 715 | fin.read((char*)&fHeaderSizeRun, 4);
|
|---|
| 716 | if (fHeaderSizeRun<346)
|
|---|
| 717 | {
|
|---|
| 718 | *fLog << err << "ERROR - Event header too small (<388b)." << endl;
|
|---|
| 719 | return kFALSE;
|
|---|
| 720 | }
|
|---|
| 721 |
|
|---|
| 722 | TArrayC h(fHeaderSizeRun-12);
|
|---|
| 723 | fin.read(h.GetArray(), h.GetSize());
|
|---|
| 724 | if (!fin)
|
|---|
| 725 | return kFALSE;
|
|---|
| 726 |
|
|---|
| 727 | // ----- convert -----
|
|---|
| 728 | const Byte_t *Char = reinterpret_cast<Byte_t* >(h.GetArray());
|
|---|
| 729 | const UInt_t *Int = reinterpret_cast<UInt_t* >(h.GetArray());
|
|---|
| 730 | //const Float_t *Float = reinterpret_cast<Float_t*>(h.GetArray());
|
|---|
| 731 |
|
|---|
| 732 | // ----- Start interpretation -----
|
|---|
| 733 |
|
|---|
| 734 | fHeaderSizeEvt = Int[0];
|
|---|
| 735 | fHeaderSizeCrate = Int[1];
|
|---|
| 736 | fSoftVersion = Int[2];
|
|---|
| 737 | fFadcType = Int[3];
|
|---|
| 738 | fCameraVersion = Int[4];
|
|---|
| 739 | fTelescopeNumber = Int[5];
|
|---|
| 740 | fRunType = Int[6];
|
|---|
| 741 | fRunNumber = Int[7];
|
|---|
| 742 | fFileNumber = Int[8];
|
|---|
| 743 |
|
|---|
| 744 | memcpy(fProjectName, Char+ 36, 100); // 25
|
|---|
| 745 | memcpy(fSourceName, Char+136, 80); // 20
|
|---|
| 746 | memcpy(fObservationMode, Char+216, 60); // 15
|
|---|
| 747 |
|
|---|
| 748 | //F32 fSourceRA = Float[69];
|
|---|
| 749 | //F32 fSourceDEC = Float[70];
|
|---|
| 750 | //F32 fTelescopeRA = Float[71];
|
|---|
| 751 | //F32 fTelescopeDEC = Float[72];
|
|---|
| 752 |
|
|---|
| 753 | memcpy(fSourceEpochChar, Char+232, 4);
|
|---|
| 754 |
|
|---|
| 755 | fSourceEpochDate = Int[74];
|
|---|
| 756 | fNumCrates = Int[75];
|
|---|
| 757 | fNumPixInCrate = Int[76];
|
|---|
| 758 | fNumSamplesHiGain = Int[77];
|
|---|
| 759 | fNumSamplesLoGain = 0;
|
|---|
| 760 |
|
|---|
| 761 | //fNumSamplesRemovedHead = Int[78];
|
|---|
| 762 | //fNumSamplesRemovedTail = Int[79];
|
|---|
| 763 |
|
|---|
| 764 | fNumEvents = Int[80];
|
|---|
| 765 | fNumEventsRead = Int[81];
|
|---|
| 766 | fNumBytesPerSample = Int[82];
|
|---|
| 767 | fSamplingFrequency = Int[83];
|
|---|
| 768 | fFadcResolution = Int[84];
|
|---|
| 769 |
|
|---|
| 770 | fRunStart.SetBinary(Int+85);
|
|---|
| 771 | fRunStop.SetBinary(Int+91);
|
|---|
| 772 |
|
|---|
| 773 | // ----- 388 bytes so far -----
|
|---|
| 774 |
|
|---|
| 775 | const UInt_t n = fNumCrates*fNumPixInCrate;
|
|---|
| 776 | if (fHeaderSizeRun<388+n*4)
|
|---|
| 777 | {
|
|---|
| 778 | *fLog << err << "ERROR - Event header too small to contain pix assignment." << endl;
|
|---|
| 779 | return kFALSE;
|
|---|
| 780 | }
|
|---|
| 781 |
|
|---|
| 782 | // ----- Pixel Assignment -----
|
|---|
| 783 | fPixAssignment->Set(n);
|
|---|
| 784 |
|
|---|
| 785 | for (UInt_t i=0; i<n; i++)
|
|---|
| 786 | (*fPixAssignment)[i] = Int[97+i];
|
|---|
| 787 |
|
|---|
| 788 | // ----- Fixes for broken files or contents -----
|
|---|
| 789 | if (!Fixes())
|
|---|
| 790 | return kFALSE;
|
|---|
| 791 |
|
|---|
| 792 | // ----- Consistency checks -----
|
|---|
| 793 | return IsConsistent();
|
|---|
| 794 | }
|
|---|
| 795 | /*
|
|---|
| 796 | Bool_t MRawRunHeader::WriteEvt(ostream& out) const
|
|---|
| 797 | {
|
|---|
| 798 | //
|
|---|
| 799 | // write one RUN HEADER from the input stream
|
|---|
| 800 | //
|
|---|
| 801 | const UInt_t n = fNumCrates*fNumPixInCrate;
|
|---|
| 802 |
|
|---|
| 803 | const UShort_t magicnumber = kMagicNumber;
|
|---|
| 804 | const UInt_t formatversion = 11;
|
|---|
| 805 | const UInt_t headersizerun = (97+n)*4; //???
|
|---|
| 806 |
|
|---|
| 807 | // FIXME: Write fixed number (c0c0)
|
|---|
| 808 | out.write((char*)&magicnumber, 2); // Total=2
|
|---|
| 809 | out.write((char*)&formatversion, 2); // Total=4
|
|---|
| 810 | out.write((char*)&formatversion, 4);
|
|---|
| 811 | out.write((char*)&headersizerun, 4);
|
|---|
| 812 |
|
|---|
| 813 | TArrayC h(headersizerun-12);
|
|---|
| 814 |
|
|---|
| 815 | // ----- convert -----
|
|---|
| 816 | Byte_t *Char = reinterpret_cast<Byte_t* >(h.GetArray());
|
|---|
| 817 | UInt_t *Int = reinterpret_cast<UInt_t* >(h.GetArray());
|
|---|
| 818 | //const Float_t *Float = reinterpret_cast<Float_t*>(h.GetArray());
|
|---|
| 819 |
|
|---|
| 820 | // ----- Start interpretation -----
|
|---|
| 821 |
|
|---|
| 822 | Int[0] = 0; // fHeaderSizeEvt;
|
|---|
| 823 | Int[1] = 0; // fHeaderSizeCrate;
|
|---|
| 824 | Int[2] = 0; // fSoftVersion;
|
|---|
| 825 | Int[3] = fFadcType;
|
|---|
| 826 | Int[4] = fCameraVersion;
|
|---|
| 827 | Int[5] = fTelescopeNumber;
|
|---|
| 828 | Int[5] = fRunType;
|
|---|
| 829 | Int[6] = fRunNumber;
|
|---|
| 830 | Int[7] = fFileNumber;
|
|---|
| 831 |
|
|---|
| 832 | memcpy(Char+ 36, fProjectName, 100); // 25
|
|---|
| 833 | memcpy(Char+136, fSourceName, 80); // 20
|
|---|
| 834 | memcpy(Char+216, fObservationMode, 60); // 15
|
|---|
| 835 |
|
|---|
| 836 | //F32 fSourceRA = Float[69];
|
|---|
| 837 | //F32 fSourceDEC = Float[70];
|
|---|
| 838 | //F32 fTelescopeRA = Float[71];
|
|---|
| 839 | //F32 fTelescopeDEC = Float[72];
|
|---|
| 840 |
|
|---|
| 841 | memcpy(Char+232, fSourceEpochChar, 4);
|
|---|
| 842 |
|
|---|
| 843 | Int[74] = fSourceEpochDate;
|
|---|
| 844 | Int[75] = fNumCrates;
|
|---|
| 845 | Int[76] = fNumPixInCrate;
|
|---|
| 846 | Int[77] = fNumSamplesHiGain;
|
|---|
| 847 |
|
|---|
| 848 | //fNumSamplesRemovedHead = Int[78];
|
|---|
| 849 | //fNumSamplesRemovedTail = Int[79];
|
|---|
| 850 |
|
|---|
| 851 | Int[80] = fNumEvents;
|
|---|
| 852 | Int[81] = fNumEvents; //fNumEventsRead;
|
|---|
| 853 | Int[82] = fNumBytesPerSample;
|
|---|
| 854 | Int[83] = fSamplingFrequency;
|
|---|
| 855 | Int[84] = fFadcResolution;
|
|---|
| 856 |
|
|---|
| 857 | fRunStart.GetBinary(Int+85);
|
|---|
| 858 | fRunStop.GetBinary(Int+91);
|
|---|
| 859 |
|
|---|
| 860 | // ----- 388 bytes so far -----
|
|---|
| 861 |
|
|---|
| 862 | //const UInt_t n = fNumCrates*fNumPixInCrate;
|
|---|
| 863 | //if (fHeaderSizeRun<(97+n)*4)
|
|---|
| 864 | //{
|
|---|
| 865 | // *fLog << err << "ERROR - Event header too small to contain pix assignment." << endl;
|
|---|
| 866 | // return kFALSE;
|
|---|
| 867 | //}
|
|---|
| 868 |
|
|---|
| 869 | // ----- Pixel Assignment -----
|
|---|
| 870 | for (UInt_t i=0; i<n; i++)
|
|---|
| 871 | Int[97+i] = (*fPixAssignment)[i];
|
|---|
| 872 |
|
|---|
| 873 | out.write(h.GetArray(), h.GetSize());
|
|---|
| 874 |
|
|---|
| 875 | return out;
|
|---|
| 876 | }
|
|---|
| 877 | */
|
|---|
| 878 | // --------------------------------------------------------------------------
|
|---|
| 879 | //
|
|---|
| 880 | // Return the run type as string ("Data", "Pedestal", ...), for example
|
|---|
| 881 | // to print it as readable text.
|
|---|
| 882 | //
|
|---|
| 883 | const char *MRawRunHeader::GetRunTypeStr() const
|
|---|
| 884 | {
|
|---|
| 885 | switch (fRunType)
|
|---|
| 886 | {
|
|---|
| 887 | case kRTData:
|
|---|
| 888 | return "Data";
|
|---|
| 889 | case kRTPedestal:
|
|---|
| 890 | return "Pedestal";
|
|---|
| 891 | case kRTCalibration:
|
|---|
| 892 | return "Calibration";
|
|---|
| 893 | case kRTLinearity:
|
|---|
| 894 | return "Linearity";
|
|---|
| 895 | case kRTPointRun:
|
|---|
| 896 | return "Point-Run";
|
|---|
| 897 | case kRTMonteCarlo:
|
|---|
| 898 | return "Monte Carlo";
|
|---|
| 899 | case kRTNone:
|
|---|
| 900 | return "<none>";
|
|---|
| 901 | default:
|
|---|
| 902 | return "<unknown>";
|
|---|
| 903 | }
|
|---|
| 904 | }
|
|---|
| 905 |
|
|---|
| 906 | // --------------------------------------------------------------------------
|
|---|
| 907 | //
|
|---|
| 908 | // print run header information on *fLog. The option 'header' supresses
|
|---|
| 909 | // the pixel index translation table.
|
|---|
| 910 | //
|
|---|
| 911 | void MRawRunHeader::Print(Option_t *t) const
|
|---|
| 912 | {
|
|---|
| 913 | *fLog << all << endl;
|
|---|
| 914 | *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - ";
|
|---|
| 915 | switch (fMagicNumber)
|
|---|
| 916 | {
|
|---|
| 917 | case kMagicNumber: *fLog << "OK"; break;
|
|---|
| 918 | case kMagicNumber+1: *fLog << "File not closed!"; break;
|
|---|
| 919 | default: *fLog << "Wrong!"; break;
|
|---|
| 920 | }
|
|---|
| 921 | *fLog << endl;
|
|---|
| 922 | *fLog << "Versions: " << dec << "Format=" << fFormatVersion << " ";
|
|---|
| 923 | *fLog << "Software=" << fSoftVersion << " ";
|
|---|
| 924 | if (fFormatVersion>5)
|
|---|
| 925 | *fLog << "Camera=" << fCameraVersion;
|
|---|
| 926 | *fLog << endl;
|
|---|
| 927 | if (fFormatVersion>10)
|
|---|
| 928 | *fLog << "Header sizes: " << fHeaderSizeRun << "b (run), " << fHeaderSizeEvt << "b (evt), " << fHeaderSizeCrate << "b (crate)" << endl;
|
|---|
| 929 | if (fFormatVersion>5)
|
|---|
| 930 | *fLog << "Telescope: " << fTelescopeNumber << endl;
|
|---|
| 931 | if (fFormatVersion>7)
|
|---|
| 932 | {
|
|---|
| 933 | *fLog << "FadcType: " << fFadcType << " (";
|
|---|
| 934 | switch (fFadcType)
|
|---|
| 935 | {
|
|---|
| 936 | case 1: *fLog << "Siegen"; break;
|
|---|
| 937 | case 2: *fLog << "MUX"; break;
|
|---|
| 938 | default: *fLog << "unknown";
|
|---|
| 939 | }
|
|---|
| 940 | *fLog << ")" << endl;
|
|---|
| 941 | }
|
|---|
| 942 | *fLog << "RunNumber: " << fRunNumber;
|
|---|
| 943 | if (fFormatVersion>10)
|
|---|
| 944 | *fLog << "/" << fFileNumber << " (id=" << GetFileID() << ")";
|
|---|
| 945 | *fLog << " (Type=" << GetRunTypeStr() << ")" << endl;
|
|---|
| 946 | *fLog << "ProjectName: '" << fProjectName << "'" << endl;
|
|---|
| 947 | if (fFormatVersion>5)
|
|---|
| 948 | *fLog << "Observation: '" << fObservationMode << "'" << endl;
|
|---|
| 949 | *fLog << "Source: '" << fSourceName << "' " << " ";
|
|---|
| 950 | *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
|
|---|
| 951 | *fLog << "Run Start: " << fRunStart << endl;
|
|---|
| 952 | *fLog << "Run Stop: " << fRunStop << endl;
|
|---|
| 953 | *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
|
|---|
| 954 | *fLog << "Num Pixels: " << GetNumNormalPixels() << " (normal) + " << GetNumSpecialPixels() << " (special) = " << GetNumConnectedPixels() << " (total)" << endl;
|
|---|
| 955 | if (fFormatVersion>6)
|
|---|
| 956 | *fLog << "Sampling: " << fSamplingFrequency << "MHz with " << (int)fFadcResolution << " significant bits" << endl;
|
|---|
| 957 | *fLog << "Samples: " << fNumSamplesHiGain << "/" << fNumSamplesLoGain << " (hi/lo) * " << fNumBytesPerSample << "B/sample = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate * fNumBytesPerSample/1000 << "kB/Evt" << endl;
|
|---|
| 958 | *fLog << "Evt Counter: " << fNumEvents;
|
|---|
| 959 | if (fFormatVersion>8)
|
|---|
| 960 | *fLog << " (read=" << fNumEventsRead << ")";
|
|---|
| 961 | *fLog << endl;
|
|---|
| 962 |
|
|---|
| 963 | if (TString(t).Contains("header", TString::kIgnoreCase))
|
|---|
| 964 | return;
|
|---|
| 965 |
|
|---|
| 966 | *fLog << inf3 << "Assignment:" << hex << endl;
|
|---|
| 967 | for (int i=0; i<GetNumPixel(); i++)
|
|---|
| 968 | *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
|
|---|
| 969 |
|
|---|
| 970 | *fLog << dec << setfill(' ') << endl;
|
|---|
| 971 | }
|
|---|
| 972 |
|
|---|
| 973 | // --------------------------------------------------------------------------
|
|---|
| 974 | //
|
|---|
| 975 | // Return the assigned pixel number for the given FADC channel
|
|---|
| 976 | //
|
|---|
| 977 | Short_t MRawRunHeader::GetPixAssignment(UShort_t i) const
|
|---|
| 978 | {
|
|---|
| 979 | // FIXME: Do we need a range check here?
|
|---|
| 980 | return (Short_t)(*fPixAssignment)[i];
|
|---|
| 981 | }
|
|---|
| 982 |
|
|---|
| 983 | // --------------------------------------------------------------------------
|
|---|
| 984 | //
|
|---|
| 985 | // Return the number of pixel which are markes as connected in the
|
|---|
| 986 | // pix assignment (!=0)
|
|---|
| 987 | //
|
|---|
| 988 | UShort_t MRawRunHeader::GetNumConnectedPixels() const
|
|---|
| 989 | {
|
|---|
| 990 | const Int_t num = fPixAssignment->GetSize();
|
|---|
| 991 |
|
|---|
| 992 | UShort_t rc = 0;
|
|---|
| 993 | for (int i=0; i<num; i++)
|
|---|
| 994 | {
|
|---|
| 995 | if (GetPixAssignment(i)!=0)
|
|---|
| 996 | rc++;
|
|---|
| 997 | }
|
|---|
| 998 | return rc;
|
|---|
| 999 | }
|
|---|
| 1000 |
|
|---|
| 1001 | // --------------------------------------------------------------------------
|
|---|
| 1002 | //
|
|---|
| 1003 | // Return the number of pixel which are markes as connected and so-called
|
|---|
| 1004 | // 'normal' pixels in the pix assignment (>0)
|
|---|
| 1005 | //
|
|---|
| 1006 | UShort_t MRawRunHeader::GetNumNormalPixels() const
|
|---|
| 1007 | {
|
|---|
| 1008 | const Int_t num = fPixAssignment->GetSize();
|
|---|
| 1009 |
|
|---|
| 1010 | UShort_t rc = 0;
|
|---|
| 1011 | for (int i=0; i<num; i++)
|
|---|
| 1012 | {
|
|---|
| 1013 | if (GetPixAssignment(i)>0)
|
|---|
| 1014 | rc++;
|
|---|
| 1015 | }
|
|---|
| 1016 | return rc;
|
|---|
| 1017 | }
|
|---|
| 1018 |
|
|---|
| 1019 | // --------------------------------------------------------------------------
|
|---|
| 1020 | //
|
|---|
| 1021 | // Return the number of pixel which are markes as connected and so-called
|
|---|
| 1022 | // 'special' pixels in the pix assignment (<0)
|
|---|
| 1023 | //
|
|---|
| 1024 | UShort_t MRawRunHeader::GetNumSpecialPixels() const
|
|---|
| 1025 | {
|
|---|
| 1026 | const Int_t num = fPixAssignment->GetSize();
|
|---|
| 1027 |
|
|---|
| 1028 | UShort_t rc = 0;
|
|---|
| 1029 | for (int i=0; i<num; i++)
|
|---|
| 1030 | {
|
|---|
| 1031 | if (GetPixAssignment(i)<0)
|
|---|
| 1032 | rc++;
|
|---|
| 1033 | }
|
|---|
| 1034 | return rc;
|
|---|
| 1035 | }
|
|---|
| 1036 |
|
|---|
| 1037 | // --------------------------------------------------------------------------
|
|---|
| 1038 | //
|
|---|
| 1039 | // Return the maximum id which exists in the pix assignment
|
|---|
| 1040 | //
|
|---|
| 1041 | UShort_t MRawRunHeader::GetMaxPixId() const
|
|---|
| 1042 | {
|
|---|
| 1043 | const Int_t num = fPixAssignment->GetSize();
|
|---|
| 1044 |
|
|---|
| 1045 | Short_t rc = 0;
|
|---|
| 1046 | for (int i=0; i<num; i++)
|
|---|
| 1047 | rc = TMath::Max(GetPixAssignment(i), rc);
|
|---|
| 1048 |
|
|---|
| 1049 | return rc;
|
|---|
| 1050 | }
|
|---|
| 1051 |
|
|---|
| 1052 | // --------------------------------------------------------------------------
|
|---|
| 1053 | //
|
|---|
| 1054 | // Return minus th minimum id which exists in the pix assignment
|
|---|
| 1055 | //
|
|---|
| 1056 | UShort_t MRawRunHeader::GetMinPixId() const
|
|---|
| 1057 | {
|
|---|
| 1058 | const Int_t num = fPixAssignment->GetSize();
|
|---|
| 1059 |
|
|---|
| 1060 | Short_t rc = 0;
|
|---|
| 1061 | for (int i=0; i<num; i++)
|
|---|
| 1062 | rc = TMath::Min(GetPixAssignment(i), rc);
|
|---|
| 1063 |
|
|---|
| 1064 | return (UShort_t)-rc;
|
|---|
| 1065 | }
|
|---|
| 1066 |
|
|---|
| 1067 | // --------------------------------------------------------------------------
|
|---|
| 1068 | //
|
|---|
| 1069 | // Return the number of pixel in this event.
|
|---|
| 1070 | //
|
|---|
| 1071 | // WARNING: This is the number of pixels stored in this file which is
|
|---|
| 1072 | // a multiple of the number of pixels per crate and in general
|
|---|
| 1073 | // a number which is larger than the camera size!
|
|---|
| 1074 | //
|
|---|
| 1075 | // To know the range of the pixel indices please use the geometry
|
|---|
| 1076 | // container!
|
|---|
| 1077 | //
|
|---|
| 1078 | UShort_t MRawRunHeader::GetNumPixel() const
|
|---|
| 1079 | {
|
|---|
| 1080 | return fPixAssignment->GetSize();
|
|---|
| 1081 | }
|
|---|
| 1082 |
|
|---|
| 1083 | // --------------------------------------------------------------------------
|
|---|
| 1084 | //
|
|---|
| 1085 | // Returns absolute size in bytes of the run header as read from a raw file.
|
|---|
| 1086 | // This must be done _after_ the header is read, because the header doesn't
|
|---|
| 1087 | // have a fixed size (used in MRawSocketRead)
|
|---|
| 1088 | //
|
|---|
| 1089 | Int_t MRawRunHeader::GetNumTotalBytes() const
|
|---|
| 1090 | {
|
|---|
| 1091 | switch (fFormatVersion)
|
|---|
| 1092 | {
|
|---|
| 1093 | case 1:
|
|---|
| 1094 | return 80+fNumCrates*fNumPixInCrate*2+16;
|
|---|
| 1095 | case 2:
|
|---|
| 1096 | case 3:
|
|---|
| 1097 | case 4:
|
|---|
| 1098 | case 5:
|
|---|
| 1099 | return 84+fNumCrates*fNumPixInCrate*2+16;
|
|---|
| 1100 | case 6:
|
|---|
| 1101 | return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8;
|
|---|
| 1102 | case 7:
|
|---|
| 1103 | return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8 +3-16;
|
|---|
| 1104 | }
|
|---|
| 1105 | return 0;
|
|---|
| 1106 | }
|
|---|
| 1107 |
|
|---|
| 1108 | // --------------------------------------------------------------------------
|
|---|
| 1109 | //
|
|---|
| 1110 | // Monte Carlo Interface
|
|---|
| 1111 | //
|
|---|
| 1112 | // This is a (prelimiary) way to setup an existing FADC system.
|
|---|
| 1113 | //
|
|---|
| 1114 | // 1: Siegen FADCs
|
|---|
| 1115 | // 2: MUX FADCs
|
|---|
| 1116 | //
|
|---|
| 1117 | void MRawRunHeader::InitFadcType(UShort_t type)
|
|---|
| 1118 | {
|
|---|
| 1119 | switch (type)
|
|---|
| 1120 | {
|
|---|
| 1121 | case 1:
|
|---|
| 1122 | fNumSamplesLoGain = 15;
|
|---|
| 1123 | fNumSamplesHiGain = 15;
|
|---|
| 1124 | fNumBytesPerSample = 1; // number of bytes per sample
|
|---|
| 1125 | fSamplingFrequency = 300; // Sampling Frequency [MHz]
|
|---|
| 1126 | fFadcResolution = 8; // number of significant bits
|
|---|
| 1127 | break;
|
|---|
| 1128 | case 2:
|
|---|
| 1129 | fNumSamplesHiGain = 50;
|
|---|
| 1130 | fNumSamplesLoGain = 0;
|
|---|
| 1131 | fNumBytesPerSample = 2; // number of bytes per sample
|
|---|
| 1132 | fSamplingFrequency = 2000; // Sampling Frequency [MHz]
|
|---|
| 1133 | fFadcResolution = 12; // number of significant bits
|
|---|
| 1134 | break;
|
|---|
| 1135 | case 3:
|
|---|
| 1136 | fNumSamplesHiGain = 150;
|
|---|
| 1137 | fNumSamplesLoGain = 0;
|
|---|
| 1138 | fNumBytesPerSample = 2; // number of bytes per sample
|
|---|
| 1139 | fSamplingFrequency = 1000; // Sampling Frequency [MHz]
|
|---|
| 1140 | fFadcResolution = 12; // number of significant bits
|
|---|
| 1141 | break;
|
|---|
| 1142 | }
|
|---|
| 1143 |
|
|---|
| 1144 | fFadcType = type;
|
|---|
| 1145 | }
|
|---|
| 1146 |
|
|---|
| 1147 | // --------------------------------------------------------------------------
|
|---|
| 1148 | //
|
|---|
| 1149 | // Monte Carlo Interface
|
|---|
| 1150 | //
|
|---|
| 1151 | // Init a camera
|
|---|
| 1152 | //
|
|---|
| 1153 | void MRawRunHeader::InitCamera(UShort_t type)
|
|---|
| 1154 | {
|
|---|
| 1155 | switch (type)
|
|---|
| 1156 | {
|
|---|
| 1157 | case 1:
|
|---|
| 1158 | fNumCrates = 1;
|
|---|
| 1159 | fNumPixInCrate = 577;
|
|---|
| 1160 | break;
|
|---|
| 1161 | case 2:
|
|---|
| 1162 | fNumCrates = 1;
|
|---|
| 1163 | fNumPixInCrate = 703;
|
|---|
| 1164 | break;
|
|---|
| 1165 | }
|
|---|
| 1166 |
|
|---|
| 1167 | fCameraVersion = type;
|
|---|
| 1168 |
|
|---|
| 1169 | const Int_t n = fNumCrates*fNumPixInCrate;
|
|---|
| 1170 |
|
|---|
| 1171 | fPixAssignment->Set(n);
|
|---|
| 1172 |
|
|---|
| 1173 | for (int i=0; i<n; i++)
|
|---|
| 1174 | (*fPixAssignment)[i] = i+1;
|
|---|
| 1175 | }
|
|---|
| 1176 |
|
|---|
| 1177 | // --------------------------------------------------------------------------
|
|---|
| 1178 | //
|
|---|
| 1179 | // Monte Carlo Interface
|
|---|
| 1180 | //
|
|---|
| 1181 | // Set run-type, telescope number, run-number and file-number
|
|---|
| 1182 | //
|
|---|
| 1183 | void MRawRunHeader::SetRunInfo(UShort_t type, UShort_t tel, UInt_t run, UInt_t file)
|
|---|
| 1184 | {
|
|---|
| 1185 | fRunType = type;
|
|---|
| 1186 | fTelescopeNumber = tel;
|
|---|
| 1187 | fRunNumber = run;
|
|---|
| 1188 | fFileNumber = file;
|
|---|
| 1189 | }
|
|---|
| 1190 |
|
|---|
| 1191 | // --------------------------------------------------------------------------
|
|---|
| 1192 | //
|
|---|
| 1193 | // Monte Carlo Interface
|
|---|
| 1194 | //
|
|---|
| 1195 | // Set source-name, epoch (default J) and date (default 2000)
|
|---|
| 1196 | //
|
|---|
| 1197 | void MRawRunHeader::SetSourceInfo(const char src[80], char epoch, UShort_t date)
|
|---|
| 1198 | {
|
|---|
| 1199 | memcpy(fSourceName, src, 80);
|
|---|
| 1200 |
|
|---|
| 1201 | fSourceEpochChar[0] = epoch; // epoch char of the source
|
|---|
| 1202 | fSourceEpochChar[1] = 0; // epoch char of the source
|
|---|
| 1203 |
|
|---|
| 1204 | fSourceEpochDate = date; // epoch date of the source
|
|---|
| 1205 | }
|
|---|
| 1206 |
|
|---|
| 1207 | // --------------------------------------------------------------------------
|
|---|
| 1208 | //
|
|---|
| 1209 | // Monte Carlo Interface
|
|---|
| 1210 | //
|
|---|
| 1211 | // Set run-start and -stop time
|
|---|
| 1212 | //
|
|---|
| 1213 | void MRawRunHeader::SetRunTime(const MTime &start, const MTime &end)
|
|---|
| 1214 | {
|
|---|
| 1215 | fRunStart = start;
|
|---|
| 1216 | fRunStop = end;
|
|---|
| 1217 | }
|
|---|
| 1218 |
|
|---|
| 1219 | // --------------------------------------------------------------------------
|
|---|
| 1220 | //
|
|---|
| 1221 | // Monte Carlo Interface
|
|---|
| 1222 | //
|
|---|
| 1223 | // Set project name and observation mode
|
|---|
| 1224 | //
|
|---|
| 1225 | void MRawRunHeader::SetObservation(const char mode[60], const char proj[100])
|
|---|
| 1226 | {
|
|---|
| 1227 | memcpy(fProjectName, proj, 100);
|
|---|
| 1228 | memcpy(fObservationMode, mode, 60);
|
|---|
| 1229 | }
|
|---|
| 1230 |
|
|---|
| 1231 | // --------------------------------------------------------------------------
|
|---|
| 1232 | //
|
|---|
| 1233 | // Monte Carlo Interface
|
|---|
| 1234 | //
|
|---|
| 1235 | // Set number of events in file.
|
|---|
| 1236 | //
|
|---|
| 1237 | void MRawRunHeader::SetNumEvents(UInt_t num)
|
|---|
| 1238 | {
|
|---|
| 1239 | fNumEvents = num;
|
|---|
| 1240 | fNumEventsRead = num;
|
|---|
| 1241 | }
|
|---|