Index: trunk/MagicSoft/include-Classes/MRawEvt.cxx
===================================================================
--- trunk/MagicSoft/include-Classes/MRawEvt.cxx	(revision 374)
+++ trunk/MagicSoft/include-Classes/MRawEvt.cxx	(revision 434)
@@ -6,4 +6,5 @@
 #include "MRawEvt.h"
 #include "MRawPixel.h"
+#include "MRawCrate.h"
 
 #include "Mdefine.h"
@@ -14,7 +15,8 @@
 // (Photomultipliers) from the Camera of MAGIC. So all data (FADC) of the 
 // interesting pixels are the modules of an event. To describe pixels the 
-// class MRawPixel is used.  To define a single events
-// some other data members are needed (Time of the events, kind of event..).
-//
+// class MRawPixel is used and the class MRawCrate to describe Crates.
+// To define a single events some other data members are needed 
+// (Time of the events, tirgger pattern of event..)
+// 
 // To describe one event on the level of FADC values the Class MRawEvt is
 // created. It has the following data members: 
@@ -22,5 +24,5 @@
 // ----------
 //
-// UInt_t    EvtNo    
+// UInt_t    DAQEvtNumber    
 //
 // This it the number of the Event in one 
@@ -37,5 +39,5 @@
 // ----------
 //
-// ULong_t   fTimeStamp
+// UInt_t   AbsTime[2]
 //   
 // Time of the event. 
@@ -43,5 +45,5 @@
 // the millenium. From that start point the time is
 // measured in 200ns-count. One day for example
-// contains 432.e9 counts. An unsigned Long is able to 
+// contains 432.e9 counts. An array of two unsigned Int is able to 
 // contain 1.8e19 200ns-counts. This corresponds to 41.e6
 // days. This should be more than the livetime of MAGIC.
@@ -49,13 +51,5 @@
 // ----------
 //
-// UChar_t   EvtStatus 
-//
-// Status of Event. 
-// This is a Byte (8 bit) to indicated the status of 
-// the event (Pedestal, Calibration, etc). 
-//
-// ----------
-//
-// UShort_t  Trig1st
+// UInt_t  FstLvlTrigNumber
 //
 // Number of first level trigger
@@ -70,24 +64,64 @@
 // ----------
 //
-// UShort_t  MultPixel
-//
-// Multiplicity of Pixels
-// Each event consists of a specific number of 
-// pixels. This is the number of pixels in one event. 
-// The array of ClonesPixels (taClonesArray) is of this
-// size. 
-//
-// ----------
-//
-// TClonesArray  *Pixels
-//
-// Array of Pixels 
+// UInt_t  SecLvlTrigNumber
+//
+// Number of second level trigger
+// This member counts the number of Second Level Trigger
+// between the last and this event. 
+//
+// ----------
+//
+// UInt_t  TriggerPattern[2]
+//
+// Trigger Pattern used for this event
+// Each event triggers for a particular configuration and each  
+// configuration shoul have an ID (which is not fixed yet).
+//
+// ----------
+//
+// Byte_t   TriggerType 
+//
+// Type of Trigger. 
+// This is a Byte (8 bit) to indicated the status of 
+// the event (Normal (0), Pedestal (1), Calibration (2), etc). 
+//
+// ----------
+//
+// Byte_t   AllLowGainOn
+//
+// Type of Trigger. 
+// This is a Byte (8 bit) to indicated if any of the pixels 
+// have a non-negligible low gain (1) or not (0) 
+//
+// ----------
+//
+// TClonesArray  *Crates
+//
+// Array of Crates
+// The Clones array is a list of the Crates used in one
+// event with the information about the Crate. 
+//
+// ----------
+//
+// TClonesArray  *PixelsHigh
+//
+// Array of Pixels for their high voltage channel
 // The Clones array is a list of the Pixels used in one
 // event with the information about the Pixels. 
 //
 //
