]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALPreprocessor.cxx
#102990: Patch for compilation on Mavericks
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALPreprocessor.cxx
index 9cd6e9d6ee1ec9dbc73668221ea4a509b47ca7a0..93af03ca6a2a50b14a364bff64111619e63df7b0 100644 (file)
  **************************************************************************/
 
 /* $Id$ */
-/* History of cvs commits:
- *
- * $Log$
- * Revision 1.4  2007/01/24 16:57:14  gustavo
- * Calibratio file sources machines are now not hardcoded but retreived from shuttle
- *
- * Revision 1.3  2006/12/20 10:53:28  gustavo
- * Change const char * by TString, change AliInfos per AliPreprocessor::Log or AliDebug
- *
- * Revision 1.2  2006/12/12 17:16:09  gustavo
- * Detector name hardcoded in Preprocesor with new detector name notation (3 letters). New way to take reference histogram to avoid problems in case of low number of entries or no existing histogram. Change return 0 by return 1
- *
- * Revision 1.1  2006/12/07 16:32:16  gustavo
- * First shuttle code, online calibration histograms producer, EMCAL preprocessor
- * 
- *
-*/
+
 ///////////////////////////////////////////////////////////////////////////////
 // EMCAL Preprocessor class. It runs by Shuttle at the end of the run,
-// calculates calibration coefficients and dead/bad channels
-// to be posted in OCDB
+// calculates stuff to be posted in OCDB
 //
 // Author: Boris Polichtchouk, 4 October 2006
 // Adapted for EMCAL by Gustavo Conesa Balbastre, October 2006
+// Updated by David Silvermyr May 2008, based on TPC code
 ///////////////////////////////////////////////////////////////////////////////
 
 //Root
 #include "TFile.h"
-#include "TH1.h"
-#include "TMap.h"
-#include "TRandom.h"
-#include "TKey.h"
-#include "TList.h"
-#include "TString.h"
-#include "TObjString.h"
+#include "TTree.h"
+#include "TEnv.h"
+#include "TParameter.h"
+
+#include <TTimeStamp.h>
 
 //AliRoot
+#include "AliShuttleInterface.h"
 #include "AliEMCALPreprocessor.h"
 #include "AliLog.h"
+#include "AliDCSValue.h"
 #include "AliCDBMetaData.h"
-#include "AliEMCALCalibData.h"
+#include "AliEMCALTriggerTRUDCSConfig.h"
+#include "AliEMCALTriggerSTUDCSConfig.h"
+#include "AliEMCALTriggerDCSConfig.h"
+#include "AliCaloCalibPedestal.h"
+#include "AliCaloCalibSignal.h"
+#include "AliEMCALSensorTempArray.h"
 
-ClassImp(AliEMCALPreprocessor)
+const Int_t kValCutTemp = 100;               // discard temperatures > 100 degrees
+const Int_t kDiffCutTemp = 5;               // discard temperature differences > 5 degrees
+const TString kPedestalRunType = "PEDESTAL";  // pedestal run identifier
+const TString kPhysicsRunType = "PHYSICS";   // physics run identifier
+const TString kStandAloneRunType = "STANDALONE_BC"; // standalone run identifier
+const TString kAmandaTemp = "PT_%02d.Temperature"; // Amanda string for temperature entries
+//const Double_t kFitFraction = 0.7;                 // Fraction of DCS sensor fits required 
+const Double_t kFitFraction = -1.0;          // Don't require minimum number of fits during commissioning 
+
+const TString kMetaResponsible = "David Silvermyr";
+//legacy comments and return codes from TPC
+const TString kMetaComment = "Preprocessor AliEMCAL data base entries.";
+const int kReturnCodeNoInfo = 9;
+const int kReturnCodeNoObject = 2;
+const int kReturnCodeNoEntries = 1;
 
+const int kNTRU = 32; // From 2012; 10 + 2/3 SuperModules (SM) * 3 TRU per SM
+
+ClassImp(AliEMCALPreprocessor)
+  
 //_______________________________________________________________________________________
 AliEMCALPreprocessor::AliEMCALPreprocessor() :
-AliPreprocessor("EMC",0)
+  AliPreprocessor("EMC",0),
+  fConfEnv(0), 
+  fTemp(0), 
+  fConfigOK(kTRUE)
 {
   //default constructor
 }
 
 //_______________________________________________________________________________________
 AliEMCALPreprocessor::AliEMCALPreprocessor(AliShuttleInterface* shuttle):
