]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDPreprocessor.cxx
All FMD corrections are now divided into the analysis + adding new corrections
[u/mrichter/AliRoot.git] / TRD / AliTRDPreprocessor.cxx
index 0cdc2e2f77f3eaddbc4011047e02fb0f5e9b32d2..e42d9ffd186775ca9adb82503679bc08b89e6c44 100644 (file)
 //                                                                        //
 ////////////////////////////////////////////////////////////////////////////
 
+#include <fstream>
+
 #include <TFile.h>
 #include <TProfile2D.h>
-#include <TStopwatch.h>
 #include <TObjString.h>
 #include <TString.h>
 #include <TList.h>
-#include <TCollection.h>
 #include <TSAXParser.h>
 
 #include "AliCDBMetaData.h"
 #include "AliTRDCalibraMode.h"
 #include "AliTRDCalibPadStatus.h"
 #include "AliTRDSaxHandler.h"
-#include "Cal/AliTRDCalDet.h"
+#include "AliTRDgeometry.h"
 #include "Cal/AliTRDCalPad.h"
 #include "Cal/AliTRDCalPadStatus.h"
 #include "Cal/AliTRDCalDCS.h"
 #include "Cal/AliTRDCalSingleChamberStatus.h"
 #include "Cal/AliTRDCalROC.h"
 
-
 ClassImp(AliTRDPreprocessor)
 
 //______________________________________________________________________________________________
@@ -107,7 +106,7 @@ UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
   Log(Form("runtype %s\n",runType.Data()));
   
   // always process the configuration data
-  /*  Int_t resultDCSC = */ProcessDCSConfigData(); // for testing!
+ if(ProcessDCSConfigData()) return 1; 
   
   if (runType=="PEDESTAL"){
     if(ExtractPedestals()) return 1;
@@ -116,17 +115,17 @@ UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
 
   if ((runType=="PHYSICS") || (runType=="STANDALONE") || (runType=="DAQ")){
     // DCS
-    /*if(*/ProcessDCS(dcsAliasMap)/*) return 1*/; // for testing!
+    if(ProcessDCS(dcsAliasMap)) return 1; 
     if(runType=="PHYSICS"){
       // HLT if On
       //TString runPar = GetRunParameter("HLTStatus");
       //if(runPar=="1") {
       if(GetHLTStatus()) {
-       /*if(*/ExtractHLT()/*) return 1*/; // for testing!
+       if(ExtractHLT()) return 1; // for testing!
       } 
       // DAQ if HLT failed
       if(!fVdriftHLT) {
-       /*if(*/ExtractDriftVelocityDAQ()/*) return 1*/; // for testing!
+       if(ExtractDriftVelocityDAQ()) return 1; // for testing!
       }
     }
   }
@@ -480,8 +479,11 @@ Bool_t AliTRDPreprocessor::ExtractPedestals()
   return error; 
   
 }
+
 //__________________________________________________________________
