]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/ITSSDDBASda.cxx
TOF + macros to each detector folder
[u/mrichter/AliRoot.git] / ITS / ITSSDDBASda.cxx
index 1cc0c9d30242891313f73d8a3bf76ed2662e9ee4..2ff40bf05dbebb676ad52ef0d8d2b83724216cdf 100644 (file)
@@ -1,9 +1,9 @@
 /*
 - Contact: - prino@to.infn.it
-- Link: - http://www.to.infn.it/~prino/alice/RawData/run11161.date
+- Link: - alien:///alice/data/2009/LHC09c_SDD/000079094/raw/09000079094024.10.root
 - Run Type: - PEDESTAL_RUN
 - DA Type: - LDC
-- Number of events needed: 100
+- Number of events needed: > 10
 - Input Files: - 
 - Output Files: - SDDbase_step1_ddl*c*_sid*.data SDDbase_step2_ddl*c*_sid*.data
 - Trigger types used: 
@@ -45,17 +45,26 @@ extern "C" {
 #include <TH2F.h>
 #include <TROOT.h>
 #include <TPluginManager.h>
+#include <TObjArray.h>
+#include <TObjString.h>
+#include <TDatime.h>
 
 // AliRoot includes
 #include "AliRawReaderDate.h"
 #include "AliITSOnlineSDDBase.h"
 #include "AliITSOnlineSDDCMN.h"
 #include "AliITSRawStreamSDD.h"
+#include "AliITSRawStreamSDDCompressed.h"
+
+#ifdef ALI_AMORE
+#include <AmoreDA.h>
+#endif
+
 /* Main routine
       Arguments: list of DATE raw data files
 */
 int main(int argc, char **argv) {
-
+  // main - Arguments: list of DATE raw data files
   int status = 0;
 
   // line added to solve IO problems
@@ -80,25 +89,16 @@ int main(int argc, char **argv) {
   const Int_t kTotDDL=24;
   const Int_t kModPerDDL=12;
   const Int_t kSides=2;
-  Int_t adcSamplFreq=40;
-  Bool_t readfeeconf=kFALSE;
+  UInt_t amSamplFreq=40;
+
   gSystem->Exec("rm -f SDDbase_*.data");
-  if(gSystem->Getenv("DAQ_DETDB_LOCAL")!=NULL){
-    const char* dir=gSystem->Getenv("DAQ_DETDB_LOCAL");    
-    TString filnam=Form("%s/fee.conf",dir); 
-    FILE* feefil=fopen(filnam.Data(),"r"); 
-    if(feefil){
-      fscanf(feefil,"%d \n",&adcSamplFreq);
-      fclose(feefil);
-      readfeeconf=kTRUE;
-      printf("ADC sampling frequency = %d MHz\n",adcSamplFreq);
-    }
-  }
-  if(!readfeeconf) printf("File fee.conf not found, sampling frequency set to 40 MHz\n");
+  gSystem->Exec("rm -f  SDDbase_step2_LDC.tar");
   
   AliITSOnlineSDDBase **base=new AliITSOnlineSDDBase*[kTotDDL*kModPerDDL*kSides];
   AliITSOnlineSDDCMN **corr=new AliITSOnlineSDDCMN*[kTotDDL*kModPerDDL*kSides];
   TH2F **histo=new TH2F*[kTotDDL*kModPerDDL*kSides];
+  Bool_t isFilled[kTotDDL*kModPerDDL*kSides];
+  Bool_t writtenoutput=kFALSE;
 
   Char_t hisnam[20];
   for(Int_t iddl=0; iddl<kTotDDL;iddl++){
@@ -106,30 +106,33 @@ int main(int argc, char **argv) {
       for(Int_t isid=0;isid<kSides;isid++){
        Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
        base[index]=new AliITSOnlineSDDBase(iddl,imod,isid);
-       if(adcSamplFreq==20) base[index]->SetLastGoodTB(126);
-       else base[index]->SetLastGoodTB(254);
        sprintf(hisnam,"h%02dc%02ds%d",iddl,imod,isid);
        histo[index]=new TH2F(hisnam,"",256,-0.5,255.5,256,-0.5,255.5);
+       isFilled[index]=0;
       }
     }
   }
   
   /* report progress */
   daqDA_progressReport(8);
+
   Int_t iev;
   Int_t ievPed;
+  Int_t ievUsed;
+  Int_t nEvToBeSkipped=5;
+
   for(Int_t iStep=0;iStep<2;iStep++){
     printf("Start Analysis Step %d\n",iStep);
     iev=0;
     ievPed=0;
+    ievUsed=0;
     if(iStep==1){
       for(Int_t iddl=0; iddl<kTotDDL;iddl++){
        for(Int_t imod=0; imod<kModPerDDL;imod++){
          for(Int_t isid=0;isid<kSides;isid++){
            Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
            corr[index]=new AliITSOnlineSDDCMN(iddl,imod,isid);
-           if(adcSamplFreq==20) corr[index]->SetLastGoodTB(126);
-           else corr[index]->SetLastGoodTB(254);
+           isFilled[index]=0;
          }
        }
       }
@@ -189,18 +192,25 @@ int main(int argc, char **argv) {
        case CALIBRATION_EVENT:
          break;  // uncomment this line for test raw data
        case PHYSICS_EVENT: // uncomment this line for test raw data
-         printf(" event number = %i \n",iev);
-         ievPed++; 
+         printf(" Event number = %i ",iev);
+         ievPed++;
+         if(ievPed<=nEvToBeSkipped){
+           printf(" -> SKIP\n");
+           break;
+         }
+         printf("  -> Analyze\n");
+         ievUsed++;
          AliRawReader *rawReader = new AliRawReaderDate((void*)event);
-
-
-         Int_t evtyp=0;
-         while(rawReader->ReadHeader()){
-           const UInt_t *subev = rawReader->GetSubEventAttributes();
-           if(subev[0]==0 && subev[1]==0 && subev[2]==0) evtyp=1; 
+         rawReader->Reset();
+         UChar_t cdhAttr=AliITSRawStreamSDD::ReadBlockAttributes(rawReader);
+         amSamplFreq=AliITSRawStreamSDD::ReadAMSamplFreqFromCDH(cdhAttr);
+         AliITSRawStream* s=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader,cdhAttr);
+         if(!writtenoutput){
+           printf("Use %s raw stream, sampling frequency %d MHz\n",s->ClassName(),amSamplFreq);
+           writtenoutput=kTRUE;
          }
 
-         rawReader->Reset();
+
          for(Int_t iddl=0; iddl<kTotDDL;iddl++){
            for(Int_t imod=0; imod<kModPerDDL;imod++){
              for(Int_t isid=0;isid<kSides;isid++){
@@ -209,25 +219,34 @@ int main(int argc, char **argv) {
              }
            }
          }
-         AliITSRawStreamSDD s(rawReader);
 
-         while(s.Next()){
+         while(s->Next()){
            Int_t iDDL=rawReader->GetDDLID();
-           Int_t iCarlos=s.GetCarlosId();
-           if(s.IsCompletedModule()) continue;
-           if(s.IsCompletedDDL()) continue;
+           Int_t iCarlos=s->GetCarlosId();
+           if(s->IsCompletedModule()) continue;
+           if(s->IsCompletedDDL()) continue;
            if(iDDL>=0 && iDDL<kTotDDL){ 
-             Int_t index=kSides*(kModPerDDL*iDDL+iCarlos)+s.GetChannel(); 
-             histo[index]->Fill(s.GetCoord2(),s.GetCoord1(),s.GetSignal());
+             Int_t index=kSides*(kModPerDDL*iDDL+iCarlos)+s->GetChannel(); 
+             histo[index]->Fill(s->GetCoord2(),s->GetCoord1(),s->GetSignal());
+             isFilled[index]=1;
            }
          }
+         delete s;
          delete rawReader;
          for(Int_t iddl=0; iddl<kTotDDL;iddl++){
            for(Int_t imod=0; imod<kModPerDDL;imod++){
              for(Int_t isid=0;isid<kSides;isid++){
                Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
-               if(iStep==0) base[index]->AddEvent(histo[index]);
-               if(iStep==1) corr[index]->AddEvent(histo[index]);
+               if(iStep==0){
+                 if(amSamplFreq==20) base[index]->SetLastGoodTB(126);
+                 else base[index]->SetLastGoodTB(254);
+                 base[index]->AddEvent(histo[index]);
+               }
+               if(iStep==1){
+                 if(amSamplFreq==20) corr[index]->SetLastGoodTB(126);
+                 else corr[index]->SetLastGoodTB(254);
+                 corr[index]->AddEvent(histo[index]);
+               }
              }
            }
          }
@@ -235,7 +254,7 @@ int main(int argc, char **argv) {
          /* free resources */
          free(event);
        }
-       if(ievPed>=maxNEvents) break;
+       if(ievUsed>=maxNEvents) break;
       }
     }
 
@@ -253,26 +272,66 @@ int main(int argc, char **argv) {
   }
 
   /* write report */
-  printf("Run #%s, received %d calibration events\n",getenv("DATE_RUN_NUMBER"),ievPed);
+  TDatime time;
+  TObjString timeinfo(Form("%02d%02d%02d%02d%02d%02d",time.GetYear()-2000,time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond()));
+  printf("Run #%s, received %d calibration events, time %s\n",getenv("DATE_RUN_NUMBER"),ievUsed,timeinfo.GetString().Data());
 
   /* report progress */
   daqDA_progressReport(90);
 
+  TObjArray* basHistos=new TObjArray();
+  TObjArray* noiseHistos=new TObjArray();
+  TObjArray* cmnHistos=new TObjArray();
+  TObjArray* corrnHistos=new TObjArray();
+  TObjArray* statusHistos=new TObjArray();
 
 
-  TFile *fh=new TFile("SDDbaseHistos.root","RECREATE");
+  Char_t filnam[100],command[150];
   for(Int_t iddl=0; iddl<kTotDDL;iddl++){
     for(Int_t imod=0; imod<kModPerDDL;imod++){
       for(Int_t isid=0;isid<kSides;isid++){
        Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
        corr[index]->ValidateAnodes();
        corr[index]->WriteToASCII();
-       corr[index]->WriteToROOT(fh);
+       if(isFilled[index]){
+         basHistos->AddLast(corr[index]->GetBaselineAnodeHisto());
+         noiseHistos->AddLast(corr[index]->GetRawNoiseAnodeHisto());
+         cmnHistos->AddLast(corr[index]->GetCMNCoefAnodeHisto());
+         corrnHistos->AddLast(corr[index]->GetCorrNoiseAnodeHisto());
+         statusHistos->AddLast(corr[index]->GetStatusAnodeHisto());
+         sprintf(filnam,"SDDbase_step2_ddl%02dc%02d_sid%d.data",iddl,imod,isid);
+         sprintf(command,"tar -rf SDDbase_step2_LDC.tar %s",filnam);
+         gSystem->Exec(command);
+       }
       }
     }
   }
-  fh->Close();
 
+#ifdef ALI_AMORE
+  amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
+  Int_t statusamore =0;
+  statusamore += amoreDA.Send("TimeInfoPedestal",&timeinfo);
+  statusamore += amoreDA.Send("Baselines",basHistos);
+  statusamore += amoreDA.Send("RawNoise",noiseHistos);
+  statusamore += amoreDA.Send("CommonMode",cmnHistos);
+  statusamore += amoreDA.Send("CorrectedNoise",corrnHistos);
+  statusamore += amoreDA.Send("NoisyChannels",statusHistos);
+  if ( statusamore )
+    printf("Warning: Failed to write Arrays in the AMORE database\n");
+  else 
+    printf("amoreDA.Send() OK\n");
+#else
+  printf("Warning: SDDBAS DA not compiled with AMORE support\n");
+#endif
+    
+    
+  TFile *fh=new TFile("SDDbaseHistos.root","RECREATE");
+  basHistos->Write();
+  noiseHistos->Write();
+  cmnHistos->Write();
+  corrnHistos->Write();
+  statusHistos->Write();
+  fh->Close();
 
   /* report progress */
   daqDA_progressReport(100);