]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDBaseDA.cxx
Mods in QuadraticRoots
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDA.cxx
index e6793602ce16baaba0d9b7d02e74ee7cce969dc2..2cb422c7a4d1859d17f961ad48fc9662d404a8f2 100644 (file)
 
 #include "AliFMDBaseDA.h"
 #include "iostream"
-
 #include "AliFMDRawReader.h"
 #include "AliFMDCalibSampleRate.h"
+#include "AliFMDCalibStripRange.h"
 #include "AliLog.h"
+#include "AliRawEventHeaderBase.h"
+
 //_____________________________________________________________________
 ClassImp(AliFMDBaseDA)
 #if 0 
@@ -82,15 +84,18 @@ AliFMDBaseDA::GetDetectorPath(UShort_t det,
 }
 
 //_____________________________________________________________________
-AliFMDBaseDA::AliFMDBaseDA() : TNamed(),
+AliFMDBaseDA::AliFMDBaseDA() : 
+  TNamed(),
   fDiagnosticsFilename("diagnosticsHistograms.root"),
   fOutputFile(),
   fConditionsFile(),
   fSaveHistograms(kFALSE),
   fDetectorArray(),
+  fPulseSize(10),
+  fPulseLength(10),
   fRequiredEvents(0),
   fCurrentEvent(0)
-{
+ {
   fDetectorArray.SetOwner();
   fConditionsFile.open("conditions.csv");
 }
@@ -102,6 +107,8 @@ AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
   fConditionsFile(),
   fSaveHistograms(baseDA.fSaveHistograms),
   fDetectorArray(baseDA.fDetectorArray),
+  fPulseSize(baseDA.fPulseSize),
+  fPulseLength(baseDA.fPulseLength),
   fRequiredEvents(baseDA.fRequiredEvents),
   fCurrentEvent(baseDA.fCurrentEvent)
 {
@@ -123,44 +130,65 @@ void AliFMDBaseDA::Run(AliRawReader* reader)
   if (fSaveHistograms)
     diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
 
-  InitContainer(diagFile);
-  Init();
-
-
+  
+  
+  
+  
   reader->Reset();
   
   AliFMDRawReader* fmdReader  = new AliFMDRawReader(reader,0);
   TClonesArray*    digitArray = new TClonesArray("AliFMDDigit",0);
   
-  WriteConditionsData();
+  Bool_t SOD_read = kFALSE;
+  
+  for(Int_t i=0;i<3;i++) {
+    reader->NextEvent(); // Read Start-of-Run / Start-of-Files event
+    
+    UInt_t eventType = reader->GetType();
+    if(eventType == AliRawEventHeaderBase::kStartOfData || 
+       eventType == AliRawEventHeaderBase::kFormatError) { 
+      
+      WriteConditionsData(fmdReader);
+      Init();
+      SOD_read = kTRUE;
+      break;
+    }
+  }
+  
+  InitContainer(diagFile);
+  
+  if(!SOD_read) 
+    AliWarning("No SOD event detected!");
   
-  reader->NextEvent(); // Read Start-of-Run event
-  reader->NextEvent(); // Read Start-of-Files event
   int lastProgress = 0;
   
+  
+  
   for(Int_t n =1;n <= GetRequiredEvents(); n++) {
     if(!reader->NextEvent()) continue;
-    
-    SetCurrentEvent(*(reader->GetEventId()));
-    
+    SetCurrentEvent(n);
     digitArray->Clear();
     fmdReader->ReadAdcs(digitArray);
     
-    AliDebug(5, Form("In event # %d with %d entries", 
-                    *(reader->GetEventId()), digitArray->GetEntriesFast()));
+    //std::cout<<"in event "<<*(reader->GetEventId())<<"   "<<n<<std::endl;
+    //AliDebug(5, Form("In event # %d with %d entries", 
+    //              *(reader->GetEventId()), digitArray->GetEntriesFast()));
     
     for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
       AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
       FillChannels(digit);
     }
     
+   
     FinishEvent();
+    
     int progress = int((n *100)/ GetRequiredEvents()) ;
     if (progress <= lastProgress) continue;
     lastProgress = progress;
     std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
+    
   }
-
+  
   AliInfo(Form("Looped over %d events",GetCurrentEvent()));
   WriteHeaderToFile();
   
@@ -178,21 +206,26 @@ void AliFMDBaseDA::Run(AliRawReader* reader)
        }
        std::cout << '.' << std::flush;
       }
-      diagFile->Flush();
+      if(fSaveHistograms)
+       diagFile->Flush();
       std::cout << "done" << std::endl;
     }
   }
-
+  
   if(fOutputFile.is_open()) {
     fOutputFile.write("# EOF\n",6);
     fOutputFile.close();
   }
   
+  Terminate(diagFile);
+    
   if(fSaveHistograms ) {
+    
     AliInfo("Closing diagnostics file - please wait ...");
     // diagFile->Write();
     diagFile->Close();
     AliInfo("done");
+    
   }
 }
 //_____________________________________________________________________
