LCOV - code coverage report
Current view: top level - TPC/TPCbase - AliTPCPreprocessor.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 10 1021 1.0 %
Date: 2016-06-14 17:26:59 Functions: 10 31 32.3 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 2007, ALICE Experiment at CERN, All rights reserved.      *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : 
      17             : #include "AliTPCPreprocessor.h"
      18             : #include "AliShuttleInterface.h"
      19             : 
      20             : #include "AliCDBMetaData.h"
      21             : #include "AliDCSValue.h"
      22             : #include "AliLog.h"
      23             : #include "AliTPCSensorTempArray.h"
      24             : #include "AliTPCROC.h"
      25             : #include "AliTPCCalROC.h"
      26             : #include "AliTPCCalPad.h"
      27             : #include "AliTPCCalibPedestal.h"
      28             : #include "AliTPCCalibPulser.h"
      29             : #include "AliTPCCalibCE.h"
      30             : #include "AliTPCCalibRaw.h"
      31             : #include "AliTPCdataQA.h"
      32             : #include "ARVersion.h"
      33             : #include "TFile.h"
      34             : #include "TTree.h"
      35             : #include "TGraph.h" 
      36             : #include "TEnv.h"
      37             : #include "TParameter.h"
      38             : 
      39             : #include <TTimeStamp.h>
      40             : 
      41             : const Int_t kValCutTemp = 100;               // discard temperatures > 100 degrees
      42             : const Int_t kDiffCutTemp = 5;                // discard temperature differences > 5 degrees
      43             : const Double_t kHighVoltageDifference = 1e-4; // don't record High Voltage points 
      44             :                                              // differing by less than 1e-4 from
      45             :                                              // previous point.
      46             : const Double_t kGasCompositionDifference = 1e-3; // don't record Gas Composition points 
      47             :                                              // differing by less than 1e-3 from
      48             :                                              // previous point
      49          24 : const TString kPedestalRunType = "PEDESTAL";  // pedestal run identifier
      50          24 : const TString kPulserRunType = "PULSER";     // pulser run identifier
      51          24 : const TString kPhysicsRunType = "PHYSICS";   // physics run identifier
      52          24 : const TString kCosmicRunType = "COSMIC";     // cosmic run identifier
      53          24 : const TString kLaserRunType = "LASER";       // laser run identifier
      54          24 : const TString kDaqRunType = "DAQ";         // DAQ run identifier
      55          24 : const TString kStandaloneRunType = "STANDALONE";  // STANDALONE run identifier
      56          24 : const TString kAmandaTemp = "TPC_PT_%d_TEMPERATURE"; // Amanda string for temperature entries
      57          24 : const TString kAmandaDDL = "DDL%d";   // Amanda string for list of active DDLs
      58             : const Int_t  kNumDDL = 216;           // number of TPC DDLs
      59             : const Int_t  kFirstDDL = 768;         // identifier of first DDL
      60             : //const Double_t kFitFraction = 0.7;                 // Fraction of DCS sensor fits required              
      61             : const Double_t kFitFraction = -1.0;          // Don't require minimum number of fits in commissioning run 
      62             : const Int_t   kNumPressureSensors = 3;    // number of pressure sensors
      63             : const char* kPressureSensorNames[kNumPressureSensors] = {
      64             :                    "CavernAtmosPressure",
      65             :                    "CavernAtmosPressure2",
      66             :                    "SurfaceAtmosPressure" };
      67             : const Int_t  kMinCESectors = 32;      // minimum number of sectors (per side)
      68             :                                       // to accept CE calibration
      69             :       
      70             : 
      71             : //
      72             : // This class is the SHUTTLE preprocessor for the TPC detector.
      73             : //
      74             : 
      75          24 : ClassImp(AliTPCPreprocessor)
      76             : 
      77             : //______________________________________________________________________________________________
      78             : AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
      79           0 :   AliPreprocessor("TPC",shuttle),
      80           0 :   fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0),
      81           0 :   fPressure(0), fGasComposition(0), fConfigOK(kTRUE), fROC(0),
      82           0 :   fForceSingleRun(kFALSE)
      83           0 : {
      84             :   // constructor
      85           0 :   fROC = AliTPCROC::Instance();
      86             : 
      87             :   // define run types to be processed
      88             :   
      89           0 :   AddRunType(kPedestalRunType);
      90           0 :   AddRunType(kPulserRunType);
      91           0 :   AddRunType(kPhysicsRunType);
      92           0 :   AddRunType(kCosmicRunType);
      93           0 :   AddRunType(kLaserRunType);
      94           0 :   AddRunType(kDaqRunType);
      95           0 :   AddRunType(kStandaloneRunType);
      96             :   
      97           0 : }
      98             : //______________________________________________________________________________________________
      99             :  AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor&  ) :
     100           0 :    AliPreprocessor("TPC",0),
     101           0 :    fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0),
     102           0 :    fPressure(0), fGasComposition(0), fConfigOK(kTRUE), fROC(0),
     103           0 :    fForceSingleRun(kFALSE)
     104           0 :  {
     105             : 
     106           0 :    Fatal("AliTPCPreprocessor", "copy constructor not implemented");
     107             : //
     108             : // //  fTemp = new AliTPCSensorTempArray(*(org.fTemp));
     109           0 :  }
     110             : 
     111             : //______________________________________________________________________________________________
     112             : AliTPCPreprocessor::~AliTPCPreprocessor()
     113           0 : {
     114             :   // destructor
     115             : 
     116           0 :   delete fTemp;
     117           0 :   delete fHighVoltage;
     118           0 :   delete fHighVoltageStat;
     119           0 :   delete fGoofie;
     120           0 :   delete fGasComposition;
     121           0 :   delete fPressure;
     122           0 : }
     123             : //______________________________________________________________________________________________
     124             : AliTPCPreprocessor& AliTPCPreprocessor::operator = (const AliTPCPreprocessor& )
     125             : {
     126           0 :   Fatal("operator =", "assignment operator not implemented");
     127           0 :   return *this;
     128             : }
     129             : 
     130             : 
     131             : //______________________________________________________________________________________________
     132             : void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
     133             :         UInt_t endTime)
     134             : {
     135             : 
     136           0 :   AliPreprocessor::Initialize(run, startTime, endTime);
     137             : 
     138           0 :         AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
     139             :                 TTimeStamp((time_t)startTime,0).AsString(),
     140             :                 TTimeStamp((time_t)endTime,0).AsString()));
     141             : 
     142             :   // Preprocessor configuration
     143             : 
     144           0 :         AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
     145           0 :         if (entry) fConfEnv = (TEnv*) entry->GetObject();
     146           0 :         if ( fConfEnv==0 ) {
     147           0 :            Log("AliTPCPreprocsessor: Preprocessor Config OCDB entry missing.\n");
     148           0 :            fConfigOK = kFALSE;
     149           0 :            return;
     150             :         }
     151             : 
     152             :   // Temperature sensors
     153             : 
     154             :        TTree *confTree = 0;
     155             : 
     156           0 :        TString tempConf = fConfEnv->GetValue("Temperature","ON");
     157           0 :        tempConf.ToUpper();
     158           0 :        if (tempConf != "OFF" ) {
     159           0 :         entry = GetFromOCDB("Config", "Temperature");
     160           0 :         if (entry) confTree = (TTree*) entry->GetObject();
     161           0 :         if ( confTree==0 ) {
     162           0 :            Log("AliTPCPreprocsessor: Temperature Config OCDB entry missing.\n");
     163           0 :            fConfigOK = kFALSE;
     164           0 :            return;
     165             :         }
     166           0 :         fTemp = new AliTPCSensorTempArray(startTime, endTime, confTree, kAmandaTemp);
     167           0 :         fTemp->SetValCut(kValCutTemp);
     168           0 :         fTemp->SetDiffCut(kDiffCutTemp);
     169           0 :        }
     170             : 
     171             :   // High voltage measurements
     172             : 
     173           0 :       TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
     174           0 :       hvConf.ToUpper();
     175           0 :       if (hvConf != "OFF" ) { 
     176             :         confTree=0;
     177             :         entry=0;
     178           0 :         entry = GetFromOCDB("Config", "HighVoltage");
     179           0 :         if (entry) confTree = (TTree*) entry->GetObject();
     180           0 :         if ( confTree==0 ) {
     181           0 :            Log("AliTPCPreprocsessor: High Voltage Config OCDB entry missing.\n");
     182           0 :            fConfigOK = kFALSE;
     183           0 :            return;
     184             :         }
     185           0 :         time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
     186           0 :         time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
     187           0 :         fHighVoltage = new AliDCSSensorArray (UInt_t(timeStart), 
     188           0 :                                             UInt_t(timeEnd), confTree);
     189           0 :       }
     190             : 
     191             :    // High voltage status values
     192             :      
     193           0 :       TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
     194           0 :       hvStatConf.ToUpper();
     195           0 :       if (hvStatConf != "OFF" ) { 
     196             :         confTree=0;
     197             :         entry=0;
     198           0 :         entry = GetFromOCDB("Config", "HighVoltageStat");
     199           0 :         if (entry) confTree = (TTree*) entry->GetObject();
     200           0 :         if ( confTree==0 ) {
     201           0 :            Log("AliTPCPreprocsessor: High Voltage Status Config OCDB entry missing.\n");
     202           0 :            fConfigOK = kFALSE;
     203           0 :            return;
     204             :         }
     205           0 :         fHighVoltageStat = new AliDCSSensorArray(startTime, endTime, confTree);
     206           0 :       }
     207             : 
     208             :    // Goofie values
     209             :      
     210           0 :       TString goofieConf = fConfEnv->GetValue("Goofie","ON");
     211           0 :       goofieConf.ToUpper();
     212           0 :       if (goofieConf != "OFF" ) { 
     213             :         confTree=0;
     214             :         entry=0;
     215           0 :         entry = GetFromOCDB("Config", "Goofie");
     216           0 :         if (entry) confTree = (TTree*) entry->GetObject();
     217           0 :         if ( confTree==0 ) {
     218           0 :            Log("AliTPCPreprocsessor: Goofie Config OCDB entry missing.\n");
     219           0 :            fConfigOK = kFALSE;
     220           0 :            return;
     221             :         }
     222           0 :         fGoofie = new AliDCSSensorArray(startTime, endTime, confTree);
     223           0 :       }
     224             : 
     225             : 
     226             :   // Gas composition measurements
     227             : 
     228           0 :       TString gasConf = fConfEnv->GetValue("GasComposition","OFF");
     229           0 :       gasConf.ToUpper();
     230           0 :       if (gasConf != "OFF" ) { 
     231             :         confTree=0;
     232             :         entry=0;
     233           0 :         entry = GetFromOCDB("Config", "GasComposition");
     234           0 :         if (entry) confTree = (TTree*) entry->GetObject();
     235           0 :         if ( confTree==0 ) {
     236           0 :            Log("AliTPCPreprocsessor: Gas Composition Config OCDB entry missing.\n");
     237           0 :            fConfigOK = kFALSE;
     238           0 :            return;
     239             :         }
     240           0 :         time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
     241           0 :         time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
     242           0 :         fGasComposition = new AliDCSSensorArray (UInt_t(timeStart), 
     243           0 :                                             UInt_t(timeEnd), confTree);
     244           0 :       }
     245             :    // Pressure values
     246             :      
     247           0 :        TString runType = GetRunType();
     248             : 
     249           0 :        if( runType == kPhysicsRunType || 
     250           0 :         runType == kLaserRunType || runType == kStandaloneRunType ) {    
     251           0 :        TString pressureConf = fConfEnv->GetValue("Pressure","ON");
     252           0 :        pressureConf.ToUpper();
     253           0 :        if (pressureConf != "OFF" ) { 
     254           0 :          TClonesArray * array = new TClonesArray("AliDCSSensor",kNumPressureSensors); 
     255           0 :          for(Int_t j = 0; j < kNumPressureSensors; j++) {
     256           0 :            AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
     257           0 :            sens->SetStringID(kPressureSensorNames[j]);
     258             :          }
     259           0 :          fPressure = new AliDCSSensorArray(startTime, endTime, array);
     260           0 :        }
     261           0 :      }
     262           0 : }
     263             : 
     264             : //______________________________________________________________________________________________
     265             : UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
     266             : {
     267             :   // Fills data into TPC calibrations objects
     268             : 
     269             :   // Amanda servers provide information directly through dcsAliasMap
     270             : 
     271             :   
     272           0 :   if (!fConfigOK) return 9;
     273             :   UInt_t result = 0;
     274           0 :   TObjArray *resultArray = new TObjArray();
     275           0 :   TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
     276           0 :   errorHandling.ToUpper();
     277             :   TObject * status;
     278             : 
     279             :   UInt_t dcsResult=0;
     280           0 :   if (!dcsAliasMap) { 
     281             :      dcsResult=1;
     282           0 :   } else {
     283           0 :      if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;
     284             :   }  
     285           0 :   status = new TParameter<int>("dcsResult",dcsResult);
     286           0 :   resultArray->Add(status);
     287             : 
     288             : 
     289           0 :   TString runType = GetRunType();
     290             : 
     291           0 :   if ( dcsResult == 0 ) {
     292             : 
     293             :   // Temperature sensors are processed by AliTPCCalTemp
     294             : 
     295           0 :     TString tempConf = fConfEnv->GetValue("Temperature","ON");
     296           0 :     tempConf.ToUpper();
     297           0 :     if (tempConf != "OFF" ) {
     298           0 :       UInt_t tempResult = MapTemperature(dcsAliasMap);
     299           0 :       if ( tempConf != "TRY") result+=tempResult;
     300           0 :       status = new TParameter<int>("tempResult",tempResult);
     301           0 :       resultArray->Add(status);
     302           0 :     }
     303             : 
     304             :   // High Voltage recordings
     305             : 
     306             : 
     307           0 :     TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
     308           0 :     hvConf.ToUpper();
     309           0 :     if (hvConf != "OFF" ) { 
     310           0 :      UInt_t hvResult = MapHighVoltage(dcsAliasMap);
     311           0 :      if (hvConf != "TRY") result+=hvResult;
     312           0 :      status = new TParameter<int>("hvResult",hvResult);
     313           0 :      resultArray->Add(status);
     314           0 :     }
     315             : 
     316             :     // Goofie values
     317             : 
     318             : 
     319           0 :     TString goofieConf = fConfEnv->GetValue("Goofie","ON");
     320           0 :     goofieConf.ToUpper();
     321           0 :     if (goofieConf != "OFF" ) { 
     322           0 :      UInt_t goofieResult = MapGoofie(dcsAliasMap);
     323           0 :      if (goofieConf != "TRY") result+=goofieResult;
     324           0 :      status = new TParameter<int>("goofieResult",goofieResult);
     325           0 :      resultArray->Add(status);
     326           0 :     }
     327             : 
     328             : 
     329             :     // Gas composition recordings
     330             : 
     331             : 
     332           0 :     TString gasConf = fConfEnv->GetValue("GasComposition","OFF");
     333           0 :     gasConf.ToUpper();
     334           0 :     if (gasConf != "OFF" ) { 
     335           0 :      UInt_t gasResult = MapGasComposition(dcsAliasMap);
     336           0 :      if (gasConf != "TRY") result+=gasResult;
     337           0 :      status = new TParameter<int>("gasResult",gasResult);
     338           0 :      resultArray->Add(status);
     339           0 :     }
     340             : 
     341             :     // Pressure values
     342             : 
     343           0 :     if( runType == kPhysicsRunType || 
     344           0 :       runType == kLaserRunType || runType == kStandaloneRunType ) {    
     345             : 
     346           0 :       TString pressureConf = fConfEnv->GetValue("Pressure","ON");
     347           0 :       pressureConf.ToUpper();
     348           0 :       if (pressureConf != "OFF" ) { 
     349           0 :        UInt_t pressureResult = MapPressure(dcsAliasMap);
     350           0 :        status = new TParameter<int>("pressureResult",pressureResult);
     351           0 :        resultArray->Add(status);
     352           0 :       }
     353           0 :     }
     354           0 :   }
     355             :   // Other calibration information will be retrieved through FXS files
     356             :   //  examples:
     357             :   //    TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
     358             :   //    const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
     359             :   //
     360             :   //    TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
     361             :   //    const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
     362             : 
     363             :   // pedestal entries
     364             : 
     365           0 :   if(runType == kPedestalRunType) {
     366             :     Int_t numSources = 1;
     367           0 :     Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
     368           0 :     TString source = fConfEnv->GetValue("Pedestal","DAQ");
     369           0 :     source.ToUpper();
     370           0 :     if (source != "OFF" ) { 
     371           0 :      if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
     372           0 :      if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
     373           0 :      if (source == "HLTDAQ" ) {
     374             :          numSources=2;
     375           0 :          pedestalSource[0] = AliShuttleInterface::kHLT;
     376           0 :          pedestalSource[1] = AliShuttleInterface::kDAQ;
     377           0 :      }
     378           0 :      if (source == "DAQHLT" ) numSources=2;
     379             :      UInt_t pedestalResult=0;
     380           0 :      for (Int_t i=0; i<numSources; i++ ) {   
     381           0 :        pedestalResult = ExtractPedestals(pedestalSource[i]);
     382           0 :        if ( pedestalResult == 0 ) break;
     383             :      }
     384           0 :      result += pedestalResult;
     385           0 :      status = new TParameter<int>("pedestalResult",pedestalResult);
     386           0 :      resultArray->Add(status);
     387           0 :     }
     388           0 :   }
     389             : 
     390             :   // pulser trigger processing
     391             : 
     392           0 :   if(runType == kPulserRunType) {
     393             :     Int_t numSources = 1;
     394           0 :     Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
     395           0 :     TString source = fConfEnv->GetValue("Pulser","DAQ");
     396           0 :     source.ToUpper();
     397           0 :     if ( source != "OFF") { 
     398           0 :      if ( source == "HLT") pulserSource[0] = AliShuttleInterface::kHLT;
     399           0 :      if (!GetHLTStatus()) pulserSource[0] = AliShuttleInterface::kDAQ;
     400           0 :      if (source == "HLTDAQ" ) {
     401             :          numSources=2;
     402           0 :          pulserSource[0] = AliShuttleInterface::kHLT;
     403           0 :          pulserSource[1] = AliShuttleInterface::kDAQ;
     404           0 :      }
     405           0 :      if (source == "DAQHLT" ) numSources=2;
     406           0 :      if (source == "TRY" ) numSources=1;
     407             :      UInt_t pulserResult=0;
     408           0 :      for (Int_t i=0; i<numSources; i++ ) {   
     409           0 :        pulserResult = ExtractPulser(pulserSource[i]);
     410           0 :        if ( pulserResult == 0 ) break;
     411             :      }
     412           0 :      if (source != "TRY") result += pulserResult;
     413           0 :      status = new TParameter<int>("pulserResult",pulserResult);
     414           0 :      resultArray->Add(status);
     415           0 :     }
     416           0 :   }
     417             : 
     418             : 
     419             : // raw calibration processing
     420             : 
     421           0 :   if(runType == kPhysicsRunType) {
     422             :     Int_t numSources = 1;
     423           0 :     Int_t rawSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
     424           0 :     TString source = fConfEnv->GetValue("Raw","DAQ");
     425           0 :     source.ToUpper();
     426           0 :     if ( source != "OFF") { 
     427           0 :      if ( source == "HLT") rawSource[0] = AliShuttleInterface::kHLT;
     428           0 :      if (!GetHLTStatus()) rawSource[0] = AliShuttleInterface::kDAQ;
     429           0 :      if (source == "HLTDAQ" ) {
     430             :          numSources=2;
     431           0 :          rawSource[0] = AliShuttleInterface::kHLT;
     432           0 :          rawSource[1] = AliShuttleInterface::kDAQ;
     433           0 :      }
     434           0 :      if (source == "DAQHLT" ) numSources=2;
     435           0 :      if (source == "TRY" ) numSources=1;
     436             :      UInt_t rawResult=0;
     437           0 :      for (Int_t i=0; i<numSources; i++ ) {   
     438           0 :        rawResult = ExtractRaw(rawSource[i]);
     439           0 :        if ( rawResult == 0 ) break;
     440             :      }
     441           0 :      if (source != "TRY" )result += rawResult;
     442           0 :      status = new TParameter<int>("rawResult",rawResult);
     443           0 :      resultArray->Add(status);
     444           0 :     }
     445           0 :   }
     446             : 
     447             : 
     448             :   // Altro configuration
     449             : 
     450             : 
     451           0 :   TString altroConf = fConfEnv->GetValue("AltroConf","ON");
     452           0 :   altroConf.ToUpper();
     453           0 :   if (altroConf != "OFF" ) { 
     454           0 :    UInt_t altroResult = ExtractAltro(AliShuttleInterface::kDCS,dcsAliasMap);
     455           0 :    if (altroConf != "TRY" ) result+=altroResult;
     456           0 :    status = new TParameter<int>("altroResult",altroResult);
     457           0 :    resultArray->Add(status);
     458           0 :   }
     459             : 
     460             : 
     461             :   // Central Electrode processing
     462             : 
     463           0 :   if( runType == kPhysicsRunType || 
     464           0 :       runType == kLaserRunType ) {    
     465             : 
     466             :     Int_t numSources = 1;
     467           0 :     Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
     468           0 :     TString source = fConfEnv->GetValue("CE","DAQ");
     469           0 :     source.ToUpper();
     470           0 :     if ( source != "OFF" ) { 
     471           0 :      if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
     472           0 :      if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
     473           0 :      if (source == "HLTDAQ" ) {
     474             :         numSources=2;
     475           0 :         ceSource[0] = AliShuttleInterface::kHLT;
     476           0 :         ceSource[1] = AliShuttleInterface::kDAQ;
     477           0 :      }
     478           0 :      if (source == "DAQHLT" ) numSources=2;
     479           0 :      if (source == "TRY" ) numSources=1;
     480             :      UInt_t ceResult=0;
     481           0 :      for (Int_t i=0; i<numSources; i++ ) {   
     482           0 :        ceResult = ExtractCE(ceSource[i]);
     483           0 :        if ( ceResult == 0 ) break;
     484             :      }
     485             : 
     486             :    // only flag error if CE result is missing from LASER runs
     487             :    //    -- for PHYSICS run do CE processing if data available
     488             :    
     489           0 :      if ( runType == kLaserRunType && source != "TRY"  && ceResult<10 ) result += ceResult;
     490           0 :      status = new TParameter<int>("ceResult",ceResult);
     491           0 :      resultArray->Add(status);
     492             : 
     493             :     numSources = 1;
     494           0 :     Int_t qaSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
     495           0 :     source = fConfEnv->GetValue("QA","DAQ");
     496           0 :     source.ToUpper();
     497           0 :     if ( source != "OFF" ) { 
     498           0 :      if ( source == "HLT") qaSource[0] = AliShuttleInterface::kHLT;
     499           0 :      if (!GetHLTStatus()) qaSource[0] = AliShuttleInterface::kDAQ;
     500           0 :      if (source == "HLTDAQ" ) {
     501             :         numSources=2;
     502           0 :         qaSource[0] = AliShuttleInterface::kHLT;
     503           0 :         qaSource[1] = AliShuttleInterface::kDAQ;
     504           0 :      }
     505           0 :      if (source == "DAQHLT" ) numSources=2;
     506           0 :      if (source == "TRY" ) numSources=1;
     507             :      UInt_t qaResult=0;
     508           0 :      for (Int_t i=0; i<numSources; i++ ) {   
     509           0 :        qaResult = ExtractQA(qaSource[i]);
     510           0 :        if ( qaResult == 0 ) break;
     511             :      }
     512             : //     result += qaResult;
     513           0 :      if ( qaResult !=0 ) Log ("ExtractQA failed, no QA entry available.");
     514           0 :      status = new TParameter<int>("qaResult",qaResult);
     515           0 :      resultArray->Add(status);
     516           0 :     }
     517           0 :    }
     518           0 :   }
     519             :   
     520             : // Store component status to OCDB
     521             : 
     522           0 :   AliCDBMetaData metaData;
     523           0 :   metaData.SetBeamPeriod(0);
     524           0 :   metaData.SetResponsible("Haavard Helstrup");
     525           0 :   metaData.SetAliRootVersion(ALIROOT_VERSION);
     526           0 :   metaData.SetComment("Preprocessor AliTPC status.");
     527           0 :   Bool_t storeOK = Store("Calib", "PreprocStatus", resultArray, &metaData, 0,  kFALSE);
     528           0 :   if (!storeOK) Log ("Unable to store preprocessor status entry");
     529             :  
     530           0 :   resultArray->Delete();
     531           0 :   delete resultArray;
     532             : 
     533           0 :   if (errorHandling == "OFF" ) return 0;
     534           0 :   return result;
     535             :   
     536           0 : }
     537             : //______________________________________________________________________________________________
     538             : UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
     539             : {
     540             : 
     541             :    // extract DCS temperature maps. Perform fits to save space
     542             : 
     543             :   UInt_t result=0;
     544           0 :   TMap *map = fTemp->ExtractDCS(dcsAliasMap);
     545           0 :   if (map) {
     546           0 :     fTemp->MakeSplineFit(map);
     547           0 :     Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors(); 
     548           0 :     if (fitFraction > kFitFraction ) {
     549           0 :       AliInfo(Form("Temperature values extracted, fits performed.\n"));
     550           0 :     } else { 
     551           0 :       Log ("Too few temperature maps fitted. \n");
     552             :       result = 9;
     553             :     }
     554           0 :   } else {
     555           0 :     Log("No temperature map extracted. \n");
     556             :     result=9;
     557             :   }
     558           0 :   delete map;
     559             :   // Now store the final CDB file
     560             : 
     561           0 :   if ( result == 0 ) {
     562           0 :         AliCDBMetaData metaData;
     563           0 :         metaData.SetBeamPeriod(0);
     564           0 :         metaData.SetResponsible("Haavard Helstrup");
     565           0 :         metaData.SetAliRootVersion(ALIROOT_VERSION);
     566           0 :         metaData.SetComment("Preprocessor AliTPC data base entries.");
     567             : 
     568           0 :         Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
     569           0 :         if ( !storeOK )  result=1;
     570             : 
     571           0 :    }
     572             : 
     573           0 :    return result;
     574             : 
     575           0 : }
     576             : //______________________________________________________________________________________________
     577             : UInt_t AliTPCPreprocessor::MapPressure(TMap* dcsAliasMap)
     578             : {
     579             : 
     580             :    // extract DCS pressure maps. Perform fits to save space
     581             : 
     582             :   UInt_t result=0;
     583           0 :   TMap *map = fPressure->ExtractDCS(dcsAliasMap);
     584           0 :   if (map) {
     585           0 :     fPressure->MakeSplineFit(map);
     586           0 :     Double_t fitFraction = 1.0*fPressure->NumFits()/fPressure->NumSensors(); 
     587           0 :     if (fitFraction > kFitFraction ) {
     588           0 :       AliInfo(Form("Pressure values extracted, fits performed.\n"));
     589           0 :     } else { 
     590           0 :       Log ("Too few pressure maps fitted. \n");
     591             :       result = 9;
     592             :     }
     593           0 :   } else {
     594           0 :     Log("No pressure map extracted. \n");
     595             :     result=9;
     596             :   }
     597           0 :   delete map;
     598           0 :   return result;
     599             : }
     600             : 
     601             : //______________________________________________________________________________________________
     602             : UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
     603             : {
     604             : 
     605             :    // extract DCS HV maps. Perform fits to save space
     606             : 
     607             :   UInt_t result=0;
     608           0 :   TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
     609           0 :   if (map) {
     610           0 :     fHighVoltage->ClearFit();
     611           0 :     fHighVoltage->SetGraph(map);
     612           0 :     fHighVoltage->RemoveGraphDuplicates(kHighVoltageDifference);
     613             :                // don't keep new point if too similar to previous one
     614           0 :   } else {
     615           0 :     Log("No high voltage recordings extracted. \n");
     616             :     result=9;
     617             :   }
     618           0 :   delete map;
     619             : 
     620           0 :   TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
     621           0 :   hvStatConf.ToUpper();
     622           0 :   if (hvStatConf != "OFF" ) { 
     623           0 :     TMap *map2 = fHighVoltageStat->ExtractDCS(dcsAliasMap);
     624           0 :     if (map2) {
     625           0 :       fHighVoltageStat->ClearFit();
     626           0 :       fHighVoltageStat->SetGraph(map2);
     627             :     } else {
     628           0 :        Log("No high voltage status recordings extracted. \n");
     629             :       result=9;
     630             :     }
     631           0 :     delete map2;
     632             : 
     633             :     // add status maps to high voltage sensor array
     634             : 
     635           0 :     fHighVoltage->AddSensors(fHighVoltageStat);
     636           0 :    }
     637             :   // Now store the final CDB file
     638             : 
     639           0 :   if ( result == 0 ) {
     640           0 :         AliCDBMetaData metaData;
     641           0 :         metaData.SetBeamPeriod(0);
     642           0 :         metaData.SetResponsible("Haavard Helstrup");
     643           0 :         metaData.SetAliRootVersion(ALIROOT_VERSION);
     644           0 :         metaData.SetComment("Preprocessor AliTPC data base entries.");
     645             : 
     646           0 :         Bool_t storeOK = Store("Calib", "HighVoltage", fHighVoltage, &metaData, 0, kFALSE);
     647           0 :         if ( !storeOK )  result=1;
     648             : 
     649           0 :    }
     650             : 
     651             :    return result;
     652             : 
     653           0 : }
     654             : 
     655             : //______________________________________________________________________________________________
     656             : UInt_t AliTPCPreprocessor::MapGoofie(TMap* dcsAliasMap)
     657             : {
     658             : 
     659             :    // extract DCS Goofie maps. Do not perform fits (low update rate)
     660             : 
     661             :   UInt_t result=0;
     662             : 
     663           0 :   TMap *map = fGoofie->ExtractDCS(dcsAliasMap);
     664           0 :   if (map) {
     665           0 :     fGoofie->ClearFit();
     666           0 :     fGoofie->SetGraph(map);
     667           0 :   } else {
     668           0 :     Log("No Goofie recordings extracted. \n");
     669             :     result=9;
     670             :   }
     671           0 :   delete map;
     672             : 
     673             :   // Now store the final CDB file
     674             : 
     675           0 :   if ( result == 0 ) {
     676           0 :         AliCDBMetaData metaData;
     677           0 :         metaData.SetBeamPeriod(0);
     678           0 :         metaData.SetResponsible("Haavard Helstrup");
     679           0 :         metaData.SetAliRootVersion(ALIROOT_VERSION);
     680           0 :         metaData.SetComment("Preprocessor AliTPC data base entries.");
     681             : 
     682           0 :         Bool_t storeOK = Store("Calib", "Goofie", fGoofie, &metaData, 0, kFALSE);
     683           0 :         if ( !storeOK )  result=1;
     684             : 
     685           0 :    }
     686             : 
     687           0 :    return result;
     688             : 
     689           0 : }
     690             : 
     691             : //______________________________________________________________________________________________
     692             : UInt_t AliTPCPreprocessor::MapGasComposition(TMap* dcsAliasMap)
     693             : {
     694             : 
     695             :    // extract DCS HV maps. Perform fits to save space
     696             : 
     697             :   UInt_t result=0;
     698           0 :   TMap *map = fGasComposition->ExtractDCS(dcsAliasMap);
     699           0 :   if (map) {
     700           0 :     fGasComposition->ClearFit();
     701           0 :     fGasComposition->SetGraph(map);
     702           0 :     fGasComposition->RemoveGraphDuplicates(kGasCompositionDifference);
     703             :                // don't keep new point if too similar to previous one
     704           0 :   } else {
     705           0 :     Log("No gas composition recordings extracted. \n");
     706             :     result=9;
     707             :   }
     708           0 :   delete map;
     709             : 
     710             :   // Now store the final CDB file
     711             : 
     712           0 :   if ( result == 0 ) {
     713           0 :         AliCDBMetaData metaData;
     714           0 :         metaData.SetBeamPeriod(0);
     715           0 :         metaData.SetResponsible("Haavard Helstrup");
     716           0 :         metaData.SetAliRootVersion(ALIROOT_VERSION);
     717           0 :         metaData.SetComment("Preprocessor AliTPC data base entries.");
     718             : 
     719           0 :         Bool_t storeOK = Store("Calib", "GasComposition", fGasComposition, &metaData, 0, kFALSE);
     720           0 :         if ( !storeOK )  result=1;
     721             : 
     722           0 :    }
     723             : 
     724           0 :    return result;
     725             : 
     726           0 : }
     727             : 
     728             : 
     729             : //______________________________________________________________________________________________
     730             : 
     731             : UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
     732             : {
     733             :  //
     734             :  //  Read pedestal file from file exchage server
     735             :  //  Keep original entry from OCDB in case no new pedestals are available
     736             :  //
     737             :  AliTPCCalPad *calPadPedOCDB=0;
     738           0 :  AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
     739           0 :  if (entry) calPadPedOCDB = (AliTPCCalPad*)entry->GetObject();
     740           0 :  if ( calPadPedOCDB==NULL ) {
     741           0 :      Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
     742           0 :  }
     743             : 
     744             :  AliTPCCalPad *calPadRMSOCDB=0;
     745           0 :  entry = GetFromOCDB("Calib", "PadNoise");
     746           0 :  if (entry) calPadRMSOCDB = (AliTPCCalPad*)entry->GetObject();
     747           0 :  if ( calPadRMSOCDB==NULL ) {
     748           0 :      Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
     749           0 :  }
     750             : 
     751           0 :   AliTPCCalPad* calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
     752           0 :   AliTPCCalPad* calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
     753             : 
     754             : 
     755             :  UInt_t result=0;
     756             : 
     757           0 :  Int_t nSectors = fROC->GetNSectors();
     758           0 :  TVectorD foundSectorsPed(nSectors);
     759           0 :  foundSectorsPed=0;
     760           0 :  TVectorD foundSectorsRMS(nSectors);
     761           0 :  foundSectorsRMS=0;
     762             : 
     763           0 :  TList* list = GetFileSources(sourceFXS,"pedestals");
     764             :  
     765           0 :  if (list && list->GetEntries()>0) {
     766             : 
     767             : //  loop through all files from LDCs
     768             : 
     769             :     Bool_t changed=false;
     770             :     UInt_t index = 0;
     771           0 :     while (list->At(index)!=NULL) {
     772           0 :      TObjString* fileNameEntry = (TObjString*) list->At(index);
     773           0 :      if (fileNameEntry!=NULL) {
     774           0 :         TString fileName = GetFile(sourceFXS, "pedestals",
     775           0 :                                          fileNameEntry->GetString().Data());
     776           0 :         TFile *f = TFile::Open(fileName);
     777           0 :         if (!f) {
     778           0 :           Log ("Error opening pedestal file.");
     779             :           result =2;
     780           0 :           break;
     781             :         }
     782           0 :         AliTPCCalibPedestal *calPed;
     783           0 :         f->GetObject("tpcCalibPedestal",calPed);
     784           0 :         if ( !calPed ) {
     785           0 :           Log ("No pedestal calibration object in file.");
     786             :           result = 2;
     787           0 :           break;
     788             :         }
     789             : 
     790             :         //  replace entries for the sectors available in the present file
     791             : 
     792             :         changed=true;
     793           0 :         for (Int_t sector=0; sector<nSectors; sector++) {
     794           0 :            AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
     795           0 :            if ( rocPed ) {
     796           0 :                AliTPCCalROC* roc=calPadPed->GetCalROC(sector);
     797           0 :                roc->Add(rocPed,1);
     798           0 :                foundSectorsPed[sector]++;
     799           0 :            }
     800           0 :            AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
     801           0 :            if ( rocRMS )  {
     802           0 :                AliTPCCalROC* roc=calPadRMS->GetCalROC(sector);
     803           0 :                roc->Add(rocRMS,1);
     804           0 :                foundSectorsRMS[sector]++;
     805           0 :            } 
     806             :         }
     807           0 :         delete calPed; 
     808           0 :         f->Close();
     809           0 :       }
     810           0 :      ++index;
     811           0 :     }  // while(list)
     812             : 
     813             : //
     814             : //  Check if calibration is complete -- otherwise take from old OCDB entry
     815             : 
     816             : // inner sectors
     817           0 :     for (Int_t sector=0; sector<nSectors/2; sector++) {
     818           0 :        if (foundSectorsPed[sector] < 1 ) {
     819           0 :           if (calPadPedOCDB) {
     820           0 :             AliTPCCalROC *rocOCDB=calPadPedOCDB->GetCalROC(sector);
     821           0 :             calPadPed->SetCalROC(rocOCDB,sector);
     822           0 :           } else {
     823             :             const int mess_length=100;
     824           0 :             char message[mess_length];
     825           0 :             snprintf(message,mess_length,"Missing pedestals for sector %d - also not available from previous OCDB entry.\n",
     826             :                      sector);
     827           0 :             Log (message);
     828             :             result = 2;
     829           0 :           }
     830             :        }
     831           0 :        if (foundSectorsRMS[sector] < 1 ) {
     832           0 :           if (calPadRMSOCDB) {
     833           0 :             AliTPCCalROC *rocOCDB=calPadRMSOCDB->GetCalROC(sector);
     834           0 :             calPadRMS->SetCalROC(rocOCDB,sector);
     835           0 :           } else {
     836             :             const int mess_length=100;
     837           0 :             char message[mess_length];
     838           0 :             snprintf(message,mess_length,"Missing pedestal RMS for sector %d - also not available from previous OCDB entry.\n",
     839             :                      sector);
     840           0 :             Log (message);
     841             :             result = 2;
     842           0 :           }       
     843             :        }
     844             :     }
     845             : 
     846             : // outer sectors -- two updates needed
     847             : 
     848           0 :     for (Int_t sector=nSectors/2; sector<nSectors; sector++) {
     849           0 :        if (foundSectorsPed[sector] < 2 ) {
     850           0 :           if (calPadPedOCDB) {
     851           0 :             AliTPCCalROC *rocOCDB=calPadPedOCDB->GetCalROC(sector);
     852           0 :             calPadPed->SetCalROC(rocOCDB,sector);
     853           0 :           } else {
     854             :             const int mess_length=100;
     855           0 :             char message[mess_length];
     856           0 :             snprintf(message,mess_length,"Missing pedestals for sector %d - also not available from previous OCDB entry.\n",
     857             :                      sector);
     858           0 :             Log (message);
     859             :             result = 2;
     860           0 :           }
     861             : 
     862             :        }
     863           0 :        if (foundSectorsRMS[sector] < 2 ) {
     864           0 :           if (calPadRMSOCDB) {
     865           0 :             AliTPCCalROC *rocOCDB=calPadRMSOCDB->GetCalROC(sector);
     866           0 :             calPadRMS->SetCalROC(rocOCDB,sector);
     867           0 :           } else {
     868             :             const int mess_length=100;
     869           0 :             char message[mess_length];
     870           0 :             snprintf(message,mess_length,"Missing pedestal RMS for sector %d - also not available from previous OCDB entry.\n",
     871             :                      sector);
     872           0 :             Log (message);
     873             :             result = 2;
     874           0 :           }       
     875             : 
     876             :        }       
     877             :     }
     878             : 
     879             :     
     880             : //
     881             : //  Store updated pedestal entry to OCDB
     882             : //
     883           0 :     if (changed) {
     884           0 :      AliCDBMetaData metaData;
     885           0 :      metaData.SetBeamPeriod(0);
     886           0 :      metaData.SetResponsible("Haavard Helstrup");
     887           0 :      metaData.SetAliRootVersion(ALIROOT_VERSION);
     888           0 :      metaData.SetComment("Preprocessor AliTPC data base entries."); 
     889             :  
     890           0 :      Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE ^ fForceSingleRun);
     891           0 :      if ( !storeOK ) ++result;
     892           0 :      storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE ^ fForceSingleRun);
     893           0 :      if ( !storeOK ) ++result;
     894           0 :     }
     895           0 :   } else {
     896           0 :     Log ("Error: no entries in pedestal file list!");
     897             :     result = 1;
     898             :   }
     899             : 
     900           0 :   delete calPadPed;
     901           0 :   delete calPadRMS;
     902           0 :   delete calPadPedOCDB;
     903           0 :   delete calPadRMSOCDB;
     904             : 
     905             :   return result;
     906           0 : }
     907             : 
     908             : //______________________________________________________________________________________________
     909             : 
     910             : 
     911             : UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
     912             : {
     913             :  //
     914             :  //  Read pulser calibration file from file exchage server
     915             :  //  Keep original entry from OCDB in case no new pulser calibration is available
     916             :  //
     917             :  
     918           0 :  TObjArray *pulserObjects = new TObjArray;
     919             :  TObjArray *pulserObjectsOCDB=0;   
     920           0 :  pulserObjects->SetOwner(kTRUE);
     921             : 
     922             :   
     923           0 :  AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
     924           0 :  if (entry) pulserObjectsOCDB = (TObjArray*)entry->GetObject();
     925           0 :  if ( pulserObjectsOCDB==NULL ) {
     926           0 :      Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
     927           0 :  } else {
     928           0 :      pulserObjectsOCDB->SetOwner(kTRUE);
     929             :  }
     930             : 
     931           0 :  AliTPCCalPad *pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
     932           0 :  pulserObjects->Add(pulserTmean);
     933             :  
     934           0 :  AliTPCCalPad *pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
     935           0 :  pulserObjects->Add(pulserTrms);
     936             :  
     937           0 :  AliTPCCalPad *pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
     938           0 :  pulserObjects->Add(pulserQmean);
     939             :  
     940             : 
     941             : 
     942             :  UInt_t result=0;
     943             : 
     944           0 :  Int_t nSectors = fROC->GetNSectors();
     945           0 :  TVectorD foundTmean(nSectors);
     946           0 :  foundTmean=0;
     947           0 :  TVectorD foundTrms(nSectors);
     948           0 :  foundTrms=0;
     949           0 :  TVectorD foundQmean(nSectors);
     950           0 :  foundQmean=0;
     951             : 
     952             : 
     953           0 :  TList* list = GetFileSources(sourceFXS,"pulser");
     954             :  
     955           0 :  if (list && list->GetEntries()>0) {
     956             : 
     957             : //  loop through all files from LDCs
     958             : 
     959             :     Bool_t changed=false;
     960             :     UInt_t index = 0;
     961           0 :     while (list->At(index)!=NULL) {
     962           0 :      TObjString* fileNameEntry = (TObjString*) list->At(index);
     963           0 :      if (fileNameEntry!=NULL) {
     964           0 :         TString fileName = GetFile(sourceFXS, "pulser",
     965           0 :                                          fileNameEntry->GetString().Data());
     966           0 :         TFile *f = TFile::Open(fileName);
     967           0 :         if (!f) {
     968           0 :           Log ("Error opening pulser file.");
     969             :           result =2;
     970           0 :           break;
     971             :         }
     972           0 :         AliTPCCalibPulser *calPulser;
     973           0 :         f->GetObject("tpcCalibPulser",calPulser);
     974           0 :         if ( !calPulser ) {
     975           0 :           Log ("No pulser calibration object in file.");
     976             :           result = 2;
     977           0 :           break;
     978             :         }
     979             : 
     980             :         //  replace entries for the sectors available in the present file
     981             : 
     982             :         changed=true;
     983           0 :         for (Int_t sector=0; sector<nSectors; sector++) {
     984           0 :            AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
     985           0 :            if ( rocTmean ) {
     986           0 :                AliTPCCalROC* roc=pulserTmean->GetCalROC(sector);
     987           0 :                roc->Add(rocTmean,1);
     988           0 :                foundTmean[sector]++;
     989           0 :            }
     990           0 :            AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
     991           0 :            if ( rocTrms ) {
     992           0 :                AliTPCCalROC* roc=pulserTrms->GetCalROC(sector);
     993           0 :                roc->Add(rocTrms,1);
     994           0 :                foundTrms[sector]++;
     995           0 :            }
     996           0 :            AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
     997           0 :            if ( rocQmean ) {
     998           0 :                AliTPCCalROC* roc=pulserQmean->GetCalROC(sector);
     999           0 :                roc->Add(rocQmean,1);
    1000           0 :                foundQmean[sector]++;
    1001           0 :            }
    1002             :         }
    1003           0 :        delete calPulser;
    1004           0 :        f->Close();
    1005           0 :       }
    1006           0 :      ++index;
    1007           0 :     }  // while(list)
    1008             : 
    1009             : 
    1010             : 
    1011             : 
    1012           0 : if (pulserObjectsOCDB) {
    1013           0 :   AliTPCCalPad* pulserTmeanOCDB = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserTmean");
    1014           0 :   AliTPCCalPad* pulserTrmsOCDB  = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserTrms");
    1015           0 :   AliTPCCalPad* pulserQmeanOCDB = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserQmean");
    1016             :  
    1017             : //
    1018             : //  Check if calibration is complete -- otherwise take from old OCDB entry
    1019             : 
    1020             : // inner sectors
    1021           0 :     for (Int_t sector=0; sector<nSectors/2; sector++) {
    1022           0 :        if (foundTmean[sector] < 1 ) {
    1023           0 :          if (pulserTmeanOCDB) {
    1024           0 :           AliTPCCalROC* rocOCDB = pulserTmeanOCDB->GetCalROC(sector);
    1025           0 :           if ( rocOCDB ) pulserTmean->SetCalROC(rocOCDB,sector);
    1026           0 :          }
    1027             :        }
    1028           0 :        if (foundTrms[sector] < 1 ) {
    1029           0 :          if (pulserTrmsOCDB) {
    1030           0 :           AliTPCCalROC* rocOCDB = pulserTrmsOCDB->GetCalROC(sector);
    1031           0 :           if ( rocOCDB ) pulserTrms->SetCalROC(rocOCDB,sector);
    1032           0 :          }
    1033             :        }
    1034           0 :        if (foundQmean[sector] < 1 ) {
    1035           0 :          if (pulserQmeanOCDB) {
    1036           0 :           AliTPCCalROC* rocOCDB = pulserQmeanOCDB->GetCalROC(sector);
    1037           0 :           if ( rocOCDB ) pulserQmean->SetCalROC(rocOCDB,sector);
    1038           0 :          }
    1039             :        }
    1040             :     }
    1041             :   
    1042             : // outer sectors -- two updates needed
    1043             : 
    1044           0 :     for (Int_t sector=0; sector<nSectors/2; sector++) {
    1045           0 :        if (foundTmean[sector] < 2 ) {
    1046           0 :          if (pulserTmeanOCDB) {
    1047           0 :           AliTPCCalROC* rocOCDB = pulserTmeanOCDB->GetCalROC(sector);
    1048           0 :           if ( rocOCDB ) pulserTmean->SetCalROC(rocOCDB,sector);
    1049           0 :          }
    1050             :        }
    1051           0 :        if (foundTrms[sector] < 2 ) {
    1052           0 :          if (pulserTrmsOCDB) {
    1053           0 :           AliTPCCalROC* rocOCDB = pulserTrmsOCDB->GetCalROC(sector);
    1054           0 :           if ( rocOCDB ) pulserTrms->SetCalROC(rocOCDB,sector);
    1055           0 :          }
    1056             :        }
    1057           0 :        if (foundQmean[sector] < 2 ) {
    1058           0 :          if (pulserQmeanOCDB) {
    1059           0 :           AliTPCCalROC* rocOCDB = pulserQmeanOCDB->GetCalROC(sector);
    1060           0 :           if ( rocOCDB ) pulserQmean->SetCalROC(rocOCDB,sector);
    1061           0 :          }
    1062             :        }
    1063             : 
    1064             :     }
    1065           0 : }
    1066             : 
    1067             : //
    1068             : //  Store updated pedestal entry to OCDB
    1069             : //
    1070           0 :     if (changed) {
    1071           0 :      AliCDBMetaData metaData;
    1072           0 :      metaData.SetBeamPeriod(0);
    1073           0 :      metaData.SetResponsible("Haavard Helstrup");
    1074           0 :      metaData.SetAliRootVersion(ALIROOT_VERSION);
    1075           0 :      metaData.SetComment("Preprocessor AliTPC data base entries.");
    1076             : 
    1077           0 :      Bool_t storeOK = Store("Calib", "Pulser", pulserObjects, &metaData, 0, kTRUE ^ fForceSingleRun);
    1078           0 :      if ( !storeOK ) ++result;
    1079           0 :     }  
    1080           0 :   } else {
    1081           0 :     Log ("Error: no entries in pulser file list!");
    1082             :     result = 1;
    1083             :   }
    1084           0 :   pulserObjects->Delete();
    1085           0 :   delete pulserObjects;
    1086           0 :   if (pulserObjectsOCDB) {
    1087           0 :     pulserObjectsOCDB->Delete();
    1088             :   }
    1089           0 :   delete pulserObjectsOCDB;
    1090             : 
    1091             :   return result;
    1092           0 : }
    1093             : 
    1094             : //______________________________________________________________________________________________
    1095             : 
    1096             : 
    1097             : UInt_t AliTPCPreprocessor::ExtractRaw(Int_t sourceFXS)
    1098             : {
    1099             :  //
    1100             :  //  Read Raw calibration file from file exchage server
    1101             :  //
    1102             :  
    1103             :  UInt_t result=0;
    1104           0 :  TObjArray* rawArray = new TObjArray;
    1105           0 :  rawArray->SetOwner(kTRUE);
    1106             : 
    1107           0 :  TList* list = GetFileSources(sourceFXS,"tpcCalibRaw");
    1108             :  
    1109           0 :  if (list && list->GetEntries()>0) {
    1110             : 
    1111             : //  loop through all files
    1112             : 
    1113             :     UInt_t index = 0;
    1114           0 :     while (list->At(index)!=NULL) {
    1115           0 :      TObjString* fileNameEntry = (TObjString*) list->At(index);
    1116           0 :      if (fileNameEntry!=NULL) {
    1117           0 :         TString fileName = GetFile(sourceFXS, "tpcCalibRaw",
    1118           0 :                                          fileNameEntry->GetString().Data());
    1119           0 :         TFile *f = TFile::Open(fileName);
    1120           0 :         if (!f) {
    1121           0 :           Log ("Error opening raw file.");
    1122             :           result =2;
    1123           0 :           break;
    1124             :         }
    1125           0 :         AliTPCCalibRaw *calRaw;
    1126           0 :         f->GetObject("tpcCalibRaw",calRaw);
    1127           0 :         if ( !calRaw ) {
    1128           0 :           Log ("No raw calibration object in file.");
    1129             :           result = 2;
    1130           0 :           break;
    1131             :         }
    1132           0 :        rawArray->Add(calRaw);
    1133           0 :        f->Close();
    1134           0 :       }
    1135           0 :      ++index;
    1136           0 :     }  // while(list)
    1137             : //
    1138             : //  Store updated pedestal entry to OCDB
    1139             : //
    1140           0 :      AliCDBMetaData metaData;
    1141           0 :      metaData.SetBeamPeriod(0);
    1142           0 :      metaData.SetResponsible("Haavard Helstrup");
    1143           0 :      metaData.SetAliRootVersion(ALIROOT_VERSION);
    1144           0 :      metaData.SetComment("Preprocessor AliTPC data base entries.");
    1145             : 
    1146           0 :      Bool_t storeOK = Store("Calib", "Raw", rawArray, &metaData, 0, kTRUE ^ fForceSingleRun);
    1147           0 :      if ( !storeOK ) ++result;
    1148           0 :   } else {
    1149           0 :     Log ("Error: no entries in raw file list!");
    1150             :     result = 1;
    1151             :   }
    1152             :   
    1153           0 :   rawArray->Delete();
    1154           0 :   delete rawArray;
    1155             : 
    1156           0 :   return result;
    1157           0 : }
    1158             : //______________________________________________________________________________________________
    1159             : 
    1160             : UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
    1161             : {
    1162             :  //
    1163             :  //  Read Central Electrode file from file exchage server
    1164             :  //
    1165             :  //
    1166             :   AliTPCCalPad *ceTmean=0;
    1167             :   AliTPCCalPad *ceTrms=0;
    1168             :   AliTPCCalPad *ceQmean=0;
    1169             :   TObjArray    *rocTtime=0;
    1170             :   TObjArray    *rocQtime=0;
    1171             :   
    1172           0 :   TObjArray    *ceObjects= new TObjArray;
    1173           0 :   ceObjects->SetOwner(kTRUE);
    1174             :   
    1175           0 :   Int_t nSectors = fROC->GetNSectors();
    1176             :   
    1177           0 :   ceTmean = new AliTPCCalPad("CETmean","CETmean");
    1178           0 :   ceObjects->Add(ceTmean);
    1179             :   
    1180           0 :   ceTrms = new AliTPCCalPad("CETrms","CETrms");
    1181           0 :   ceObjects->Add(ceTrms);
    1182             :   
    1183           0 :   ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
    1184           0 :   ceObjects->Add(ceQmean);
    1185             :   
    1186           0 :   rocTtime = new TObjArray(nSectors+2);   // also make room for A and C side average
    1187           0 :   rocTtime->SetName("rocTtime");
    1188           0 :   ceObjects->Add(rocTtime);
    1189           0 :   rocTtime->SetOwner(kTRUE);
    1190             :   
    1191           0 :   rocQtime = new TObjArray(nSectors);
    1192           0 :   rocQtime->SetName("rocQtime");
    1193           0 :   ceObjects->Add(rocQtime);
    1194           0 :   rocQtime->SetOwner(kTRUE);  
    1195             : 
    1196             :   //=== new part
    1197           0 :   TObjArray *arrFitGraphs=new TObjArray;
    1198           0 :   arrFitGraphs->SetName("ceFitsDrift");
    1199           0 :   ceObjects->Add(arrFitGraphs);
    1200           0 :   arrFitGraphs->SetOwner(kTRUE);
    1201             :   
    1202             : // Temperature maps 
    1203             :   
    1204           0 :   if (fTemp) {
    1205           0 :     AliTPCSensorTempArray *tempMap = new AliTPCSensorTempArray(*fTemp);
    1206           0 :     tempMap->SetNameTitle("TempMap","TempMap");
    1207           0 :     ceObjects->Add(tempMap);
    1208           0 :   }
    1209             :   
    1210             : // Pressure maps
    1211             :   
    1212           0 :   if (fPressure) {
    1213             :     AliDCSSensor *sensor=0, *sensorCopy=0;
    1214           0 :     for (Int_t isensor=0; isensor<kNumPressureSensors; ++isensor ) {
    1215           0 :       sensor = fPressure->GetSensor(kPressureSensorNames[isensor]);
    1216           0 :       if (sensor) {
    1217           0 :         sensorCopy = new AliDCSSensor(*sensor);
    1218           0 :         sensorCopy->SetNameTitle(kPressureSensorNames[isensor],kPressureSensorNames[isensor]);
    1219           0 :         ceObjects->Add(sensorCopy);
    1220           0 :       }
    1221             :     }
    1222           0 :   }
    1223             :   
    1224             :   UInt_t result=0;
    1225             :   
    1226           0 :   TList* list = GetFileSources(sourceFXS,"CE");
    1227             :   
    1228           0 :   if (list && list->GetEntries()>0) {
    1229             :     
    1230             : //  loop through all files from LDCs
    1231             :     
    1232             :     UInt_t index = 0;
    1233           0 :     while (list->At(index)!=NULL) {
    1234           0 :       TObjString* fileNameEntry = (TObjString*) list->At(index);
    1235           0 :       if (fileNameEntry!=NULL) {
    1236           0 :         TString fileName = GetFile(sourceFXS, "CE",
    1237           0 :                                    fileNameEntry->GetString().Data());
    1238           0 :         AliTPCCalibCE *calCE=AliTPCCalibCE::ReadFromFile(fileName.Data());        
    1239             :         
    1240           0 :         if (!calCE) {
    1241           0 :           Log ("No valid calibCE object.");
    1242             :           result=2;
    1243           0 :           break;
    1244             :         }
    1245             :         //  replace entries for the sectors available in the present file
    1246             :         
    1247           0 :         for (Int_t sector=0; sector<nSectors; sector++) {
    1248           0 :           AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
    1249           0 :           if ( rocTmean )  ceTmean->SetCalROC(rocTmean,sector);
    1250           0 :           AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
    1251           0 :           if ( rocTrms )  ceTrms->SetCalROC(rocTrms,sector);
    1252           0 :           AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
    1253           0 :           if ( rocQmean )  ceQmean->SetCalROC(rocQmean,sector);
    1254           0 :           TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
    1255           0 :           if ( grT ) rocTtime->AddAt(grT,sector);
    1256           0 :           TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
    1257           0 :           if ( grQ ) rocQtime->AddAt(grQ,sector);
    1258             :         }
    1259             :         
    1260           0 :         TGraph *grT=calCE->MakeGraphTimeCE(-1,0,2); // A side average
    1261           0 :         if ( grT ) {
    1262           0 :           rocTtime->AddAt(grT,nSectors);
    1263             :         } else {
    1264             :           result=10;
    1265             :         }
    1266           0 :         grT=calCE->MakeGraphTimeCE(-2,0,2); // C side average
    1267           0 :         if ( grT ) {
    1268           0 :           rocTtime->AddAt(grT,nSectors+1);
    1269             :         } else {
    1270             :           result=10;
    1271             :         }
    1272             : 
    1273             :     //    calCE->Delete();
    1274           0 :         delete calCE;
    1275           0 :       }
    1276           0 :       ++index;
    1277           0 :     }  // while(list)
    1278             : //
    1279             : //   Check number of calibrated sectors per side
    1280             : // 
    1281             :     Int_t aside=0, cside=0;
    1282           0 :     for (Int_t ind=0; ind<nSectors/4; ind++ ) {
    1283           0 :         TGraph *grT=(TGraph*)rocTtime->At(ind);
    1284           0 :         if (grT) aside++;
    1285           0 :         grT=(TGraph*)rocTtime->At(ind+nSectors/2);
    1286           0 :         if (grT) aside++;
    1287           0 :         grT=(TGraph*)rocTtime->At(ind+nSectors/4);
    1288           0 :         if (grT) cside++;
    1289           0 :         grT=(TGraph*)rocTtime->At(ind+3*nSectors/4);
    1290           0 :         if (grT) cside++;
    1291             :      }
    1292           0 :      if ( (aside<kMinCESectors) && (cside<kMinCESectors) ) {
    1293           0 :         Log (Form("ExtractCE: Too few fitted sectors: Aside =%d, Cside=%d\n",
    1294             :              aside, cside)) ;
    1295             :         result=10;
    1296           0 :      }
    1297             : 
    1298             :     //
    1299             :     //=== New CE part
    1300             :     //    if it is validated this part needs to be modified again
    1301             :     //    currently its only processed if there is a valid standard CE object
    1302             :     //
    1303           0 :     list = GetFileSources(sourceFXS,"CEnew");
    1304             :     
    1305           0 :     if (result==0 && list && list->GetEntries()>0) {
    1306             :       
    1307             : //  loop through all files from LDCs
    1308             :       
    1309             :       UInt_t index2 = 0;
    1310           0 :       while (list->At(index2)!=NULL) {
    1311           0 :         TObjString* fileNameEntry = (TObjString*) list->At(index2);
    1312           0 :         if (fileNameEntry!=NULL) {
    1313           0 :           TString fileName = GetFile(sourceFXS, "CEnew",
    1314           0 :                                      fileNameEntry->GetString().Data());
    1315           0 :           AliTPCCalibCE *calCE=AliTPCCalibCE::ReadFromFile(fileName.Data());        
    1316             :           
    1317           0 :           if (!calCE) {
    1318           0 :             Log ("No valid new calibCE object.");
    1319             : //             result=2;
    1320           0 :             break;
    1321             :           }
    1322             : 
    1323           0 :           TIter nextObj(calCE->GetArrFitGraphs());
    1324             :           TObject *obj=0x0;
    1325           0 :           while ( (obj=nextObj()) ){
    1326           0 :             arrFitGraphs->Add(obj->Clone());
    1327             :           }
    1328             : //          calCE->Delete();
    1329           0 :           delete calCE;
    1330           0 :         }
    1331           0 :         ++index2;
    1332           0 :       }
    1333           0 :     }
    1334             :     
    1335             : //
    1336             : //  Store updated pedestal entry to OCDB
    1337             : //
    1338           0 :     AliCDBMetaData metaData;
    1339           0 :     metaData.SetBeamPeriod(0);
    1340           0 :     metaData.SetResponsible("Haavard Helstrup");
    1341           0 :     metaData.SetAliRootVersion(ALIROOT_VERSION);
    1342           0 :     metaData.SetComment("Preprocessor AliTPC data base entries.");
    1343             :     
    1344           0 :     if ( result == 0 ) {
    1345           0 :       Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE ^ fForceSingleRun);
    1346           0 :       if ( !storeOK ) ++result;
    1347           0 :     } else {
    1348           0 :       Log ("Warning: Average time graphs not available - no OCDB entry written");
    1349             :     }
    1350           0 :   } else {
    1351           0 :     Log ("Error: no CE entries available from FXS!");
    1352             :     result = 1;
    1353             :   }
    1354             :   
    1355           0 :   ceObjects->Delete();
    1356           0 :   delete ceObjects;
    1357             :   
    1358           0 :   return result;
    1359           0 : }
    1360             : //______________________________________________________________________________________________
    1361             : 
    1362             : UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
    1363             : {
    1364             :  //
    1365             :  //  Read Quality Assurance file from file exchage server
    1366             :  //
    1367             :  
    1368             :  UInt_t result=0;
    1369             : 
    1370           0 :  TList* list = GetFileSources(sourceFXS,"QA");
    1371             :  
    1372           0 :  if (list && list->GetEntries()>0) {
    1373             : 
    1374             : //  only one QA object should be available!
    1375             : 
    1376           0 :     AliTPCdataQA *calQA;
    1377             : 
    1378           0 :     UInt_t nentries = list->GetEntries();  
    1379             :     UInt_t index=0;
    1380           0 :     if ( nentries > 1) Log ( "More than one QA entry. First one processed");      
    1381           0 :     TObjString* fileNameEntry = (TObjString*) list->At(index);
    1382           0 :     if (fileNameEntry!=NULL) {
    1383           0 :         TString fileName = GetFile(sourceFXS, "QA",
    1384           0 :                                          fileNameEntry->GetString().Data());
    1385           0 :         TFile *f = TFile::Open(fileName);
    1386           0 :         if (!f) {
    1387           0 :           Log ("Error opening QA file.");
    1388             :           result =2;          
    1389           0 :         } else {
    1390           0 :           f->GetObject("tpcCalibQA",calQA);
    1391           0 :           if ( calQA ) {      
    1392             : //
    1393             : //  Store updated pedestal entry to OCDB
    1394             : //
    1395           0 :            AliCDBMetaData metaData;
    1396           0 :            metaData.SetBeamPeriod(0);
    1397           0 :            metaData.SetResponsible("Haavard Helstrup");
    1398           0 :            metaData.SetAliRootVersion(ALIROOT_VERSION);
    1399           0 :            metaData.SetComment("Preprocessor AliTPC data base entries.");
    1400             : 
    1401           0 :            Bool_t storeOK = Store("Calib", "QA", calQA, &metaData, 0, kFALSE);
    1402           0 :            if ( !storeOK ) ++result;
    1403             : 
    1404           0 :            delete calQA;
    1405           0 :           }
    1406             :         }
    1407           0 :     } else {
    1408           0 :     Log ("Error: no QA files on FXS!");
    1409             :     result = 2;
    1410             :     }
    1411           0 :   } else {
    1412           0 :     Log ("Error: no QA entries in FXS list!");
    1413             :     result = 1;
    1414             :   }
    1415           0 :   return result;
    1416           0 : }
    1417             : 
    1418             : //______________________________________________________________________________________________
    1419             : 
    1420             : 
    1421             : UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS, TMap* dcsMap)
    1422             : {
    1423             :  //
    1424             :  //  Read Altro configuration file from file exchage server
    1425             :  //  Keep original entry from OCDB in case no new pulser calibration is available
    1426             :  //
    1427             :  TObjArray    *altroObjects=0;
    1428             :  AliTPCCalPad *acqStart=0;
    1429             :  AliTPCCalPad *zsThr=0;
    1430             :  AliTPCCalPad *acqStop=0;
    1431             :  AliTPCCalPad *FPED=0;
    1432             :  AliTPCCalPad *masked=0;
    1433             :  AliTPCCalPad *k1=0, *k2=0, *k3=0;
    1434             :  AliTPCCalPad *l1=0, *l2=0, *l3=0;
    1435             :  TMap *mapRCUconfig=0;
    1436             : 
    1437           0 :  AliCDBEntry* entry = GetFromOCDB("Calib", "AltroConfig");
    1438           0 :  if (entry) altroObjects = (TObjArray*)entry->GetObject();
    1439           0 :  if ( altroObjects==NULL ) {
    1440           0 :      Log("AliTPCPreprocsessor: No previous TPC altro calibration entry available.\n");
    1441           0 :      altroObjects = new TObjArray;    
    1442           0 :  }
    1443           0 :  altroObjects->SetOwner(kTRUE);
    1444             : 
    1445           0 :  acqStart = (AliTPCCalPad*)altroObjects->FindObject("AcqStart");
    1446           0 :  if ( !acqStart ) {
    1447           0 :     acqStart = new AliTPCCalPad("AcqStart","AcqStart");
    1448           0 :     altroObjects->Add(acqStart);
    1449           0 :  }
    1450           0 :  zsThr = (AliTPCCalPad*)altroObjects->FindObject("ZsThr");
    1451           0 :  if ( !zsThr )  { 
    1452           0 :     zsThr = new AliTPCCalPad("ZsThr","ZsThr");
    1453           0 :     altroObjects->Add(zsThr);
    1454           0 :  }
    1455           0 :  FPED = (AliTPCCalPad*)altroObjects->FindObject("FPED");
    1456           0 :  if ( !FPED )  { 
    1457           0 :     FPED = new AliTPCCalPad("FPED","FPED");
    1458           0 :     altroObjects->Add(FPED);
    1459           0 :  }
    1460           0 :  acqStop = (AliTPCCalPad*)altroObjects->FindObject("AcqStop");
    1461           0 :  if ( !acqStop ) {
    1462           0 :     acqStop = new AliTPCCalPad("AcqStop","AcqStop");
    1463           0 :     altroObjects->Add(acqStop);
    1464           0 :  }
    1465           0 :  masked = (AliTPCCalPad*)altroObjects->FindObject("Masked");
    1466           0 :  if ( !masked )  { 
    1467           0 :     masked = new AliTPCCalPad("Masked","Masked");
    1468           0 :     altroObjects->Add(masked);
    1469           0 :  }
    1470           0 :  k1 = (AliTPCCalPad*)altroObjects->FindObject("K1");
    1471           0 :  if ( !k1 )  { 
    1472           0 :     k1 = new AliTPCCalPad("K1","K1");
    1473           0 :     altroObjects->Add(k1);
    1474           0 :  }
    1475           0 :  k2 = (AliTPCCalPad*)altroObjects->FindObject("K2");
    1476           0 :  if ( !k2 )  { 
    1477           0 :     k2 = new AliTPCCalPad("K2","K2");
    1478           0 :     altroObjects->Add(k2);
    1479           0 :  }
    1480           0 :  k3 = (AliTPCCalPad*)altroObjects->FindObject("K3");
    1481           0 :  if ( !k3 )  { 
    1482           0 :     k3 = new AliTPCCalPad("K3","K3");
    1483           0 :     altroObjects->Add(k3);
    1484           0 :  }
    1485           0 :  l1 = (AliTPCCalPad*)altroObjects->FindObject("L1");
    1486           0 :  if ( !l1 )  { 
    1487           0 :     l1 = new AliTPCCalPad("L1","L1");
    1488           0 :     altroObjects->Add(l1);
    1489           0 :  }
    1490           0 :  l2 = (AliTPCCalPad*)altroObjects->FindObject("L2");
    1491           0 :  if ( !l2 )  { 
    1492           0 :     l2 = new AliTPCCalPad("L2","L2");
    1493           0 :     altroObjects->Add(l2);
    1494           0 :  }
    1495           0 :  l3 = (AliTPCCalPad*)altroObjects->FindObject("L3");
    1496           0 :  if ( !l3 )  { 
    1497           0 :     l3 = new AliTPCCalPad("L3","L3");
    1498           0 :     altroObjects->Add(l3);
    1499           0 :  }
    1500           0 :  mapRCUconfig = (TMap*)altroObjects->FindObject("RCUconfig");
    1501           0 :  if (!mapRCUconfig) {
    1502           0 :     mapRCUconfig = new TMap();
    1503           0 :     mapRCUconfig->SetName("RCUconfig");
    1504           0 :     altroObjects->Add(mapRCUconfig);
    1505           0 :  }
    1506             : 
    1507             : 
    1508             :  UInt_t result=0;
    1509           0 :  TString idFXS[2]={"AltroConfigA","AltroConfigC"};
    1510             : 
    1511           0 :  Int_t nSectors = fROC->GetNSectors();
    1512             :  Bool_t changed=false;
    1513           0 :  if (altroObjects == 0 ) altroObjects = new TObjArray;
    1514           0 :  altroObjects->SetOwner(kTRUE);
    1515             : 
    1516             : // extract list of active DDLs
    1517             : 
    1518           0 :  if (dcsMap) {
    1519             :   Bool_t found; 
    1520           0 :   TString arrDDL(kNumDDL);
    1521           0 :   arrDDL.Append('x',kNumDDL);
    1522           0 :   for ( Int_t iDDL = 0; iDDL<kNumDDL; iDDL++ ) {
    1523           0 :     TString stringID = Form (kAmandaDDL.Data(),iDDL+kFirstDDL);
    1524           0 :     TPair *pair = (TPair*)dcsMap->FindObject(stringID.Data());
    1525             :     found = false;
    1526           0 :     if ( pair ) {
    1527           0 :         TObjArray *valueSet=(TObjArray*)pair->Value();
    1528           0 :         if ( valueSet) { 
    1529           0 :           AliDCSValue *val = (AliDCSValue*)valueSet->At(0);
    1530           0 :           if (val) { 
    1531           0 :               found = val->GetBool();
    1532           0 :               if (found){
    1533           0 :                arrDDL[iDDL] = '1';
    1534           0 :               } else { 
    1535           0 :                arrDDL[iDDL] = '0';
    1536             :               }
    1537             :           }    
    1538           0 :         }
    1539           0 :     } 
    1540           0 :   }
    1541           0 :   TObjString *ddlArray = new TObjString;
    1542           0 :   ddlArray->SetString(arrDDL);
    1543           0 :   TMap *activeDDL = new TMap;
    1544           0 :   activeDDL->SetName("DDLArray");
    1545           0 :   TObjString *key = new TObjString("DDLArray");
    1546           0 :   activeDDL->Add(key,ddlArray);
    1547           0 :   altroObjects->Add(activeDDL);
    1548             :   changed=true;
    1549           0 :  } else {
    1550           0 :    Log ("ExtractAltro: No DCS map available. Active DDL list cannot be obtained.");
    1551             :    result = 3;
    1552             :  }        
    1553             : 
    1554             : // extract Altro configuration files
    1555             : 
    1556           0 :  for ( Int_t id=0; id<2; id++) {
    1557           0 :    TList* list = GetFileSources(sourceFXS,idFXS[id].Data());
    1558             :  
    1559           0 :    if (list && list->GetEntries()>0) {
    1560             : 
    1561             : //  loop through all files from LDCs
    1562             : 
    1563             :     UInt_t index = 0;
    1564           0 :     while (list->At(index)!=NULL) {
    1565           0 :      TObjString* fileNameEntry = (TObjString*) list->At(index);
    1566           0 :      if (fileNameEntry!=NULL) {
    1567           0 :         TString fileName = GetFile(sourceFXS, idFXS[id].Data(),
    1568           0 :                                          fileNameEntry->GetString().Data());
    1569           0 :         TFile *f = TFile::Open(fileName);
    1570           0 :         if (!f) {
    1571             :           const int mess_length=40;
    1572           0 :           char message[mess_length];
    1573           0 :           snprintf(message,mess_length,"Error opening Altro configuration file, id = %d",id);
    1574           0 :           Log (message);
    1575             :           result =2;
    1576             :           break;
    1577           0 :         }
    1578           0 :         TObjArray *altroFXS;
    1579           0 :         f->GetObject("AltroConfig",altroFXS);
    1580           0 :         if ( !altroFXS ) {
    1581           0 :           Log ("No Altro configuration object in file.");
    1582             :           result = 2;
    1583           0 :           break;
    1584             :         }
    1585             : 
    1586             :         //  replace entries for the sectors available in the present file
    1587           0 :         AliTPCCalPad *acqStartFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStart");
    1588           0 :         AliTPCCalPad *zsThrFXS=(AliTPCCalPad*)altroFXS->FindObject("ZsThr");
    1589           0 :         AliTPCCalPad *acqStopFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStop");
    1590           0 :         AliTPCCalPad *FPEDFXS=(AliTPCCalPad*)altroFXS->FindObject("FPED");
    1591           0 :         AliTPCCalPad *maskedFXS=(AliTPCCalPad*)altroFXS->FindObject("Masked");
    1592           0 :         AliTPCCalPad *k1FXS=(AliTPCCalPad*)altroFXS->FindObject("K1");
    1593           0 :         AliTPCCalPad *k2FXS=(AliTPCCalPad*)altroFXS->FindObject("K2");
    1594           0 :         AliTPCCalPad *k3FXS=(AliTPCCalPad*)altroFXS->FindObject("K3");
    1595           0 :         AliTPCCalPad *l1FXS=(AliTPCCalPad*)altroFXS->FindObject("L1");
    1596           0 :         AliTPCCalPad *l2FXS=(AliTPCCalPad*)altroFXS->FindObject("L2");
    1597           0 :         AliTPCCalPad *l3FXS=(AliTPCCalPad*)altroFXS->FindObject("L3");
    1598           0 :         TMap *mapRCUconfigFXS = (TMap*)altroFXS->FindObject("RCUconfig");
    1599           0 :         TIterator *mapFXSiter = mapRCUconfigFXS->MakeIterator();
    1600             :         
    1601             :         changed=true;
    1602           0 :         for (Int_t sector=0; sector<nSectors; sector++) {
    1603             :             
    1604           0 :            if (acqStartFXS) {
    1605           0 :               AliTPCCalROC *rocAcqStart=acqStartFXS->GetCalROC(sector);
    1606           0 :               if ( rocAcqStart )  acqStart->SetCalROC(rocAcqStart,sector);
    1607           0 :            }
    1608           0 :            if (zsThrFXS ) {
    1609           0 :               AliTPCCalROC *rocZsThr=zsThrFXS->GetCalROC(sector);
    1610           0 :               if ( rocZsThr )  zsThr->SetCalROC(rocZsThr,sector);
    1611           0 :            }
    1612           0 :            if (acqStopFXS) {
    1613           0 :               AliTPCCalROC *rocAcqStop=acqStopFXS->GetCalROC(sector);
    1614           0 :               if ( rocAcqStop )  acqStop->SetCalROC(rocAcqStop,sector);
    1615           0 :            }
    1616           0 :            if (FPEDFXS ) {
    1617           0 :               AliTPCCalROC *rocFPED=FPEDFXS->GetCalROC(sector);
    1618           0 :               if ( rocFPED )  FPED->SetCalROC(rocFPED,sector);
    1619           0 :            }
    1620           0 :            if (maskedFXS) {
    1621           0 :               AliTPCCalROC *rocMasked=maskedFXS->GetCalROC(sector);
    1622           0 :               if ( rocMasked )  masked->SetCalROC(rocMasked,sector);
    1623           0 :            }
    1624           0 :            if (k1FXS) {
    1625           0 :               AliTPCCalROC *rocK1=k1FXS->GetCalROC(sector);
    1626           0 :               if ( rocK1 )  k1->SetCalROC(rocK1,sector);
    1627           0 :            }
    1628           0 :            if (k2FXS) {
    1629           0 :               AliTPCCalROC *rocK2=k2FXS->GetCalROC(sector);
    1630           0 :               if ( rocK2 )  k2->SetCalROC(rocK2,sector);
    1631           0 :            }
    1632           0 :            if (k3FXS) {
    1633           0 :               AliTPCCalROC *rocK3=k3FXS->GetCalROC(sector);
    1634           0 :               if ( rocK3 )  k3->SetCalROC(rocK3,sector);
    1635           0 :            }
    1636           0 :            if (l1FXS) {
    1637           0 :               AliTPCCalROC *rocL1=l1FXS->GetCalROC(sector);
    1638           0 :               if ( rocL1 )  l1->SetCalROC(rocL1,sector);
    1639           0 :            }
    1640           0 :            if (l2FXS) {
    1641           0 :               AliTPCCalROC *rocL2=l2FXS->GetCalROC(sector);
    1642           0 :               if ( rocL2 )  l2->SetCalROC(rocL2,sector);
    1643           0 :            }
    1644           0 :            if (l3FXS) {
    1645           0 :               AliTPCCalROC *rocL3=l3FXS->GetCalROC(sector);
    1646           0 :               if ( rocL3 )  l3->SetCalROC(rocL3,sector);
    1647           0 :            }
    1648             :          }
    1649           0 :          if (mapRCUconfigFXS) {
    1650           0 :           Int_t mapEntries = mapRCUconfigFXS->GetEntries();
    1651             :           TObjString* keyFXS;
    1652             :           TVectorF* vecFXS;
    1653             :           TVectorF* vec;              // nSectors = 72  (total number of inner/outer sectors)
    1654           0 :           for (Int_t i=0; i<mapEntries; ++i) {
    1655           0 :             keyFXS=(TObjString*)mapFXSiter->Next();
    1656           0 :             vecFXS=(TVectorF*)mapRCUconfigFXS->GetValue(keyFXS);
    1657           0 :             vec=(TVectorF*)mapRCUconfig->GetValue(keyFXS);
    1658           0 :             if (!vec) {
    1659           0 :               vec = new TVectorF(3*nSectors);
    1660           0 :               *vec = -1;
    1661           0 :               mapRCUconfig->Add(keyFXS,vec);
    1662             :             }
    1663           0 :             if (vec->GetNoElements() != 3*nSectors ) {
    1664           0 :               vec->ResizeTo(3*nSectors);
    1665             :             }
    1666           0 :             if (id==0) {                        // A side
    1667           0 :               vec->SetSub(0,vecFXS->GetSub(0,nSectors/2-1));
    1668           0 :               vec->SetSub(nSectors,vecFXS->GetSub(nSectors,2*nSectors-1));
    1669           0 :             } else {                             // C side
    1670           0 :               vec->SetSub(nSectors/2,vecFXS->GetSub(nSectors/2,nSectors-1));
    1671           0 :               vec->SetSub(2*nSectors,vecFXS->GetSub(2*nSectors,3*nSectors-1));
    1672             :             }
    1673             :           }
    1674           0 :         }
    1675           0 :        altroFXS->Delete();
    1676           0 :        delete altroFXS;
    1677           0 :        f->Close();
    1678           0 :       }
    1679           0 :      ++index;
    1680           0 :      }  // while(list)
    1681           0 :     } else {
    1682           0 :       Log ("Error: no entries in AltroConfig file list!");
    1683             :       result = 1;
    1684             :     }
    1685             : 
    1686             :    }   // for - id
    1687             : //
    1688             : //  Store updated pedestal entry to OCDB
    1689             : //
    1690           0 :     if (changed) {
    1691           0 :      AliCDBMetaData metaData;
    1692           0 :      metaData.SetBeamPeriod(0);
    1693           0 :      metaData.SetResponsible("Haavard Helstrup");
    1694           0 :      metaData.SetAliRootVersion(ALIROOT_VERSION);
    1695           0 :      metaData.SetComment("Preprocessor AliTPC data base entries.");
    1696             : 
    1697           0 :      Bool_t storeOK = Store("Calib", "AltroConfig", altroObjects, &metaData, 0, kFALSE);
    1698           0 :      if ( !storeOK ) ++result;
    1699           0 :     }  
    1700             :     
    1701           0 :   altroObjects->Delete();
    1702           0 :   delete altroObjects;
    1703             :   
    1704             :   return result;
    1705           0 : }

Generated by: LCOV version 1.11