X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;ds=inline;f=EMCAL%2FAliEMCALCalibMapAPD.cxx;h=51791fb6d68a1cdff05f6e3c35670409a8bc27fa;hb=f09766dd4fbf7947bf2e32b683b8aca78c47300d;hp=8f8573e48e9070cf198b55a5a9215b35c51ece52;hpb=d81e64232e236a9d83c3dc91c3795b6efc2b59cf;p=u%2Fmrichter%2FAliRoot.git diff --git a/EMCAL/AliEMCALCalibMapAPD.cxx b/EMCAL/AliEMCALCalibMapAPD.cxx index 8f8573e48e9..51791fb6d68 100644 --- a/EMCAL/AliEMCALCalibMapAPD.cxx +++ b/EMCAL/AliEMCALCalibMapAPD.cxx @@ -20,6 +20,8 @@ #include #include +#include +#include #include "AliEMCALCalibMapAPD.h" @@ -28,16 +30,21 @@ using namespace std; ClassImp(AliEMCALCalibMapAPD) //____________________________________________________________________________ -AliEMCALCalibMapAPD::AliEMCALCalibMapAPD() : - fNSuperModule(0), - fSuperModuleData(0) +AliEMCALCalibMapAPD::AliEMCALCalibMapAPD(const int nSM) : + fNSuperModule(nSM), + fSuperModuleData() { //Default constructor. + for (int i=0; i> iSM; - t.fSuperModuleNum = iSM; + t->SetSuperModuleNum(iSM); for (Int_t j=0; j> iCol >> iRow >> iHW - >> APDNum >> V30 - >> Par[0] >> Par[1] >> Par[2] - >> ParErr[0] >> ParErr[1] >> ParErr[2] - >> BreakDown >> DarkCurrent; + >> iAPDNum >> v30 + >> par[0] >> par[1] >> par[2] + >> parErr[0] >> parErr[1] >> parErr[2] + >> iBreakDown >> darkCurrent; + + // check that input values are not out bounds + if (iCol<0 || iCol>(AliEMCALGeoParams::fgkEMCALCols-1) || + iRow<0 || iRow>(AliEMCALGeoParams::fgkEMCALRows-1) ) { + printf("AliEMCALCalibMapAPD::ReadCalibMapAPDInfo - Error while reading input file; j %d iCol %d iRow %d\n", j, iCol, iRow); + return; + } // assume that this info is already swapped and done for this basis? if (swapSides) { @@ -89,19 +101,19 @@ void AliEMCALCalibMapAPD::ReadCalibMapAPDInfo(Int_t nSM, const TString &txtFileN iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow; } - AliEMCALCalibMapAPDVal &v = t.fAPDVal[iCol][iRow]; - - v.fHardWareId = iHW; - v.fAPDNum = APDNum; - v.fV30 = V30; - v.fPar[0] = Par[0]; - v.fPar[1] = Par[1]; - v.fPar[2] = Par[2]; - v.fParErr[0] = ParErr[0]; - v.fParErr[1] = ParErr[1]; - v.fParErr[2] = ParErr[2]; - v.fBreakDown = BreakDown; - v.fDarkCurrent = DarkCurrent; + AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow); + + v->SetHardWareId(iHW); + v->SetAPDNum(iAPDNum); + v->SetV30(v30); + v->SetPar(0, par[0]); + v->SetPar(1, par[1]); + v->SetPar(2, par[2]); + v->SetParErr(0, parErr[0]); + v->SetParErr(1, parErr[1]); + v->SetParErr(2, parErr[2]); + v->SetBreakDown(iBreakDown); + v->SetDarkCurrent(darkCurrent); } } // i, SuperModule @@ -112,8 +124,8 @@ void AliEMCALCalibMapAPD::ReadCalibMapAPDInfo(Int_t nSM, const TString &txtFileN } //____________________________________________________________________________ -void AliEMCALCalibMapAPD::WriteCalibMapAPDInfo(const TString &txtFileName, - Bool_t swapSides) +void AliEMCALCalibMapAPD::WriteTextCalibMapAPDInfo(const TString &txtFileName, + Bool_t swapSides) { // write data to txt file. ; coordinates given on SuperModule basis @@ -129,14 +141,14 @@ void AliEMCALCalibMapAPD::WriteCalibMapAPDInfo(const TString &txtFileName, Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows; for (Int_t i = 0; i < fNSuperModule; i++) { - AliEMCALSuperModuleCalibMapAPD &t = fSuperModuleData[i]; - outputFile << t.fSuperModuleNum << endl; + AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[i]; + outputFile << t->GetSuperModuleNum() << endl; for (Int_t j=0; jGetAPDVal(iCol, iRow); if (swapSides) { // C side, oriented differently than A side: swap is requested @@ -144,11 +156,11 @@ void AliEMCALCalibMapAPD::WriteCalibMapAPDInfo(const TString &txtFileName, iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow; } - outputFile << iCol << " " << iRow << " " << v.fHardWareId - << " " << v.fAPDNum << " " << v.fV30 - << " " << v.fPar[0] << " " << v.fPar[1] << " " << v.fPar[2] - << " " << v.fParErr[0] << " " << v.fParErr[1] << " " << v.fParErr[2] - << " " << v.fBreakDown << " " << v.fDarkCurrent << endl; + outputFile << iCol << " " << iRow << " " << v->GetHardWareId() + << " " << v->GetAPDNum() << " " << v->GetV30() + << " " << v->GetPar(0) << " " << v->GetPar(1) << " " << v->GetPar(2) + << " " << v->GetParErr(0) << " " << v->GetParErr(1) << " " << v->GetParErr(2) + << " " << v->GetBreakDown() << " " << v->GetDarkCurrent() << endl; } } // i, SuperModule @@ -159,34 +171,178 @@ void AliEMCALCalibMapAPD::WriteCalibMapAPDInfo(const TString &txtFileName, } //____________________________________________________________________________ -AliEMCALCalibMapAPD::~AliEMCALCalibMapAPD() +void AliEMCALCalibMapAPD::ReadRootCalibMapAPDInfo(const TString &rootFileName, + Bool_t swapSides) { - delete [] fSuperModuleData; + //Read data from root file. ; coordinates given on SuperModule basis + TFile inputFile(rootFileName, "read"); + + TTree *tree = (TTree*) inputFile.Get("tree"); + + ReadTreeCalibMapAPDInfo(tree, swapSides); + + inputFile.Close(); + + return; } //____________________________________________________________________________ -AliEMCALCalibMapAPD::AliEMCALSuperModuleCalibMapAPD AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDId(Int_t supModIndex)const +void AliEMCALCalibMapAPD::ReadTreeCalibMapAPDInfo(TTree *tree, + Bool_t swapSides) { - AliEMCALSuperModuleCalibMapAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really.. - if (!fSuperModuleData) - return t; + // how many SuperModule's worth of entries / APDs do we have? + Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows; + fNSuperModule = tree->GetEntries() / nAPDPerSM; + + Int_t iSM = 0; // SuperModule index + Int_t iCol = 0; + Int_t iRow = 0; + // list of values to be read + Int_t iHW = 0; + Int_t iAPDNum = 0; + Float_t v30 = 0; + Float_t par[3] = {0}; + Float_t parErr[3] = {0}; + Int_t iBreakDown = 0; + Float_t darkCurrent = 0; + // end - all values - return fSuperModuleData[supModIndex]; + // declare the branches + tree->SetBranchAddress("iSM", &iSM); + tree->SetBranchAddress("iCol", &iCol); + tree->SetBranchAddress("iRow", &iRow); + tree->SetBranchAddress("iHW", &iHW); + tree->SetBranchAddress("APDNum", &iAPDNum); + tree->SetBranchAddress("V30", &v30); + tree->SetBranchAddress("Par", par); + tree->SetBranchAddress("ParErr", parErr); + tree->SetBranchAddress("BreakDown", &iBreakDown); + tree->SetBranchAddress("DarkCurrent", &darkCurrent); + + for (int ient=0; ientGetEntries(); ient++) { + tree->GetEntry(ient); + + // assume the index SuperModules come in order: i=iSM + AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[iSM]; + t->SetSuperModuleNum(iSM); + + // assume that this info is already swapped and done for this basis? + if (swapSides) { + // C side, oriented differently than A side: swap is requested + iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol; + iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow; + } + + AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow); + + v->SetHardWareId(iHW); + v->SetAPDNum(iAPDNum); + v->SetV30(v30); + v->SetPar(0, par[0]); + v->SetPar(1, par[1]); + v->SetPar(2, par[2]); + v->SetParErr(0, parErr[0]); + v->SetParErr(1, parErr[1]); + v->SetParErr(2, parErr[2]); + v->SetBreakDown(iBreakDown); + v->SetDarkCurrent(darkCurrent); + } // + + return; } //____________________________________________________________________________ -AliEMCALCalibMapAPD::AliEMCALSuperModuleCalibMapAPD AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDNum(Int_t supModIndex)const +void AliEMCALCalibMapAPD::WriteRootCalibMapAPDInfo(const TString &rootFileName, + Bool_t swapSides) { - AliEMCALSuperModuleCalibMapAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really.. - if (!fSuperModuleData) - return t; + // write data to root file. ; coordinates given on SuperModule basis + TFile destFile(rootFileName, "recreate"); + if (destFile.IsZombie()) { + return; + } + destFile.cd(); + TTree *tree = new TTree("tree",""); + + // variables for filling the TTree + Int_t iSM = 0; // SuperModule index + Int_t iHW = 0; + Int_t iAPDNum = 0; + Float_t v30 = 0; + Float_t par[3] = {0}; + Float_t parErr[3] = {0}; + Int_t iBreakDown = 0; + Float_t darkCurrent = 0; + // + Int_t iCol = 0; + Int_t iRow = 0; + // declare the branches + tree->Branch("iSM", &iSM, "iSM/I"); + tree->Branch("iCol", &iCol, "iCol/I"); + tree->Branch("iRow", &iRow, "iRow/I"); + tree->Branch("iHW", &iHW, "iHW/I"); + tree->Branch("APDNum", &iAPDNum, "APDNum/I"); + tree->Branch("V30", &v30, "V30/F"); + tree->Branch("Par", &par, "Par[3]/F"); + tree->Branch("ParErr", &parErr, "ParErr[3]/F"); + tree->Branch("BreakDown", &iBreakDown, "BreakDown/I"); + tree->Branch("DarkCurrent", &darkCurrent, "DarkCurrent/F"); + + Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows; + + for (iSM = 0; iSM < fNSuperModule; iSM++) { + AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD *) fSuperModuleData[iSM]; + + for (Int_t j=0; jGetAPDVal(iCol, iRow); + + if (swapSides) { + // C side, oriented differently than A side: swap is requested + iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol; + iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow; + } + + iHW = v->GetHardWareId(); + iAPDNum = v->GetAPDNum(); + v30 = v->GetV30(); + for (int k=0; k<3; k++) { + par[k] = v->GetPar(k); + parErr[k] = v->GetParErr(k); + } + iBreakDown = v->GetBreakDown(); + darkCurrent = v->GetDarkCurrent(); + + tree->Fill(); + } + + } // i, SuperModule + + tree->Write(); + destFile.Close(); + + return; +} + +//____________________________________________________________________________ +AliEMCALCalibMapAPD::~AliEMCALCalibMapAPD() +{ + fSuperModuleData.Delete(); +} + +//____________________________________________________________________________ +AliEMCALSuperModuleCalibMapAPD * AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDNum(Int_t supModIndex)const +{ // getter via index for (int i=0; iGetSuperModuleNum() == supModIndex) { + return t; } } - return t; + // if we arrived here, then nothing was found.. just return a NULL pointer + return NULL; }