da documentation page is defined in the Link
[u/mrichter/AliRoot.git] / PMD / PMDPEDESTALda.cxx
index 2d755f5..d99b2bb 100644 (file)
@@ -2,12 +2,13 @@
 PMD DA for online calibration
 
 contact: basanta@phy.iitb.ac.in
-Link:/afs/cern.ch/user/a/alicepmd/public/pedestaldata/run31270.raw
-Run Type: STANDALONE
+Link: https://twiki.cern.ch/twiki/bin/view/ALICE/DA
+Reference Run:/afs/cern.ch/user/s/sjena/public/run83496.raw
+Run Type: PEDESTAL
 DA Type: LDC
 Number of events needed: 1000
-Input Files: data raw
-Output Files: pmd_ped.root, to be exported to the DAQ FXS
+Input Files: Run0_999999999_v0_s0.root
+Output Files: pmd_ped.root, to be exported to the DAQ FXS, pedestal230*.ped
 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>
@@ -26,6 +26,8 @@ extern "C" {
 //AliRoot
 #include "AliRawReaderDate.h"
 #include "AliPMDCalibPedestal.h"
+#include "AliLog.h"
+#include "AliCDBManager.h"
 
 //ROOT
 #include "TFile.h"
@@ -34,8 +36,7 @@ extern "C" {
 #include "TTree.h"
 #include "TROOT.h"
 #include "TPluginManager.h"
-
-
+#include "TSystem.h"
 
 /* Main routine
       Arguments: 
@@ -51,11 +52,11 @@ int main(int argc, char **argv) {
                                          "TStreamerInfo()");
 
     
-    AliPMDCalibPedestal calibped;
+    AliPMDCalibPedestal *calibped = new AliPMDCalibPedestal();
 
-    TTree *ped  = new TTree("ped","PMD Pedestal tree");
+    TTree *ped = NULL;
 
-    TH1F::AddDirectory(0);
+    //    TH1F::AddDirectory(0);
   
       
     // decoding the events
@@ -87,14 +88,49 @@ int main(int argc, char **argv) {
     monitorSetNoWaitNetworkTimeout(1000);
     
     /* log start of process */
-    printf("DA example case2 monitoring program started\n");  
+    printf("PMD PED DA - started generating mean and rms of each channel\n");  
     
     /* init some counters */
 
 
     struct eventHeaderStruct *event;
-    eventTypeType eventT;
+    eventTypeType eventT = 0;
     Int_t iev=0;
+
+    // Get run number
+
+    int runNr = 0;
+    if (getenv("DATE_RUN_NUMBER")==0) {
+      printf("DATE_RUN_NUMBER not properly set.\n");
+      //return -1;
+      printf("Run Number is set to Zero \n");
+    }
+    else
+      {
+       runNr = atoi(getenv("DATE_RUN_NUMBER"));
+      }
+
+    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(;;) {
@@ -135,11 +171,13 @@ int main(int argc, char **argv) {
                break;
                
            case PHYSICS_EVENT:
-               printf(" event number = %i \n",iev);
-               //if (iev == 10) break;
+
                AliRawReader *rawReader = new AliRawReaderDate((void*)event);
-               calibped.ProcessEvent(rawReader);
+               TObjArray *pmdddlcont = new TObjArray();
+               calibped->ProcessEvent(rawReader,pmdddlcont);
                
+               delete pmdddlcont;
+               pmdddlcont = 0;
                delete rawReader;
                rawReader = 0x0;
        }
@@ -148,26 +186,59 @@ int main(int argc, char **argv) {
        free(event);
        
        /* exit when last event received, no need to wait for TERM signal */
-       if (eventT==END_OF_RUN) {
-           printf("EOR event detected\n");
-           calibped.Analyse(ped);
-           break;
-       }
 
-       /*
-       if (iev == 10) {
-           printf("EOR event detected\n");
-           calibped.Analyse(ped);
+       // either END_OF_RUN or 1000 events
+
+       if (iev == 1000)
+         {
+           printf("-- 1000 pedestal events processed : terminating --\n");
+           printf("-- eventT is set to END_OF_RUN --\n");
+           eventT = END_OF_RUN;
            break;
-       }
-       */
+         }
+
     }
+
+    printf(" Total number of events processed = %i \n",iev);
+
+    ped = new TTree("ped","PMD Pedestal tree");
     
+    if (eventT==END_OF_RUN) {
+      printf("EOR event detected\n");
+      calibped->Analyse(ped);
+    }
     
     TFile * pedRun = new TFile ("PMD_PED.root","RECREATE"); 
     ped->Write();
     pedRun->Close();
 
+    delete ped;
+    ped = 0;
+
+    delete calibped;
+
+/* store the pedestal file in database */
+
+    status = daqDA_DB_storeFile("PMD_PED.root","PMD_PED.root");
+
+    if (!status)
+      {
+       printf("--- PEDESTAL root FILE IS IN THE DAQ DATABASE\n");
+      }
+    else
+      {
+       printf("--- Storing the root file into the database failed\n");
+      }
+
+/* store the pedestal file on FES */
+    status = daqDA_FES_storeFile("PMD_PED.root","PMD_PED.root");
+    if (status) {
+       status = -2;
+    }
+
+
+
 
     return status;
 }