@@ -259,43 +292,138 @@ void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
 }
 
 //_____________________________________________________________________ 
-void AliFMDBaseDA::WriteConditionsData() 
+void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader
 {
   AliFMDParameters* pars       = AliFMDParameters::Instance();
   fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
-  fConditionsFile.write("# Sample Rate, timebins \n",25);
   
-  UInt_t defSampleRate = 4;
-  UInt_t timebins   = 544;
   AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
-  for(UShort_t det=1;det<=3;det++) {
+  AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
+  
+  fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength);
+  
+  // Sample Rate
+  /*
+    UShort_t defSampleRate = 4;
+    UShort_t sampleRateFromSOD;
+    
+  AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
+
+  UShort_t firstStrip = 0;
+  UShort_t lastStrip  = 127;
+  UShort_t firstStripSOD;
+  UShort_t lastStripSOD;
+  AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
+  
+  for(Int_t det=1;det<=3;det++) {
     UShort_t FirstRing = (det == 1 ? 1 : 0);
     for (UShort_t ir = FirstRing; ir < 2; ir++) {
       Char_t   ring = (ir == 0 ? 'O' : 'I');
       UShort_t nsec = (ir == 0 ? 40  : 20);
-      UShort_t nstr = (ir == 0 ? 256 : 512);
       for(UShort_t sec =0; sec < nsec;  sec++)  {
-       for(UShort_t strip = 0; strip < nstr; strip++) {
-         sampleRate->Set(det,ring,sec,strip,defSampleRate);
-       }
+       sampleRateFromSOD = defSampleRate;
+       sampleRate->Set(det,ring,sec,0,sampleRateFromSOD);
+       firstStripSOD = firstStrip;
+       lastStripSOD  = lastStrip;
+       stripRange->Set(det,ring,sec,0,firstStripSOD,lastStripSOD);
+       
       }
     }
   }
+  */
+  sampleRate->WriteToFile(fConditionsFile);
+  stripRange->WriteToFile(fConditionsFile);
+  //pars->SetSampleRate(sampleRate);
+  //pars->SetStripRange(stripRange);
+
+  // Zero Suppresion
   
-  pars->SetSampleRate(sampleRate);
+  // Strip Range
   
+  fConditionsFile.write("# Gain Events \n",15);
+  
+  for(UShort_t det=1; det<=3;det++) {
+    UShort_t firstring = (det == 1 ? 1 : 0);
+    for(UShort_t iring = firstring; iring <=1;iring++) {
+      Char_t ring = (iring == 1 ? 'I' : 'O');
+      for(UShort_t board =0 ; board <=1; board++) {
+       
+       Int_t idx = GetHalfringIndex(det,ring,board);
+       
+       fConditionsFile << det                     << ','
+                       << ring                    << ','
+                       << board                   << ','
+                       << fPulseLength.At(idx)    << "\n";
+       
+      }
+    }
+  }
   
-  fConditionsFile     << defSampleRate   << ',' 
-                     << timebins     <<"\n";
+  fConditionsFile.write("# Gain Pulse \n",14);
   
+  for(UShort_t det=1; det<=3;det++) {
+    UShort_t firstring = (det == 1 ? 1 : 0);
+    for(UShort_t iring = firstring; iring <=1;iring++) {
+      Char_t ring = (iring == 1 ? 'I' : 'O');
+      for(UShort_t board =0 ; board <=1; board++) {
+       
+       Int_t idx = GetHalfringIndex(det,ring,board);
+       
+       fConditionsFile << det                     << ','
+                       << ring                    << ','
+                       << board                   << ','
+                       << fPulseSize.At(idx)      << "\n";
+       
+      }
+    }
+  }
+  
+  
+
+  // Gain Relevant stuff
+  /*
+  UShort_t defPulseSize = 32 ; 
+  UShort_t defPulseLength = 100 ; 
+  UShort_t pulseSizeFromSOD;
+  UShort_t pulseLengthFromSOD;  
+  
+  fPulseSize.Reset(defPulseSize);
+  fPulseLength.Reset(defPulseLength);
+  
+  for(UShort_t det=1;det<=3;det++)
+    for(UShort_t iring=0;iring<=1;iring++)
+      for(UShort_t board=0;board<=1;board++) {
+       pulseSizeFromSOD = defPulseSize;
+       pulseLengthFromSOD = defPulseLength;
+
+       fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
+       fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
+      }
+         
+  
+  //  fConditionsFile     << defSampleRate   << ',' 
+  //                 << timebins     <<"\n";
+  */
   if(fConditionsFile.is_open()) {
     
-    //  fConditionsFile.write("# EOF\n",6);
+    fConditionsFile.write("# EOF\n",6);
     fConditionsFile.close();
     
   }
   
 }
+//_____________________________________________________________________ 
+Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
+
+  UShort_t iring  =  (ring == 'I' ? 1 : 0);
+  
+  Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
+  
+  return index-2;
+  
+}
+
 
 //_____________________________________________________________________ 
 //