]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/PHOS/AliHLTPHOSRawAnalyzerComponent.cxx
New classes that updates histograms contniously during run.
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRawAnalyzerComponent.cxx
index 26530aeef8b1e5b306f423c552ce169c4949a3c7..52ca390651bc1db6943a5dd7346f77fba0bae512 100644 (file)
@@ -1,9 +1,11 @@
-
 /**************************************************************************
- * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved.      *
- *                                                                        *
- * Author: Per Thomas Hille for the ALICE HLT Project.                    *
+ * This file is property of and copyright by the Experimental Nuclear     *
+ * Physics Group, Dep. of Physics                                         *
+ * University of Oslo, Norway, 2007                                       *
+ *                                                                        * 
+ * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
  * Contributors are mentioned in the code where appropriate.              *
+ * Please report bugs to perthi@fys.uio.no                                * 
  *                                                                        *
  * Permission to use, copy, modify and distribute this software and its   *
  * documentation strictly for non-commercial purposes is hereby granted   *
 #include "AliHLTPHOSRawAnalyzerComponent.h"
 #include <iostream>
 #include "stdio.h"
-
 #include "AliRawReaderMemory.h"
 #include "AliCaloRawStream.h"
 #include <cstdlib>
-//#include "TH2.h"
-
-//#include "AliHLTTPCDefinitions.h"
+#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
 
 const AliHLTComponentDataType AliHLTPHOSRawAnalyzerComponent::inputDataTypes[]={kAliHLTVoidDataType,{0,"",""}}; //'zero' terminated array
-const AliHLTComponentDataType AliHLTPHOSRawAnalyzerComponent::outputDataType=kAliHLTVoidDataType;
-
-
-//AliHLTPHOSRawAnalyzerComponent gAliHLTPHOSRawAnalyzerComponent;
-//ClassImp(AliHLTPHOSRawAnalyzerComponent) 
-AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTProcessor(),  eventCount(0), fPHOSRawStream(), fRawMemoryReader(0)
+int   AliHLTPHOSRawAnalyzerComponent::fEventCount = 0; 
+
+
+/**
+ * @class AliHLTPHOSRawAnalyzerComponent
+ * Base class of PHOS HLT online raw analysis component.
+ * The class provides a common interface for the implementation of PHOS 
+ * HLT raw data
+ * processors components. The class is intended for processing of 
+ * arrays of raw data samples to evaluate energy and timing.
+ * The Energy will be given in entities of ADC leves ranging from 0 to
+ * 1023. Timing will be given in entities of samples periods.
+ * Drived clases  must implement the fucntions
+ * - @ref GetComponentID
+ * - @ref Spawn
+ */
+AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTProcessor(), analyzerPtr(0), fEquippmentID(0), fRcuX(0), 
+fRcuZ(0),fRcuZOffset(0), fRcuXOffset(0),  fModuleID(0), fPHOSRawStream(0), fRawMemoryReader(0), fOutPtr(0)
 {
-  //  fRawMemoryReader = NULL;
+
 } 
 
 AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
@@ -51,21 +62,32 @@ AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
 
 
 
-AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent(const AliHLTPHOSRawAnalyzerComponent & ) : AliHLTProcessor(),  eventCount(0), fPHOSRawStream(),fRawMemoryReader(0)
+AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent(const AliHLTPHOSRawAnalyzerComponent & ) : AliHLTProcessor(), analyzerPtr(0), 
+fEquippmentID(0), fRcuX(0), fRcuZ(0),fRcuZOffset(0), fRcuXOffset(0),  fModuleID(0), fPHOSRawStream(0), fRawMemoryReader(0), fOutPtr(0)
 {
-  //  fRawMemoryReader = NULL;
 }
 
 
+/*
+ *Deinit function called by the HLT framwork at end of run
+ *@return 0 if the denitialzation was sucessfull.
+ */
 int 
 AliHLTPHOSRawAnalyzerComponent::Deinit()
 {
+  cout <<  "Deinit" << endl;
   return 0;
 }
 
+
+/*
+ *Deinit function called by the HLT framwork at end of run
+ *@return 0 if the denitialzation was sucessfull.
+ */
 int 
 AliHLTPHOSRawAnalyzerComponent::DoDeinit()
 {
+  cout << "DoDeinit" << endl;
   Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen DoDeinit");
 
   if(fRawMemoryReader !=0)
@@ -81,12 +103,17 @@ AliHLTPHOSRawAnalyzerComponent::DoDeinit()
 
 }
 
