X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=ZDC%2FAliZDCPreprocessor.cxx;h=9ef09c65eb87474ba1cb201d67816ea750e40ace;hb=a0c1e804db5ce371682f7e7fa7f96d0bc10109bc;hp=c4c4235f50efb2df7e3ea79e4332721231b4f667;hpb=6024ec85f13938a59e638242cefa1200aa7df2d2;p=u%2Fmrichter%2FAliRoot.git diff --git a/ZDC/AliZDCPreprocessor.cxx b/ZDC/AliZDCPreprocessor.cxx index c4c4235f50e..9ef09c65eb8 100644 --- a/ZDC/AliZDCPreprocessor.cxx +++ b/ZDC/AliZDCPreprocessor.cxx @@ -14,18 +14,45 @@ #include "AliAlignObjParams.h" #include "AliLog.h" #include "AliZDCDataDCS.h" +#include "AliZDCChMap.h" #include "AliZDCPedestals.h" -#include "AliZDCCalib.h" -#include "AliZDCRecParam.h" +#include "AliZDCLaserCalib.h" +#include "AliZDCEnCalib.h" +#include "AliZDCTowerCalib.h" +#include "AliZDCMBCalib.h" ///////////////////////////////////////////////////////////////////// // // -// Class implementing ZDC pre-processor. // -// It takes data from DCS and passes it to the class AliZDCDataDCS // -// The class is then written to the CDB. // +// Class implementing Shuttle ZDC pre-processor. // +// It takes data from DCS and DAQ and writes calibration objects // +// in the OCDB and reference values/histos in the ReferenceData. // // // ///////////////////////////////////////////////////////////////////// +// ****************************************************************** +// RETURN CODES: +// return 0 : everything OK +// return 1 : no DCS input data Map +// return 2 : error storing DCS data in RefData +// return 3 : error storing alignment object in OCDB +// return 4 : error in ZDCMapping.dat file retrieved from DAQ FXS (not existing|empty|corrupted) +// return 5 : error storing mapping obj. in OCDB +// return 6 : error storing energy calibration obj. in OCDB +// return 7 : error storing tower inter-calibration obj. in OCDB +// return 8 : error in ZDCEnergyCalib.dat file retrieved from DAQ FXS +// return 9 : error in ZDCTowerCalib.dat file retrieved from DAQ FXS +// return 10: error in ZDCPedestal.dat file retrieved from DAQ FXS +// return 11: error storing pedestal calibration obj. in OCDB +// return 12: error in ZDCPedHisto.root file retrieved from DAQ FXS +// return 13: error storing pedestal histos in RefData +// return 14: error in ZDCLaserCalib.dat file retrieved from DAQ FXS +// return 15: error storing laser calibration obj. in OCDB +// return 16: error in ZDCLaserHisto.root file retrieved from DAQ FXS +// return 17: error storing laser histos in RefData +// return 18: error in ZDCMBCalib.root file retrieved from DAQ FXS +// return 19: error storing MB calibration obj. in OCDB +// ****************************************************************** + ClassImp(AliZDCPreprocessor) //______________________________________________________________________________________________ @@ -34,8 +61,20 @@ AliZDCPreprocessor::AliZDCPreprocessor(AliShuttleInterface* shuttle) : fData(0) { // constructor + // May 2009 - run types updated according to + // http://alice-ecs.web.cern.ch/alice-ecs/runtypes_3.36.html + AddRunType("STANDALONE_PEDESTAL"); + AddRunType("STANDALONE_LASER"); + AddRunType("STANDALONE_COSMIC"); + AddRunType("CALIBRATION_EMD"); + AddRunType("CALIBRATION_MB"); + AddRunType("CALIBRATION_CENTRAL"); + AddRunType("CALIBRATION_SEMICENTRAL"); + AddRunType("CALIBRATION_BC"); + AddRunType("PHYSICS"); } + //______________________________________________________________________________________________ AliZDCPreprocessor::~AliZDCPreprocessor() { @@ -44,50 +83,91 @@ AliZDCPreprocessor::~AliZDCPreprocessor() //______________________________________________________________________________________________ -void AliZDCPreprocessor::Initialize(Int_t run, UInt_t startTime, - UInt_t endTime) +void AliZDCPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime) { // Creates AliZDCDataDCS object AliPreprocessor::Initialize(run, startTime, endTime); - Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, + AliDebug(2,Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run, TTimeStamp(startTime).AsString(), - TTimeStamp(endTime).AsString())); + TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString())); + + fRun = run; + fStartTime = startTime; + fEndTime = endTime; + + fData = new AliZDCDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery()); +} - fRun = run; - fStartTime = startTime; - fEndTime = endTime; +//_____________________________________________________________________________ +Bool_t AliZDCPreprocessor::ProcessDCS(){ + + // tells whether DCS should be processed or not + + TString runType = GetRunType(); + Log(Form("RunType %s",runType.Data())); + + if (runType=="STANDALONE_COSMIC" || runType=="STANDALONE_PEDESTAL"){ + return kFALSE; + } - fData = new AliZDCDataDCS(fRun, fStartTime, fEndTime); + return kTRUE; } //______________________________________________________________________________________________ -UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap) +UInt_t AliZDCPreprocessor::ProcessDCSData(TMap* dcsAliasMap) { - // *************** From DCS ****************** + // Fills data into a AliZDCDataDCS object - if(!dcsAliasMap) return 1; + if(!dcsAliasMap){ + Log(" No DCS map found: ZDC exiting from Shuttle"); + if(fData){ + delete fData; + fData = 0; + } + return 1; + } + Log(Form("Processing data from DCS")); + // The processing of the DCS input data is forwarded to AliZDCDataDCS - Float_t dcsValues[28]; // DCSAliases=28 - fData->ProcessData(*dcsAliasMap, dcsValues); - //dcsAliasMap->Print(""); - // + //dcsAliasMap->Print(""); + Bool_t resDCSProcess = fData->ProcessData(*dcsAliasMap); + if(resDCSProcess==kFALSE){ + Log(" Problems in processing DCS DP"); + return 1; + } + + // ------------------------------------------------------ + // Change introduced 26/9/09 in order NOT to process the + // HV DP since some of them are never found in amanda DB + // ------------------------------------------------------ + // Store DCS data as reference + AliCDBMetaData metadata; + metadata.SetResponsible("Chiara Oppedisano"); + metadata.SetComment("DCS DP TMap for ZDC"); + Bool_t resDCSRef = kTRUE; + resDCSRef = StoreReferenceData("DCS","Data", dcsAliasMap, &metadata); + + if(resDCSRef==kFALSE) return 2; + // --- Writing ZDC table positions into alignment object TClonesArray *array = new TClonesArray("AliAlignObjParams",10); TClonesArray &alobj = *array; AliAlignObjParams a; Double_t dx=0., dz=0., dpsi=0., dtheta=0., dphi=0.; // Vertical table position in mm from DCS - Double_t dyZN1 = (Double_t) (dcsValues[0]/10.); - Double_t dyZP1 = (Double_t) (dcsValues[1]/10.); - Double_t dyZN2 = (Double_t) (dcsValues[2]/10.); - Double_t dyZP2 = (Double_t) (dcsValues[3]/10.); - const char *n1ZDC="ZDC/NeutronZDC1"; - const char *p1ZDC="ZDC/ProtonZDC1"; - const char *n2ZDC="ZDC/NeutronZDC2"; - const char *p2ZDC="ZDC/ProtonZDC2"; + Double_t dyZN1 = (Double_t) (fData->GetAlignData(0)/10.); + Double_t dyZP1 = (Double_t) (fData->GetAlignData(1)/10.); + Double_t dyZN2 = (Double_t) (fData->GetAlignData(2)/10.); + Double_t dyZP2 = (Double_t) (fData->GetAlignData(3)/10.); + // + const char *n1ZDC="ZDC/NeutronZDC_C"; + const char *p1ZDC="ZDC/ProtonZDC_C"; + const char *n2ZDC="ZDC/NeutronZDC_A"; + const char *p2ZDC="ZDC/ProtonZDC_A"; + // UShort_t iIndex=0; AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer; UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex); @@ -96,236 +176,624 @@ UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap) new(alobj[1]) AliAlignObjParams(p1ZDC, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE); new(alobj[2]) AliAlignObjParams(n2ZDC, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE); new(alobj[3]) AliAlignObjParams(p2ZDC, volid, dx, dyZP2, dz, dpsi, dtheta, dphi, kTRUE); + // save in CDB storage - AliCDBMetaData md; - md.SetResponsible("Chiara Oppedisano"); - md.SetComment("Alignment object for ZDC"); - Bool_t resultAl = kFALSE; - resultAl = Store("Align","Data", array, &md, 0, 0); + AliCDBMetaData mdDCS; + mdDCS.SetResponsible("Chiara Oppedisano"); + mdDCS.SetComment("Alignment object for ZDC"); + Bool_t resultAl = Store("Align","Data", array, &mdDCS, 0, kFALSE); + if(resultAl==kFALSE) return 3; -// *************** From DAQ ****************** -Bool_t resPedCal = kFALSE, resECal = kFALSE, resRecPar = kFALSE; -// ***************************************************** -// [a] PEDESTALS -> Pedestal subtraction -// ***************************************************** -TString runType = GetRunType(); -printf("\n\t AliZDCPreprocessor -> runType detected %s\n\n",runType.Data()); -if(runType == "PEDESTAL_RUN"){ - TList* daqSources = GetFileSources(kDAQ, "PEDESTALS"); - if(!daqSources){ - Log(Form("No source for PEDESTALS run %d !", fRun)); - return 1; + return 0; +} + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::ProcessChMap() +{ + const int kNch=48, kNScch=32; + + // Reading the file for mapping from FXS + TList* daqSource = GetFileSources(kDAQ, "MAPPING"); + if(!daqSource){ + AliError(Form("No sources for file ZDCChMapping.dat in run %d ", fRun)); + return 4; } - Log("\t List of sources for PEDESTALS"); - daqSources->Print(); + if(daqSource->GetEntries()==0) return 4; + Log("\t List of DAQ sources for MAPPING id: "); daqSource->Print(); // - TIter iter(daqSources); + TIter iter(daqSource); TObjString* source = 0; - Int_t i=0; + Int_t isou = 0; + Int_t readMap[kNch][6]; + // while((source = dynamic_cast (iter.Next()))){ - Log(Form("\n\t Getting file #%d\n",++i)); - TString stringPedFileName = GetFile(kDAQ, "PEDESTALS", source->GetName()); - if(stringPedFileName.Length() <= 0){ - Log(Form("No PEDESTAL file from source %s!", source->GetName())); - return 1; - } - // --- Initializing pedestal calibration object - AliZDCPedestals *pedCalib = new AliZDCPedestals("ZDC"); - // --- Reading file with pedestal calibration data - const char* pedFileName = stringPedFileName.Data(); - // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48 - const Int_t knZDCch = 48; - if(pedFileName){ - FILE *file; - if((file = fopen(pedFileName,"r")) == NULL){ - printf("Cannot open file %s \n",pedFileName); - return 1; - } - Log(Form("File %s connected to process pedestal data", pedFileName)); - Float_t pedVal[(3*knZDCch)][2]; - for(Int_t i=0; i<(3*knZDCch); i++){ - for(Int_t j=0; j<2; j++){ - fscanf(file,"%f",&pedVal[i][j]); - //if(j==1) printf("pedVal[%d] -> %f, %f \n",i,pedVal[i][0],pedVal[i][1]); - } - if(iSetMeanPed(i,pedVal[i][0]); - pedCalib->SetMeanPedWidth(i,pedVal[i][1]); - } - else if(i>=knZDCch && i<(2*knZDCch)){ - pedCalib->SetOOTPed(i-knZDCch,pedVal[i][0]); - pedCalib->SetOOTPedWidth(i-knZDCch,pedVal[i][1]); - } - else if(i>=(2*knZDCch) && i<(3*knZDCch)){ - pedCalib->SetPedCorrCoeff(i-(2*knZDCch),pedVal[i][0],pedVal[i][1]); - } - } - } - else{ - Log(Form("File %s not found", pedFileName)); - return 1; + TString fileName = GetFile(kDAQ, "MAPPING", source->GetName()); + Log(Form("\t Getting file #%d: ZDCChMapping.dat from %s\n",++isou, source->GetName())); + + if(fileName.Length() <= 0){ + Log(Form("No file from source %s!", source->GetName())); + return 4; + } + // --- Reading file with calibration data + //const char* fname = fileName.Data(); + if(fileName){ + FILE *file; + if((file = fopen(fileName,"r")) == NULL){ + printf("Cannot open file %s \n",fileName.Data()); + return 4; } + Log(Form("File %s connected to process data for ADC mapping", fileName.Data())); // - //pedCalib->Print(""); - // - AliCDBMetaData metaData; - metaData.SetBeamPeriod(0); - metaData.SetResponsible("Chiara"); - metaData.SetComment("Filling AliZDCPedestals object"); - // - resPedCal = Store("Calib","Pedestals",pedCalib, &metaData, 0, 1); + for(Int_t j=0; jGetObject(); + for(Int_t i=0; iGetADCModule(i)) + && (readMap[i][2] == chMap->GetADCChannel(i)) + && (readMap[i][4] == chMap->GetDetector(i)) + && (readMap[i][5] == chMap->GetSector(i))){ + updateOCDB = kFALSE; + } + else updateOCDB = kTRUE; + } + } + // + Bool_t resChMapStore = kTRUE; + if(updateOCDB==kTRUE){ + Log(" A new entry ZDC/Calib/ChMap will be created"); + // + // --- Initializing mapping calibration object + AliZDCChMap *mapCalib = new AliZDCChMap("ZDC"); + // Writing channel map in the OCDB + for(Int_t k=0; kSetADCModule(k,readMap[k][1]); + mapCalib->SetADCChannel(k,readMap[k][2]); + mapCalib->SetDetector(k,readMap[k][4]); + mapCalib->SetSector(k,readMap[k][5]); + // TEMPORARY!!!! Until no mapping from scaler is provided!!!!!!! + if(kSetScChannel(k, 0); + mapCalib->SetScDetector(k, 0); + mapCalib->SetScSector(k, 0); + } + } + mapCalib->Print(""); + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + //metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("Filling AliZDCChMap object"); + // + resChMapStore = Store("Calib","ChMap",mapCalib, &metaData, 0, kTRUE); + printf(" Mapping object stored in OCDB\n"); + } + else{ + Log(" ZDC/Calib/ChMap entry in OCDB is valid and won't be updated"); + resChMapStore = kTRUE; + } + + delete daqSource; daqSource=0; + + if(resChMapStore==kFALSE) return 5; + else return 0; + +} + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::ProcessppData() +{ + Bool_t resEnCal=kTRUE, resTowCal=kTRUE; + + // *********** Energy calibration + // --- Cheking if there is already the entry in the OCDB + AliCDBEntry *cdbEnEntry = GetFromOCDB("Calib", "EnergyCalib"); + if(!cdbEnEntry){ + Log(Form(" ZDC/Calib/EnergyCalib entry will be created")); + // --- Initializing calibration object + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + // + AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC"); + for(Int_t j=0; j<6; j++) eCalib->SetEnCalib(j,1.); + metaData.SetComment("AliZDCEnCalib object"); + //eCalib->Print(""); + resEnCal = Store("Calib", "EnergyCalib", eCalib, &metaData, 0, kTRUE); + } + else{ + // if entry exists it is still valid (=1 for all runs!) + Log(Form(" Valid ZDC/Calib/EnergyCalib object already existing in OCDB!!!")); + resEnCal = kTRUE; + } + + if(resEnCal==kFALSE) return 6; + + // + // *********** Tower inter-calibration + // --- Cheking if there is already the entry in the OCDB + AliCDBEntry *cdbTowEntry = GetFromOCDB("Calib", "TowerCalib"); + if(!cdbTowEntry){ + AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC"); + for(Int_t j=0; j<5; j++){ + towCalib->SetZN1EqualCoeff(j, 1.); + towCalib->SetZP1EqualCoeff(j, 1.); + towCalib->SetZN2EqualCoeff(j, 1.); + towCalib->SetZP2EqualCoeff(j, 1.); + } + //towCalib->Print(""); + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("AliZDCTowerCalib object"); + // + resTowCal = Store("Calib", "TowerCalib", towCalib, &metaData, 0, kTRUE); + } + else{ + // if entry exists it is still valid (=1 for all runs!) + Log(Form(" Valid ZDC/Calib/TowerCalib object already existing in OCDB!!!")); + resTowCal = kTRUE; + } + + if(resTowCal==kFALSE) return 7; + + return 0; } -// ***************************************************** -// [b] EMD EVENTS -> Energy calibration and equalization -// ***************************************************** -else if(runType == "PULSER_RUN"){ - TList* daqSources = GetFileSources(kDAQ, "EMDCALIB"); + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::ProcessCalibData() +{ + TList* daqSources = GetFileSources(kDAQ, "EMDENERGYCALIB"); if(!daqSources){ - AliError(Form("No sources for PULSER_RUN run %d !", fRun)); - return 1; + AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun)); + return 8; } - Log("\t List of sources for PULSER_RUN"); - daqSources->Print(); + Log("\t List of DAQ sources for EMDENERGYCALIB id: "); daqSources->Print(); // TIter iter2(daqSources); TObjString* source = 0; - Int_t j=0; + Int_t i=0; + Bool_t resEnCal=kTRUE, resTowCal=kTRUE; + while((source = dynamic_cast (iter2.Next()))){ - Log(Form("\n\t Getting file #%d\n",++j)); - TString stringEMDFileName = GetFile(kDAQ, "EMDCALIB", source->GetName()); - if(stringEMDFileName.Length() <= 0){ - Log(Form("No EMDCALIB file from source %s!", source->GetName())); - return 1; - } - // --- Initializing pedestal calibration object - AliZDCCalib *eCalib = new AliZDCCalib("ZDC"); - // --- Reading file with pedestal calibration data - const char* emdFileName = stringEMDFileName.Data(); - if(emdFileName){ - FILE *file; - if((file = fopen(emdFileName,"r")) == NULL){ - printf("Cannot open file %s \n",emdFileName); - return 1; - } - Log(Form("File %s connected to process data from EM dissociation events", emdFileName)); - // - Float_t fitValEMD[6]; Float_t equalCoeff[5][4]; - Float_t calibVal[4]; - for(Int_t j=0; j<10; j++){ - if(j<6){ - fscanf(file,"%f",&fitValEMD[j]); - if(j<4){ - calibVal[j] = fitValEMD[j]/2.76; - eCalib->SetEnCalib(j,calibVal[j]); - } - else eCalib->SetEnCalib(j,fitValEMD[j]); - } - else{ - for(Int_t k=0; k<5; k++){ - fscanf(file,"%f",&equalCoeff[j][k]); - if(j==6) eCalib->SetZN1EqualCoeff(k, equalCoeff[j][k]); - else if(j==7) eCalib->SetZP1EqualCoeff(k, equalCoeff[j][k]); - else if(j==8) eCalib->SetZN2EqualCoeff(k, equalCoeff[j][k]); - else if(j==9) eCalib->SetZP2EqualCoeff(k, equalCoeff[j][k]); - } - } + TString stringEMDFileName = GetFile(kDAQ, "EMDENERGYCALIB", source->GetName()); + if(stringEMDFileName.Length() <= 0){ + Log(Form("No file from source %s!", source->GetName())); + return 8; + } + const char* emdFileName = stringEMDFileName.Data(); + Log(Form("\t Getting file #%d: %s from %s\n",++i,emdFileName,source->GetName())); + // + // --- Initializing energy calibration object + AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC"); + // --- Reading file with calibration data + if(emdFileName){ + FILE *file; + if((file = fopen(emdFileName,"r")) == NULL){ + printf("Cannot open file %s \n",emdFileName); + return 8; + } + Log(Form("File %s connected to process data from EM dissociation events", emdFileName)); + // + Float_t fitValEMD[6]; + for(Int_t j=0; j<6; j++){ + if(j<6){ + int iread = fscanf(file,"%f",&fitValEMD[j]); + if(iread==0) AliDebug(3," Failing reading daa from EMD calibration data file"); + eCalib->SetEnCalib(j,fitValEMD[j]); + } + } + // + fclose(file); + } + else{ + Log(Form("File %s not found", emdFileName)); + return 8; + } + //eCalib->Print(""); + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("Filling AliZDCEnCalib object"); + // + resEnCal = Store("Calib","EnergyCalib",eCalib, &metaData, 0, kTRUE); + if(resEnCal==kFALSE) return 6; + } + delete daqSources; daqSources = 0; + + TList* daqSourcesH = GetFileSources(kDAQ, "EMDTOWERCALIB"); + if(!daqSourcesH){ + AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun)); + return 9; + } + Log("\t List of DAQ sources for EMDTOWERCALIB id: "); daqSourcesH->Print(); + // + TIter iter2H(daqSourcesH); + TObjString* sourceH = 0; + Int_t iH=0; + while((sourceH = dynamic_cast (iter2H.Next()))){ + TString stringtowEMDFileName = GetFile(kDAQ, "EMDTOWERCALIB", sourceH->GetName()); + if(stringtowEMDFileName.Length() <= 0){ + Log(Form("No file from source %s!", sourceH->GetName())); + return 9; + } + const char * towEMDFileName = stringtowEMDFileName.Data(); + Log(Form("\t Getting file #%d: %s from source %s\n",++iH,towEMDFileName,sourceH->GetName())); + // --- Initializing energy calibration object + AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC"); + // --- Reading file with calibration data + if(towEMDFileName){ + FILE *file; + if((file = fopen(towEMDFileName,"r")) == NULL){ + printf("Cannot open file %s \n",towEMDFileName); + return 9; + } + // + Float_t equalCoeff[4][5]; + for(Int_t j=0; j<4; j++){ + for(Int_t k=0; k<5; k++){ + int leggi = fscanf(file,"%f",&equalCoeff[j][k]); + if(leggi==0) AliDebug(3," Failing reading data from EMD calibration file"); + if(j==0) towCalib->SetZN1EqualCoeff(k, equalCoeff[j][k]); + else if(j==1) towCalib->SetZP1EqualCoeff(k, equalCoeff[j][k]); + else if(j==2) towCalib->SetZN2EqualCoeff(k, equalCoeff[j][k]); + else if(j==3) towCalib->SetZP2EqualCoeff(k, equalCoeff[j][k]); } - } - else{ - Log(Form("File %s not found", emdFileName)); - return 1; - } - //calibdata->Print(""); - // - AliCDBMetaData metaData; - metaData.SetBeamPeriod(0); - metaData.SetResponsible("Chiara"); - metaData.SetComment("Filling AliZDCCalib object"); + } // - resECal = Store("Calib","Calib",eCalib, &metaData, 0, 1); + fclose(file); + } + else{ + Log(Form("File %s not found", towEMDFileName)); + return 9; + } + //towCalib->Print(""); + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("Filling AliZDCTowerCalib object"); + // + resTowCal = Store("Calib","TowerCalib",towCalib, &metaData, 0, kTRUE); + if(resTowCal==kFALSE) return 7; } + delete daqSourcesH; daqSourcesH = 0; + + + return 0; } -// ******************************************************** -// [c] PHYSICS RUNS -> Parameters needed for reconstruction -// ******************************************************** -else if(runType == "PHYSICS"){ - TList* daqSources = GetFileSources(kDAQ, "PHYSICS"); + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::ProcessPedestalData() +{ + TList* daqSources = GetFileSources(kDAQ, "PEDESTALDATA"); if(!daqSources){ - AliError(Form("No sources for PHYSICS run %d !", fRun)); - return 1; + Log(Form("No source for STANDALONE_PEDESTAL run %d !", fRun)); + return 10; + } + if(daqSources->GetEntries()==0) return 10; + Log("\t List of DAQ sources for PEDESTALDATA id: "); daqSources->Print(); + // + TIter iter(daqSources); + TObjString* source; + Int_t i=0; + Bool_t resPedCal=kTRUE, resPedHist=kTRUE; + + while((source = dynamic_cast (iter.Next()))){ + TString stringPedFileName = GetFile(kDAQ, "PEDESTALDATA", source->GetName()); + if(stringPedFileName.Length() <= 0){ + Log(Form("No PEDESTALDATA file from source %s!", source->GetName())); + return 10; + } + const char* pedFileName = stringPedFileName.Data(); + Log(Form("\t Getting file #%d: %s from %s\n",++i,pedFileName,source->GetName())); + // + // --- Initializing pedestal calibration object + AliZDCPedestals *pedCalib = new AliZDCPedestals("ZDC"); + // --- Reading file with pedestal calibration data + // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48 + const Int_t knZDCch = 48; + FILE *file; + if((file = fopen(pedFileName,"r")) == NULL){ + printf("Cannot open file %s \n",pedFileName); + return 10; + } + Log(Form("File %s connected to process pedestal data", pedFileName)); + Float_t pedVal[(2*knZDCch)][2]; + for(Int_t k=0; k<(2*knZDCch); k++){ + for(Int_t j=0; j<2; j++){ + int aleggi = fscanf(file,"%f",&pedVal[k][j]); + if(aleggi==0) AliDebug(3," Failing reading data from pedestal file"); + //if(j==1) printf("pedVal[%d] -> %f, %f \n",k,pedVal[k][0],pedVal[k][1]); + } + if(kSetMeanPed(k,pedVal[k][0]); + pedCalib->SetMeanPedWidth(k,pedVal[k][1]); + } + else if(k>=knZDCch && k<(2*knZDCch)){ + pedCalib->SetOOTPed(k-knZDCch,pedVal[k][0]); + pedCalib->SetOOTPedWidth(k-knZDCch,pedVal[k][1]); + } + else if(k>=(2*knZDCch) && k<(3*knZDCch)){ + pedCalib->SetPedCorrCoeff(k-(2*knZDCch),pedVal[k][0],pedVal[k][1]); + } + } + fclose(file); + //pedCalib->Print(""); + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("Filling AliZDCPedestals object"); + // + resPedCal = Store("Calib","Pedestals",pedCalib, &metaData, 0, kTRUE); + if(resPedCal==kFALSE) return 11; + } + delete daqSources; daqSources = 0; + + TList* daqSourceH = GetFileSources(kDAQ, "PEDESTALHISTOS"); + if(!daqSourceH){ + Log(Form("No source for PEDESTALHISTOS id run %d !", fRun)); + return 12; + } + Log("\t List of DAQ sources for PEDESTALHISTOS id: "); daqSourceH->Print(); + // + TIter iterH(daqSourceH); + TObjString* sourceH = 0; + Int_t iH=0; + while((sourceH = dynamic_cast (iterH.Next()))){ + TString stringPedFileName = GetFile(kDAQ, "PEDESTALHISTOS", sourceH->GetName()); + if(stringPedFileName.Length() <= 0){ + Log(Form("No PEDESTALHISTOS file from source %s!", sourceH->GetName())); + return 12; + } + const char* pedFileName = stringPedFileName.Data(); + Log(Form("\t Getting file #%d: %s from %s\n",++iH, pedFileName, sourceH->GetName())); + resPedHist = StoreReferenceFile(pedFileName, "pedestalReference.root"); + if(resPedHist==kFALSE) return 13; + } + delete daqSourceH; daqSourceH=0; + + return 0; +} + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::ProcessLaserData() +{ + TList* daqSources = GetFileSources(kDAQ, "LASERDATA"); + if(!daqSources){ + AliError(Form("No sources for STANDALONE_LASER run %d !", fRun)); + return 14; } - Log("\t List of sources for PHYSICS"); - daqSources->Print(); + if(daqSources->GetEntries()==0) return 14; + Log("\t List of DAQ sources for LASERDATA id: "); daqSources->Print(); // TIter iter2(daqSources); TObjString* source = 0; - Int_t j=0; + Int_t i=0; + Bool_t resLaserCal=kTRUE, resLaserHist=kTRUE; + while((source = dynamic_cast (iter2.Next()))){ - Log(Form("\n\t Getting file #%d\n",++j)); - TString stringPHYSFileName = GetFile(kDAQ, "PHYSICS", source->GetName()); - if(stringPHYSFileName.Length() <= 0){ - Log(Form("No PHYSICS file from source %s!", source->GetName())); - return 1; + TString stringLaserFileName = GetFile(kDAQ, "LASERDATA", source->GetName()); + if(stringLaserFileName.Length() <= 0){ + Log(Form("No LASER file from source %s!", source->GetName())); + return 14; + } + const char* laserFileName = stringLaserFileName.Data(); + Log(Form("\t Getting file #%d: %s from %s\n",++i,laserFileName,source->GetName())); + // + // --- Initializing pedestal calibration object + AliZDCLaserCalib *lCalib = new AliZDCLaserCalib("ZDC"); + // --- Reading file with pedestal calibration data + if(laserFileName){ + FILE *file; + if((file = fopen(laserFileName,"r")) == NULL){ + printf("Cannot open file %s \n",laserFileName); + return 14; } - // --- Initializing pedestal calibration object - AliZDCRecParam *recCalib = new AliZDCRecParam("ZDC"); - // --- Reading file with pedestal calibration data - const char* physFileName = stringPHYSFileName.Data(); - if(physFileName){ - FILE *file; - if((file = fopen(physFileName,"r")) == NULL){ - printf("Cannot open file %s \n",physFileName); - return 1; - } - Log(Form("File %s connected to process data from PHYSICS runs", physFileName)); - // - Float_t physRecParam[10]; - for(Int_t j=0; j<10; j++) fscanf(file,"%f",&physRecParam[j]); - recCalib->SetZEMEndValue(physRecParam[0]); - recCalib->SetZEMCutFraction(physRecParam[1]); - recCalib->SetDZEMSup(physRecParam[2]); - recCalib->SetDZEMInf(physRecParam[3]); - recCalib->SetEZN1MaxValue(physRecParam[4]); - recCalib->SetEZP1MaxValue(physRecParam[5]); - recCalib->SetEZDC1MaxValue(physRecParam[6]); - recCalib->SetEZN2MaxValue(physRecParam[7]); - recCalib->SetEZP2MaxValue(physRecParam[8]); - recCalib->SetEZDC2MaxValue(physRecParam[9]); - } - else{ - Log(Form("File %s not found", physFileName)); - return 1; + Log(Form("File %s connected to process data from LASER events", laserFileName)); + // + Float_t ivalRead[22][4]; + for(Int_t j=0; j<22; j++){ + for(Int_t k=0; k<4; k++){ + int aleggi = fscanf(file,"%f",&ivalRead[j][k]); + if(aleggi==0) AliDebug(3," Failng reading data from laser file"); + //printf(" %d %1.0f ",k, ivalRead[j][k]); + } + lCalib->SetDetector(j, (Int_t) ivalRead[j][0]); + lCalib->SetSector(j, (Int_t) ivalRead[j][1]); + lCalib->SetfPMValue(j, ivalRead[j][2]); + lCalib->SetfPMWidth(j, ivalRead[j][3]); } - //calibdata->Print(""); - // - AliCDBMetaData metaData; - metaData.SetBeamPeriod(0); - metaData.SetResponsible("Chiara"); - metaData.SetComment("Filling AliZDCCalib object"); - // - resRecPar = Store("Calib","RecParam",recCalib, &metaData, 0, 1); + fclose(file); + } + else{ + Log(Form("File %s not found", laserFileName)); + return 14; + } + //lCalib->Print(""); + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("Filling AliZDCLaserCalib object"); + // + resLaserCal = Store("Calib","LaserCalib",lCalib, &metaData, 0, kTRUE); + if(resLaserCal==kFALSE) return 15; } -} -else { - Log(Form("Nothing to do: run type is %s", runType.Data())); + delete daqSources; daqSources = 0; + + TList* daqSourceH = GetFileSources(kDAQ, "LASERHISTOS"); + if(!daqSourceH){ + AliError(Form("No sources for STANDALONE_LASER run %d !", fRun)); + return 16; + } + Log("\t List of DAQ sources for LASERHISTOS id: "); daqSourceH->Print(); + // + TIter iter2H(daqSourceH); + TObjString* sourceH = 0; + Int_t iH=0; + while((sourceH = dynamic_cast (iter2H.Next()))){ + Log(Form("\t Getting file #%d\n",++iH)); + TString stringLaserFileName = GetFile(kDAQ, "LASERHISTOS", sourceH->GetName()); + if(stringLaserFileName.Length() <= 0){ + Log(Form("No LASER file from source %s!", sourceH->GetName())); + return 16; + } + resLaserHist = StoreReferenceFile(stringLaserFileName.Data(), "laserReference.root"); + // + if(resLaserHist==kFALSE) return 17; + } + delete daqSourceH; daqSourceH = 0; + return 0; -} +} - // note that the parameters are returned as character strings! - const char* nEvents = GetRunParameter("totalEvents"); - if(nEvents) Log(Form("Number of events for run %d: %s",fRun, nEvents)); - else Log(Form("Number of events not put in logbook!")); - - UInt_t result = 0; - if(resultAl==kFALSE || resPedCal==kFALSE || resECal==kFALSE || resRecPar==kFALSE){ - if(resultAl == kFALSE) result = 1; - else if(resPedCal == kFALSE) result = 2; - else if(resECal == kFALSE) result = 3; - else if(resRecPar == kFALSE) result = 4; + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::ProcessMBCalibData() +{ + TList* daqSources = GetFileSources(kDAQ, "MBCALIB"); + if(!daqSources){ + AliError(Form("No sources for CALIBRATION_MB run %d !", fRun)); + return 18; + } + if(daqSources->GetEntries()==0) return 18; + Log("\t List of DAQ sources for MBCALIB id: "); daqSources->Print(); + // + TIter iter2(daqSources); + TObjString* source = 0; + Int_t i=0; + Bool_t resMBCal=kTRUE; + + while((source = dynamic_cast (iter2.Next()))){ + TString stringMBFileName = GetFile(kDAQ, "MBCALIB", source->GetName()); + if(stringMBFileName.Length() <= 0){ + Log(Form("No MBCALIB file from source %s!", source->GetName())); + return 18; + } + const char* mbFileName = stringMBFileName.Data(); + Log(Form("\t Getting file #%d: %s from %s\n",++i,mbFileName,source->GetName())); + // + // --- Initializing calibration object + AliZDCMBCalib *mbCalib = new AliZDCMBCalib("ZDC"); + // --- Reading file with calibration data + if(mbFileName){ + TFile * fileHistos = TFile::Open(mbFileName); + Log(Form("File %s connected to process data from CALIBRATION_MB events", mbFileName)); + // + fileHistos->cd(); + TH2F *hZDCvsZEM = (TH2F*) fileHistos->Get("hZDCvsZEM"); + TH2F *hZDCCvsZEM = (TH2F*) fileHistos->Get("hZDCCvsZEM"); + TH2F *hZDCAvsZEM = (TH2F*) fileHistos->Get("hZDCAvsZEM"); + // + mbCalib->SetZDCvsZEM(hZDCvsZEM); + mbCalib->SetZDCCvsZEM(hZDCCvsZEM); + mbCalib->SetZDCAvsZEM(hZDCAvsZEM); + // + //fileHistos->Close(); + } + else{ + Log(Form("File %s not found", mbFileName)); + return 14; + } + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("Filling AliZDCMBCalib object"); + // + //mbCalib->Dump(); + // + resMBCal = Store("Calib","MBCalib",mbCalib, &metaData, 0, kTRUE); + printf(" here 1000\n"); + if(resMBCal==kFALSE) return 19; } + delete daqSources; daqSources = 0; - return result; + return 0; +} + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap) +{ + UInt_t resDCS = 0; + UInt_t resChMap=0; + UInt_t resEnergyCalib=0, resPedestalCalib=0, resLaserCalib=0, resMBCalib=0; + + // ************************* Process DCS data **************************** + if(ProcessDCS()) resDCS = ProcessDCSData(dcsAliasMap); + + // ********************************* From DAQ ************************************ + + const char* beamType = GetRunParameter("beamType"); + TString runType = GetRunType(); + printf("\t **** AliZDCPreprocessor -> beamType %s, runType %s ****\n",beamType,runType.Data()); + + // ****************************************** + // ADC channel mapping + // ****************************************** + resChMap = ProcessChMap(); + + // ****************************************** + // Calibration param. for p-p data (all = 1) + // ****************************************** + // NO ENERGY CALIBRATION -> coefficients set to 1. + // Temp -> also inter-calibration coefficients are set to 1. + if((strcmp(beamType,"p-p")==0) || (strcmp(beamType,"P-P")==0)) resEnergyCalib = ProcessppData(); + + // ***************************************************** + // CALIBRATION_EMD -> Energy calibration and equalization + // ***************************************************** + if((strcmp(beamType,"A-A")==0) && (runType.CompareTo("CALIBRATION_EMD")==0)) + resEnergyCalib = ProcessCalibData(); + + // ***************************************************** + // STANDALONE_PEDESTALS -> Pedestal subtraction + // ***************************************************** + if(runType.CompareTo("STANDALONE_PEDESTAL")==0) resPedestalCalib = ProcessPedestalData(); + + // ***************************************************** + // STANDALONE_LASER -> Signal stability and ageing + // ***************************************************** + else if(runType.CompareTo("STANDALONE_LASER")==0) resLaserCalib = ProcessLaserData(); + + // ***************************************************** + // CALIBRATION_MB -> Signal stability and ageing + // ***************************************************** + else if(runType.CompareTo("CALIBRATION_MB")==0) resMBCalib = ProcessMBCalibData(); + + + if(resDCS!=0) return resDCS; + else if(resChMap!=0) return resChMap; + else if(resEnergyCalib!=0) return resEnergyCalib; + else if(resPedestalCalib!=0) return resPedestalCalib; + else if(resLaserCalib!=0) return resLaserCalib; + else if(resMBCalib!=0) return resMBCalib; + + return 0; }