Masking of not calibrated chambers
[u/mrichter/AliRoot.git] / T0 / AliT0PreprocessorOffline.cxx
index 0a0e40b..5b432dc 100644 (file)
 
 
 #include "AliT0PreprocessorOffline.h"
+#include "AliT0RecoParam.h"
 #include "AliT0CalibTimeEq.h"
 #include "AliCDBStorage.h"
 #include "AliCDBMetaData.h"
 #include "AliCDBManager.h"
-
+#include "AliCTPTimeParams.h"
+#include "AliLHCClockPhase.h"
+#include "AliT0CalibSeasonTimeShift.h"
+#include "AliT0CalibLatency.h"
 #include "AliCDBEntry.h"
 #include "AliLog.h"
 
@@ -41,7 +45,16 @@ ClassImp(AliT0PreprocessorOffline)
 
 //____________________________________________________
 AliT0PreprocessorOffline::AliT0PreprocessorOffline():
-TNamed("AliT0PreprocessorOffline","AliT0PreprocessorOffline")
+TNamed("AliT0PreprocessorOffline","AliT0PreprocessorOffline"),
+  startRun(0),      
+  endRun(0),  
+  startTime(0),    
+  endTime(0),     
+  ocdbStorage(""),
+  fNewDArun(9999999),
+  fStatusDelay(0),
+  fStatusAdjust(0)
+  
 {
   //constructor
 }
@@ -53,37 +66,100 @@ AliT0PreprocessorOffline::~AliT0PreprocessorOffline()
 
 }
 //____________________________________________________
+void AliT0PreprocessorOffline::Process(TString filePhysName, Int_t ustartRun, Int_t uendRun, TString pocdbStorage)
+{
+  if ( ustartRun < fNewDArun) 
+    CalibOffsetChannels(filePhysName, ustartRun, uendRun, pocdbStorage);
+  CalibT0sPosition(filePhysName, ustartRun, uendRun, pocdbStorage);
+}
 //____________________________________________________
 
-void AliT0PreprocessorOffline::CalibOffsetChannels(TString filePhysName, Int_t ustartRun, Int_t uendRun, TString ocdbStorage)
+void AliT0PreprocessorOffline::CalibOffsetChannels(TString filePhysName, Int_t ustartRun, Int_t uendRun, TString pocdbStorage)
 {
 
-
+  Float_t zero_timecdb[24]={0};
+  Float_t *timecdb = zero_timecdb;
+  Float_t *cfdvalue = zero_timecdb;
+  Float_t cfd[24][5];
+  for(Int_t i=0; i<24; i++) 
+    for (Int_t i0=0; i0<5; i0++)
+      cfd[i][i0] = 0;
+  Int_t badpmt=-1;
   //Processing data from DAQ Physics run
   AliInfo("Processing Time Offset between channels");
-  if (filePhysName)
+  if (pocdbStorage.Length()>0) ocdbStorage=pocdbStorage;
+  else
+    ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
+  AliCDBEntry *entryCalib = AliCDBManager::Instance()->Get("T0/Calib/TimeDelay");
+  if(!entryCalib) {
+    AliWarning(Form("Cannot find any AliCDBEntry for [Calib, TimeDelay]!"));
+  }
+  else
     {
-      AliT0CalibTimeEq *offline = new AliT0CalibTimeEq();
-      offline->Reset();
-      Bool_t writeok = offline->ComputeOfflineParams(filePhysName.Data());
-      AliCDBMetaData metaData;
-      metaData.SetBeamPeriod(1);
-      metaData.SetResponsible("Alla Maevskaya");
-      metaData.SetComment("Time equalizing result with slew");
+      AliT0CalibTimeEq *clb = (AliT0CalibTimeEq*)entryCalib->GetObject();
+      timecdb = clb->GetTimeEq();
+      for(Int_t i=0; i<24; i++) 
+       for (Int_t i0=0; i0<5; i0++)  cfd[i][i0] = clb->GetCFDvalue(i, i0);
       
-      if (writeok)  {
-       AliCDBId* id1=NULL;
-       id1=new AliCDBId("T0/Calib/TimeDelay", ustartRun, uendRun);
-       AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
-       gStorage->Put(offline, (*id1), &metaData);
-      }
-      else {
-       
-          AliWarning(Form("writeok = %d not enough data for equalizing",writeok));
-      }                  
-   
-      delete offline;
     }
-       
+  for(Int_t i=0; i<24; i++)cfdvalue[i]=cfd[i][0];
+  
+  AliT0CalibTimeEq *offline = new AliT0CalibTimeEq();
+  Int_t writeok = offline->ComputeOfflineParams(filePhysName.Data(), timecdb, cfdvalue, badpmt);
+  printf(" AliT0PreprocessorOffline::CalibOffsetChannels :: writeok %i \n", writeok);
+  AliCDBMetaData metaData;
+  metaData.SetBeamPeriod(1);
+  metaData.SetResponsible("Alla Maevskaya");
+  metaData.SetComment("Time equalizing result with slew");
+  fStatusDelay = writeok;
+  if (writeok==0)  {
+    AliCDBId* id1=NULL;
+    id1=new AliCDBId("T0/Calib/TimeDelay", ustartRun, uendRun );
+    AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
+    gStorage->Put(offline, (*id1), &metaData);
+  }
+  else {
+    
+    AliWarning(Form("writeok = %d data is not OK to be in OCDB",writeok));
+      }                  
+  
+  delete offline;
+}
+//-------------------------------------------------------------------------------------
+void AliT0PreprocessorOffline::CalibT0sPosition(TString filePhysName, Int_t ustartRun, Int_t uendRun, TString pocdbStorage)
+{
+  printf(" AliT0PreprocessorOffline::CalibT0sPosition \n");
+  Float_t zero_timecdb[4]={0};
+  Float_t *timecdb = zero_timecdb;
+  if (pocdbStorage.Length()>0) ocdbStorage=pocdbStorage;
+  else
+    ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
+  
+  AliT0CalibSeasonTimeShift *offline = new AliT0CalibSeasonTimeShift();
+  Int_t writeok = offline->SetT0Par(filePhysName.Data(), timecdb);
+  printf(" AliT0PreprocessorOffline::CalibT0sPosition :: writeok %i \n", writeok);
+  AliCDBMetaData metaData;
+  metaData.SetBeamPeriod(1);
+  metaData.SetResponsible("Alla Maevskaya");
+  metaData.SetComment("Time equalizing result with slew");
+  fStatusAdjust = writeok;
+  if (writeok == 0)  {
+    AliCDBId* id1=NULL;
+    id1=new AliCDBId("T0/Calib/TimeAdjust", ustartRun, uendRun);
+    AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
+    gStorage->Put(offline, (*id1), &metaData);
+  }
 
 }
+//_____________________________________________________________________________
+Int_t AliT0PreprocessorOffline::GetStatus() const
+{
+  //
+  // Checks the status
+  // fStatusPos: errors
+  // fStatusNeg: only info
+  //
+  printf("!!!! GetStatus %i delay %i adjust %i \n",fStatusAdjust+ fStatusDelay, fStatusDelay, fStatusAdjust);
+  return   fStatusAdjust+ fStatusDelay;
+}