+/*
+ *Function called by the HLT framework during initialization
+ *@return the ID of the component
+ */
 const char* 
 AliHLTPHOSRawAnalyzerComponent::GetComponentID()
 {
   return "AliPhosTestRaw";
 }
 
+
 void
 AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
 {
@@ -100,14 +127,15 @@ AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataTyp
 AliHLTComponentDataType 
 AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
 {
-  return outputDataType;
+  return AliHLTPHOSDefinitions::gkCellEnergyDataType;
 }
 
 void
 AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
 
 {
-  constBase = 0;inputMultiplier = 0;
+  constBase = 30;
+  inputMultiplier = 0.1;
 }
 
 
@@ -115,34 +143,41 @@ int AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evt
                                              AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
                                              AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
 {
-  Int_t tmpMod  = 0;
-  Int_t tmpRow  = 0;
-  Int_t tmpCol  = 0;
-  Int_t tmpGain = 0;
+  AliHLTUInt8_t tmpMod    = 0;
+  AliHLTUInt8_t tmpZ      = 0;
+  AliHLTUInt8_t tmpX      = 0;
+  AliHLTUInt8_t tmpGain   = 0;
+  Int_t sampleCnt         = 0;
   Int_t processedChannels = 0;
-  //  Int_t tmpMax  = 0;
+  UInt_t offset           = 0; 
+  UInt_t mysize           = 0;
+  UInt_t tSize            = 0;
+  Int_t tmpChannelCnt     = 0;
+  Int_t tmpStartIndex     = 0;
+  AliHLTUInt8_t* outBPtr;
+  outBPtr = outputPtr;
   const AliHLTComponentBlockData* iter = NULL; 
   unsigned long ndx;
-  Reset();
 
   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
     {
       iter = blocks+ndx;
-      if (eventCount == 0)
-       {
-         continue;
-       }
+      mysize = 0;
+      offset = tSize;
+
       if ( iter->fDataType != AliHLTPHOSDefinitions::gkDDLPackedRawDataType )
        {
-         cout << "Warning: data type = is nOT gkDDLPackedRawDataType " << endl;
          continue;
        }
-     fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
-     fRawMemoryReader->DumpData();
-     fRawMemoryReader->RewindEvents();
 
-     analyzerPtr->SetData(fTmpChannelData);
+      fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
+      analyzerPtr->SetData(fTmpChannelData);
+      fOutPtr =  (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
+      mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
+      fOutPtr->fRcuX = fRcuX;
+      fOutPtr->fRcuZ = fRcuZ;
+      fOutPtr->fModuleID = fModuleID;
+      tmpChannelCnt = 0;
  
       while(fPHOSRawStream->Next())
        {
@@ -151,72 +186,109 @@ int AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evt
              if(processedChannels > 0)
                {
                  analyzerPtr->SetData(fTmpChannelData);
-                 analyzerPtr->Evaluate(0, 1008);
-                 fMaxValues[tmpMod][tmpRow][tmpCol][tmpGain] = analyzerPtr->GetEnergy();
-                 ResetDataPtr(); 
+                 analyzerPtr->Evaluate(0, sampleCnt);
+                 //              sampleCnt = 0;
+                 fOutPtr->fValidData[tmpChannelCnt].fGain = tmpGain;
+                 fOutPtr->fValidData[tmpChannelCnt].fZ  = tmpZ;
+                 fOutPtr->fValidData[tmpChannelCnt].fX  = tmpX; 
+                 fOutPtr->fValidData[tmpChannelCnt].fEnergy  = analyzerPtr->GetEnergy();
+                 fOutPtr->fValidData[tmpChannelCnt].fTime    = analyzerPtr->GetTiming();
+                 tmpChannelCnt ++;
+                 ResetDataPtr(tmpStartIndex, sampleCnt);
+                 sampleCnt = 0;
                }
 
-             tmpMod  =  fPHOSRawStream->GetModule();
-             tmpRow  =  fPHOSRawStream->GetRow();
-             tmpCol  =  fPHOSRawStream->GetColumn();
+             tmpMod  = (AliHLTUInt8_t)fPHOSRawStream->GetModule() ;
+             tmpX  =(AliHLTUInt8_t)fPHOSRawStream->GetRow() - fRcuXOffset;
+             tmpZ  =(AliHLTUInt8_t)fPHOSRawStream->GetColumn() - fRcuZOffset;
              tmpGain =  fPHOSRawStream->IsLowGain(); 
              processedChannels ++;
            }
 
+         
+         if(sampleCnt == 0)
+           {
+             tmpStartIndex = fPHOSRawStream->GetTime();
+           }
+         
          fTmpChannelData[fPHOSRawStream->GetTime()] =  fPHOSRawStream->GetSignal();
+         sampleCnt ++;
+
+       }
+   
+      tmpChannelCnt ++;
+      analyzerPtr->SetData(fTmpChannelData);
+      analyzerPtr->Evaluate(0, sampleCnt);
+      //                 sampleCnt = 0;
+      fOutPtr->fValidData[tmpChannelCnt].fGain = tmpGain;
+      fOutPtr->fValidData[tmpChannelCnt].fZ  = tmpZ;
+      fOutPtr->fValidData[tmpChannelCnt].fX  = tmpX; 
+      fOutPtr->fValidData[tmpChannelCnt].fEnergy  = analyzerPtr->GetEnergy();
+      fOutPtr->fValidData[tmpChannelCnt].fTime    = analyzerPtr->GetTiming();
+      //      tmpChannelCnt ++;
+   
+      ResetDataPtr(tmpStartIndex, sampleCnt);
+      sampleCnt = 0;
+
+
+
+      fOutPtr->fCnt =  tmpChannelCnt;
+      AliHLTComponentBlockData bd;
+      FillBlockData( bd );
+      bd.fOffset = offset;
+      bd.fSize = mysize;
+      bd.fDataType = AliHLTPHOSDefinitions::gkCellEnergyDataType;
+      bd.fSpecification = 0xFFFFFFFF;
+      outputBlocks.push_back( bd );
+      tSize += mysize;
+      outBPtr += mysize;
+      
+      if( tSize > size )
+       {
+         Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
+                  "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
+                  , tSize, size );
+         return EMSGSIZE;
        }
     }
-  DumpData();
+
   fEventCount++; 
+  size = tSize;
   return 0;
 }//end DoEvent
 
 
