| 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@uni-sw.gwdg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MRawEvtHeader
|
|---|
| 28 | //
|
|---|
| 29 | // One Event is a sample of FADC measurements of different Pixels
|
|---|
| 30 | // (Photomultipliers) from the Camera of MAGIC. So all data (FADC) of the
|
|---|
| 31 | // interesting pixels are the modules of an event. To describe pixels the
|
|---|
| 32 | // class MRawPixel is used and the class MRawCrate to describe Crates.
|
|---|
| 33 | // To define a single events some other data members are needed
|
|---|
| 34 | // (Time of the events, tirgger pattern of event..)
|
|---|
| 35 | //
|
|---|
| 36 | // To describe one event on the level of FADC values the Class MRawEvtHeader is
|
|---|
| 37 | // created. It has the following data members:
|
|---|
| 38 | //
|
|---|
| 39 | // UInt_t fDAQEvtNumber
|
|---|
| 40 | // -----------------------
|
|---|
| 41 | // This it the number of the Event in one
|
|---|
| 42 | // data run. The first event in this run get
|
|---|
| 43 | // the number zero. The next one is one bigger.
|
|---|
| 44 | //
|
|---|
| 45 | // Assuming that one run takes 1 hour and a
|
|---|
| 46 | // triggerrate of 1kHz the number must be able
|
|---|
| 47 | // to reach 3.6e6 Events. To reach this number
|
|---|
| 48 | // you need at least 22 bits. This is the reason
|
|---|
| 49 | // why we use an integer (of root type UInt_t)
|
|---|
| 50 | // with a range to 4.2e9.
|
|---|
| 51 | //
|
|---|
| 52 | // MTime fRawEvtTime
|
|---|
| 53 | // -------------------
|
|---|
| 54 | // Time of the event.
|
|---|
| 55 | // The start point of the time determination can be
|
|---|
| 56 | // the millenium. From that start point the time is
|
|---|
| 57 | // measured in 200ns-count. One day for example
|
|---|
| 58 | // contains 432.e9 counts. An array of two unsigned Int is able to
|
|---|
| 59 | // contain 1.8e19 200ns-counts. This corresponds to 41.e6
|
|---|
| 60 | // days. This should be more than the livetime of MAGIC.
|
|---|
| 61 | // Private member of MTime.h
|
|---|
| 62 | //
|
|---|
| 63 | // UInt_t fNumTrigLvl1
|
|---|
| 64 | // --------------------
|
|---|
| 65 | //
|
|---|
| 66 | // Number of first level trigger
|
|---|
| 67 | // This member counts the number of First Level Trigger
|
|---|
| 68 | // between the last and this event. May be that due to
|
|---|
| 69 | // dead time of the DAQ this number is different from 1.
|
|---|
| 70 | // If the DAQ is fast enough, this value should be 1.
|
|---|
| 71 | // This may be usefull in GammaRayBursts and if we
|
|---|
| 72 | // apply a data reduction in the DAQ-chain, which selects
|
|---|
| 73 | // only good events.
|
|---|
| 74 | //
|
|---|
| 75 | // UInt_t fNumTrigLvl2
|
|---|
| 76 | // ------------------ -
|
|---|
| 77 | //
|
|---|
| 78 | // Number of second level trigger
|
|---|
| 79 | // This member counts the number of Second Level Trigger
|
|---|
| 80 | // between the last and this event.
|
|---|
| 81 | //
|
|---|
| 82 | // UInt_t fTrigPattern[2]
|
|---|
| 83 | // -----------------------
|
|---|
| 84 | // Trigger Pattern used for this event
|
|---|
| 85 | // Each event triggers for a particular configuration and each
|
|---|
| 86 | // configuration shoul have an ID (which is not fixed yet).
|
|---|
| 87 | //
|
|---|
| 88 | // UShort_t fAllLowGainOn
|
|---|
| 89 | // ----------------------
|
|---|
| 90 | // Type of Trigger.
|
|---|
| 91 | // This is a Byte (8 bit) to indicated if any of the pixels
|
|---|
| 92 | // have a non-negligible low gain (1) or not (0)
|
|---|
| 93 | //
|
|---|
| 94 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 95 | #include "MRawEvtHeader.h"
|
|---|
| 96 |
|
|---|
| 97 | #include <iomanip>
|
|---|
| 98 | #include <fstream>
|
|---|
| 99 |
|
|---|
| 100 | #include "MLog.h"
|
|---|
| 101 | #include "MLogManip.h"
|
|---|
| 102 |
|
|---|
| 103 | #include "MTime.h"
|
|---|
| 104 | #include "MArrayB.h"
|
|---|
| 105 | #include "MRawRunHeader.h"
|
|---|
| 106 |
|
|---|
| 107 | ClassImp(MRawEvtHeader);
|
|---|
| 108 |
|
|---|
| 109 | using namespace std;
|
|---|
| 110 |
|
|---|
| 111 | // --------------------------------------------------------------------------
|
|---|
| 112 | //
|
|---|
| 113 | // Default constructor. Create the array to store the data.
|
|---|
| 114 | //
|
|---|
| 115 | MRawEvtHeader::MRawEvtHeader(const char *name, const char *title)
|
|---|
| 116 | {
|
|---|
| 117 | fName = name ? name : "MRawEvtHeader";
|
|---|
| 118 | fTitle = title ? title : "Raw Event Header Information";
|
|---|
| 119 |
|
|---|
| 120 | //
|
|---|
| 121 | // set all member to zero, init the pointer to ClonesArray,
|
|---|
| 122 | //
|
|---|
| 123 | fPixLoGainOn = new MArrayB;
|
|---|
| 124 |
|
|---|
| 125 | Clear();
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | // --------------------------------------------------------------------------
|
|---|
| 129 | //
|
|---|
| 130 | // Destructor. Deletes the array to store pixlogainon
|
|---|
| 131 | //
|
|---|
| 132 | MRawEvtHeader::~MRawEvtHeader()
|
|---|
| 133 | {
|
|---|
| 134 | delete fPixLoGainOn;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | // --------------------------------------------------------------------------
|
|---|
| 138 | //
|
|---|
| 139 | // you have to init the conatainer before you can read from
|
|---|
| 140 | // a raw binary file
|
|---|
| 141 | //
|
|---|
| 142 | void MRawEvtHeader::Init(MRawRunHeader *rh, MTime *t)
|
|---|
| 143 | {
|
|---|
| 144 | //
|
|---|
| 145 | // this is the number of entries in the array like specification
|
|---|
| 146 | //
|
|---|
| 147 | UInt_t fN = (rh->GetNumCrates() * rh->GetNumPixInCrate() + 7) / 8;
|
|---|
| 148 |
|
|---|
| 149 | //
|
|---|
| 150 | // initialize the array
|
|---|
| 151 | //
|
|---|
| 152 | fPixLoGainOn->Set(fN);
|
|---|
| 153 |
|
|---|
| 154 | //
|
|---|
| 155 | // this is the conatiner where we have to store the time of the event we
|
|---|
| 156 | // read from the input stream
|
|---|
| 157 | //
|
|---|
| 158 | fTime = t;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | // --------------------------------------------------------------------------
|
|---|
| 162 | //
|
|---|
| 163 | // Implementation of the Clear function
|
|---|
| 164 | //
|
|---|
| 165 | // Resets all members to zero, clear the list of Pixels
|
|---|
| 166 | //
|
|---|
| 167 | void MRawEvtHeader::Clear(Option_t *)
|
|---|
| 168 | {
|
|---|
| 169 | fDAQEvtNumber = 0;
|
|---|
| 170 | fNumTrigLvl1 = 0;
|
|---|
| 171 | fNumTrigLvl2 = 0;
|
|---|
| 172 | fTrigPattern[0] = 0;
|
|---|
| 173 | fTrigPattern[1] = 0;
|
|---|
| 174 | fTrigType = 0;
|
|---|
| 175 | fNumLoGainOn = 0;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | // --------------------------------------------------------------------------
|
|---|
| 179 | //
|
|---|
| 180 | // This member function prints all Data of one Event to *fLog.
|
|---|
| 181 | //
|
|---|
| 182 | void MRawEvtHeader::Print(Option_t *o) const
|
|---|
| 183 | {
|
|---|
| 184 | *fLog << all;
|
|---|
| 185 | *fLog << "DAQEvtNr: " << dec << fDAQEvtNumber << " (";
|
|---|
| 186 | *fLog << "Trigger: ";
|
|---|
| 187 | *fLog << "NumLvl1=" << fNumTrigLvl1 << " ";
|
|---|
| 188 | *fLog << "NumLvl2=" << fNumTrigLvl2 << " ";
|
|---|
| 189 | *fLog << "Pattern=" << hex << setfill('0');
|
|---|
| 190 | *fLog << setw(2) << fTrigPattern[0];
|
|---|
| 191 | *fLog << setw(2) << fTrigPattern[1] << " " << dec;
|
|---|
| 192 |
|
|---|
| 193 | *fLog << "Type=";
|
|---|
| 194 | switch (fTrigType)
|
|---|
| 195 | {
|
|---|
| 196 | case 0:
|
|---|
| 197 | *fLog << "Trigger";
|
|---|
| 198 | break;
|
|---|
| 199 | case 1:
|
|---|
| 200 | *fLog << "Pedestal";
|
|---|
| 201 | break;
|
|---|
| 202 | case 2:
|
|---|
| 203 | *fLog << "Calibration";
|
|---|
| 204 | break;
|
|---|
| 205 | }
|
|---|
| 206 | *fLog << ")" << endl;
|
|---|
| 207 | *fLog << "Number of Lo Gains On: " << fNumLoGainOn << endl;
|
|---|
| 208 |
|
|---|
| 209 | TString str(o);
|
|---|
| 210 | str.ToLower();
|
|---|
| 211 |
|
|---|
| 212 | if (str.Contains("nogains"))
|
|---|
| 213 | return;
|
|---|
| 214 |
|
|---|
| 215 | for (unsigned int i=0; i<fPixLoGainOn->GetSize(); i++)
|
|---|
| 216 | {
|
|---|
| 217 | for (int j=0; j<8; j++)
|
|---|
| 218 | {
|
|---|
| 219 | const UInt_t on = (*fPixLoGainOn)[i]&(1<<j) ? 1 : 0;
|
|---|
| 220 | *fLog << on;
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 | if (fPixLoGainOn->GetSize())
|
|---|
| 224 | *fLog << endl;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | // --------------------------------------------------------------------------
|
|---|
| 228 | //
|
|---|
| 229 | // used to set the header information (eg. from MC)
|
|---|
| 230 | //
|
|---|
| 231 | void MRawEvtHeader::FillHeader(UInt_t uiN, Float_t ulTP)
|
|---|
| 232 | {
|
|---|
| 233 | fDAQEvtNumber = uiN;
|
|---|
| 234 | fTrigPattern[0] = (UInt_t)(ulTP/4294967296.0) ;
|
|---|
| 235 | fTrigPattern[1] = (UInt_t)(ulTP-fTrigPattern[0]*4294967296.0);
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | Bool_t MRawEvtHeader::DecodeTime(UInt_t abstime[2]) const
|
|---|
| 239 | {
|
|---|
| 240 | // BADC|1032 --> DCBA|3210 (Byte swap - exchange MSB and LSB)
|
|---|
| 241 | *fLog << hex << all << endl << abstime[0] << " " << abstime[1] << endl;
|
|---|
| 242 |
|
|---|
| 243 | abstime[0] = (abstime[0]<<16) | (abstime[0]>>16);
|
|---|
| 244 | // abstime[1] = (abstime[1]<<16) | (abstime[1]>>16);
|
|---|
| 245 | // *fLog << hex << abstime[0] << " " << abstime[1] << endl;
|
|---|
| 246 | // *fLog << dec;
|
|---|
| 247 |
|
|---|
| 248 | abstime[0] = abstime[0]<<8&0xff00 | abstime[0]>>8&0x00ff | abstime[0]&0xffff0000;
|
|---|
| 249 | abstime[1] = abstime[1]<<8&0xff00 | abstime[1]>>8&0x00ff | abstime[1]&0xffff0000;
|
|---|
| 250 |
|
|---|
| 251 | for (int i=4*8-1; i>=0; i--)
|
|---|
| 252 | *fLog << (int)(abstime[0]&BIT(i)?1:0);
|
|---|
| 253 | *fLog << " ";
|
|---|
| 254 | for (int i=4*8-1; i>=0; i--)
|
|---|
| 255 | *fLog << (int)(abstime[1]&BIT(i)?1:0);
|
|---|
| 256 | *fLog << endl;
|
|---|
| 257 |
|
|---|
| 258 | /* *fLog << hex << abstime[0] << " " << abstime[1] << endl;
|
|---|
| 259 | */
|
|---|
| 260 |
|
|---|
| 261 | // Strange thing!
|
|---|
| 262 | Char_t t = abstime[0]>>8 &0xf;
|
|---|
| 263 | abstime[0] &= 0xfffff0ff;
|
|---|
| 264 |
|
|---|
| 265 | // *fLog << abstime[0]<< " " << (int)t << endl;
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 | for (int i=0; i<4; i++)
|
|---|
| 269 | {
|
|---|
| 270 | abstime[0] |= (t&BIT(i) ? 1 : 0)<<(11-i);
|
|---|
| 271 | //*fLog << ((t&BIT(i) ? 1 : 0)<<(11-i)) << " ";
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | //*fLog << endl << abstime[0]<< endl;
|
|---|
| 275 |
|
|---|
| 276 | // Decode
|
|---|
| 277 | const Byte_t h = (abstime[0]>>18 & 0x3)*10 + (abstime[0]>>14 & 0xf);
|
|---|
| 278 | const Byte_t m = (abstime[0]>>11 & 0x7)*10 + (abstime[0]>> 7 & 0xf);
|
|---|
| 279 | const Byte_t s = (abstime[0]>> 4 & 0x7)*10 + (abstime[0]>> 0 & 0xf);
|
|---|
| 280 | const Int_t ms =
|
|---|
| 281 | ((abstime[0]>>12)&0xf)*1000 +
|
|---|
| 282 | ((abstime[0]>> 8)&0xf)* 100 +
|
|---|
| 283 | ((abstime[0]>> 4)&0xf)* 10 +
|
|---|
| 284 | ((abstime[0]>> 0)&0xf)* 1;
|
|---|
| 285 |
|
|---|
| 286 | // hms =3210 --> h=2:4 m=3:4 s=3:4
|
|---|
| 287 | // subsec=DCBA --> subsec?
|
|---|
| 288 | *fLog << all << dec << setfill('0') << setw(2) << (int)h << ":" << setw(2) << (int)m << ":" << setw(2) << (int)s;
|
|---|
| 289 | *fLog << " " << hex;
|
|---|
| 290 | *fLog << (int)(abstime[0]>>12 & 0xf) << ".";
|
|---|
| 291 | *fLog << (int)(abstime[0]>> 8 & 0xf) << ".";
|
|---|
| 292 | *fLog << (int)(abstime[0]>> 4 & 0xf) << ".";
|
|---|
| 293 | *fLog << (int)(abstime[0]>> 0 & 0xf);
|
|---|
| 294 | *fLog << endl;
|
|---|
| 295 |
|
|---|
| 296 | // Update the time stamp with the current event time.
|
|---|
| 297 | // Make sure, that the time stamp was initialized correctly
|
|---|
| 298 | // with the start-date/time of the run (after reading the run header)
|
|---|
| 299 | //
|
|---|
| 300 | // Here the nanosec precision is ignored... (FIXME!)
|
|---|
| 301 |
|
|---|
| 302 | static int i=0;
|
|---|
| 303 | i++;
|
|---|
| 304 | fTime->Print();
|
|---|
| 305 | fTime->UpdMagicTime(h, m, s, 0/*ms*/);
|
|---|
| 306 | fTime->Print();
|
|---|
| 307 | return i<5;
|
|---|
| 308 | //return fTime->UpdMagicTime(h, m, s, ms);
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | // --------------------------------------------------------------------------
|
|---|
| 312 | //
|
|---|
| 313 | // read the EVENT HEADER information from the input stream
|
|---|
| 314 | // return FALSE if there is now header anymore, else TRUE
|
|---|
| 315 | //
|
|---|
| 316 | // Updates the time stamp with the current event time.
|
|---|
| 317 | // Make sure, that the time stamp was initialized correctly
|
|---|
| 318 | // with the start-date/time of the run (after reading the run header)
|
|---|
| 319 | //
|
|---|
| 320 | // Remark: This 'feature' disallows single runs of more than 11h!
|
|---|
| 321 | //
|
|---|
| 322 | int MRawEvtHeader::ReadEvt(istream &fin)
|
|---|
| 323 | {
|
|---|
| 324 | fin.read((char*)&fDAQEvtNumber, 4); // Total=4
|
|---|
| 325 |
|
|---|
| 326 | *fLog << "N: " << fDAQEvtNumber << endl;
|
|---|
| 327 |
|
|---|
| 328 | UInt_t abstime[2]; // BADC|1032
|
|---|
| 329 | fin.read((char*)abstime, 8); // Total=12
|
|---|
| 330 | if (!DecodeTime(abstime))
|
|---|
| 331 | {
|
|---|
| 332 | *fLog << err << "ERROR - Event time in event header invalid... abort." << endl;
|
|---|
| 333 | return kFALSE;
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | Byte_t dummy[4];
|
|---|
| 337 | fin.read((char*)&fNumTrigLvl1, 4); // Total=16
|
|---|
| 338 | fin.read((char*)&fNumTrigLvl2, 4); // Total=20
|
|---|
| 339 | fin.read((char*)fTrigPattern, 8); // Total=28
|
|---|
| 340 | fin.read((char*)&fTrigType, 2); // Total=30
|
|---|
| 341 | fin.read((char*)dummy, 2); // Total=32, was fAllLoGainOn
|
|---|
| 342 | fin.read((char*)fPixLoGainOn->GetArray(), fPixLoGainOn->GetSize());
|
|---|
| 343 |
|
|---|
| 344 | *fLog << "T: " << fTrigType << endl;
|
|---|
| 345 |
|
|---|
| 346 | fNumLoGainOn = 0;
|
|---|
| 347 | for (unsigned int i=0; i<fPixLoGainOn->GetSize(); i++)
|
|---|
| 348 | for (int j=0; j<8; j++)
|
|---|
| 349 | if ((*fPixLoGainOn)[i] & (1<<j))
|
|---|
| 350 | fNumLoGainOn++;
|
|---|
| 351 |
|
|---|
| 352 | fin.read((char*)&dummy, 4);
|
|---|
| 353 |
|
|---|
| 354 | return !fin.eof();
|
|---|
| 355 | }
|
|---|