-
-//
-void GetFadcNoise ( UChar_t asF[] ) 
+// ----------
+//
+// TClonesArray  *PixelsLow
+//
+// Array of Pixels for their low voltage channel
+// The Clones array is a list of the Pixels used in one
+// event that have a significant signal in the low gain channel
+// with the information about the Pixels. 
+//
+//
+
+//
+void GetFadcNoise ( Byte_t asF[] ) 
 {
   static TRandom Gen ; 
@@ -95,5 +129,5 @@
   for (Int_t i=0; i<FADC_SLICES; i++ ) {   
     Gen.Rannor(z1, z2) ;
-    asF[i] = 10 + (UChar_t)(z1*4) ;  
+    asF[i] = 10 + (Byte_t)(z1*4) ;  
     // if (asF[i] < 0 ) asF[i] = 0 ; 
   } 
@@ -108,9 +142,11 @@
   //   set all member to zero, init the pointer to ClonesArray, 
 
-  EvtNo      = 0 ; 
-  fTimeStamp  = 0 ; 
-  EvtStatus  = 0 ; 
-  Trig1st    = 0 ;
-  MultPixel  = 0 ; 
+  DAQEvtNumber      = 0 ; 
+  AbsTime[0] = AbsTime [1]  = 0 ; 
+  FstLvlTrigNumber = 0 ;
+  SecLvlTrigNumber = 0 ;
+  TriggerPattern[0] = TriggerPattern[1] = 0 ;
+  TriggerType = 0 ;
+  AllLowGainOn = 0 ;
 
   // 
@@ -120,5 +156,7 @@
   //   initialize the list to this global pointer
   
-  Pixels = new TClonesArray ("MRawPixel", 2*CAMERA_PIXELS ) ; 
+  PixelsHigh = new TClonesArray ("MRawPixel", 5*CAMERA_PIXELS ) ; 
+  PixelsLow = new TClonesArray ("MRawPixel", CAMERA_PIXELS ) ; 
+  Crates = new TClonesArray ("MRawCrate", 25 ) ; 
 
   cout << " default constructor " << endl ; 
@@ -130,5 +168,7 @@
   //   Implementation of the default destructor
   //
-  delete Pixels ; 
+  delete PixelsHigh ;
+  delete PixelsLow ;
+  delete Crates ;
   cout << " default destructor " << endl ; 
 }
@@ -140,11 +180,15 @@
   //   Resets all members to zero, clear the list of Pixels
   //
-  EvtNo      = 0 ; 
-  fTimeStamp  = 0 ; 
-  EvtStatus  = 0 ; 
-  Trig1st    = 0 ;
-  MultPixel  = 0 ; 
-
-  Pixels->Clear() ; 
+  DAQEvtNumber      = 0 ; 
+  AbsTime[0] = AbsTime [1]  = 0 ; 
+  FstLvlTrigNumber = 0 ;
+  SecLvlTrigNumber = 0 ;
+  TriggerPattern[0] = TriggerPattern[1] = 0 ;
+  TriggerType = 0 ;
+  AllLowGainOn = 0 ;
+
+  PixelsHigh->Clear() ; 
+  PixelsLow->Clear() ; 
+  Crates -> Clear() ;
 }
 
@@ -156,50 +200,53 @@
   //
 
+  Int_t i = 0;
+
   // Prints out the data of one Pixel
