//_HADES_CLASS_DESCRIPTION ///////////////////////////////////////////////////////////// // // HFRpcStripPar // // Container class for FRpc calibration parameters // ///////////////////////////////////////////////////////////// #include "hfrpcstrippar.h" #include "frpcdef.h" #include "hades.h" #include "hdetpario.h" #include "hfrpcdetector.h" #include "hpario.h" #include "hspectrometer.h" #include #include #include using namespace std; void HFRpcStripParCell::clear() { for (Int_t i = 0; i < nzones; ++i) strip_pars[i] = 0.f; } void HFRpcStripParCell::fill(Float_t *data) { memcpy(strip_pars, data, sizeof(strip_pars[0]) * nzones); } void HFRpcStripParCell::fill(HFRpcStripParCell &r) { memcpy(strip_pars, r.strip_pars, sizeof(strip_pars[0]) * nzones); } HFRpcStripParSec::HFRpcStripParSec(Int_t n) { // constructor creates an array of pointers of type HFRpcStripParCell array = new TObjArray(n); for (Int_t i = 0; i < n; i++) { array->AddAt(new HFRpcStripParCell(), i); } } HFRpcStripParSec::~HFRpcStripParSec() { // destructor array->Delete(); delete array; } HFRpcStripPar::HFRpcStripPar(const Char_t *name, const Char_t *title, const Char_t *context) : HParSet(name, title, context) { // constructor creates an array of pointers of type HFRpcStripParSec // constructor creates an array of pointers of type HEmcStripParSec strcpy(detName, "FRpc"); HFRpcDetector *det = (HFRpcDetector *)(gHades->getSetup()->getDetector("FRpc")); if (!det) { Error("HFRpcStripPar", "FRpc detector doesn't exists\n"); abort(); } array = new TObjArray(FRPC_MAX_SECTORS); for (Int_t i = 0; i < FRPC_MAX_SECTORS; i++) { if (det->getModule(i, 0) > 0) { array->AddAt(new HFRpcStripParSec(FRPC_MAX_STRIPS), i); } else { array->AddAt(new HFRpcStripParSec(0), i); } } } HFRpcStripPar::~HFRpcStripPar() { // destructor if (array) { array->Delete(); delete array; } } Bool_t HFRpcStripPar::init(HParIo *inp, Int_t *set) { // intitializes the container from an input HDetParIo *input = inp->getDetParIo("HFRpcParIo"); if (input) return (input->init(this, set)); return kFALSE; } Int_t HFRpcStripPar::write(HParIo *output) { // writes the container to an output HDetParIo *out = output->getDetParIo("HFRpcParIo"); if (out) return out->write(this); return -1; } void HFRpcStripPar::clear() { // clears the container for (Int_t i = 0; i < getSize(); i++) { HFRpcStripParSec &sec = (*this)[i]; for (Int_t j = 0; j < sec.getSize(); j++) sec[j].clear(); } status = kFALSE; resetInputVersions(); } void HFRpcStripPar::printParams() { // prints the calibration parameters printf("Calibration parameters for the FRpc\n"); printf(" sector(0...3) strip(0...31) StripPars 0..n\n"); Float_t data[HFRpcStripParCell::nzones]; for (Int_t i = 0; i < getSize(); i++) { HFRpcStripParSec &sec = (*this)[i]; for (Int_t j = 0; j < sec.getSize(); j++) { HFRpcStripParCell &cell = sec[j]; cell.getData(data); printf("%4i %4i", i, j); for (Int_t k = 0; k < HFRpcStripParCell::nzones; ++k) printf(" %f", data[k]); putchar('\n'); } } } void HFRpcStripPar::readline(const Char_t *buf, Int_t *set) { // decodes one line read from ASCII file I/O Int_t sector, strip; Float_t data[HFRpcStripParCell::nzones] = {0.f}; Int_t read_bytes = 0, read_bytes_f = 0; Int_t n = sscanf(buf, "%i%i%n", §or, &strip, &read_bytes); for (Int_t k = 0; k < HFRpcStripParCell::nzones; ++k) { n += sscanf(buf + read_bytes, "%f%n", &data[k], &read_bytes_f); read_bytes += read_bytes_f; } if (n < (HFRpcStripParCell::nzones + 2)) { Error("readline", "Not enough values in line %s\n", buf); } else if (n > (HFRpcStripParCell::nzones + 2)) { Error("readline", "Too many values in line %s\n", buf); } else { if (sector < 0 || sector > 3) return; if (!set[sector]) return; if (strip < 0) { Error("readline", "FRPC strip %d not defined\n", strip); return; } (*this)[sector][strip].fill(data); set[sector] = 999; } } void HFRpcStripPar::putAsciiHeader(TString &header) { // puts the ascii header to the string used in HFRpcParAsciiFileIo header = "# Calibration parameters for the FRpc\n" "# Format:\n" "# sector(0...3) strip(0...31) StripPars 0..n\n"; } void HFRpcStripPar::write(fstream &fout) { Text_t buf[20 + HFRpcStripParCell::nzones * 16]; Float_t data[HFRpcStripParCell::nzones]; for (Int_t i = 0; i < getSize(); i++) { HFRpcStripParSec §or = (*this)[i]; for (Int_t j = 0; j < sector.getSize(); j++) { HFRpcStripParCell &cell = sector[j]; cell.getData(data); Int_t last_pos = sprintf(buf, "%4i %4i", i, j); for (Int_t k = 0; k < HFRpcStripParCell::nzones; ++k) last_pos += sprintf(buf + last_pos, " %f", data[k]); fout << buf<< endl; } } }