-
 int
 AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
 {
-  cout << "DOINIT argc =" << argc << endl;
-  cout << "DOINIT argv[0] =" << argv[0] << endl;
-  cout << "DOINIT argv[1] =" << argv[1] << endl;
-  cout << "DOINIT argv[2] =" << argv[2] << endl;
-  cout << "DOINIT argv[3] =" << argv[3] << endl;
-  cout << "DOINIT argv[4] =" << argv[4] << endl;
-  cout << "DOINIT argv[5] =" << argv[5] << endl;
-  cout << "DOINIT argv[6] =" << argv[6] << endl;
-  int equippmentId = atoi(argv[6]);
-  cout << "The equipment ID was set to " <<equippmentId << endl;
-  
- //fRawMemoryReader->SetEquipmentID(1806); 
-
+  int equippmentID = atoi(argv[6]);
   Reset();
-  cout << "AliHLTPHOSRawAnalyzerComponent::DoInit Creating new  AliRawReaderMemory()" << endl; 
-  legoPlotPtr   = new TH2S("Lego plot 1","Phi0 20Gev, High gain", 56*5, 0, 56*5, 64, 0, 64);
   fRawMemoryReader = new AliRawReaderMemory();
   fPHOSRawStream = new  AliCaloRawStream(fRawMemoryReader,"PHOS");
-  fRawMemoryReader->SetEquipmentID(equippmentId); 
-
-  cout <<"AliHLTPHOSRawAnalyzerComponent::DoIni  DONE!" << endl;
+  fPHOSRawStream->SetOldRCUFormat(kFALSE);
+  fRawMemoryReader->SetEquipmentID(equippmentID); 
+  SetEquippmentID(equippmentID);
+  SetCoordinates(equippmentID);
   if (argc==0 && argv==NULL) {
     // this is currently just to get rid of the warning "unused parameter"
   }
   return 0;
 }
 
+
 void
