DA & preprocessor for cosmic runs from Michal
authoralla <alla@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 22 Feb 2008 09:32:17 +0000 (09:32 +0000)
committeralla <alla@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 22 Feb 2008 09:32:17 +0000 (09:32 +0000)
T0/AliT0PreprocessorCosmic.cxx [new file with mode: 0644]
T0/AliT0PreprocessorCosmic.h [new file with mode: 0644]
T0/T0Cosmicda.cxx [new file with mode: 0644]

diff --git a/T0/AliT0PreprocessorCosmic.cxx b/T0/AliT0PreprocessorCosmic.cxx
new file mode 100644 (file)
index 0000000..3cfd434
--- /dev/null
@@ -0,0 +1,258 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/*
+$Log: AliT0PreprocessorCosmic.cxx,v $
+Revision 1.8  2007/12/07 15:22:51  alla
+bug fixed by Alberto
+
+Revision 1.7  2007/12/06 16:35:24  alla
+new bugs fixed by Tomek
+
+Revision 1.5  2007/11/23 19:28:52  alla
+bug fixed
+
+Version 2.1  2007/11/21 
+Preprocessor storing data to OCDB (T.Malkiewicz)
+
+Version 1.1  2006/10   
+Preliminary test version (T.Malkiewicz)
+*/   
+// T0 preprocessor:
+// 1) takes data from DCS and passes it to the class AliTOFDataDCS 
+// for processing and writes the result to the Reference DB.
+// 2) takes data form DAQ (both from Laser Calibration and Physics runs), 
+// processes it, and stores either to OCDB or to Reference DB.
+
+
+#include "AliT0PreprocessorCosmic.h"
+#include "AliT0DataDCS.h"
+#include "AliT0CalibWalk.h"
+#include "AliT0CalibTimeEq.h"
+
+#include "AliCDBMetaData.h"
+#include "AliDCSValue.h"
+#include "AliLog.h"
+
+#include <TTimeStamp.h>
+#include <TFile.h>
+#include <TObjString.h>
+#include <TNamed.h>
+#include "AliT0Dqclass.h"
+
+
+ClassImp(AliT0PreprocessorCosmic)
+
+//____________________________________________________
+AliT0PreprocessorCosmic::AliT0PreprocessorCosmic(AliShuttleInterface* shuttle) : 
+  AliPreprocessor("T00", shuttle), 
+  fData(0)
+{
+  //constructor
+}
+//____________________________________________________
+
+AliT0PreprocessorCosmic::~AliT0PreprocessorCosmic()
+{
+  //destructor
+  delete fData;
+  fData = 0;
+}
+//____________________________________________________
+
+void AliT0PreprocessorCosmic::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
+{
+  // Creates AliT0DataDCS object
+  AliPreprocessor::Initialize(run, startTime, endTime);
+  AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, TTimeStamp(startTime).AsString(), TTimeStamp(endTime).AsString()));
+  fData = new AliT0DataDCS(fRun, fStartTime, fEndTime);
+}
+//____________________________________________________
+
+Bool_t AliT0PreprocessorCosmic::ProcessDCS(){
+       // Check whether DCS should be processed or not...
+       TString runType = GetRunType();
+       Log(Form("ProcessDCS - RunType: %s",runType.Data()));
+
+       if((runType == "STANDALONE")||(runType == "PHYSICS")){
+               return kFALSE;
+       }else{
+       return kFALSE;
+       }
+}
+//____________________________________________________
+
+UInt_t AliT0PreprocessorCosmic::ProcessDCSDataPoints(TMap* dcsAliasMap){
+       // Fills data into AliT0DataDCS object
+       Log("Processing DCS DP");
+       Bool_t resultDCSMap=kFALSE;
+       Bool_t resultDCSStore=kFALSE;
+
+        if(!dcsAliasMap)
+        {
+          Log("No DCS input data");
+          return 1;
+        }
+        else
+        {
+          resultDCSMap=fData->ProcessData(*dcsAliasMap);
+          if(!resultDCSMap)
+          {
+            Log("Error when processing DCS data");
+            return 2;// return error Code for processed DCS data not stored
+          }
+          else
+          {
+            AliCDBMetaData metaDataDCS;
+            metaDataDCS.SetBeamPeriod(0);
+            metaDataDCS.SetResponsible("Tomasz Malkiewicz");
+            metaDataDCS.SetComment("This preprocessor fills an AliTODataDCS object.");
+            AliInfo("Storing DCS Data");
+            resultDCSStore = Store("Calib","DCSData",fData, &metaDataDCS);
+            if (!resultDCSStore)
+            {
+              Log("Some problems occurred while storing DCS data results in ReferenceDB");
+              return 2;// return error Code for processed DCS data not stored
+            }
+          }
+        }
+       return 0;
+}
+//____________________________________________________
+
+UInt_t AliT0PreprocessorCosmic::ProcessLaser(){
+       // Processing data from DAQ Standalone run
+       Log("Processing Laser calibration");
+       
+       Bool_t resultLaser=kFALSE;
+       //processing DAQ
+        TList* list = GetFileSources(kDAQ, "COSMIC");
+        if (list)
+        {
+            TIter iter(list);
+            TObjString *source;
+            while ((source = dynamic_cast<TObjString *> (iter.Next())))
+            {
+              const char *laserFile = GetFile(kDAQ, "COSMIC", source->GetName());
+              if (laserFile)
+              {
+                Log(Form("File with Id COSMIC found in source %s!", source->GetName()));
+                AliT0CalibWalk *laser = new AliT0CalibWalk();
+                laser->MakeWalkCorrGraph(laserFile);
+                AliCDBMetaData metaData;
+                metaData.SetBeamPeriod(0);
+                metaData.SetResponsible("Tomek&Michal");
+                metaData.SetComment("Walk correction from laser runs.");
+               resultLaser=Store("Calib","Slewing_Walk", laser, &metaData, 0, 1);
+                delete laser;
+              }
+              else
+              {
+                Log(Form("Could not find file with Id COSMIC in source %s!", source->GetName()));
+                return 1;
+              }
+            }
+            if (!resultLaser)
+            {
+              Log("No Laser Data stored");
+              return 3;//return error code for failure in storing Laser Data
+            }
+          } else {
+               Log("No sources found for id COSMIC!");
+               return 1;
+         }
+       return 0;
+}
+//____________________________________________________
+
+UInt_t AliT0PreprocessorCosmic::ProcessPhysics(){
+       //Processing data from DAQ Physics run
+       Log("Processing Physics");
+
+       Bool_t resultOnline=kFALSE;  
+       //processing DAQ
+       TList* listPhys = GetFileSources(kDAQ, "COSMIC");
+        if (listPhys)
+          {
+            TIter iter(listPhys);
+            TObjString *sourcePhys;
+            while ((sourcePhys = dynamic_cast<TObjString *> (iter.Next())))
+            {
+              const char *filePhys = GetFile(kDAQ, "COSMIC", sourcePhys->GetName());
+              if (filePhys)
+              {
+                AliT0CalibTimeEq *online = new AliT0CalibTimeEq();
+                online->Reset();
+                online->ComputeOnlineParams(filePhys);
+                AliCDBMetaData metaData;
+                metaData.SetBeamPeriod(0);
+                metaData.SetResponsible("Tomek&Michal");
+                metaData.SetComment("Time equalizing result.");
+                resultOnline = Store("Calib","TimeDelay", online, &metaData, 0, 1);
+                delete online;
+              }
+              else
+              {
+                Log(Form("Could not find file with Id COSMIC in source %s!", sourcePhys->GetName()));
+                return 1;
+              }
+            }
+            if (!resultOnline)
+            {
+              Log("No Laser Data stored");
+              return 4;//return error code for failure in storing OCDB Data
+            }
+          } else {
+               Log("No sources found for id COSMIC!");
+               return 1;
+         }
+       return 0;
+}
+//____________________________________________________
+
+UInt_t AliT0PreprocessorCosmic::Process(TMap* dcsAliasMap )
+{
+  // T0 preprocessor return codes:
+  // return=0 : all ok
+  // return=1 : no DCS input data 
+  // return=2 : failed to store DCS data
+  // return=3 : no Laser data (Walk correction)
+  // return=4 : failed to store OCDB time equalized data
+  // return=5 : no DAQ input for OCDB
+  // return=6 : failed to retrieve DAQ data from OCDB
+  // return=7 : failed to store T0 OCDB data
+       Bool_t dcsDP = ProcessDCS();
+       Log(Form("dcsDP = %d",dcsDP));  
+        TString runType = GetRunType();
+       Log(Form("RunType: %s",runType.Data()));
+       //processing
+       if((runType == "STANDALONE")||(runType == "PHYSICS")){
+               Int_t iresultLaser = ProcessLaser();
+               Int_t iresultPhysics = ProcessPhysics();
+               if(dcsDP==1){
+                       Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
+                       return iresultDCS;
+               }
+               if(iresultLaser==0){
+                       Log(Form("iresultLaser = %d", iresultLaser));
+                       Log(Form("iresultPhysics = %d", iresultPhysics));
+                       return iresultPhysics;
+               }
+               else return iresultLaser;
+       }
+       else{ return 0; }       
+
+  return 0;
+}
diff --git a/T0/AliT0PreprocessorCosmic.h b/T0/AliT0PreprocessorCosmic.h
new file mode 100644 (file)
index 0000000..6214d31
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef ALI_T0_PREPROCESSOR_COSMIC_H
+#define ALI_T0_PREPRECESSOR_COSMIC_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id: AliT0PreprocessorCosmic.h 24021 2008-02-19 18:53:25Z alla $ */
+
+
+// T0 preprocessor. 
+// Takes data from DCS and passes it to the class AliTOFDataDCS for processing and writes the result to the Reference DB.
+// Takes data form DAQ (both from Laser Calibration and Physics runs), processes it, and stores either to OCDB or to Reference DB.
+
+#include "AliPreprocessor.h"
+
+class AliT0DataDCS;
+
+class AliT0PreprocessorCosmic: public AliPreprocessor 
+{
+  public:
+        AliT0PreprocessorCosmic(): AliPreprocessor("T00",0),  
+         fData(0)
+ { }
+        AliT0PreprocessorCosmic(AliShuttleInterface* shuttle);
+       virtual ~AliT0PreprocessorCosmic();
+  
+  protected:
+        virtual void Initialize(Int_t run, UInt_t startTime, UInt_t endTime);
+       virtual UInt_t Process(TMap* dcsAliasMap);
+       virtual Bool_t ProcessDCS();
+
+  private:
+       AliT0PreprocessorCosmic(const AliT0PreprocessorCosmic & proc); // copy constructor      
+       AliT0PreprocessorCosmic& operator=(const AliT0PreprocessorCosmic&); //operator
+       UInt_t ProcessDCSDataPoints(TMap* dcsAliasMap);
+       UInt_t ProcessLaser();
+       UInt_t ProcessPhysics();
+       AliT0DataDCS *fData;                    // Data member to process DCS data      
+       ClassDef(AliT0PreprocessorCosmic, 1)
+};
+
+#endif
diff --git a/T0/T0Cosmicda.cxx b/T0/T0Cosmicda.cxx
new file mode 100644 (file)
index 0000000..88b9d60
--- /dev/null
@@ -0,0 +1,295 @@
+/*
+T0 DA for online calibration
+
+Contact: Michal.Oledzki@cern.ch
+Link: http://users.jyu.fi/~mioledzk/
+Run Type: PHYSICS
+DA Type: MON
+Number of events needed: 400000 
+Input Files: inCosmicLaser.dat, external parameters
+Output Files: daCosmicLaser.root, to be exported to the DAQ FXS
+Trigger types used: PHYSICS_EVENT
+
+*/
+
+#define FILE_OUT "daCosmic.root"
+#define FILE_IN "inCosmic.dat"
+#include <daqDA.h>
+#include <event.h>
+#include <monitor.h>
+#include <Riostream.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+//AliRoot
+#include <AliRawReaderDate.h>
+#include <AliRawReader.h>
+#include <AliT0RawReader.h>
+
+//ROOT
+#include "TROOT.h"
+#include "TPluginManager.h"
+#include "TFile.h"
+#include "TKey.h"
+#include "TH2S.h"
+#include "TObject.h"
+#include "TBenchmark.h"
+#include "TRandom.h"
+#include "TMath.h"
+#include "TCanvas.h"
+#include "TString.h"
+#include "TH1.h"
+#include "TF1.h"
+#include "TSpectrum.h"
+#include "TVirtualFitter.h"
+//#include "TProfile.h"
+int cqbx,cqby,clbx,clby,cbx,ccbx;
+float cqlx,cqmx,cqly,cqmy,cllx,clmx,clly,clmy,clx,cmx,cclx,ccmx;
+/* Main routine
+      Arguments: 
+      1- monitoring data source
+*/
+int main(int argc, char **argv) {
+  int status;
+  
+  /* magic line */
+  gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
+                                       "*",
+                                       "TStreamerInfo",
+                                       "RIO",
+                                       "TStreamerInfo()"); 
+  
+  if(daqDA_DB_getFile(FILE_IN, FILE_IN)){
+     printf("Couldn't get input file >>inCosmic.dat<< from DAQ_DB !!!\n");
+     return -1;
+  }
+  
+  FILE *inp;
+  char c;
+  inp = fopen(FILE_IN, "r");  
+  if(!inp){
+       printf("Input file >>inCosmic.dat<< not found !!!\n");
+       return -1;
+  }
+
+  while((c=getc(inp))!=EOF) {
+    switch(c) {
+      case 'a': {fscanf(inp, "%d", &cqbx ); break;} //N of X bins hCFD_QTC
+      case 'b': {fscanf(inp, "%f", &cqlx ); break;} //Low x hCFD_QTC
+      case 'c': {fscanf(inp, "%f", &cqmx ); break;} //High x hCFD_QTC
+      case 'd': {fscanf(inp, "%d", &cqby ); break;} //N of Y bins hCFD_QTC
+      case 'e': {fscanf(inp, "%f", &cqly ); break;} //Low y hCFD_QTC
+      case 'f': {fscanf(inp, "%f", &cqmy ); break;} //High y hCFD_QTC
+      case 'g': {fscanf(inp, "%d", &clbx ); break;} //N of X bins hCFD_LED
+      case 'h': {fscanf(inp, "%f", &cllx ); break;} //Low x hCFD_LED
+      case 'i': {fscanf(inp, "%f", &clmx ); break;} //High x hCFD_LED
+      case 'j': {fscanf(inp, "%d", &clby ); break;} //N of Y bins hCFD_LED
+      case 'k': {fscanf(inp, "%f", &clly ); break;} //Low y hCFD_LED
+      case 'l': {fscanf(inp, "%f", &clmy ); break;} //High y hCFD_LED
+      case 'm': {fscanf(inp, "%d", &cbx ); break;}  //N of Y bins hCFD 
+      case 'n': {fscanf(inp, "%f", &clx ); break;}  //Low x hCFD
+      case 'o': {fscanf(inp, "%f", &cmx ); break;}  //High x hCFD
+      case 'p': {fscanf(inp, "%d", &ccbx ); break;} //N of X bins hCFD1_CFD
+      case 'r': {fscanf(inp, "%f", &cclx ); break;} //Low x hCFD1_CFD
+      case 's': {fscanf(inp, "%f", &ccmx ); break;} //High x hCFD1_CFD
+    }
+  }
+  fclose(inp);
+
+  if (argc!=2) {
+    printf("Wrong number of arguments\n");
+    return -1;
+  }
+
+
+  /* define data source : this is argument 1 */  
+  status=monitorSetDataSource( argv[1] );
+  if (status!=0) {
+    printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
+    return -1;
+  }
+
+
+  /* declare monitoring program */
+  status=monitorDeclareMp( __FILE__ );
+  if (status!=0) {
+    printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
+    return -1;
+  }
+
+
+  /* define wait event timeout - 1s max */
+  monitorSetNowait();
+  monitorSetNoWaitNetworkTimeout(1000);
+  
+
+  /* log start of process */
+  printf("T0 monitoring program started\n");  
+
+  // Allocation of histograms - start
+  TH1F *hCFD[24];
+  TH1F *hCFD1minCFD[24]; 
+  TH2F *hCFDvsQTC[24];
+  TH2F *hCFDvsLED[24]; 
+
+   for(Int_t ic=0; ic<24; ic++) {
+      hCFDvsQTC[ic] = new TH2F(Form("CFD_QTC%d",ic+1),"CFD_QTC",cqbx,cqlx,cqmx,cqby,cqly,cqmy);
+      hCFDvsLED[ic] = new TH2F(Form("CFD_LED%d",ic+1),"CFD_LED",clbx,cllx,clmx,clby,clly,clmy);
+      hCFD1minCFD[ic] = new TH1F(Form("CFD1-CFD%d",ic+1),"CFD-CFD",ccbx,cclx,ccmx);
+      if(ic<12){
+       hCFD[ic] = new TH1F(Form("T0_C_%d_CFD",ic+1),"CFD", cbx,clx,cmx);       
+      }
+      else{
+        hCFD[ic] = new TH1F(Form("T0_A_%d_CFD",ic-11),"CFD", cbx,clx,cmx); 
+      }
+    }
+
+  // Allocation of histograms - end
+
+  Int_t iev=0;
+  /* main loop (infinite) */
+  for(;;) {
+    struct eventHeaderStruct *event;
+    eventTypeType eventT;
+  
+    /* check shutdown condition */
+    if (daqDA_checkShutdown()) {break;}
+    
+    /* get next event (blocking call until timeout) */
+    status=monitorGetEventDynamic((void **)&event);
+    if (status==(int)MON_ERR_EOF) {
+      printf ("End of File detected\n");
+      break; /* end of monitoring file has been reached */
+    }
+    
+    if (status!=0) {
+      printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
+      break;
+    }
+
+    /* retry if got no event */
+    if (event==NULL) {
+      continue;
+    }
+//    iev++; 
+
+    /* use event - here, just write event id to result file */
+    eventT=event->eventType;
+   
+    switch (event->eventType){
+
+      case START_OF_RUN:
+       break;
+
+      case END_OF_RUN:
+       break;
+
+      case CALIBRATION_EVENT:
+//      case PHYSICS_EVENT:
+      iev++; 
+
+      if(iev==1){
+           printf("First event - %i\n",iev);
+      }
+
+      // Initalize raw-data reading and decoding
+      AliRawReader *reader = new AliRawReaderDate((void*)event);
+          
+      // Enable the following two lines in case of real-data
+         reader->RequireHeader(kTRUE);
+      AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
+
+      // Read raw data
+      Int_t allData[105][5];
+      for(Int_t i0=0;i0<105;i0++)
+       for(Int_t j0=0;j0<5;j0++)
+               allData[i0][j0] = 0;
+     
+      if(start->Next())
+      for (Int_t i=0; i<105; i++) {
+       for(Int_t iHit=0;iHit<5;iHit++){
+         allData[i][iHit]= start->GetData(i,iHit);
+        }
+      }
+       else 
+       printf("No T0 data found!!\n");
+
+      // Fill the histograms
+       
+      for (Int_t ik = 0; ik<24; ik+=2)
+         for (Int_t iHt=0; iHt<5; iHt++){
+                Int_t cc = ik/2;
+               if((allData[cc+1][iHt]-allData[0][0]+5000)!=0 && allData[cc+1][iHt]>0){
+                hCFD[cc]->Fill(allData[cc+1][iHt]-allData[0][0]+5000);
+               }
+               if((allData[cc+1][iHt]!=0) && (allData[1][iHt]!=0)){
+                hCFD1minCFD[cc]->Fill(allData[cc+1][iHt]-allData[1][iHt]);
+               }
+               if(allData[ik+25][iHt]!=0 && allData[ik+26][iHt]!=0 && allData[cc+1][iHt]!=0){
+                 hCFDvsQTC[cc]->Fill((allData[ik+25][iHt]-allData[ik+26][iHt]) , (allData[cc+1][iHt]-allData[0][0]+5000));
+               } 
+                if(allData[cc+13][iHt]!=0 && allData[cc+1][iHt]!=0){
+                hCFDvsLED[cc]->Fill(allData[cc+13][iHt]-allData[cc+1][iHt],allData[cc+1][iHt]-allData[0][0]+5000);
+               }
+       }
+
+      for (Int_t ik = 24; ik<48; ik+=2)
+         for (Int_t iHt=0; iHt<5; iHt++){
+                Int_t cc = ik/2;
+                if((allData[cc+45][iHt]-allData[0][0]+5000)!=0 && allData[cc+45][iHt]>0){
+                 hCFD[cc]->Fill(allData[cc+45][iHt]-allData[0][0]+5000);
+               }
+               if((allData[cc+45][iHt]!=0) && (allData[57][iHt]!=0)){
+                hCFD1minCFD[cc]->Fill(allData[cc+45][iHt]-allData[57][iHt]);
+                }
+                if(allData[ik+57][iHt]!=0 && allData[ik+58][iHt]!=0 && allData[cc+45][iHt]!=0){
+                 hCFDvsQTC[cc]->Fill(allData[ik+57][iHt]-allData[ik+58][iHt],allData[cc+45][iHt]-allData[0][0]+5000);
+               }
+                if(allData[cc+57][iHt]!=0 && allData[cc+45][iHt]!=0){
+                 hCFDvsLED[cc]->Fill(allData[cc+57][iHt]-allData[cc+45][iHt],allData[cc+45][iHt]-allData[0][0]+5000);
+                }
+       }
+       
+     delete start;
+       start = 0x0;
+     reader->Reset();
+      // End of fill histograms
+
+    }
+
+    /* 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");
+      printf("Number of events processed - %i\n ",iev);
+      break;
+    }
+  }
+  printf("After loop, before writing histos\n");
+  // write a file with the histograms
+  TFile *hist = new TFile(FILE_OUT,"RECREATE");
+
+  for(Int_t j=0;j<24;j++){
+     hCFDvsQTC[j]->Write();
+     hCFDvsLED[j]->Write();
+     hCFD[j]->Write();
+     hCFD1minCFD[j]->Write();
+    }
+  hist->Close();
+  delete hist;
+
+  status=0;
+
+  /* export file to FXS */
+  if (daqDA_FES_storeFile(FILE_OUT, "COSMIC")) {
+    status=-2;
+  }
+
+  return status;
+}
+