]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PMD/PMDGAINda.cxx
retrieving mapping file from daqDatabase
[u/mrichter/AliRoot.git] / PMD / PMDGAINda.cxx
index 96f6eff6bea7fa2124f4ee3d2937bb7f09986130..2c387e0c71dc213665c66e8366d8f3873e2142af 100644 (file)
@@ -2,12 +2,13 @@
 PMD DA for online calibration
 
 contact: basanta@phy.iitb.ac.in
-Link:/afs/cern.ch/user/b/bnandi/public/
+Link:
+Reference run:/afs/cern.ch/user/b/bnandi/public/gaindata/pythia100evts.date
 Run Type: PHYSICS
 DA Type: MON
 Number of events needed: 1 million for PB+PB, 200 milion for p+p
-Input Files: data raw
-Output Files: pmd_calib.root, to be exported to the DAQ FXS
+Input Files: PMD_PED.root, PMD_GAIN_CONFIGFILE, pmd_gain_tempfile.dat
+Output Files: PMDGAINS.root, to be exported to the DAQ FES
 Trigger types used: PHYSICS_EVENT
 
 */
@@ -17,7 +18,6 @@ extern "C" {
 
 #include "event.h"
 #include "monitor.h"
-//#include "daqDA.h"
 
 #include <Riostream.h>
 #include <stdio.h>
@@ -27,6 +27,8 @@ extern "C" {
 #include "AliRawReaderDate.h"
 #include "AliPMDCalibPedestal.h"
 #include "AliPMDCalibGain.h"
+#include "AliLog.h"
+#include "AliCDBManager.h"
 
 //ROOT
 #include "TFile.h"
@@ -35,7 +37,7 @@ extern "C" {
 #include "TTree.h"
 #include "TROOT.h"
 #include "TPluginManager.h"
-
+#include "TSystem.h"
 
 
 /* Main routine
@@ -51,29 +53,93 @@ int main(int argc, char **argv) {
                                          "RIO",
                                          "TStreamerInfo()");
 
+
+    int status = 0;
+
+
+    Int_t filestatus = -1, xvar = 5;
+    Int_t totevt = -1, maxevt = -1;
+    Int_t hotevtsize = -1;
+    Bool_t hotfilestatus = false;
+
+    // Reads the pedestal file and keep the values in memory for subtraction
+
     AliPMDCalibGain calibgain;
 
-    TTree *gain = new TTree("gain","PMD Gain tree");
+    // Fetch the pedestal file - PMD_PED.root 
+
+    status = daqDA_DB_getFile("PMD_PED.root","PMD_PED.root");
+
+    if(!status)
+      {
+       printf("*** Pedestal file retrieved from DB *** \n");
+      }
+    else
+      {
+       printf("*** Pedestal file NOT retrieved from DB *** \n");
+       return -1;
+      }
+    
+    Int_t pstatus = calibgain.ExtractPedestal("PMD_PED.root");
+
+    if(pstatus == -3) return -3;
+
+    TTree *ic    = NULL;
+    TTree *meanc = NULL;
+
+    // Retrieve the PMD_GAIN_CONFIGFILE
+    status = daqDA_DB_getFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
+
+    FILE *fp1 = NULL;
+
+    fp1 = fopen("PMD_GAIN_CONFIGFILE","r");
+
+    if (fp1 == NULL)
+      {
+       printf("*** PMD GAIN Configfile doesn't exist,Provide one ***\n");
+       return -1;
+      }
+    else
+      {
+       fscanf(fp1,"%d %d %d %d %d\n",&filestatus, &xvar, &totevt, &maxevt, &hotevtsize);
+       //printf("%d %d %d %d %d\n",filestatus, xvar, totevt, maxevt, hotevtsize);
+      }
+    fclose(fp1);
 
-    TH1F::AddDirectory(0);
-  
     
+    if (filestatus == 1)
+      {
+       // Retrieve the Temporray ascii file from DB
+       status = daqDA_DB_getFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat");
+       if(!status)
+         {
+           calibgain.ReadTempFile("pmd_gain_tempfile.dat");
+         }
+       else
+         {
+           printf("--- pmd_gain_tempfile.dat: not retrieved from DB ---\n");
+         }
+       // Retrieve the hot cell file from DB - PMD_HOT.root
+       status = daqDA_DB_getFile("PMD_HOT.root","PMD_HOT.root");
+       if(!status)
+         {
+           calibgain.ExtractHotChannel("PMD_HOT.root");
+         }
+       else
+         {
+           printf("--- pmd_gain_tempfile.dat: not retrieved from DB ---\n");
+         }
+      }
+
+
     // decoding the events
     
-    int status;
 
     if (argc!=2) {
        printf("Wrong number of arguments\n");
        return -1;
     }
     
-    /* open result file */
-    FILE *fp=NULL;
-    fp=fopen("./result.txt","a");
-    if (fp==NULL) {
-       printf("Failed to open file\n");
-       return -1;
-    }
     
     /* define data source : this is argument 1 */  
     status=monitorSetDataSource( argv[1] );
@@ -94,15 +160,49 @@ int main(int argc, char **argv) {
     monitorSetNoWaitNetworkTimeout(1000);
     
     /* log start of process */
-    printf("DA example case2 monitoring program started\n");  
+    printf("PMD GAIN DA - strted generating the gain of a cell\n");  
     
     /* init some counters */
     int nevents_physics=0;
     int nevents_total=0;
     
     struct eventHeaderStruct *event;
-    eventTypeType eventT;
+    eventTypeType eventT = 0;
+
     Int_t iev=0;
+
+    // Get run number
+    /*
+    if (getenv("DATE_RUN_NUMBER")==0) {
+      printf("DATE_RUN_NUMBER not properly set.\n");
+      return -1;
+    }
+    int runNr = atoi(getenv("DATE_RUN_NUMBER"));
+    */
+
+    int runNr = 0;
+
+    if (gSystem->AccessPathName("localOCDB/PMD/Calib/Mapping",kFileExists))
+      {
+       if (gSystem->mkdir("localOCDB/PMD/Calib/Mapping",kTRUE) != 0)
+         {
+           printf("Failed to create directory: localOCDB/PMD/Calib/Mapping");
+           return -1;
+         }
+      }
+    status = daqDA_DB_getFile("PMD/Calib/Mapping","localOCDB/PMD/Calib/Mapping/Run0_999999999_v0_s0.root");
+    if (status)
+      {
+       printf("Failed to get PMD-Mapping file (PMD/Calib/Mapping) from DAQdetDB, status=%d\n", status);
+       return -1;
+      }
+
+    // Global initializations
+    AliLog::SetGlobalLogLevel(AliLog::kError);
+    AliCDBManager *man = AliCDBManager::Instance();
+    man->SetDefaultStorage("local://localOCDB");
+    man->SetRun(runNr);
+
     
     /* main loop (infinite) */
     for(;;) {
@@ -145,9 +245,15 @@ int main(int argc, char **argv) {
                
            case PHYSICS_EVENT:
                nevents_physics++;
+               totevt++;
+               //if(nevents_physics%100 == 0)printf("Physis Events = %d\n",nevents_physics);
                AliRawReader *rawReader = new AliRawReaderDate((void*)event);
-               calibgain.ProcessEvent(rawReader);
+               TObjArray *pmdddlcont = new TObjArray();
+               calibgain.ProcessEvent(rawReader, pmdddlcont);
 
+               if (totevt%hotevtsize == 0) hotfilestatus = true;
+               delete pmdddlcont;
+               pmdddlcont = 0x0;
                delete rawReader;
                rawReader = 0x0;
                
@@ -156,36 +262,134 @@ int main(int argc, char **argv) {
        /* free resources */
        free(event);
        
-       /* exit when last event received, no need to wait for TERM signal */
-       if (eventT==END_OF_RUN) {
-           printf("EOR event detected\n");
-           calibgain.Analyse(gain);
-           
-           break;
-       }
     }
-    
-    //write the Run level file   
-    TFile * fileRun = new TFile ("outPMDdaRun.root","RECREATE"); 
-    TBenchmark *bench = new TBenchmark();
-    bench->Start("PMD");
-    bench->Stop("PMD");
-    bench->Print("PMD");
-    fileRun->Close();
-    
-    /* write report */
-    fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
-    
 
-    TFile * gainRun = new TFile ("pmd_calib.root","RECREATE"); 
-    gain->Write();
-    gainRun->Close();
-    
-    
+    /* exit when last event received, no need to wait for TERM signal */
+
+
+    ic    = new TTree("ic","PMD Gain tree");
+    meanc = new TTree("meanc","PMD Module mean tree");
+
+    if (filestatus == 0)
+      {
+       TFile *hotRun = new TFile ("PMD_HOT.root","RECREATE");
+
+       TTree *hot = new TTree("hot","PMD Hot cell tree");
+       
+       calibgain.FindHotCell(hot,xvar);
+       
+       hot->Write();
+       hotRun->Close();
+
+       // store the hot cell root file in the DB
+
+       status = daqDA_DB_storeFile("PMD_HOT.root","PMD_HOT.root");
+
+       // store the hot cell root file in the file exchange server
+
+       printf("root file for hot cell is created and getting exported\n");
+       status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root");
+      }
+
+    if (hotfilestatus)
+      {
+       TFile *hotRun = new TFile ("PMD_HOT.root","RECREATE");
+
+       TTree *hot = new TTree("hot","PMD Hot cell tree");
+       
+       calibgain.FindHotCell(hot,xvar);
+       
+       hot->Write();
+       hotRun->Close();
+
+       // store the hot cell root file in the DB
+
+       status = daqDA_DB_storeFile("PMD_HOT.root","PMD_HOT.root");
+       
+       // store the hot cell root file in the file exchange server
+
+       printf("root file for hot cell is created and getting exported\n");
+       status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root");
+      }
+
+
+    fp1 = fopen("PMD_GAIN_CONFIGFILE","w+");
+
+    if (totevt < maxevt)
+      {
+       printf("-----------------------------------------------\n");
+       printf("***  Required Number of Events not reached  ***\n");
+       printf("***  Number of Events processed = %d        ***\n",totevt);
+       printf("***  Writing the intermediate ASCII file    ***\n");
+       printf("-----------------------------------------------\n");
+
+       calibgain.WriteTempFile("pmd_gain_tempfile.dat");
+
+       // Store the Intermediate ascii file in the DB
+       status = daqDA_DB_storeFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat");
+
+       filestatus = 1;
+       fprintf(fp1,"%d %d %d %d %d\n",filestatus,xvar,totevt,maxevt,hotevtsize);
+       fclose(fp1);
+
+       // Store the configfile in the DB
+       status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
+
+      }
+    else if (totevt >= maxevt)
+      {
+       printf("-----------------------------------------------\n");
+       printf("***  Required Number of Events reached = %d ***\n",totevt);
+       printf("***  Writing the PMDGAINS.root file           ***\n");
+       printf("-----------------------------------------------\n");
+
+       calibgain.Analyse(ic, meanc);
+
+       TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE"); 
+       ic->Write();
+       gainRun->Close();
+
+       TFile * meanRun = new TFile ("PMD_MEAN_SM.root","RECREATE"); 
+       meanc->Write();
+       meanRun->Close();
+
+
+       filestatus = 0;
+       totevt     = 0;
+       fprintf(fp1,"%d %d %d %d %d\n",filestatus,xvar,totevt,maxevt,hotevtsize);
+       fclose(fp1);
+
+       // Store the configfile in the DB
+       status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
+      }
     
-    /* close result file */
-    fclose(fp);
+    delete ic;
+    ic = 0;
+
+    delete meanc;
+    meanc = 0;
     
+
+    /* store the result file on FES */
+    if (filestatus == 0)
+      {
+       printf("root file for cell gain is created and getting exported\n");
+       status = daqDA_FES_storeFile("PMDGAINS.root","PMDGAINS.root");
+       printf("root file for normalised means of different modules\n");
+       status = daqDA_FES_storeFile("PMD_MEAN_SM.root","PMD_MEAN_SM.root");
+      }
+
+    if (hotfilestatus)
+      {
+      }
+
     
+    if (status) {
+      status = -2;
+    }
+
+
+
     return status;
 }