-  cout << endl << "EventNumber      " << EvtNo          ; 
-  cout << endl << "Event Time Stamp " << fTimeStamp      ;
-  cout << endl << "Event Status     " << (int) EvtStatus      ; 
-  cout << endl << "Trigger 1. Level " << Trig1st        ; 
-  cout << endl << "Number of Pixels " << MultPixel      ; 
-
-  for (Int_t i=0 ; i<MultPixel; i++ ) {
-    ((MRawPixel *)Pixels->At(i))->Print() ;    
+  cout << endl << "EventNumber      " << DAQEvtNumber          ; 
+  cout << endl << "Event Time Stamp " << (Float_t) AbsTime[0]*4294967296
+    +AbsTime[1]    ;
+  cout << endl << "Trigger 1. Level " << FstLvlTrigNumber        ; 
+  cout << endl << "Trigger 2. Level " << SecLvlTrigNumber        ; 
+  cout << endl << "Trigger Pattern " << (Float_t) TriggerPattern[0]*4294967296
+    +TriggerPattern[1]    ;
+  cout << endl << "Trigger Type ";
+  switch (TriggerType){
+  case 0:   
+    cout<<" Normal Trigger ";
+    break;
+  case 1:  
+    cout<<" Pedestal ";
+    break;
+  case 2:
+    cout<<" Calibration ";
+    break;
+  default:
+    cout<<TriggerType;
+    break;
   }
-}
-
-
-void MRawEvt::FillRandom ( UInt_t uiN, ULong_t ulT,  UShort_t usMuPi ) {
-  //
-  //  This is neccessary to fill the MRawEvt Class with randomized FADC
-  //  values. The EventNumber, EventTime and the Number of Pixels are given 
-  //  as parameters. 
-  // 
-
-  EvtNo      = uiN ; 
-  fTimeStamp  = ulT ; 
-
-  UChar_t   ucA[FADC_SLICES] ;
-
-  for (UShort_t i = 0 ; i< usMuPi; i++ ) {
-    GetFadcNoise ( ucA ) ;   
-  
-    TClonesArray &caP = *Pixels ;
-    new ( caP[MultPixel++] ) MRawPixel((MultPixel), 0, ucA) ; 
+
+  cout<<"High Voltage channel"<<endl;
+  while (PixelsHigh+i) {
+    ((MRawPixel *)PixelsHigh->At(i))->Print() ;
+    i++;    
   }
-}
-
-void MRawEvt::FillHeader ( UInt_t uiN, ULong_t ulT, UChar_t ucSta ) {
+  cout<<"Low Voltage channel"<<endl;
+  while (PixelsLow+i) {
+    ((MRawPixel *)PixelsLow->At(i))->Print() ;
+    i++;    
+  }
+}
+
+void MRawEvt::FillHeader ( UInt_t uiN, Float_t ulT, Float_t ulTP ) {
    
-  EvtNo      = uiN ; 
-  fTimeStamp  = ulT ; 
-  
-  EvtStatus  = ucSta ; 
-  Trig1st    = 0 ;
-  MultPixel  = 0   ; 
-
-  Pixels->Clear()  ; 
-}
-
-void MRawEvt::FillPixel ( UShort_t uiPix, Float_t *array ) {
+  DAQEvtNumber = uiN ; 
+  AbsTime[0]  = (UInt_t) (ulT/4294967296) ; 
+  AbsTime[1]  = (UInt_t) (ulT-AbsTime[0]*4294967296) ;
+  TriggerPattern[0]  = (UInt_t) (ulTP/4294967296) ;
+  TriggerPattern[1] = (UInt_t) (ulTP-TriggerPattern[0]*4294967296) ;
+
+}
+
+void MRawEvt::FillPixel ( Short_t siPix, UShort_t *MultPixel, Float_t *array ) {
   //
   //  This is to fill the data of one pixel to the MRawEvt Class. 
@@ -207,49 +254,41 @@
   // 
 
-  UChar_t   ucA[FADC_SLICES] ;
-
-  for (UShort_t i = 0 ; i< FADC_SLICES ; i++ ) {
-    ucA[i] = (UShort_t) array[i] ; 
+  Int_t i = 0;
+  Byte_t   ucA[FADC_SLICES] ;
+
+  for(i=0;i<FADC_SLICES;i++){
+    ucA[i] = (Byte_t) array[i] ; 
   } 
   
-  TClonesArray &caP = *Pixels ;
-  new ( caP[MultPixel++] ) MRawPixel((uiPix), 0, ucA) ; 
-}
-
-void MRawEvt::FillMontCarl ( UInt_t uiN, ULong_t ulT,  Float_t *array ) {
-  //
-  //  This is neccessary to fill the MRawEvt Class with randomized FADC
-  //  values. The EventNumber, EventTime and the Number of Pixels are given 
-  //  as parameters. 
+  TClonesArray &caP = *PixelsHigh ;
+  new ( caP[(*(MultPixel))++] ) MRawPixel((siPix), ucA) ; 
+}
+
+void MRawEvt::FillPixelLow ( Short_t siPix, UShort_t *MultPixel, Float_t *array ) {
+  //
+  //  This is to fill the data of one pixel to the MRawEvt Class. 
+  //  The parameters are the pixelnumber and the FADC_SLICES values of ADCs
   // 
 
-  EvtNo      = uiN ; 
-  fTimeStamp  = ulT ; 
-
-  MultPixel = 0 ; 
-
-  UChar_t   ucA[FADC_SLICES] ;
-
-  for (UShort_t i = 0 ; i< CAMERA_PIXELS; i++ ) {
-
-    if ( array[i] > 0. ) { 
-      for ( Int_t ii = 0 ; ii < FADC_SLICES ; ii++ ) { 
-	ucA[ii] = 0 ; 
-      }
-      ucA[5] = (UShort_t) (array[i]) ; 
-      
-      TClonesArray &caP = *Pixels ;
-      new ( caP[MultPixel++] ) MRawPixel(i, 0, ucA) ; 
-    }
-  }
-}
-
-UShort_t MRawEvt::GetMultPixel() {
-  //
-  //  returns the pixel multiplicity of the Event
-  //
-  return MultPixel;
-}
-
+  Int_t i = 0;
+  Byte_t   ucA[FADC_SLICES] ;
+
+  for(i=0;i<FADC_SLICES;i++){
+    ucA[i] = (Byte_t) array[i] ; 
+  } 
+  
+  TClonesArray &caP = *PixelsLow ;
+  new ( caP[(*(MultPixel))++] ) MRawPixel((siPix), ucA) ; 
+}
+
+UShort_t MRawEvt::GetMultPixel(){
+  //
+  // returns the number of pixells which are already in the list
+  //
+
+  UShort_t i =0;
+  while(PixelsHigh+i) i++;
+  return (i);
+}
 
 //  void MRawEvt::AddPixel ( UShort_t usP ) {
@@ -261,8 +300,5 @@
 //  }
 
-//  void MRawEvt::AddPixel ( UShort_t usP, UChar_t ucStat, UChar_t ausAR[] ) {
+//  void MRawEvt::AddPixel ( UShort_t usP, UChar_t ucStat, Byte_t ausAR[] ) {
 //    cout << " need implementation 2 " << endl ;  
 //  }
-
-
-
