//_HADES_CLASS_DESCRIPTION ////////////////////////////////////////////////////////////////////////////// // HStsParOra2Io // // Interface class to database Oracle for input/output of parameters needed // by the FWDET for runs since 2019 // (uses the Oracle C/C++ precompiler) // ////////////////////////////////////////////////////////////////////////////// using namespace std; #include "hstsparora2io.h" #include "hparora2set.h" #include "hststrb3lookup.h" #include "hstscalpar.h" #include "hstsgeompar.h" #include "hgeomcompositevolume.h" #include "hora2geomdetversion.h" #include "hora2geomobj.h" //#include "fwdetdef.h" // JAM2019 - here we have const int instead defines. does this work for precompiler arrays? // better redefine it here: #define FWDET_STRAW_MAX_MODULES 2 #define FWDET_STRAW_MAX_LAYERS 4 #define FWDET_STRAW_MAX_STRAWS 224 #define FWDET_STRAW_MAX_SUBCELLS 4 #define FWDET_STRAW_MAX_GLOBALCELLS \ FWDET_STRAW_MAX_MODULES * FWDET_STRAW_MAX_LAYERS * FWDET_STRAW_MAX_STRAWS * FWDET_STRAW_MAX_SUBCELLS // = 7168 #define FWDET_STRAW_MAX_GLOBAL_LAYERS FWDET_STRAW_MAX_MODULES * FWDET_STRAW_MAX_LAYERS #define FWDET_STRAW_MAX_LAYER_CELLS FWDET_STRAW_MAX_STRAWS * FWDET_STRAW_MAX_SUBCELLS #include "TClass.h" #include "TList.h" #include #include #include #define SQLCA_STORAGE_CLASS extern #define ORACA_STORAGE_CLASS extern // Oracle communication area #include // SQL Communications Area #include ClassImp(HStsParOra2Io) HStsParOra2Io::HStsParOra2Io(HOra2Conn* pC) : HDetParOra2Io(pC) { // constructor // sets the name of the I/O class "HStsParIo" // gets the pointer to the connection class fName="HStsParIo"; initModules=new TArrayI(FWDET_STRAW_MAX_GLOBAL_LAYERS); geomVers=0; sensVolume=0; } HStsParOra2Io::~HStsParOra2Io(void) { // destructor if (initModules) delete initModules; if (geomVers) delete geomVers; if (sensVolume) delete sensVolume; } Bool_t HStsParOra2Io::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,"HStsTrb3Lookup")==0) return read(((HStsTrb3Lookup*)pPar)); if (strcmp(name,"HStsCalPar")==0) return read(((HStsCalPar*)pPar)); if (strcmp(name,"HStsGeomPar")==0) return read(((HStsGeomPar*)pPar),set); cout<<"No read-interface to Oracle for parameter container " <GetName()<IsA()->GetName(); cout <<"HStsParOra2Io::write("<GetName()<contextId==-1 || runStart==-1) { 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; } const Char_t* containerClass=pPar->IsA()->GetName(); 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,"HStsTrb3Lookup")==0) { EXEC SQL SELECT version, hanadate.date_to_number(valid_since), hanadate.date_to_number(valid_until) INTO :vers, :since, :until FROM fwdet_ana2.straw_trb3lookup_vers_at_date WHERE context_id = :context; } else if (strcmp(containerClass,"HStsCalPar")==0) { EXEC SQL SELECT version, hanadate.date_to_number(valid_since), hanadate.date_to_number(valid_until) INTO :vers, :since, :until FROM fwdet_ana2.straw_calpar_vers_at_date WHERE context_id = :context; } else {} version=vers; oraSet->versDate[0]=since; oraSet->versDate[1]=until; return kTRUE; notfound: pPar->setInputVersion(-1,inputNumber); version=-1; return kFALSE; }; Bool_t HStsParOra2Io::read(HStsTrb3Lookup* pPar) { // reads the lookup table for the Trb3 unpacker and fill the container FwdetStrawTrb3Lookup 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[FWDET_STRAW_MAX_GLOBALCELLS]; int channel[FWDET_STRAW_MAX_GLOBALCELLS]; int module[FWDET_STRAW_MAX_GLOBALCELLS]; int layer [FWDET_STRAW_MAX_GLOBALCELLS]; int straw[FWDET_STRAW_MAX_GLOBALCELLS]; int updown[FWDET_STRAW_MAX_GLOBALCELLS]; } lookup; EXEC SQL END DECLARE SECTION; vers=oraVersion; EXEC SQL WHENEVER SQLERROR DO showSqlError("read(HStsTrb3Lookup*)"); EXEC SQL WHENEVER NOT FOUND CONTINUE; EXEC SQL SELECT trbnet_address, channel, module, layer, straw, updown INTO :lookup FROM fwdet_ana2.straw_trb3lookup_data_view WHERE vers_id = :vers; Int_t nData=sqlca.sqlerrd[2]; for (Int_t i=0;ifill(lookup.address[i],lookup.channel[i], lookup.module[i]-1,lookup.layer[i]-1, lookup.straw[i]-1, lookup.updown[i]); } rc=kTRUE; if (nData>0) { setChanged(pPar,oraVersion); cout<GetName()<<" initialized from Oracle"<setInputVersion(-1,inputNumber); rc=kFALSE; } return rc; } // JAM22 TODO Bool_t HStsParOra2Io::read(HStsCalPar* pPar) { // reads the lookup table for the Trb3 unpacker and fill the container FRpcTrb3Lookup 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; int globalstrip; struct { int module[FWDET_STRAW_MAX_GLOBALCELLS]; int layer[FWDET_STRAW_MAX_GLOBALCELLS]; int straw[FWDET_STRAW_MAX_GLOBALCELLS]; short updown[FWDET_STRAW_MAX_GLOBALCELLS]; float time_offset[FWDET_STRAW_MAX_GLOBALCELLS]; float time_max[FWDET_STRAW_MAX_GLOBALCELLS]; float time_slope[FWDET_STRAW_MAX_GLOBALCELLS]; float tof_reference[FWDET_STRAW_MAX_GLOBALCELLS]; float iso_par_0[FWDET_STRAW_MAX_GLOBALCELLS]; float iso_par_1[FWDET_STRAW_MAX_GLOBALCELLS]; float iso_par_2[FWDET_STRAW_MAX_GLOBALCELLS]; float iso_par_3[FWDET_STRAW_MAX_GLOBALCELLS]; float iso_par_4[FWDET_STRAW_MAX_GLOBALCELLS]; float tot_par_0[FWDET_STRAW_MAX_GLOBALCELLS]; float tot_par_1[FWDET_STRAW_MAX_GLOBALCELLS]; } cal; struct { short module[FWDET_STRAW_MAX_GLOBALCELLS]; short layer[FWDET_STRAW_MAX_GLOBALCELLS]; short straw[FWDET_STRAW_MAX_GLOBALCELLS]; short updown[FWDET_STRAW_MAX_GLOBALCELLS]; short time_offset[FWDET_STRAW_MAX_GLOBALCELLS]; short time_max[FWDET_STRAW_MAX_GLOBALCELLS]; short time_slope[FWDET_STRAW_MAX_GLOBALCELLS]; short tof_reference[FWDET_STRAW_MAX_GLOBALCELLS]; short iso_par_0[FWDET_STRAW_MAX_GLOBALCELLS]; short iso_par_1[FWDET_STRAW_MAX_GLOBALCELLS]; short iso_par_2[FWDET_STRAW_MAX_GLOBALCELLS]; short iso_par_3[FWDET_STRAW_MAX_GLOBALCELLS]; short iso_par_4[FWDET_STRAW_MAX_GLOBALCELLS]; short tot_par_0[FWDET_STRAW_MAX_GLOBALCELLS]; short tot_par_1[FWDET_STRAW_MAX_GLOBALCELLS]; } cal_Ind; EXEC SQL END DECLARE SECTION; vers=oraVersion; EXEC SQL WHENEVER SQLERROR DO showSqlError("read(HStsCalPar*,Int_t*)"); EXEC SQL WHENEVER NOT FOUND CONTINUE; EXEC SQL SELECT module, layer, straw, updown, time_offset, time_max, time_slope, tof_reference, iso_par_0, iso_par_1, iso_par_2, iso_par_3, iso_par_4, tot_par_0, tot_par_1 INTO :cal INDICATOR :cal_Ind FROM fwdet_ana2.straw_calpar_data_view WHERE vers_id = :vers; Int_t nData=sqlca.sqlerrd[2]; Int_t sec=-1, mod=-1, tube=-1, kind=-1; for(Int_t i=0;iAddAt(1,pos); } } Bool_t allFound=kTRUE; // if (nData>0) { // for(Int_t i=0;iAt(i)==0) allFound=kFALSE; // } // } else allFound=kFALSE; // if (allFound) { setChanged(pPar,oraVersion); printInfo(pPar->GetName()); } else { pPar->setInputVersion(-1,inputNumber); } return allFound; } /////////////////////////// GEOMETRY follows /////////////////////////////////// Bool_t HStsParOra2Io::read(HStsGeomPar* pPar, Int_t* set) { // reads the geometry of the Sts and fills the StsGeomPar container Bool_t allFound=kTRUE; Int_t detId=-1; if (!geomVers) { detId=getDetectorId(pPar->getDetectorName()); geomVers=new HOra2GeomDetVersion( pPar->getDetectorName(),detId); //std::cout<< "HStsParOra2Io::read HStsGeomPar got id"<getDetectorName() << std::endl; } else { detId=geomVers->getDetectorId(); } if (detId<=0) { allFound=kFALSE; delete geomVers; geomVers=0; } if (detId>0&&pPar->isFirstInitialization()) { //std::cout<< "HStsParOra2Io::read HStsGeomPar with detId;"<isFirstInitialization()<< std::endl; if (!readModGeomNames(pPar,set) || !readCompGeomNames(pPar,set)) { allFound=kFALSE; pPar->clear(); //std::cout<< "HStsParOra2Io::read HStsGeomPar failed after readModGeomNames or readCompGeomNames"<< std::endl; } else addGeomOraSet(pPar); } if (allFound) allFound=readDetectorGeometry(pPar,set,geomVers); //std::cout<< "HStsParOra2Io::read HStsGeomPar returns"<Reset(); for(Int_t i=0;igetModule(l,m); if (pMod && set[s]) { if (mods_Ind.oname[i]!=-1) { mods.oname[i].arr[mods.oname[i].len]='\0'; //std::cout<< "HStsParOra2Io::readModGeomNames at "<SetName((Char_t*)(mods.oname[i].arr)); initModules->AddAt(s+1,s); Int_t refid=mods.mod[i]-1; HGeomCompositeVolume* refMod=pPar->getRefVolume(refid); if (refMod==0) { strcpy(ref,(Char_t*)(mods.oname[i].arr)); refMod=new HGeomCompositeVolume(pPar->getNumComponents()); refMod->SetName(ref); pPar->addRefVolume(refMod,refid); //std::cout<< "JAMSTSDEB: Add reference module for"<setVolume(refMod); pMod->setRefName(ref); //std::cout<< "JAMSTSDEB: Reference module has set for"<GetName()<0 && initModules->At(i)==0) allFound=kFALSE; } //std::cout<< "HStsParOra2Io:readModGeomNames returns"<< allFound<< std::endl; return allFound; } Bool_t HStsParOra2Io::readCompGeomNames(HStsGeomPar* pPar,Int_t* set) { // reads the names of all cells in the geometry tables //std::cout<< "HStsParOra2Io:readCompGeomNames.... "<< std::endl; EXEC SQL BEGIN DECLARE SECTION; struct { int cell_index[FWDET_STRAW_MAX_LAYER_CELLS]; int module[FWDET_STRAW_MAX_LAYER_CELLS]; varchar oname[FWDET_STRAW_MAX_LAYER_CELLS][9]; } lrecG; EXEC SQL END DECLARE SECTION; EXEC SQL WHENEVER SQLERROR DO showSqlError("readCompGeomNames(...)"); EXEC SQL WHENEVER NOT FOUND CONTINUE; EXEC SQL SELECT cell_index, module_kind, geom_obj_name INTO :lrecG FROM fwdet_ana2.straw_layer_cell WHERE geom_obj_name IS NOT NULL; Int_t nCells=sqlca.sqlerrd[2]; Int_t cell=-1; for(Int_t k=0;kgetCompNum(cName); // JAM2021: note that we do _not_ use the Oracle internal cell_index, but a more dense index for TObjArray here Int_t refid=lrecG.module[k]-1; //std::cout<< "HStsParOra2Io::readCompGeomNames got at module kind "<getRefVolume(refid); if(pRefMod==0){ std::cout<<"HStsParOra2Io::readCompGeomNames ERROR: no reference module for index"<getComponent(cell); if (volu){ volu->SetName(cName); } else { Error("readCompGeomNames","Index for cell %s not found",cName.Data()); return kFALSE; } } //std::cout<< "HStsParOra2Io:readCompGeomNames has read"<0) ? kTRUE : kFALSE; } Int_t HStsParOra2Io::createVers(HParSet* pPar) { // creates a new version for parameters // returns the new version cout<<"--------------- "<GetName()<<" ---------------\n"; if (strlen(pPar->getAuthor())==0) { Error("createVers(HParSet*)", "author of parameters not defined"); return -1; } if (strlen(pPar->getDescription())==0) { Error("createVers(HParSet*)", "descriction of parameters not defined"); return -1; } const Char_t* contName=pPar->IsA()->GetName(); EXEC SQL BEGIN DECLARE SECTION; int vers=-1; int context; 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,"HStsTrb3Lookup")==0) { EXEC SQL EXECUTE BEGIN SELECT fwdet_ana2.straw_par_query.next_version INTO :vers FROM DUAL; INSERT INTO fwdet_ana2.straw_trb3lookup_vers (vers_id, orig_context_id, run_id, author, description) VALUES (:vers, :context, :run, :creator, :descript); END; END-EXEC; } else if (strcmp(contName,"HStsCalPar")==0) { EXEC SQL EXECUTE BEGIN SELECT fwdet_ana2.straw_par_query.next_version INTO :vers FROM DUAL; INSERT INTO fwdet_ana2.straw_calpar_vers (vers_id, orig_context_id, run_id, author, description) VALUES (:vers, :context, :run, :creator, :descript); END; END-EXEC; } else { } cout<<"Oracle version for "<GetName()<<" created: "<getArrayOffset(); for(Int_t t=0;tgetSize();t++) { HStsTrb3LookupTdc* tdc=(*pPar)[t]; if (tdc) { nChan=0; for(Int_t c=0;cgetSize();c++) { HStsTrb3LookupChan& rChan=(*tdc)[c]; if (rChan.getModule()!=-1 && rChan.getLayer()!=-1 && rChan.getCell()!=-1 && rChan.getSubCell()!=-1) { vers[nChan]=version; address[nChan]=arrayOffset+t; channel[nChan]=c; module[nChan]=rChan.getModule() +1; layer[nChan]=rChan.getLayer() +1; straw[nChan]=rChan.getCell() +1; updown[nChan]=rChan.getSubCell(); nChan++; } } rows_to_insert=nChan; EXEC SQL WHENEVER SQLERROR GOTO errorfound; EXEC SQL WHENEVER NOT FOUND GOTO errorfound; EXEC SQL FOR :rows_to_insert INSERT INTO fwdet_ana2.straw_trb3lookup_data (vers_id, trbnet_address, channel_id, cell_id) VALUES (:vers, :address, :channel, fwdet_ana2.straw_par_query.get_cell_id(:module, :layer, :straw, :updown) ); cout<<"Trbnet-address "<<"0x"<setChanged(kFALSE); return version; errorfound: showSqlError("writePar(HStsTrb3Lookup*)"); rollback(); pPar->setChanged(kFALSE); return -1; } // JAM TODO Int_t HStsParOra2Io::writePar(HStsCalPar* 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 module[FWDET_STRAW_MAX_GLOBALCELLS]; int layer[FWDET_STRAW_MAX_GLOBALCELLS]; int straw[FWDET_STRAW_MAX_GLOBALCELLS]; int kind[FWDET_STRAW_MAX_GLOBALCELLS]; int vers[FWDET_STRAW_MAX_GLOBALCELLS]; float time_offset[FWDET_STRAW_MAX_GLOBALCELLS]; float time_max[FWDET_STRAW_MAX_GLOBALCELLS]; float time_slope[FWDET_STRAW_MAX_GLOBALCELLS]; float tof_reference[FWDET_STRAW_MAX_GLOBALCELLS]; float iso_par_0[FWDET_STRAW_MAX_GLOBALCELLS]; float iso_par_1[FWDET_STRAW_MAX_GLOBALCELLS]; float iso_par_2[FWDET_STRAW_MAX_GLOBALCELLS]; float iso_par_3[FWDET_STRAW_MAX_GLOBALCELLS]; float iso_par_4[FWDET_STRAW_MAX_GLOBALCELLS]; float tot_par_0[FWDET_STRAW_MAX_GLOBALCELLS]; float tot_par_1[FWDET_STRAW_MAX_GLOBALCELLS]; int rows_to_insert; EXEC SQL END DECLARE SECTION; Int_t nRod=0; for(Int_t m=0; mgetSize(); m++) { HStsCalParMod& rMod=(*pPar)[m]; for(Int_t s=0; s= 159) continue; //if(m==1 && c >= 223) continue; // JAM workaround for fake input file HStsCalParCell& rStraw= rSec[c]; for(Int_t k=0; ksetChanged(kFALSE); return version; not_found: showSqlError("writePar(HStsCalPar*)"); rollback(); pPar->setChanged(kFALSE); return -1; } void HStsParOra2Io::printInfo(const Char_t* contName) { // prints the sectors initialized from Oracle Bool_t first=kTRUE; for(Int_t i=0;iAt(i)) { if (first) { cout<