-AliPreprocessor("EMC",shuttle)
+  AliPreprocessor("EMC",shuttle),
+  fConfEnv(0), 
+  fTemp(0), 
+  fConfigOK(kTRUE)
 {
-  // Constructor
+  // Constructor AddRunType(kPedestalRunType);
+  
+  // define run types to be processed
+  AddRunType(kPedestalRunType);
+  AddRunType(kPhysicsRunType);
 }
 
-//_______________________________________________________________________________________
-UInt_t AliEMCALPreprocessor::Process(TMap* /*valueSet*/)
+//______________________________________________________________________________________________
+AliEMCALPreprocessor::AliEMCALPreprocessor(const AliEMCALPreprocessor&  ) :
+  AliPreprocessor("EMCAL",0),
+  fConfEnv(0), fTemp(0), fConfigOK(kTRUE)
+{
+  Fatal("AliEMCALPreprocessor", "copy constructor not implemented");
+}
+
+// assignment operator; use copy ctor to make life easy.
+//______________________________________________________________________________________________
+AliEMCALPreprocessor& AliEMCALPreprocessor::operator = (const AliEMCALPreprocessor &source ) 
+{
+  // assignment operator; use copy ctor
+  if (&source == this) return *this;
+  
+  new (this) AliEMCALPreprocessor(source);
+  return *this;
+}
+
+//____________________________________________________________________________
+AliEMCALPreprocessor::~AliEMCALPreprocessor()
 {
-  // process data retrieved by the Shuttle
+  // destructor
+  if (fTemp) delete fTemp;
+}
+
+//______________________________________________________________________________________________
+void AliEMCALPreprocessor::Initialize(Int_t run, UInt_t startTime,
+                                     UInt_t endTime)
+{
+  // Creates AliTestDataDCS object -- start maps half an hour beforre actual run start
+  UInt_t startTimeLocal = startTime-1800;
+  AliPreprocessor::Initialize(run, startTimeLocal, endTime);
   
-  // The fileName with the histograms which have been produced by
-  // AliEMCALCalibHistoProducer.
-  // It is a responsibility of the SHUTTLE framework to form the fileName
+  AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
+              TTimeStamp((time_t)startTime,0).AsString(),
+              TTimeStamp((time_t)endTime,0).AsString()));
   
-  AliEMCALCalibData calibData;
+  // Preprocessor configuration
+  AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
+  if (entry) fConfEnv = (TEnv*) entry->GetObject();
+  if ( fConfEnv==0 ) {
+    Log("AliEMCALPreprocessor: Preprocessor Config OCDB entry missing.\n");
+    fConfigOK = kFALSE;
+    return;
+  }
   
+  // Temperature sensors
+  TTree *confTree = 0;
   
