// File: hrichparora2io.pc // // AUTHOR : Ilse Koenig // Created : 10/03/2010 by I. Koenig // //_HADES_CLASS_DESCRIPTION ////////////////////////////////////////////////////////////////////////////// // HRichParOra2Io // // Interface class to database Oracle for input/output of parameters needed // by the Rich for runs since 2010 // (uses the Oracle C/C++ precompiler) // ////////////////////////////////////////////////////////////////////////////// using namespace std; #include "hrichparora2io.h" #include "hparora2set.h" #include "hrichmappingpar.h" #include "hrichcalpar.h" #include "hrichcalparcell.h" #include "hrichthresholdpar.h" #include "hrich700trb3lookup.h" #include "hrich700thresholdpar.h" #include "hrich700geompar.h" #include "hgeomcompositevolume.h" #include "hora2geomdetversion.h" #include "richdef.h" #include "TClass.h" #include #include #include #define SQLCA_STORAGE_CLASS extern #define ORACA_STORAGE_CLASS extern // JAM2018: enable this one to get verbose output when reading geometry parameter //#define JAM_GEO_DEBUG 1 // Oracle communication area #include // SQL Communications Area /* Include the SQL Communications Area, a structure through * which ORACLE makes runtime status information such as error * codes, warning flags, and diagnostic text available to the * program. */ #include ClassImp(HRichParOra2Io) #define RICH_MAXSECT 6 #define RICH_MAXPADS 4900 #define RICH700_MAXPMT 576 HRichParOra2Io::HRichParOra2Io(HOra2Conn* pC) : HDetParOra2Io(pC), geomVers(0) { // constructor // sets the name of the I/O class "HRichParIo" // gets the pointer to the connection class fName="HRichParIo"; initModules=new TArrayI(RICH_MAX_SECTORS); } HRichParOra2Io::~HRichParOra2Io() { // destructor if (initModules) delete initModules; } Bool_t HRichParOra2Io::init(HParSet* pPar,Int_t* set) { // calls special read-function for each parameter container if (getRunStart(pPar)<0) { pPar->setInputVersion(-1,inputNumber); return kFALSE; } const Text_t* name=pPar->IsA()->GetName(); if (strcmp(name,"HRichMappingPar")==0) return read(((HRichMappingPar*)pPar),set); if (strcmp(name,"HRichCalPar")==0) return read(((HRichCalPar*)pPar),set); if (strcmp(name,"HRichThresholdPar")==0) return read(((HRichThresholdPar*)pPar),set); if (strcmp(name,"HRich700Trb3Lookup")==0) return read(((HRich700Trb3Lookup*)pPar),set); if (strcmp(name,"HRich700ThresholdPar")==0) return read(((HRich700ThresholdPar*)pPar),set); if (strcmp(name,"HRich700GeomPar")==0) return read(((HRich700GeomPar*)pPar),set); cout<<"No read-interface to Oracle for parameter container " <GetName()<IsA()->GetName(); if (!strcmp(name,"HRichMappingPar")) return writePar((HRichMappingPar*)pPar); if (!strcmp(name,"HRichCalPar")) return writePar((HRichCalPar*)pPar); if (!strcmp(name,"HRichThresholdPar")) return writePar((HRichThresholdPar*)pPar); if (!strcmp(name,"HRich700Trb3Lookup")) return writePar((HRich700Trb3Lookup*)pPar); if (!strcmp(name,"HRich700ThresholdPar")) return writePar((HRich700ThresholdPar*)pPar); if (!strcmp(name,"HRich700GeomPar")) return writeAlignment((HRich700GeomPar*)pPar); cout<<"No write-interface to Oracle for parameter container " <GetName()<At(i)) { if (first) { cout<At(i)-1)<<" "; } } cout<<'\n'; } Bool_t HRichParOra2Io::getVersion(HParSet* pPar,Int_t& version) { // checks, if the parameter container needs to be reinitialized // reads the newest version valid for the current event file // returns kTRUE, if new parameters must be read // returns kFALSE, if no reinitialization needed or no valid version found HParOra2Set* oraSet=getOraSet(pPar); const Char_t* containerClass=pPar->IsA()->GetName(); if (strcmp(containerClass,"HRichThresholdPar")==0) oraSet->contextId=0; // container has no context if (oraSet->contextId==-1 || runStart<0) { pPar->setInputVersion(-1,inputNumber); version=-1; return kFALSE; } Int_t contVers=pPar->getInputVersion(inputNumber); if (contVers!=-1 && runStart>=oraSet->versDate[0] && runStart<=oraSet->versDate[1]) { version=contVers; return kFALSE; } oraSet->clearVersDate(); EXEC SQL BEGIN DECLARE SECTION; int context; int vers; double since; double until; EXEC SQL END DECLARE SECTION; context=oraSet->contextId; EXEC SQL WHENEVER SQLERROR DO showSqlError("getVersion(HParSet*,Int_t&)"); EXEC SQL WHENEVER NOT FOUND GOTO notfound; if (strcmp(containerClass,"HRichCalPar")==0) { EXEC SQL SELECT version, hanadate.date_to_number(valid_since), hanadate.date_to_number(valid_until) INTO :vers, :since, :until FROM rich_ana2.rich_calpar_vers_at_date WHERE context_id = :context; } else if (strcmp(containerClass,"HRichMappingPar")==0) { EXEC SQL SELECT version, hanadate.date_to_number(valid_since), hanadate.date_to_number(valid_until) INTO :vers, :since, :until FROM rich_ana2.rich_mappingpar_vers_at_date WHERE context_id = :context; } else if (strcmp(containerClass,"HRichThresholdPar")==0) { EXEC SQL SELECT version, hanadate.date_to_number(valid_since), hanadate.date_to_number(valid_until) INTO :vers, :since, :until FROM rich_ana2.rich_thresholdpar_vers_at_date; } else if (strcmp(containerClass,"HRich700Trb3Lookup")==0) { EXEC SQL SELECT version, hanadate.date_to_number(valid_since), hanadate.date_to_number(valid_until) INTO :vers, :since, :until FROM rich_ana2.rich700_lookup_vers_at_date WHERE context_id = :context; } else if (strcmp(containerClass,"HRich700ThresholdPar")==0) { EXEC SQL SELECT version, hanadate.date_to_number(valid_since), hanadate.date_to_number(valid_until) INTO :vers, :since, :until FROM rich_ana2.rich700_threshold_vers_at_date WHERE context_id = :context; } version=vers; oraSet->versDate[0]=since; oraSet->versDate[1]=until; return kTRUE; notfound: pPar->setInputVersion(-1,inputNumber); version=-1; return kFALSE; } Bool_t HRichParOra2Io::read(HRichMappingPar* pPar, Int_t* set) { // reads the unpacker lookup table and fill the RichMappingPar container Int_t oraVersion=-1; Bool_t rc=getVersion(pPar,oraVersion); if (oraVersion<0) return kFALSE; if (oraVersion>=0&&rc==kFALSE) return kTRUE; pPar->clear(); EXEC SQL BEGIN DECLARE SECTION; int vers; struct { int p_col[RICH_MAXPADS]; int p_row[RICH_MAXPADS]; unsigned int adc[RICH_MAXPADS]; unsigned int apv[RICH_MAXPADS]; unsigned int chan[RICH_MAXPADS]; } map; EXEC SQL END DECLARE SECTION; vers=oraVersion; EXEC SQL WHENEVER SQLERROR DO showSqlError("read(HRichMappingPar*,Int_t*)"); EXEC SQL WHENEVER NOT FOUND continue; EXEC SQL SELECT pad_col, pad_row, adc, apv, channel INTO :map FROM rich_ana2.rich_mappingpar_data_view WHERE vers_id =:vers; rc=kTRUE; for (Int_t i=0;isetAddress(map.p_row[i],map.p_col[i],map.adc[i],map.apv[i],map.chan[i]); } if (sqlca.sqlerrd[2]>0&&rc) { setChanged(pPar,oraVersion); cout<GetName()<<" initialized from Oracle"<setInputVersion(-1,inputNumber); } return rc; } Bool_t HRichParOra2Io::read(HRichCalPar* pPar, Int_t* set) { // reads the calibration parameters and fill the RichCalPar container Int_t oraVersion=-1; Bool_t rc=getVersion(pPar,oraVersion); if (oraVersion<0) return kFALSE; if (oraVersion>=0&&rc==kFALSE) return kTRUE; pPar->clear(); initModules->Reset(); EXEC SQL BEGIN DECLARE SECTION; int vers; struct { int sec[RICH_MAXPADS]; int p_col[RICH_MAXPADS]; int p_row[RICH_MAXPADS]; float of[RICH_MAXPADS]; //offset float si[RICH_MAXPADS]; //sigma } cal; EXEC SQL END DECLARE SECTION; vers=oraVersion; EXEC SQL WHENEVER SQLERROR DO showSqlError("read(HRichCalPar*,Int_t*)"); EXEC SQL WHENEVER NOT FOUND CONTINUE; EXEC SQL DECLARE cal_cur CURSOR FOR SELECT sector, pad_col, pad_row, offset, sigma FROM rich_ana2.rich_calpar_data_view WHERE vers_id =:vers; Bool_t isOpenCursor=kFALSE; Bool_t allFound=kTRUE; Int_t s=-1, nTot=0, nLast=0; HLocation loc; loc.setNIndex(3); HRichCalParCell* pCell=0; vers=oraVersion; EXEC SQL OPEN cal_cur; isOpenCursor=kTRUE; do { EXEC SQL FETCH cal_cur INTO :cal; nLast=sqlca.sqlerrd[2]-nTot; if (nLast>0) { for (Int_t i=0;igetSlot(loc); if (pCell) { pCell->setParams(cal.of[i],cal.si[i]); } else { Error("read(HRichCalPar*,Int_t*)", "slot not found: %i %i %i",loc[0],loc[1],loc[2]); allFound=kFALSE; break; } initModules->AddAt(1,s); } nTot++; } } } while (nLast==RICH_MAXPADS&&nTot<=29400&&allFound); if (isOpenCursor) { EXEC SQL CLOSE cal_cur; for(Int_t i=0;i0 && initModules->At(i)==0) allFound=kFALSE; } } else allFound=kFALSE; if (allFound) { setChanged(pPar,oraVersion); printInfo(pPar->GetName()); } else { pPar->setInputVersion(-1,inputNumber); } return allFound; } Bool_t HRichParOra2Io::read(HRichThresholdPar* pPar, Int_t* set) { // reads the thresholds and fill the RichThresholdPar container Int_t oraVersion=-1; Bool_t rc=getVersion(pPar,oraVersion); if (oraVersion<0) return kFALSE; if (oraVersion>=0&&rc==kFALSE) return kTRUE; pPar->clear(); EXEC SQL BEGIN DECLARE SECTION; int vers; struct { int sec[RICH_MAXSECT]; int calparvers[RICH_MAXSECT]; float multsigma[RICH_MAXSECT]; } thres; EXEC SQL END DECLARE SECTION; vers=oraVersion; EXEC SQL WHENEVER SQLERROR DO showSqlError("read(HRichThresholdPar*,Int_t*)"); EXEC SQL WHENEVER NOT FOUND continue; EXEC SQL SELECT sector_id, calpar_vers_id, multiply_sigma INTO :thres FROM rich_ana2.rich_thresholdpar_data_view WHERE vers_id =:vers; rc=kTRUE; for (Int_t i=0;isetCalParVers(thres.calparvers[i]); pPar->setSigmaMultiplier(thres.sec[i]-1,thres.multsigma[i]); } if (sqlca.sqlerrd[2]>0) { setChanged(pPar,oraVersion); cout<GetName()<<" initialized from Oracle"<setInputVersion(-1,inputNumber); rc=kFALSE; } return rc; } Bool_t HRichParOra2Io::read(HRich700Trb3Lookup* pPar, Int_t* set) { // reads the rich700 trb3 unpacker lookup table and fills container JAM 2017 Int_t oraVersion=-1; Bool_t rc=getVersion(pPar,oraVersion); if (oraVersion<0) return kFALSE; if (oraVersion>=0&&rc==kFALSE) return kTRUE; pPar->clear(); EXEC SQL BEGIN DECLARE SECTION; int vers; struct { int address[RICH700_MAXPIXELS]; int chan[RICH700_MAXPIXELS]; int pmt[RICH700_MAXPIXELS]; int pixel[RICH700_MAXPIXELS]; } lookup; EXEC SQL END DECLARE SECTION; vers=oraVersion; EXEC SQL WHENEVER SQLERROR DO showSqlError("read(HRich700Trb3Lookup*)"); EXEC SQL WHENEVER NOT FOUND CONTINUE; EXEC SQL SELECT trbnet_address, channel, pmt_id, pmt_pixel INTO :lookup FROM rich_ana2.rich700_trb3lookup_data_view WHERE vers_id = :vers; Int_t nData=sqlca.sqlerrd[2]; for (Int_t i=0;ifill(lookup.address[i],lookup.chan[i], lookup.pmt[i],lookup.pixel[i]); } if (nData>0) { setChanged(pPar,oraVersion); cout<GetName()<<" initialized from Oracle"<setInputVersion(-1,inputNumber); rc=kFALSE; } return rc; } Bool_t HRichParOra2Io::read(HRich700ThresholdPar* pPar, Int_t* set) { // reads the rich700 trb3 unpacker pixel threshold table and fills container JAM 2017 Int_t oraVersion=-1; Bool_t rc=getVersion(pPar,oraVersion); if (oraVersion<0) return kFALSE; if (oraVersion>=0&&rc==kFALSE) return kTRUE; pPar->clear(); EXEC SQL BEGIN DECLARE SECTION; int vers; struct { int pmt[RICH700_MAXPIXELS]; int pixel[RICH700_MAXPIXELS]; float tmin [RICH700_MAXPIXELS]; float tmax [RICH700_MAXPIXELS]; float totmin [RICH700_MAXPIXELS]; float totmax [RICH700_MAXPIXELS]; int flag[RICH700_MAXPIXELS]; } thresholds; EXEC SQL END DECLARE SECTION; vers=oraVersion; EXEC SQL WHENEVER SQLERROR DO showSqlError("read(HRich700ThresholdPar*)"); EXEC SQL WHENEVER NOT FOUND CONTINUE; EXEC SQL SELECT pmt_id, pmt_pixel, t_min, t_max, tot_min, tot_max, status INTO :thresholds FROM rich_ana2.rich700_threshold_data_view WHERE vers_id = :vers; Int_t nData=sqlca.sqlerrd[2]; for (Int_t i=0;isetPixelThreshold( thresholds.pmt[i],thresholds.pixel[i], thresholds.tmin[i],thresholds.tmax[i], thresholds.totmin[i],thresholds.totmax[i], thresholds.flag[i] ); } if (nData>0) { setChanged(pPar,oraVersion); cout<GetName()<<" initialized from Oracle"<setInputVersion(-1,inputNumber); rc=kFALSE; } return rc; } Bool_t HRichParOra2Io::read(HRich700GeomPar* pPar, Int_t* set) { // reads the geometry of the Forward Wall and fills the Rich700GeomPar container Bool_t allFound=kTRUE; Int_t detId=-1; if (!geomVers) { #ifdef JAM_GEO_DEBUG std::cout<<" HRichParOra2Io::read(HRich700GeomPar* ) has detector name "<getDetectorName()<< std::endl; #endif detId=getDetectorId(pPar->getDetectorName()); #ifdef JAM_GEO_DEBUG std::cout<<" HRichParOra2Io::read(HRich700GeomPar* ) has detector id "<getDetectorName(),detId); #ifdef JAM_GEO_DEBUG std::cout<<" HRichParOra2Io::read(HRich700GeomPar* ) has geomVers:"<GetName()<< std::endl; geomVers->Print(); #endif } else { detId=geomVers->getDetectorId(); } if (detId<=0) { allFound=kFALSE; delete geomVers; geomVers=0; } if (detId>0&&pPar->isFirstInitialization()) { if (!readModGeomNames(pPar) || !readCompGeomNames(pPar)) { allFound=kFALSE; pPar->clear(); } else addGeomOraSet(pPar); } if (allFound) allFound=readDetectorGeometry(pPar,set,geomVers); return allFound; } Bool_t HRichParOra2Io::readModGeomNames(HRich700GeomPar* pPar) { // sets the geometry object name of the module and creates the reference volume if not existing Bool_t allFound=kFALSE; TString modName=pPar->getDetectorName(); modName.ToUpper(); HModGeomPar* pMod=pPar->getModule(-1,0); if (pMod) { pMod->SetName(modName); pMod->setRefName(modName); HGeomCompositeVolume* refMod=pPar->getRefVolume(0); if (refMod==0) { #ifdef JAM_GEO_DEBUG std::cout<<" HRichParOra2Io::readModGeomNames(HRich700GeomPar* ) creates new refmod with "<getNumComponents() <<" components and name "<getNumComponents()); refMod->SetName(modName); pPar->addRefVolume(refMod,0); } pMod->setVolume(refMod); allFound=kTRUE; } return allFound; } Bool_t HRichParOra2Io::readCompGeomNames(HRich700GeomPar* pPar) { // reads the names of all cells in the geometry tables EXEC SQL BEGIN DECLARE SECTION; struct { int cell [RICH700_MAX_PMT]; varchar oname[RICH700_MAX_PMT][9]; } lrecG; EXEC SQL END DECLARE SECTION; EXEC SQL WHENEVER SQLERROR DO showSqlError("readCompGeomNames(...)"); EXEC SQL WHENEVER NOT FOUND CONTINUE; EXEC SQL SELECT pmt_id, geom_obj_name INTO :lrecG FROM rich_ana2.rich700_pmt WHERE geom_obj_name IS NOT NULL; Int_t nCells=sqlca.sqlerrd[2]; #ifdef JAM_GEO_DEBUG std::cout<<" HRichParOra2Io::readCompGeomNames(HRich700GeomPar* ) finds "<getModule(-1,0); #ifdef JAM_GEO_DEBUG if(!pMod) { std::cout<<" HRichParOra2Io::readCompGeomNames(HRich700GeomPar* ) can not find first module! "<< std::endl; return kFALSE; } std::cout<<" HRichParOra2Io::readCompGeomNames(HRich700GeomPar* ) has first module "<GetName()<< std::endl; #endif HGeomCompositeVolume* pRefMod=pMod->getRefVolume(); #ifdef JAM_GEO_DEBUG if(!pRefMod) { std::cout<<" HRichParOra2Io::readCompGeomNames(HRich700GeomPar* ) can not find reference volume! "<< std::endl; return kFALSE; } std::cout<<" HRichParOra2Io::readCompGeomNames(HRich700GeomPar* ) has reference volume "<GetName()<< std::endl; #endif lrecG.oname[k].arr[lrecG.oname[k].len]='\0'; HGeomVolume* volu=pRefMod->getComponent((lrecG.cell[k]-1)); #ifdef JAM_GEO_DEBUG if(!volu) { std::cout<<" HRichParOra2Io::readCompGeomNames(HRich700GeomPar* ) can not find component volume "<SetName((Char_t*)(lrecG.oname[k].arr)); #ifdef JAM_GEO_DEBUG std::cout<<" HRichParOra2Io::readCompGeomNames(HRich700GeomPar* ) sets component volume name to"<GetName()<< std::endl; #endif } return (nCells>0) ? kTRUE : kFALSE; } Int_t HRichParOra2Io::createVers(HParSet* pPar) { // creates a new version for the parameters // returns the new version cout<<"--------------- "<GetName()<<" ---------------\n"; if (strlen(pPar->getAuthor())==0) { Error("createVers(...)", "author of parameters not defined"); return -1; } if (strlen(pPar->getDescription())==0) { Error("createVers(...)", "descriction of parameters not defined"); return -1; } const Char_t* contName=pPar->IsA()->GetName(); EXEC SQL BEGIN DECLARE SECTION; int context; int vers=-1; int run; char* creator; char* descript; EXEC SQL END DECLARE SECTION; context = getContextId(contName,pPar->getParamContext()); if (context==-1) return -1; run=getActRunId(); creator=(Char_t*)pPar->getAuthor(); descript=(Char_t*)pPar->getDescription(); EXEC SQL WHENEVER SQLERROR GOTO not_found; EXEC SQL WHENEVER NOT FOUND GOTO not_found; if (strcmp(contName,"HRichCalPar")==0) { EXEC SQL EXECUTE BEGIN SELECT rich_ana2.rich_par_query.next_version INTO :vers FROM DUAL; INSERT INTO rich_ana2.rich_calpar_vers (vers_id, orig_context_id, run_id, author, description) VALUES (:vers, :context, :run, :creator, :descript); END; END-EXEC; } else if (strcmp(contName,"HRichMappingPar")==0) { EXEC SQL EXECUTE BEGIN SELECT rich_ana2.rich_par_query.next_version INTO :vers FROM DUAL; INSERT INTO rich_ana2.rich_mappingpar_vers (vers_id, orig_context_id, run_id, author, description) VALUES (:vers, :context, :run, :creator, :descript); END; END-EXEC; } else if (strcmp(contName,"HRich700Trb3Lookup")==0) { EXEC SQL EXECUTE BEGIN SELECT rich_ana2.rich_par_query.next_version INTO :vers FROM DUAL; INSERT INTO rich_ana2.rich700_trb3lookup_vers (vers_id, orig_context_id, run_id, author, description) VALUES (:vers, :context, :run, :creator, :descript); END; END-EXEC; } else if (strcmp(contName,"HRich700ThresholdPar")==0) { EXEC SQL EXECUTE BEGIN SELECT rich_ana2.rich_par_query.next_version INTO :vers FROM DUAL; INSERT INTO rich_ana2.rich700_threshold_vers (vers_id, orig_context_id, run_id, author, description) VALUES (:vers, :context, :run, :creator, :descript); END; END-EXEC; } cout<<"Oracle version for "<GetName()<<" created: "<getHWAddress(r,c,a1,a2,a3)) { vers[nCell]=version; x[nCell]=c; y[nCell]=r; adc[nCell]=a1; apv[nCell]=a2; chan[nCell]=a3; nCell++; } } } if (nCell>0) {; rows_to_insert=nCell; EXEC SQL WHENEVER SQLERROR GOTO not_found; EXEC SQL WHENEVER NOT FOUND GOTO not_found; EXEC SQL FOR :rows_to_insert INSERT INTO rich_ana2.rich_mappingpar_data (vers_id, pad_pos_id, adc, apv, channel) VALUES (:vers, rich_ana2.rich_par_query.get_pad_pos_id(:x,:y), :adc, :apv, :chan); cout<setChanged(kFALSE); return version; not_found: showSqlError("writePar(HRichMappingPar*)"); rollback(); pPar->setChanged(kFALSE); return -1; } Int_t HRichParOra2Io::writePar(HRichCalPar* pPar) { // creates a new version and writes the calibration parameters to Oracle // returns the version number or -1 if an error occurs cout<<"****************************************************************\n"; Int_t version=createVers(pPar); if (version==-1) return -1; EXEC SQL BEGIN DECLARE SECTION; int vers[RICH_MAXPADS]; int sec[RICH_MAXPADS]; int x[RICH_MAXPADS]; int y[RICH_MAXPADS]; float ofs[RICH_MAXPADS]; float sig[RICH_MAXPADS]; int rows_to_insert; EXEC SQL END DECLARE SECTION; HLocation loc; loc.set(3,0,0,0); HRichCalParCell* pCell=0; Float_t csi=0.F; for(Int_t s=0;sgetObject(loc); if (pCell) { csi=pCell->getSigma(); if (csi != 0.F) { // only non-default values vers[nCell]=version; sec[nCell]=s+1; x[nCell]=c; y[nCell]=r; ofs[nCell]=pCell->getOffset(); sig[nCell]=csi; nCell++; } } } } if (nCell==0) continue; rows_to_insert=nCell; EXEC SQL WHENEVER SQLERROR GOTO not_found; EXEC SQL WHENEVER NOT FOUND GOTO not_found; EXEC SQL FOR :rows_to_insert INSERT INTO rich_ana2.rich_calpar_data (vers_id, pad_id, offset, sigma) VALUES (:vers, rich_ana2.rich_par_query.get_pad_id(:sec,:x,:y), :ofs, :sig); cout<<"sector: "<<(s+1)<<" "<setChanged(kFALSE); return version; not_found: showSqlError("writePar(HRichCalPar*)"); rollback(); pPar->setChanged(kFALSE); return -1; } Int_t HRichParOra2Io::createThresholdVers(HRichThresholdPar* pPar) { // creates a new version for the parameters // returns the new version cout<<"--------------- "<GetName()<<" ---------------\n"; if (strlen(pPar->getAuthor())==0) { Error("createVers(...)", "author of parameters not defined"); return -1; } EXEC SQL BEGIN DECLARE SECTION; int vers=-1; int calparvers; char* creator; char* descript; short descript_Ind; EXEC SQL END DECLARE SECTION; calparvers=pPar->getCalParVers(); creator=(Char_t*)pPar->getAuthor(); descript=0; if (strlen(pPar->getDescription())>0) { descript=(Char_t*)pPar->getDescription(); descript_Ind=0; } else descript_Ind=-1; EXEC SQL WHENEVER SQLERROR GOTO not_found; EXEC SQL WHENEVER NOT FOUND GOTO not_found; EXEC SQL EXECUTE BEGIN SELECT rich_ana2.rich_par_query.next_version INTO :vers FROM DUAL; INSERT INTO rich_ana2.rich_thresholdpar_vers (vers_id, calpar_vers_id, author, description) VALUES (:vers, :calparvers, :creator, :descript:descript_Ind); END; END-EXEC; cout<<"Oracle version for "<GetName()<<" created: "<getSigmaMultiplier(s); nData++; } if (nData>0) {; rows_to_insert=nData; EXEC SQL WHENEVER SQLERROR GOTO not_found; EXEC SQL WHENEVER NOT FOUND GOTO not_found; EXEC SQL FOR :rows_to_insert INSERT INTO rich_ana2.rich_thresholdpar_data (vers_id, sector_id, multiply_sigma) VALUES (:vers, :sec, :multsigma ); cout<setChanged(kFALSE); return version; not_found: showSqlError("writePar(HRichThresholdPar*)"); rollback(); pPar->setChanged(kFALSE); return -1; } Int_t HRichParOra2Io::writePar(HRich700Trb3Lookup* pPar) { // creates a new version and writes the lookup table to Oracle Int_t version=createVers(pPar); if (version==-1) return -1; EXEC SQL BEGIN DECLARE SECTION; int rows_to_insert; int vers[RICH700_MAXPIXELS]; int address[RICH700_MAXPIXELS]; int chan[RICH700_MAXPIXELS]; int pmt[RICH700_MAXPIXELS]; int pixel[RICH700_MAXPIXELS]; EXEC SQL END DECLARE SECTION; Int_t nChan=0; Int_t arrayOffset=pPar->getArrayOffset(); for(Int_t t=0;tgetSize();t++) { HRich700Trb3LookupTdc* tdc=(*pPar)[t]; if (tdc) { nChan=0; for(Int_t c=0;cgetSize();c++) { HRich700Trb3LookupChan& rChan=(*tdc)[c]; if (rChan.getPMT()!=-1 && rChan.getPixel()!=-1) { vers[nChan]=version; address[nChan]=arrayOffset+t; chan[nChan]=c; pmt[nChan]=rChan.getPMT(); pixel[nChan]=rChan.getPixel(); nChan++; } } // JAM TODO: insert pmt, pixid into data table // since we directly map pmt and pixel, no further query function is needed now rows_to_insert=nChan; EXEC SQL WHENEVER SQLERROR GOTO errorfound; EXEC SQL WHENEVER NOT FOUND GOTO errorfound; EXEC SQL FOR :rows_to_insert //CALL rich_ana2.rich700_par_query.get_pixel_id(:col, :row, :pmt, :pmt_pixel); INSERT INTO rich_ana2.rich700_trb3lookup_data (vers_id, trbnet_address, channel_id, pmt_id, pmt_pixel) VALUES (:vers, :address, :chan, :pmt, :pixel); cout<<"Trbnet-address "<<"0x"<setChanged(kFALSE); return version; errorfound: showSqlError("writePar(HRich700Trb3Lookup*)"); rollback(); pPar->setChanged(kFALSE); return -1; } Int_t HRichParOra2Io::writePar(HRich700ThresholdPar* pPar) { // JAM 1-Nov-2017: creates a new version and writes the threshold table to Oracle Int_t version=createVers(pPar); if (version==-1) return -1; EXEC SQL BEGIN DECLARE SECTION; int rows_to_insert; int vers[RICH700_MAXPIXELS]; int pmt[RICH700_MAXPIXELS]; int pixel[RICH700_MAXPIXELS]; float tmin [RICH700_MAXPIXELS]; float tmax [RICH700_MAXPIXELS]; float totmin [RICH700_MAXPIXELS]; float totmax [RICH700_MAXPIXELS]; int flag[RICH700_MAXPIXELS]; EXEC SQL END DECLARE SECTION; HLocation loc; loc.set(2,0,0); HRich700PixelThreshold* pCell=0; Int_t nCell=0; for (Int_t p = 1; p <= RICH700_MAX_PMT; ++p) { loc[0] = p; for (Int_t q = 1; q <= RICH700_MAX_PMTPIXELS; ++q) { loc[1] = q; pCell = static_cast(pPar->getObject(loc)); if (NULL != pCell) { if(pCell->getFlag() == -1) continue; // skip non configured pixels with default flag vers[nCell]=version; pmt[nCell]=pCell->getPMT(); pixel[nCell]=pCell->getPixel(); tmin [nCell]=pCell->getT_Min(); tmax [nCell]=pCell->getT_Max(); totmin [nCell]=pCell->getTot_Min(); totmax [nCell]=pCell->getTot_Max(); flag[nCell]=pCell->getFlag(); nCell++; } // pCell } //pix } //pmt if (nCell==0) return -1; rows_to_insert=nCell; EXEC SQL WHENEVER SQLERROR GOTO errorfound; EXEC SQL WHENEVER NOT FOUND GOTO errorfound; EXEC SQL FOR :rows_to_insert INSERT INTO rich_ana2.rich700_threshold_data (vers_id, pmt_id, pmt_pixel, par_0, par_1, par_2, par_3, status) VALUES (:vers, :pmt, :pixel, :tmin, :tmax, :totmin, :totmax, :flag); cout<<"HRich700ThresholdPar inserted "<setChanged(kFALSE); return version; errorfound: showSqlError("writePar(HRich700ThresholdPar*)"); rollback(); pPar->setChanged(kFALSE); return -1; }