-AliHLTPHOSRawAnalyzerComponent::DumpData()
+AliHLTPHOSRawAnalyzerComponent::DumpData(int gain)
 {
-  for(int mod = 0; mod <5; mod ++)
+  for(int mod = 0; mod < N_MODULES; mod ++)
     {
       printf("\n ***********  MODULE %d ************\n", mod);
-      for(int row = 0; row < 64; row ++)
+      for(int row = 0; row <  N_ROWS_MOD; row ++)
        {
-         for(int col = 0; col < 56; col ++)
+         for(int col = 0; col <  N_COLUMNS_MOD; col ++)
            {
              if( fMaxValues[mod][row][col][0] != 0)
                { 
-                 cout << fMaxValues[mod][row][col][0] << "\t";
+                 cout << fMaxValues[mod][row][col][gain] << "\t";
                }
            }
        } 
@@ -224,16 +296,48 @@ AliHLTPHOSRawAnalyzerComponent::DumpData()
 }
 
 
+void
+AliHLTPHOSRawAnalyzerComponent::DumpData()
+{
+  DumpData(0);
+}
+
+void
+AliHLTPHOSRawAnalyzerComponent::DumpChannelData(Double_t *data)
+{
+      cout << endl;
+      
+      for(int i=0; i<  ALTRO_MAX_SAMPLES; i++)
+       {
+         if (data[i] != 0)
+           {
+             cout <<i <<"\t";
+           }
+       }
+      cout << endl;
+      
+      for(int i=0; i<  ALTRO_MAX_SAMPLES; i++)
+       {
+         if (data[i] != 0)
+           {
+             cout <<data[i] <<"\t";
+           }
+       }
+      
+      cout << endl;
+}
+
+
 void
 AliHLTPHOSRawAnalyzerComponent::Reset()
 {
-  for(int mod = 0; mod <5; mod ++)
+  for(int mod = 0; mod < N_MODULES; mod ++)
     {
-      for(int row = 0; row < 64; row ++)
+      for(int row = 0; row < N_ROWS_MOD; row ++)
        {
-         for(int col = 0; col < 56; col ++)
+         for(int col = 0; col < N_COLUMNS_MOD; col ++)
            {
-             for(int gain = 0; gain <2; gain ++ )
+             for(int gain = 0; gain < N_GAINS; gain ++ )
                {
                  fMaxValues[mod][row][col][gain] = 0;
                }
@@ -241,17 +345,93 @@ AliHLTPHOSRawAnalyzerComponent::Reset()
        }
     }
 
-  for(int i = 0 ; i< 1008; i++)
+  ResetDataPtr();
+
+} // end Reset
+
+
+void
+AliHLTPHOSRawAnalyzerComponent::ResetDataPtr()
+{
+  for(int i = 0 ; i< ALTRO_MAX_SAMPLES; i++)
     {
       fTmpChannelData[i] = 0;
     }
-} // end Reset
+}
 
 void
-AliHLTPHOSRawAnalyzerComponent::ResetDataPtr()
+AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int sampleCnt)
+{
+  for(int i = 0 ; i< sampleCnt; i++)
+    {
+      fTmpChannelData[i] = 0;
+    }
+}
+
+void
+AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int startindex, int sampleCnt)
 {
-  for(int i = 0 ; i< 1008; i++)
+  for(int i = startindex ; i< sampleCnt; i++)
     {
       fTmpChannelData[i] = 0;
     }
 }
+
+void 
+AliHLTPHOSRawAnalyzerComponent::SetEquippmentID(AliHLTUInt16_t id)
+{
+  fEquippmentID = id;
+}
+
+
+AliHLTUInt16_t
+AliHLTPHOSRawAnalyzerComponent::GetEquippmentID()
+{
+  return  fEquippmentID;
+}
+
+
+void 
+AliHLTPHOSRawAnalyzerComponent::SetCoordinates(AliHLTUInt16_t equippmentID)
+{
+  int rcuIndex =  (fEquippmentID - 1792)%N_RCUS_PER_MODULE;
+  fModuleID = (fEquippmentID  -1792 -rcuIndex)/N_RCUS_PER_MODULE;
+  
+  if(rcuIndex == 0)
+    {
+      fRcuX = 0; 
+      fRcuZ = 0;
+    }
+
+  if(rcuIndex == 1)
+    {
+      fRcuX = 0; 
+      fRcuZ = 1;
+    }
+  if(rcuIndex == 2)
+    {
+      fRcuX = 1; 
+      fRcuZ = 0;
+    }
+
+  if(rcuIndex == 3)
+    {
+      fRcuX = 1; 
+      fRcuZ = 1;
+    }
+
+
+
+  fRcuZOffset =  N_ZROWS_RCU*fRcuZ;
+  fRcuXOffset =  N_XCOLUMNS_RCU*fRcuX;
+
+  cout <<"********InitInfo************"<< endl;
+  cout <<"AliHLTPHOSRawAnalyzerComponent::SetCoordinate"<< endl;
+  cout <<"Equpippment ID =\t"<< fEquippmentID <<endl;
+  cout <<"Module ID =\t"<<  (int)fModuleID<<endl;
+  cout <<"RCUX =\t\t" << (int)fRcuX << endl;
+  cout <<"RCUZ =\t\t" << (int)fRcuZ << endl;
+  cout <<"RcuZOffset = \t" <<  (int)fRcuZOffset << endl;
+  cout <<"RcuXOffset = \t" <<  (int)fRcuXOffset << endl << endl;
+}