-  TList* list = GetFileSources(kDAQ, "AMPLITUDES");
-  if (list)
-    {
-      AliInfo("The following sources produced files with the id AMPLITUDES");
-      list->Print();
-      TIter iter(list);
-      TObjString *source;
-      while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
-       //TObjString * str = dynamic_cast<TObjString*> (list->At(0));//Only one source?
-       AliInfo(Form("found source %s", source->String().Data()));
-       
-       TString fileName = GetFile(kDAQ, "AMPLITUDES", source->GetName());
-       
-       //TString  fileName = GetFile(kDAQ, "AMPLITUDES", "GDC");
-       Log(Form("Got filename: %s",fileName.Data()));
+  TString tempConf = fConfEnv->GetValue("Temperature","ON");
+  tempConf.ToUpper();
+  if (tempConf != "OFF" ) {
+    entry = GetFromOCDB("Config", "Temperature");
+    if (entry) confTree = (TTree*) entry->GetObject();
+    if ( confTree==0 ) {
+      Log("AliEMCALPreprocessor: Temperature Config OCDB entry missing.\n");
+      fConfigOK = kFALSE;
+      return;
+    }
+    fTemp = new AliEMCALSensorTempArray(startTimeLocal, fEndTime, confTree, kAmandaTemp);
+    fTemp->SetValCut(kValCutTemp);
+    fTemp->SetDiffCut(kDiffCutTemp);
+  }
+  
+  return;
+}
+
+//______________________________________________________________________________________________
+UInt_t AliEMCALPreprocessor::Process(TMap* dcsAliasMap)
+{
+  // Fills data into EMCAL calibrations objects
+  // Amanda servers provide information directly through dcsAliasMap
+  
+  if (!fConfigOK) return kReturnCodeNoInfo;
+  UInt_t result = 0;
+  TObjArray *resultArray = new TObjArray();
+  TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
+  errorHandling.ToUpper();
+  TObject * status;
+  
+  UInt_t dcsResult=0;
+  if (errorHandling == "OFF" ) {
+    if (!dcsAliasMap) dcsResult = kReturnCodeNoEntries;
+    else if (dcsAliasMap->GetEntries() == 0 ) dcsResult = kReturnCodeNoEntries;  
+    status = new TParameter<int>("dcsResult",dcsResult);
+    resultArray->Add(status);
+  } 
+  else {
+    if (!dcsAliasMap) return kReturnCodeNoInfo;
+    else if (dcsAliasMap->GetEntries() == 0 ) return kReturnCodeNoInfo;
+  }
+  
+    
+  TString runType = GetRunType();
+  
+  // Temperature sensors are processed by AliEMCALCalTemp
+  TString tempConf = fConfEnv->GetValue("Temperature","ON");
+  tempConf.ToUpper();
+  if (tempConf != "OFF" && dcsAliasMap ) {
+    UInt_t tempResult = MapTemperature(dcsAliasMap);
+    result=tempResult;
+    status = new TParameter<int>("tempResult",tempResult);
+    resultArray->Add(status);
+  }
+  // Trigger configuration processing: only for Physics runs
+  TString triggerConf = fConfEnv->GetValue("Trigger","ON");
+  triggerConf.ToUpper();
+  if( runType == kPhysicsRunType ) {
+    if (triggerConf != "OFF" && dcsAliasMap ) {
+      UInt_t triggerResult = MapTriggerConfig(dcsAliasMap);
+      result+=triggerResult;
+      status = new TParameter<int>("triggerResult",triggerResult);
+      resultArray->Add(status);
+    }
+  }
+  
+  // Other calibration information will be retrieved through FXS files
+  //  examples:
+  //    TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
+  //    const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
+  //
+  //    TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
+  //    const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
+  
+  // PEDESTAL ENTRIES:
+  
+  if ( runType == kPedestalRunType ) {
+    Int_t numSources = 1;
+    Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ, AliShuttleInterface::kHLT} ;
+    TString source = fConfEnv->GetValue("Pedestal","DAQ");
+    source.ToUpper();
+    if (source != "OFF" ) { 
+      if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
+      if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
+      if (source == "HLTDAQ" ) {
+        numSources=2;
+        pedestalSource[0] = AliShuttleInterface::kHLT;
+        pedestalSource[1] = AliShuttleInterface::kDAQ;
+      }
+      if (source == "DAQHLT" ) numSources=2;
+      UInt_t pedestalResult=0;
+      for (Int_t i=0; i<numSources; i++ ) {    
+        pedestalResult = ExtractPedestals(pedestalSource[i]);
+        if ( pedestalResult == 0 ) break;
+      }
+      result += pedestalResult;
+      status = new TParameter<int>("pedestalResult",pedestalResult);
+      resultArray->Add(status);
+    }
+  }
+  
+  // SIGNAL/LED ENTRIES:
+  if( runType == kPhysicsRunType ) {
+    Int_t numSources = 1;
+    Int_t signalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
+    TString source = fConfEnv->GetValue("Signal","DAQ");
+    source.ToUpper();
+    if ( source != "OFF") { 
+      if ( source == "HLT") signalSource[0] = AliShuttleInterface::kHLT;
+      if (!GetHLTStatus()) signalSource[0] = AliShuttleInterface::kDAQ;
+      if (source == "HLTDAQ" ) {
+        numSources=2;
+        signalSource[0] = AliShuttleInterface::kHLT;
+        signalSource[1] = AliShuttleInterface::kDAQ;
+      }
+      if (source == "DAQHLT" ) numSources=2;
+      UInt_t signalResult=0;
+      for (Int_t i=0; i<numSources; i++ ) {    
+        signalResult = ExtractSignal(signalSource[i]);
+        if ( signalResult == 0 ) break;
+      }
+      result += signalResult;
+      status = new TParameter<int>("signalResult",signalResult);
+      resultArray->Add(status);
+    }
+  }
+  
+  
+  // overall status at the end
+  if (errorHandling == "OFF" ) {
+    AliCDBMetaData metaData;
+    metaData.SetBeamPeriod(0);
+    metaData.SetResponsible(kMetaResponsible);
+    metaData.SetComment("Preprocessor AliEMCAL status.");
+    Bool_t storeOK = Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
+    resultArray->Delete();
+    result = 0;
+    if ( !storeOK )  result=1;
+    return result;
+  } 
+  else { 
+    return result;
+  }
+  
+}
+//______________________________________________________________________________________________
+UInt_t AliEMCALPreprocessor::MapTemperature(TMap* dcsAliasMap)
+{ // extract DCS temperature maps. Perform fits to save space
+  UInt_t result=0;
+
+  TMap *map = fTemp->ExtractDCS(dcsAliasMap);
+  if (map) {
+    fTemp->MakeSplineFit(map);
+    Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors(); 
+    if (fitFraction > kFitFraction ) {
+      AliInfo(Form("Temperature values extracted, fits performed.\n"));
+    } 
+    else { 
+      Log ("Too few temperature maps fitted. \n");
+      result = kReturnCodeNoInfo;
+    }
+  } 
+  else {
+    Log("No temperature map extracted. \n");
+    result = kReturnCodeNoInfo;
+  }
+  delete map;
+  // Now store the final CDB file
+  
+  if ( result == 0 ) { // some info was found
+    AliCDBMetaData metaData;
+    metaData.SetBeamPeriod(0);
+    metaData.SetResponsible(kMetaResponsible);
+    metaData.SetComment(kMetaComment);
+    
+    Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
+    if ( !storeOK )  result=1;
+    AliInfo(Form("Temperature info stored. result %d\n", result));
+  }
+  
+  return result;
+}
+
+//______________________________________________________________________________________________
+UInt_t AliEMCALPreprocessor::MapTriggerConfig(TMap* dcsAliasMap)
+{ // extract DCS trigger info
        
-       TFile f(fileName);
        
-       if(!f.IsOpen()) {
-         Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
-         return 0;
-       }
+       AliInfo("Print DCS alias map content");
+       dcsAliasMap->Print();
        
+  AliInfo(Form("Get TRU info from DCS DPs.\n"));
+  Int_t i, iTRU;
+  const Int_t bufsize = 1000;
+  char buf[bufsize];
+
+  AliDCSValue *dcsVal;
+  TObjArray *arrL0ALGSEL, *arrPEAKFINDER, *arrGLOBALTHRESH, *arrCOSMTHRESH;
+  TObjArray *arrMASK[6];
        
-       const Int_t nMod=12; // 1:5 modules
-       const Int_t nCol=48; //1:56 columns in each module
-       Int_t nRow=24; //1:64 rows in each module
-       const Int_t nRowHalfSM = 12; //Supermodules 11 and 12 are half supermodules
+  TObjArray *arrSTUG[3][2], *arrSTUJ[3][2];
+  TObjArray *arrSTUD, *arrSTUR, *arrSTUF;
        
-       Double_t coeff;
-       char hnam[80];
-       TH1F* histo=0;
+  // overall object to hold STU and DCS config info
+  // DS comment: for now only holds TRU info, i.e. only partially filled
+  // (STU info only in raw data header; unfortunately not also picked up via DCS DPs)
+  AliEMCALTriggerDCSConfig *trigConfig = new AliEMCALTriggerDCSConfig();
+  // allocate space for TRU objects
+  TClonesArray *truArr = new TClonesArray("AliEMCALTriggerTRUDCSConfig", kNTRU);
+  for( iTRU = 0; iTRU < kNTRU; iTRU++){
+    new((*truArr)[iTRU]) AliEMCALTriggerTRUDCSConfig();
+  }
+  trigConfig->SetTRUArr(truArr);
+
+  AliEMCALTriggerSTUDCSConfig *stuConfig = new AliEMCALTriggerSTUDCSConfig();
        
+  // loop through all TRUs
+  bool debug = true; // debug flag for AliInfo printouts for each TRU
+  for( iTRU = 0; iTRU < kNTRU; iTRU++){
+    if (debug) AliInfo( Form("iTRU %d \n", iTRU) );
+    // get the shuttled values
+    snprintf( buf, bufsize, "EMC_TRU%02d_L0ALGSEL", iTRU );
+    arrL0ALGSEL = (TObjArray*) dcsAliasMap->GetValue( buf );
+    snprintf( buf, bufsize, "EMC_TRU%02d_PEAKFINDER", iTRU );
+    arrPEAKFINDER = (TObjArray*) dcsAliasMap->GetValue( buf );
+    snprintf( buf, bufsize, "EMC_TRU%02d_GLOBALTHRESH", iTRU );
+    arrGLOBALTHRESH = (TObjArray*) dcsAliasMap->GetValue( buf );
+    snprintf( buf, bufsize, "EMC_TRU%02d_COSMTHRESH", iTRU );
+    arrCOSMTHRESH = (TObjArray*) dcsAliasMap->GetValue( buf );
+    
+    for( i = 0; i < 6; i++ ){
+      snprintf( buf, bufsize, "EMC_TRU%02d_MASK%d", iTRU, i );
+      arrMASK[i] = (TObjArray*) dcsAliasMap->GetValue( buf );
+    }
+    
+    // fill the objects
+    AliEMCALTriggerTRUDCSConfig* truConfig = trigConfig->GetTRUDCSConfig(iTRU);
+    if( ! truConfig ){
+      AliWarning( Form("EMC TRU%02d config not retrieved!\n", iTRU ));
+      continue;
+    }
+
+    // get last entries. fill the TRU object
+    if( ! arrL0ALGSEL ){
+      AliWarning( Form("EMC_TRU%02d_L0ALGSEL alias not found!\n", iTRU ));
+    }
+    else{
+      if (debug) AliInfo( Form("arrL0ALGSEL has %d entries \n", arrL0ALGSEL->GetEntries()) );
+      if ( arrL0ALGSEL->GetEntries() > 0 ) {
+       dcsVal = (AliDCSValue *) arrL0ALGSEL->At( arrL0ALGSEL->GetEntries() - 1 );
+       if (dcsVal) {
+               truConfig->SetL0SEL( dcsVal->GetUInt() );
+    if (debug) AliInfo( Form("saving value: %u\n", dcsVal->GetUInt()) );
+       }
+      }
+      else
+      AliWarning( Form("EMC_TRU%02d_L0ALGSEL has no entries!\n", iTRU ));
+    }
+
+    if( ! arrPEAKFINDER ){
+      AliWarning( Form("EMC_TRU%02d_PEAKFINDER alias not found!\n", iTRU ));
+    }
+    else{
+      if (debug) AliInfo( Form("arrPEAKFINDER has %d entries \n", arrPEAKFINDER->GetEntries()) );
+      if ( arrPEAKFINDER->GetEntries() > 0 ) {
+       dcsVal = (AliDCSValue *) arrPEAKFINDER->At( arrPEAKFINDER->GetEntries() - 1 );
+       if (dcsVal){
+               truConfig->SetSELPF( dcsVal->GetUInt() );
+    if (debug) AliInfo( Form("saving value: %u\n", dcsVal->GetUInt()) );
+       }
+      }
+      else
+      AliWarning( Form("EMC_TRU%02d_PEAKFINDER has no entries!\n", iTRU ));
+    }
+
+    if( ! arrGLOBALTHRESH ){
+      AliWarning( Form("EMC_TRU%02d_GLOBALTHRESH alias not found!\n", iTRU ));
+    }
+    else{
+      if (debug) AliInfo( Form("arrGLOBALTHRESH has %d entries \n", arrGLOBALTHRESH->GetEntries()) );
+      if ( arrGLOBALTHRESH->GetEntries() > 0 ) {
+       dcsVal = (AliDCSValue *) arrGLOBALTHRESH->At( arrGLOBALTHRESH->GetEntries() - 1 );
+       if (dcsVal){
+               truConfig->SetGTHRL0( dcsVal->GetUInt() );
+    if (debug) AliInfo( Form("saving value: %u\n", dcsVal->GetUInt()) );
+       }
+      }
+      else
+      AliWarning( Form("EMC_TRU%02d_GLOBALTHRESH has no entries!\n", iTRU ));
+    }
+
+    if( ! arrCOSMTHRESH ){
+      AliWarning( Form("EMC_TRU%02d_COSMTHRESH alias not found!\n", iTRU ));
+    }
+    else{
+      if (debug) AliInfo( Form("arrCOSMTHRESH has %d entries \n", arrCOSMTHRESH->GetEntries()) );
+      if ( arrCOSMTHRESH->GetEntries() > 0 ) {
+       dcsVal = (AliDCSValue *) arrCOSMTHRESH->At( arrCOSMTHRESH->GetEntries() - 1 );
+       if (dcsVal){
+               truConfig->SetL0COSM( dcsVal->GetUInt() );
+    if (debug) AliInfo( Form("saving value: %u\n", dcsVal->GetUInt()) );
+       }
+      }
+      else
+      AliWarning( Form("EMC_TRU%02d_COSMTHRESH has no entries!\n", iTRU ));
+    }
+    
+    for( i = 0; i < 6; i++ ){
+      if( ! arrMASK[i] ){
+       AliWarning( Form("EMC_TRU%02d_MASK%d alias not found!\n", iTRU, i ));
+      }
+      else{
+       if (debug) AliInfo( Form("arrMASK[%d] has %d entries \n", i, arrMASK[i]->GetEntries()) );
+       if ( arrMASK[i]->GetEntries() > 0 ) {
+         dcsVal = (AliDCSValue *) arrMASK[i]->At( arrMASK[i]->GetEntries() - 1 );
+         if (dcsVal){
+                       truConfig->SetMaskReg( dcsVal->GetUInt(), i );
+    if (debug) AliInfo( Form("saving value: %u\n", dcsVal->GetUInt()) );
+       }
+       }
+      else
+      AliWarning( Form("EMC_TRU%02d_MASK%d has no entries!\n", iTRU, i ));
+      }
+    }
+    
+  } // TRUs
+  AliInfo(Form("TRU info retrieved.\n"));
+               
+  // STU
+  for (i = 0; i < 3; i++) {
+               for (int j = 0; j < 2; j++) {
+                       arrSTUG[i][j] = (TObjArray*)dcsAliasMap->GetValue(Form("EMC_STU_G%c%d", i + 65, j));
+                       arrSTUJ[i][j] = (TObjArray*)dcsAliasMap->GetValue(Form("EMC_STU_J%c%d", i + 65, j));    
+                       
+                       if (!arrSTUG[i][j]) {
+                               AliWarning(Form("EMC_STU_G%c%d alias not found!", i + 65, j));
+                       } else {
+                               if (debug) AliInfo( Form("EMC_STU_G%c%d has %d entries", i + 65, j, arrSTUG[i][j]->GetEntries()));
+                               if (arrSTUG[i][j]->GetEntries() > 0) {
+                                       dcsVal = (AliDCSValue*)arrSTUG[i][j]->At(arrSTUG[i][j]->GetEntries() - 1);
+                                       if (dcsVal) {
+                                               stuConfig->SetG(i, j, dcsVal->GetInt());
+                                               if (debug) AliInfo(Form("saving value: %u", dcsVal->GetInt()));
+                                       }
+                               } else
+                                       AliWarning(Form("EMC_STU_G%c%d has no entry!", i + 65, j));
+                       }
+                       
+                       if (!arrSTUJ[i][j]) {
+                               AliWarning(Form("EMC_STU_J%c%d alias not found!", i + 65, j));
+                       } else {
+                               if (debug) AliInfo( Form("EMC_STU_J%c%d has %d entries", i + 65, j, arrSTUJ[i][j]->GetEntries()));
+                               if (arrSTUJ[i][j]->GetEntries() > 0) {
+                                       dcsVal = (AliDCSValue*)arrSTUJ[i][j]->At(arrSTUJ[i][j]->GetEntries() - 1);
+                                       if (dcsVal) {
+                                               stuConfig->SetJ(i, j, dcsVal->GetInt());
+                                               if (debug) AliInfo(Form("saving value: %u", dcsVal->GetInt()));
+                                       }
+                               } else
+                                       AliWarning(Form("EMC_STU_J%c%d has no entry!", i + 65, j));
+                       }
+               }
+       }
        
-       //Get reference histogram
-       TList * keylist = f.GetListOfKeys();
-       Int_t nkeys   = f.GetNkeys();
-       Bool_t ok = kFALSE;
-       TKey  *key;
-       TString refHistoName= "";
-       Int_t ikey = 0;
-       Int_t counter = 0;
-       TH1F* hRef = new TH1F();
+       arrSTUD = (TObjArray*)dcsAliasMap->GetValue("EMC_STU_GETRAW");
+       arrSTUR = (TObjArray*)dcsAliasMap->GetValue("EMC_STU_REGION");  
+       arrSTUF = (TObjArray*)dcsAliasMap->GetValue("EMC_STU_FWVERS");  
+
+       if (!arrSTUD) {
+               AliWarning("EMC_STU_GETRAW alias not found!");
+       } else {
+               if (debug) AliInfo(Form("EMC_STU_GETRAW has %d entries", arrSTUD->GetEntries()));
+               if (arrSTUD->GetEntries() > 0) {
+                       dcsVal = (AliDCSValue*)arrSTUD->At(arrSTUD->GetEntries() - 1);
+                       if (dcsVal) {
+                               stuConfig->SetRawData(dcsVal->GetInt());
+                               if (debug) AliInfo(Form("saving value: %u", dcsVal->GetInt()));
+                       }
+               } else
+                       AliWarning("EMC_STU_GETRAW has no entry!");
+       }
        
-       //Check if the file contains any histogram
-       if(nkeys< 2){
-         Log(Form("Not enough histograms for calibration, nhist = %d",nkeys));
-         return 1;
+       if (!arrSTUR) {
+               AliWarning("EMC_STU_REGION");
+       } else {
+               if (debug) AliInfo( Form("EMC_STU_REGION has %d entries", arrSTUR->GetEntries()));
+               if (arrSTUR->GetEntries() > 0) {
+                       dcsVal = (AliDCSValue*)arrSTUR->At(arrSTUR->GetEntries() - 1);
+                       if (dcsVal) {
+                               stuConfig->SetRegion(dcsVal->GetInt());
+                               if (debug) AliInfo(Form("saving value: %u", dcsVal->GetInt()));
+                       }
+               } else
+                       AliWarning("EMC_STU_REGION has no entry!");
        }
        
-       while(!ok){
-         ikey = gRandom->Integer(nkeys);
-         key = (TKey*)keylist->At(ikey);
-         refHistoName = key->GetName();
-         hRef = (TH1F*)f.Get(refHistoName);
-         counter++;
-         // Check if the reference has too little statistics and 
-         // if the histogram has the correct name (2 kinds, mod#col#row for 
-         // reference here, and mod#, see AliEMCALHistoProducer.
-         if(refHistoName.Contains("col") && hRef->GetEntries()>2 && hRef->GetMean()>0) 
-           ok=kTRUE;
-         if(!ok && counter >= nMod*nCol*nRow+nMod){
-           Log("No histogram with enough statistics for reference");
-           return 1;
-         }
+       if (!arrSTUF) {
+               AliWarning("EMC_STU_FWVERS");
+       } else {
+               if (debug) AliInfo(Form("EMC_STU_FWVERS has %d entries", arrSTUF->GetEntries()));
+               if (arrSTUF->GetEntries() > 0) {
+                       dcsVal = (AliDCSValue*)arrSTUF->At(arrSTUF->GetEntries() - 1);
+                       if (dcsVal) {
+                               stuConfig->SetFw(dcsVal->GetInt());
+                               if (debug) AliInfo(Form("saving value: %u", dcsVal->GetInt()));
+                       }
+               } else
+                       AliWarning("EMC_STU_FWVERS has no entry!");
        }
        
-       Double_t refMean=hRef->GetMean();
+       trigConfig->SetSTUObj(stuConfig);
+       
+       AliInfo(Form("STU info retrieved."));
+
        
-       // Calculates relative calibration coefficients for all non-zero channels
+  // save the objects
+  AliCDBMetaData metaData;
+  metaData.SetBeamPeriod(0);
+  metaData.SetResponsible(kMetaResponsible);
+  metaData.SetComment(kMetaComment); 
+      
+  UInt_t result=0;
+  Bool_t storeOK = Store("Calib", "Trigger", trigConfig, &metaData, 0, kFALSE);
+  if ( !storeOK )  result=1;
+  AliInfo(Form("TRU info stored. result %d\n", result));
+
+  return result;
+}
+
+//______________________________________________________________________________________________
+UInt_t AliEMCALPreprocessor::ExtractPedestals(Int_t sourceFXS)
+{
+  //  Read pedestal file from file exchange server
+  //  Only store if new pedestal info is available
+  //
+  UInt_t result=0;
+
+  AliCaloCalibPedestal *calibPed = new AliCaloCalibPedestal(AliCaloCalibPedestal::kEmCal);
+  calibPed->Init();
+
+  TList* list = GetFileSources(sourceFXS,"pedestals");
+  if (list && list->GetEntries()>0) {
+    
+    //  loop through all files from LDCs
+
+    int changes = 0;
+    UInt_t index = 0;
+    while (list->At(index)!=NULL) {
+      TObjString* fileNameEntry = (TObjString*) list->At(index);
+      if (fileNameEntry!=NULL) {
+        TString fileName = GetFile(sourceFXS, "pedestals",
+                                  fileNameEntry->GetString().Data());
+        TFile *f = TFile::Open(fileName);
+        if (!f) {
+         Log ("Error opening pedestal file.");
+         result = kReturnCodeNoObject;
+         break;
+       }
+        AliCaloCalibPedestal *calPed;
+       f->GetObject("emcCalibPedestal",calPed);
+        if ( !calPed ) {
+         Log ("No pedestal calibration object in file.");
+         result = kReturnCodeNoObject;
+         break;
+       }
+       if ( calPed->GetNEvents()>0 && calPed->GetNChanFills()>0 ) {
+         // add info for the modules available in the present file
+         Bool_t status = calibPed->AddInfo(calPed);
+         if (status) { changes++; }
+       }
        
-       for(Int_t mod=0; mod<nMod; mod++) {
-         if(mod > 10) nRow = nRowHalfSM ;
-         for(Int_t col=0; col<nCol; col++) {
-           for(Int_t row=0; row<nRow; row++) {
-             sprintf(hnam,"mod%dcol%drow%d",mod,col,row);
-             histo = (TH1F*)f.Get(hnam);
-             //TODO: dead channels exclusion!
-             if(histo && histo->GetMean() > 0) {
-               coeff = histo->GetMean()/refMean;
-               calibData.SetADCchannel(mod+1,col+1,row+1,1./coeff);
-               AliDebug(1,Form("mod %d col %d row %d  coeff %f\n",mod,col,row,coeff));
-             }
-             else
-               calibData.SetADCchannel(mod+1,col+1,row+1,-111); 
-           }
-         }
-       }
-       f.Close();
-      }//while
-    }//If list
+        delete calPed; 
+        f->Close();
+      }
+      index++;
+    }  // while(list)
+    
+    //
+    //  Store updated pedestal entry to OCDB
+    //
+    if (changes>0) {
+      AliCDBMetaData metaData;
+      metaData.SetBeamPeriod(0);
+      metaData.SetResponsible(kMetaResponsible);
+      metaData.SetComment(kMetaComment); 
+      
+      Bool_t storeOK = StoreReferenceData("Calib", "Pedestals", calibPed, &metaData);
+      if ( !storeOK ) result++;
+    }
+  } 
   else {
-    Log("Sources not found for id AMPLITUDES");
-    return 0;
+    Log ("Error: no entries in input file list!");
+    result = kReturnCodeNoEntries;
   }
-
-  AliCDBMetaData metaData;
-  Int_t result = Store("Calib", "Data", &calibData, &metaData);
   
+  return result;
+}
 
