]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDBaseDA.cxx
Fixed coverty 'defects'
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDA.cxx
index 2cb422c7a4d1859d17f961ad48fc9662d404a8f2..e9c14346672eb12527fc8bd980389f147b669aaa 100644 (file)
@@ -33,6 +33,9 @@
 #include "AliFMDCalibStripRange.h"
 #include "AliLog.h"
 #include "AliRawEventHeaderBase.h"
+#include <TDatime.h>
+#include <TSystem.h>
+#include <TH2F.h>
 
 //_____________________________________________________________________
 ClassImp(AliFMDBaseDA)
@@ -48,6 +51,17 @@ AliFMDBaseDA::GetStripPath(UShort_t det,
                           UShort_t str, 
                           Bool_t   full) const
 {
+  // Get the strip path 
+  // 
+  // Parameters 
+  //     det      Detector number
+  //     ring     Ring identifier 
+  //     sec      Sector number 
+  //     str      Strip number
+  //     full     If true, return full path 
+  // 
+  // Return 
+  //     The path
   return Form("%s%sFMD%d%c[%02d,%03d]", 
              (full ? GetSectorPath(det, ring, sec, full) : ""), 
              (full ? "/" : ""), det, ring, sec, str);
@@ -59,6 +73,17 @@ AliFMDBaseDA::GetSectorPath(UShort_t det,
                            UShort_t sec, 
                            Bool_t   full) const
 {
+  // Get the strip path 
+  // 
+  // Parameters 
+  //     det      Detector number
+  //     ring     Ring identifier 
+  //     sec      Sector number 
+  //     str      Strip number
+  //     full     If true, return full path 
+  // 
+  // Return 
+  //     The path
   return Form("%s%sFMD%d%c[%02d]", 
              (full ? GetRingPath(det, ring, full) : ""), 
              (full ? "/" : ""), det, ring, sec);
@@ -69,6 +94,17 @@ AliFMDBaseDA::GetRingPath(UShort_t det,
                          Char_t   ring, 
                          Bool_t   full) const
 {
+  // Get the strip path 
+  // 
+  // Parameters 
+  //     det      Detector number
+  //     ring     Ring identifier 
+  //     sec      Sector number 
+  //     str      Strip number
+  //     full     If true, return full path 
+  // 
+  // Return 
+  //     The path
   return Form("%s%sFMD%d%c", 
              (full ? GetDetectorPath(det, full) : ""), 
              (full ? "/" : ""), det, ring);
@@ -78,6 +114,17 @@ const char*
 AliFMDBaseDA::GetDetectorPath(UShort_t det, 
                              Bool_t   full) const
 {
+  // Get the strip path 
+  // 
+  // Parameters 
+  //     det      Detector number
+  //     ring     Ring identifier 
+  //     sec      Sector number 
+  //     str      Strip number
+  //     full     If true, return full path 
+  // 
+  // Return 
+  //     The path
   return Form("%s%sFMD%d", 
              (full ? fDiagnosticsFilename.Data() : ""), 
              (full ? ":/" : ""), det);
@@ -90,13 +137,19 @@ AliFMDBaseDA::AliFMDBaseDA() :
   fOutputFile(),
   fConditionsFile(),
   fSaveHistograms(kFALSE),
+  fMakeSummaries(kFALSE),
   fDetectorArray(),
   fPulseSize(10),
   fPulseLength(10),
   fRequiredEvents(0),
-  fCurrentEvent(0)
- {
+  fCurrentEvent(0), 
+  fRunno(0),
+  fSummaries(0)
+{
+  //Constructor
+  fSeenDetectors[0] = fSeenDetectors[1] = fSeenDetectors[2] = kFALSE;
   fDetectorArray.SetOwner();
+  Rotate("conditions.csv", 3);
   fConditionsFile.open("conditions.csv");
 }
 //_____________________________________________________________________
@@ -106,12 +159,20 @@ AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
   fOutputFile(),
   fConditionsFile(),
   fSaveHistograms(baseDA.fSaveHistograms),
+  fMakeSummaries(baseDA.fMakeSummaries),
   fDetectorArray(baseDA.fDetectorArray),
   fPulseSize(baseDA.fPulseSize),
   fPulseLength(baseDA.fPulseLength),
   fRequiredEvents(baseDA.fRequiredEvents),
-  fCurrentEvent(baseDA.fCurrentEvent)
+  fCurrentEvent(baseDA.fCurrentEvent),
+  fRunno(baseDA.fRunno),
+  fSummaries(0)
 {
+  //Copy constructor
+  fSeenDetectors[0] = baseDA.fSeenDetectors[0];
+  fSeenDetectors[1] = baseDA.fSeenDetectors[1];
+  fSeenDetectors[2] = baseDA.fSeenDetectors[2];
+
   fDetectorArray.SetOwner();
   
 }
@@ -126,6 +187,7 @@ AliFMDBaseDA::~AliFMDBaseDA()
 //_____________________________________________________________________
 void AliFMDBaseDA::Run(AliRawReader* reader) 
 {
+  //Run the FMD DA
   TFile* diagFile = 0;
   if (fSaveHistograms)
     diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
@@ -135,14 +197,20 @@ void AliFMDBaseDA::Run(AliRawReader* reader)
   
   
   reader->Reset();
-  
+  fRunno = reader->GetRunNumber();
+
   AliFMDRawReader* fmdReader  = new AliFMDRawReader(reader,0);
   TClonesArray*    digitArray = new TClonesArray("AliFMDDigit",0);
   
-  Bool_t SOD_read = kFALSE;
+  Bool_t sodread = kFALSE;
   
   for(Int_t i=0;i<3;i++) {
-    reader->NextEvent(); // Read Start-of-Run / Start-of-Files event
+    if (reader->NextEvent()) { 
+      // Read Start-of-Run / Start-of-Files event
+      AliWarning(Form("Failed to read the %d%s event",
+                     i+1, (i == 0 ? "st" : (i == 1 ? "nd" : "rd"))));
+      break;
+    }
     
     UInt_t eventType = reader->GetType();
     if(eventType == AliRawEventHeaderBase::kStartOfData || 
@@ -150,14 +218,14 @@ void AliFMDBaseDA::Run(AliRawReader* reader)
       
       WriteConditionsData(fmdReader);
       Init();
-      SOD_read = kTRUE;
+      sodread = kTRUE;
       break;
     }
   }
   
   InitContainer(diagFile);
   
-  if(!SOD_read) 
+  if(!sodread) 
     AliWarning("No SOD event detected!");
   
   int lastProgress = 0;
@@ -170,12 +238,9 @@ void AliFMDBaseDA::Run(AliRawReader* reader)
     digitArray->Clear();
     fmdReader->ReadAdcs(digitArray);
     
-    //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));
+      fSeenDetectors[digit->Detector()-1] = kTRUE;
       FillChannels(digit);
     }
     
@@ -193,12 +258,16 @@ void AliFMDBaseDA::Run(AliRawReader* reader)
   WriteHeaderToFile();
   
   for(UShort_t det=1;det<=3;det++) {
+    if (!fSeenDetectors[det-1]) continue;
     std::cout << "FMD" << det << std::endl;
-    UShort_t FirstRing = (det == 1 ? 1 : 0);
-    for (UShort_t ir = FirstRing; ir < 2; ir++) {
+    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);
+
+      if (fMakeSummaries) MakeSummary(det, ring);
+
       std::cout << " Ring " << ring << ": " << std::flush;
       for(UShort_t sec =0; sec < nsec;  sec++)  {
        for(UShort_t strip = 0; strip < nstr; strip++) {
@@ -232,6 +301,7 @@ void AliFMDBaseDA::Run(AliRawReader* reader)
 
 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
 {
+  //Prepare container for diagnostics
   TObjArray* detArray;
   TObjArray* ringArray;
   TObjArray* sectorArray;
@@ -294,47 +364,21 @@ void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
 //_____________________________________________________________________ 
 void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader) 
 {
+  //Write the conditions data to file
   AliFMDParameters* pars       = AliFMDParameters::Instance();
   fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
+  TDatime now;
+  fConditionsFile << "# This file created from run number " << fRunno 
+                 << " at " << now.AsString() << std::endl;
   
   AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
   AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
   
-  fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength);
-  
-  // Sample Rate
-  /*
-    UShort_t defSampleRate = 4;
-    UShort_t sampleRateFromSOD;
-    
-  AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
+  fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength,
+                         fSeenDetectors);
 
-  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);
-      for(UShort_t sec =0; sec < nsec;  sec++)  {
-       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);
+  sampleRate->WriteToFile(fConditionsFile, fSeenDetectors);
+  stripRange->WriteToFile(fConditionsFile, fSeenDetectors);
 
  
   // Zero Suppresion
@@ -344,6 +388,9 @@ void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
   fConditionsFile.write("# Gain Events \n",15);
   
   for(UShort_t det=1; det<=3;det++) {
+    if (!fSeenDetectors[det-1]) { 
+      continue;
+    }
     UShort_t firstring = (det == 1 ? 1 : 0);
     for(UShort_t iring = firstring; iring <=1;iring++) {
       Char_t ring = (iring == 1 ? 'I' : 'O');
@@ -363,6 +410,9 @@ void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
   fConditionsFile.write("# Gain Pulse \n",14);
   
   for(UShort_t det=1; det<=3;det++) {
+    if (!fSeenDetectors[det-1]) { 
+      continue;
+    }
     UShort_t firstring = (det == 1 ? 1 : 0);
     for(UShort_t iring = firstring; iring <=1;iring++) {
       Char_t ring = (iring == 1 ? 'I' : 'O');
@@ -378,33 +428,9 @@ void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
       }
     }
   }
-  
-  
+  // sampleRate->WriteToFile(std::cout, fSeenDetectors);
+  // stripRange->WriteToFile(std::cout, fSeenDetectors);
 
-  // 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);
@@ -414,8 +440,18 @@ void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
   
 }
 //_____________________________________________________________________ 
-Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
-
+Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, 
+                                    UShort_t board) const 
+{
+  // Get the index corresponding to a half-ring 
+  // 
+  // Parameters: 
+  //   det    Detector number 
+  //   ring   Ring identifier 
+  //   board  Board number 
+  //
+  // Return 
+  //   Internal index of the board 
   UShort_t iring  =  (ring == 'I' ? 1 : 0);
   
   Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
@@ -423,7 +459,63 @@ Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board)
   return index-2;
   
 }
+//_____________________________________________________________________ 
+void AliFMDBaseDA::Rotate(const char* base, int max) const
+{
+  // 
+  // Rotate a set of files.   base is the basic name of the files.
+  // If the file base.max exists it is removed. 
+  // If the file base.n exists (where n < max) it is renamed to
+  // base.(n-1).  
+  // If the file base exists, it is renamed to base.1 
+  //
+  // Parameters:
+  //   base Base name of the files
+  //   max  Maximum number to keep (minus one for the current).
+
+  // Note:  TSystem::AccessPathName returns false if the condition is
+  // fulfilled! 
+
+  // Check if we have base.max, and if so, remove it. 
+  TString testName(Form("%s.%d", base, max));
+  if (!gSystem->AccessPathName(testName.Data())) 
+    gSystem->Unlink(testName.Data());
+    
+  // Loop down from max-1 to 1 and move files 
+  for (int i = max-1; i >= 1; i--) { 
+    testName = Form("%s.%d", base, i);
+    if (!gSystem->AccessPathName(testName.Data())) {
+      TString newName(Form("%s.%d", base, i+1));
+      gSystem->Rename(testName.Data(), newName.Data());
+    }
+  }
+
+  // If we have the file base, rename it to base.1 
+  testName = Form("%s", base);
+  if (!gSystem->AccessPathName(testName.Data())){
+    TString newName(Form("%s.%d", base, 1));
+    gSystem->Rename(testName.Data(), newName.Data());
+  }
+}
+
+//_____________________________________________________________________ 
+TH2*
+AliFMDBaseDA::MakeSummaryHistogram(const char* prefix, const char* title, 
+                                  UShort_t d, Char_t r) 
+{
+  Int_t nX = ((d == 1 || r == 'I' || r == 'i') ?  20 :  40);
+  Int_t nY = ((d == 1 || r == 'I' || r == 'i') ? 512 : 256);
+  
+  TH2* ret = new TH2F(Form("%sFMD%d%c", prefix, d, r), 
+                     Form("%s for FMD%d%c", title, d, r), 
+                     nX, -0.5, nX-0.5, nY, -0.5, nY-0.5);
+  ret->SetXTitle("Sector #");
+  ret->SetYTitle("Strip #");
 
+  // if (!fSummaries) fSummaries = new TObjArray;
+  fSummaries.Add(ret);
+  return ret;
+}
 
 //_____________________________________________________________________ 
 //