Masking of not calibrated chambers
[u/mrichter/AliRoot.git] / T0 / AliT0PreprocessorOffline.cxx
index b88345c..5b432dc 100644 (file)
@@ -46,11 +46,14 @@ ClassImp(AliT0PreprocessorOffline)
 //____________________________________________________
 AliT0PreprocessorOffline::AliT0PreprocessorOffline():
 TNamed("AliT0PreprocessorOffline","AliT0PreprocessorOffline"),
-  startRun(0),                         // start Run - used to make fast selection in THnSparse
-  endRun(0),                           // end   Run - used to make fast selection in THnSparse
-  startTime(0),                        // startTime - used to make fast selection in THnSparse
-  endTime(0),                          // endTime   - used to make fast selection in THnSparse
-  ocdbStorage("")                  // path to the OCDB storage
+  startRun(0),      
+  endRun(0),  
+  startTime(0),    
+  endTime(0),     
+  ocdbStorage(""),
+  fNewDArun(9999999),
+  fStatusDelay(0),
+  fStatusAdjust(0)
   
 {
   //constructor
@@ -65,7 +68,8 @@ AliT0PreprocessorOffline::~AliT0PreprocessorOffline()
 //____________________________________________________
 void AliT0PreprocessorOffline::Process(TString filePhysName, Int_t ustartRun, Int_t uendRun, TString pocdbStorage)
 {
-  CalibOffsetChannels(filePhysName, ustartRun, uendRun, pocdbStorage);
+  if ( ustartRun < fNewDArun) 
+    CalibOffsetChannels(filePhysName, ustartRun, uendRun, pocdbStorage);
   CalibT0sPosition(filePhysName, ustartRun, uendRun, pocdbStorage);
 }
 //____________________________________________________
@@ -73,104 +77,89 @@ void AliT0PreprocessorOffline::Process(TString filePhysName, Int_t ustartRun, In
 void AliT0PreprocessorOffline::CalibOffsetChannels(TString filePhysName, Int_t ustartRun, Int_t uendRun, TString pocdbStorage)
 {
 
-  Float_t *timecdb, *cfdvalue;
-  for (Int_t i=0; i<24; i++) {  timecdb[i]=999; cfdvalue=0; }
-  Int_t badpmt=0;
+  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
     {
-   if (pocdbStorage.Length()>0) ocdbStorage=pocdbStorage;
-   else
-     ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
-   //      AliCDBManager* man = AliCDBManager::Instance();
-   // man->SetDefaultStorage("raw://");
-   //   man->SetDefaultStorage("ocdbStorage");
-   //     man->SetRun(ustartRun);
-   AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
-   if (!entry) AliFatal("CTP timing parameters are not found in OCDB !");
-   AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
-   Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;
-   
-   AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
-   if (!entry1) AliFatal("CTP time-alignment is not found in OCDB !");
-   AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
-   l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
-   
-   AliCDBEntry *entry4 = AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
-   if (!entry4) AliFatal("LHC clock-phase shift is not found in OCDB !");
-   AliLHCClockPhase *phase = (AliLHCClockPhase*)entry4->GetObject();
-   Float_t fGRPdelays = l1Delay - phase->GetMeanPhase();
-   AliCDBEntry *entryL = AliCDBManager::Instance()->Get("T0/Calib/Latency");
-   AliT0CalibLatency *lat = (AliT0CalibLatency*)entryL->GetObject();
-   Float_t fLatencyHPTDC = lat->GetLatencyHPTDC();
-   Float_t fLatencyL1 = lat->GetLatencyL1();
-   AliCDBEntry *entryCalib = AliCDBManager::Instance()->Get("T0/Calib/TimeDelay");
-   if(!entryCalib) {
-     AliWarning(Form("Cannot find any AliCDBEntry for [Calib, TimeDelay]!"));
-   }
-   else
-     {
-       AliT0CalibTimeEq *clb = (AliT0CalibTimeEq*)entryCalib->GetObject();
-       timecdb = clb->GetTimeEq();
-       cfdvalue = clb->GetCFDvalue();
-       for (Int_t i=0; i<24; i++) {
-        if( cfdvalue[i] < 500 ) cfdvalue[i] =( 1000.*fLatencyHPTDC - 1000.*fLatencyL1 + 1000.*fGRPdelays)/24.4;
-        printf("Calc  mean CFD time %i %f \n",i,cfdvalue[i]);
-       }
-     }
-      AliCDBEntry *entryCalibreco = AliCDBManager::Instance()->Get("T0/Calib/RecoParam");
-      if(entryCalibreco) {
-       AliT0RecoParam *rpr = (AliT0RecoParam*) entryCalibreco->GetObject();
-       badpmt = rpr->GetRefPoint();
-       printf(" bad PMT %i \n", badpmt);
-      }
-      AliT0CalibTimeEq *offline = new AliT0CalibTimeEq();
-      offline->Reset();
-      Bool_t writeok = offline->ComputeOfflineParams(filePhysName.Data(), timecdb, cfdvalue, badpmt);
-      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 data is not OK to be in OCDB",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)
 {
-  if (filePhysName)
-    {
-      if (pocdbStorage.Length()>0) ocdbStorage=pocdbStorage;
-      else
-       ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
-      
-      AliT0CalibSeasonTimeShift *offline = new AliT0CalibSeasonTimeShift();
-      Bool_t writeok = offline->SetT0Par(filePhysName.Data());
-      AliCDBMetaData metaData;
-      metaData.SetBeamPeriod(1);
-      metaData.SetResponsible("Alla Maevskaya");
-      metaData.SetComment("Time equalizing result with slew");
-      
-      if (writeok)  {
-       AliCDBId* id1=NULL;
-       id1=new AliCDBId("T0/Calib/TimeAdjust", ustartRun, uendRun);
-       AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
-       gStorage->Put(offline, (*id1), &metaData);
-      }
-    }
+  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;
 }