+//______________________________________________________________________________________________
+UInt_t AliEMCALPreprocessor::ExtractSignal(Int_t sourceFXS)
+{ //  Read signal file from file exchange server
+  //  Only store if new signal info is available
+  //
+  UInt_t result=0;
+  AliCaloCalibSignal *calibSig = new AliCaloCalibSignal(AliCaloCalibSignal::kEmCal); 
   
+  TList* list = GetFileSources(sourceFXS,"signal");
+  if (list && list->GetEntries()>0) {
+
+    //  loop through all files from LDCs
+    
+    int changes = 0;
+    UInt_t index = 0;
+    while (list->At(index)!=NULL) {
+      TObjString* fileNameEntry = (TObjString*) list->At(index);
+      if (fileNameEntry!=NULL) {
+        TString fileName = GetFile(sourceFXS, "signal",
+                                  fileNameEntry->GetString().Data());
+        TFile *f = TFile::Open(fileName);
+        if (!f) {
+         Log ("Error opening signal file.");
+         result = kReturnCodeNoObject;
+         break;
+       }
+       AliCaloCalibSignal *calSig;
+       f->GetObject("emcCalibSignal",calSig);
+        if ( !calSig ) {
+         Log ("No signal calibration object in file.");
+         result = kReturnCodeNoObject;
+         break;
+       }
+       if ( calSig->GetNEvents()>0 ) {
+         // add info for the modules available in the present file
+         Bool_t status = calibSig->AddInfo(calSig);
+         if (status) { changes++; }
+       }
+       
+        delete calSig; 
+        f->Close();
+      }
+      index++;
+    }  // while(list)
+    
+    //
+    //  Store updated signal entry to OCDB
+    //
+    if (changes>0) {
+      AliCDBMetaData metaData;
+      metaData.SetBeamPeriod(0);
+      metaData.SetResponsible(kMetaResponsible);
+      metaData.SetComment(kMetaComment); 
+      
+      Bool_t storeOK = Store("Calib", "LED", calibSig, &metaData, 0, kFALSE);
+      if ( !storeOK ) result++;
+    }
+  } 
+  else {
+    Log ("Error: no entries in input file list!");
+    result = kReturnCodeNoEntries;
+  }
+
   return result;
-  
 }
+
+