-Bool_t AliTRDPreprocessor::AreThereDataPedestal(AliTRDCalSingleChamberStatus *calROCStatus, Bool_t second){
+Bool_t AliTRDPreprocessor::AreThereDataPedestal(AliTRDCalSingleChamberStatus * const calROCStatus
+                                              , Bool_t second)
+{
 
   //
   // Data for this half chamber
@@ -495,16 +497,21 @@ Bool_t AliTRDPreprocessor::AreThereDataPedestal(AliTRDCalSingleChamberStatus *ca
     nCol0 = nColE + 4;
     nColE = nCols;
   }
+
+  Int_t totalnumberofpads = 0;
+  Int_t totalnumberofdata = 0; 
+
   for(Int_t col = nCol0; col < nColE; col++){
     for(Int_t row = 0; row < calROCStatus->GetNrows(); row++){
+      totalnumberofpads++;
       //printf("ismasked %d\n",(Int_t)calROCStatus->IsMasked(col,row));
       if(!calROCStatus->GetStatus(col,row)) {
        data = kTRUE;
-       continue;
+       totalnumberofdata++;
       }
     }
-    if(data) continue;
   }
+  if(totalnumberofdata < (Int_t)(totalnumberofpads/2)) data = kFALSE;
 
   return data;
   
@@ -662,8 +669,10 @@ Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
       
       // if enough statistics store the results
       if ((nbtg >                  0) && 
-         (nbfit        >= 0.95*nbE)) {
+         (nbfit        >= 0.5*nbE)) {
        // create the cal objects
+       calibra->PutMeanValueOtherVectorFit(1,kTRUE);
+       calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
        TObjArray object      = calibra->GetVectorFit();
        AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
        TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
@@ -765,7 +774,7 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
       }
       // analyse
       Log("Take the CH reference data. Now we will try to fit\n");
-      calibra->SetMinEntries(1000); // If there is less than 1000 entries in the histo: no fit
+      calibra->SetMinEntries(800); // If there is less than 1000 entries in the histo: no fit
       calibra->AnalyseCH(histogain);
       Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
        + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
@@ -773,8 +782,9 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
       Int_t nbE         = calibra->GetNumberEnt();
       // enough statistics
       if ((nbtg >                  0) && 
-         (nbfit        >= 0.95*nbE)) {
+         (nbfit        >= 0.5*nbE)) {
        // create the cal objects
+       calibra->PutMeanValueOtherVectorFit(1,kTRUE);
        TObjArray object           = calibra->GetVectorFit();
        AliTRDCalDet *objgaindet   = calibra->CreateDetObjectGain(&object);
        TObject *objgainpad        = calibra->CreatePadObjectGain();
@@ -803,7 +813,7 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
       }
       // analyse
       Log("Take the PH reference data. Now we will try to fit\n");
-      calibra->SetMinEntries(1000*20); // If there is less than 20000
+      calibra->SetMinEntries(800*20); // If there is less than 20000
       calibra->AnalysePH(histodriftvelocity);
       Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
        + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
@@ -811,8 +821,10 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
       Int_t nbE          = calibra->GetNumberEnt();
       // enough statistics
       if ((nbtg >                  0) && 
-         (nbfit        >= 0.95*nbE)) {
+         (nbfit        >= 0.5*nbE)) {
        // create the cal objects
+       calibra->PutMeanValueOtherVectorFit(1,kTRUE);
+       calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
        TObjArray object  = calibra->GetVectorFit();
        AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
        TObject *objdriftvelocitypad      = calibra->CreatePadObjectVdrift();
@@ -884,56 +896,125 @@ UInt_t AliTRDPreprocessor::ProcessDCSConfigData()
 {
   // 
   // process the configuration of FEE, PTR and GTU
-  // reteive XML file from the DCS FXS
-  // parse it and store TObjArrays in the CDB
-  // return 0 for success, otherwise:
-  // 5: could not get the file from the FXS
-  // 6: ERROR in XML validation: something wrong with the file
-  // 7: ERROR while creating calibration objects in the handler
-  // 8: error while storing data in the CDB
-  // > 100: SaxHandler error code
+  // reteive XML filei(s) from the DCS FXS
+  // parse it/them and store TObjArrays in the CDB
   //
-
-  Log("Processing the DCS config summary file.");
-
-  // get the XML file
-  const char * xmlFile = GetFile(kDCS,"CONFIGSUMMARY","");
-  if (xmlFile == NULL) {
+  // return 0 for success, otherwise:
+  //  5 : could not get the SOR file from the FXS
+  //  6 : could not get the EOR file from the FXS
+  //  7 : 
+  //  8 : something wrong with the SOR file
+  //  9 : something wrong with the EOR file
+  // 10 : SOR XML is not well-formed
+  // 11 : EOR XML is not well-formed
+  // 12 : ERROR in XML SAX validation: something wrong with the content
+  // 13 :
+  // 14 : ERROR while creating calibration objects in the handler
+  // 15 : error while storing data in the CDB
+  //
+
+  Log("Processing the DCS config summary files.");
+
+  // get the XML files
+  Log("Requesting the 2 summaryfiles from the FXS..");
+  const char *xmlFileS = GetFile(kDCS,"CONFIGSUMMARYSOR","");
+  const char *xmlFileE = GetFile(kDCS,"CONFIGSUMMARYEOR","");
+  // for the time being just request BOTH files from the FXS
+  // THEN it can be created online (otherwise the FXS would be messed up)
+  // the next step is to actually read BOTH files and store their informations
+  if (xmlFileS == NULL) {
+    Log(Form("ERROR: SOR File %s not found!",xmlFileS));
     return 5;
-    Log(Form("File %s not found!",xmlFile));
+  } else if (xmlFileE == NULL) {
+    Log(Form("ERROR: EOR File %s not found!",xmlFileE));
+    return 6;
+  } else {
+    Log(Form("Both Files (%s and %s) found.",xmlFileS,xmlFileE));
   }
-
+  
+  // test the files
+  std::ifstream fileTestS, fileTestE;
+  fileTestS.open(xmlFileS, std::ios_base::binary | std::ios_base::in);
+  fileTestE.open(xmlFileE, std::ios_base::binary | std::ios_base::in);
+  if (!fileTestS.good() || fileTestS.eof() || !fileTestS.is_open()) {
+    Log(Form("ERROR: File %s not valid!",xmlFileS));
+    return 8;
+  }
+  if (!fileTestE.good() || fileTestE.eof() || !fileTestE.is_open()) {
+    Log(Form("ERROR: File %s not valid!",xmlFileE));
+    return 9;
+  }
+  fileTestS.seekg(0, std::ios_base::end);
+  fileTestE.seekg(0, std::ios_base::end);
+  if (static_cast<int>(fileTestS.tellg()) < 2) {
+    Log(Form("ERROR: File %s is empty!",xmlFileS));
+    return 8;
+  }
+  if (static_cast<int>(fileTestE.tellg()) < 2) {
+    Log(Form("ERROR: File %s is empty!",xmlFileE));
+    return 9;
+  }
+  Log("Files are tested valid.");   
+
+  // make a robust XML validation
+  TSAXParser testParser;
+  if (testParser.ParseFile(xmlFileS) < 0 ) {
+    Log("ERROR: XML content (SOR) is not well-formed.");
+    return 10;
+  } else if (testParser.ParseFile(xmlFileE) < 0 ) {
+    Log("ERROR: XML content (EOR) is not well-formed.");
+    return 11;
+  }
+  Log("XML contents are well-formed.");
+      
   // create parser and parse
-  TSAXParser saxParser;
-  AliTRDSaxHandler saxHandler;
-  saxParser.ConnectToHandler("AliTRDSaxHandler", &saxHandler);
-  saxParser.ParseFile(xmlFile);
+  TSAXParser saxParserS, saxParserE;
+  AliTRDSaxHandler saxHandlerS, saxHandlerE;
+  saxParserS.ConnectToHandler("AliTRDSaxHandler", &saxHandlerS);
+  saxParserS.ParseFile(xmlFileS);
+  saxParserE.ConnectToHandler("AliTRDSaxHandler", &saxHandlerE);
+  saxParserE.ParseFile(xmlFileE);
 
   // report errors if present
-  if (saxParser.GetParseCode() == 0) {
-    Log("XML file validation OK");
+  if ((saxParserS.GetParseCode() == 0) && (saxParserE.GetParseCode() == 0)) {
+    Log("XML file validation OK.");
   } else {
-    Log(Form("ERROR in XML file validation. Parsecode: %s", saxParser.GetParseCode()));
-    return 6;
+    Log(Form("ERROR in XML file validation. Parsecodes: SOR: %s, EOR: %s", saxParserS.GetParseCode(), saxParserE.GetParseCode()));
+    return 12;
   }
-  if (saxHandler.GetHandlerStatus() != 0) {
-    Log(Form("ERROR while creating calibration objects. Error code: %s", saxHandler.GetHandlerStatus()));
-    return 7;
+  if ((saxHandlerS.GetHandlerStatus() == 0) && (saxHandlerE.GetHandlerStatus() == 0)) {
+    Log("SAX handler reports no errors.");
+  } else  {
+    Log(Form("ERROR while creating calibration objects. Error codes: SOR: %s, EOR: %s", saxHandlerS.GetHandlerStatus(), saxHandlerE.GetHandlerStatus()));
+    return 14;
   }
 
   // get the calibration object storing the data from the handler
-  AliTRDCalDCS* fCalDCSObj = saxHandler.GetCalDCSObj();
-
+  AliTRDCalDCS* fCalDCSObjSOR = saxHandlerS.GetCalDCSObj();
+  AliTRDCalDCS* fCalDCSObjEOR = saxHandlerE.GetCalDCSObj();
+  fCalDCSObjSOR->EvaluateGlobalParameters();
+  fCalDCSObjEOR->EvaluateGlobalParameters();
+  
+  // put both objects in one TObjArray to store them
+  TObjArray* fCalObjArray = new TObjArray(2);
+  fCalObjArray->SetOwner();
+  fCalObjArray->AddAt(fCalDCSObjSOR,0);
+  fCalObjArray->AddAt(fCalDCSObjEOR,1);
+  
   // store the DCS calib data in the CDB
   AliCDBMetaData metaData1;
   metaData1.SetBeamPeriod(0);
   metaData1.SetResponsible("Frederick Kramer");
-  metaData1.SetComment("DCS configuration data in one AliTRDCalDCS object.");
-  if (!Store("Calib", "DCSCONFIG", fCalDCSObj, &metaData1, 0, kTRUE)) {
+  metaData1.SetComment("DCS configuration data in two AliTRDCalDCS objects in one TObjArray (0:SOR, 1:EOR).");
+  if (!Store("Calib", "DCS", fCalObjArray, &metaData1, 0, kTRUE)) {
     Log("problems while storing DCS config data object");
-    return 8;
+    return 15;
+  } else {
+    Log("DCS config data object stored.");
   }
 
+  //delete fCalObjArray;
+
+  Log("Processing of the DCS config summary file DONE.");  
   return 0;
 }
-