Skip to content
Snippets Groups Projects
Commit afb75f5c authored by Stephen A. Wood's avatar Stephen A. Wood
Browse files

Experimental code to get parameters from CCDB.

  CCDB must be installed and CCDB_HOME defined before compiling.
  If CCDB_HOME is not defined, hcana is compiled without CCDB support
  scons has not been updated to compile with CCDB support
  To use, instead of gHcParms->Load(filename), do
    gHcParms->OpenCCDB(runnum, ccdb_connection_string)
    gHcParms->LoadCCDBDirectory("hms","h")
    gHcParms->LoadCCDBDirectory("sos","s")
    gHcParms->LoadCCDBDirectory("gen","g")
  Parmaters will be loaded into the same internal gHcParms list as with
  ThcParmList::Load, so no changes to detector classes are needed.
  Scripts to convert existing parameters into CCDB are under development.
  Currently all ccdb constants are loaded as doubles as there is not
  a way to easily query ccdb to get the data type.
  Also strings are not loaded.
parent a6aab7fc
No related branches found
No related tags found
No related merge requests found
...@@ -139,6 +139,13 @@ ifdef WITH_DEBUG ...@@ -139,6 +139,13 @@ ifdef WITH_DEBUG
CXXFLAGS += -DWITH_DEBUG CXXFLAGS += -DWITH_DEBUG
endif endif
CCDBLIBS =
CCDBFLAGS =
ifdef CCDB_HOME
CCDBLIBS += -L$(CCDB_HOME)/lib -lccdb
CCDBFLAGS += -I$(CCDB_HOME)/include -DWITH_CCDB
endif
ifdef PROFILE ifdef PROFILE
CXXFLAGS += -pg CXXFLAGS += -pg
LDFLAGS += -pg LDFLAGS += -pg
...@@ -171,7 +178,8 @@ HALLALIBS := -L$(LIBDIR) -lHallA -ldc -lscaler ...@@ -171,7 +178,8 @@ HALLALIBS := -L$(LIBDIR) -lHallA -ldc -lscaler
src/THcInterface.d: $(HDR_COMPILEDATA) src/THcInterface.d: $(HDR_COMPILEDATA)
hcana: src/main.o $(LIBDC) $(LIBSCALER) $(LIBHALLA) $(USERLIB) hcana: src/main.o $(LIBDC) $(LIBSCALER) $(LIBHALLA) $(USERLIB)
$(LD) $(LDFLAGS) $< $(HALLALIBS) -L. -lHallC $(GLIBS) -o $@ $(LD) $(LDFLAGS) $< $(HALLALIBS) -L. -lHallC $(CCDBLIBS) \
$(GLIBS) -o $@
$(USERLIB): $(HDR) $(OBJS) $(USERLIB): $(HDR) $(OBJS)
$(LD) $(LDFLAGS) $(SOFLAGS) -o $@ $(OBJS) $(LD) $(LDFLAGS) $(SOFLAGS) -o $@ $(OBJS)
...@@ -183,7 +191,7 @@ $(HDR_COMPILEDATA) $(LIBHALLA) $(LIBDC) $(LIBSCALER): $(ANALYZER)/Makefile ...@@ -183,7 +191,7 @@ $(HDR_COMPILEDATA) $(LIBHALLA) $(LIBDC) $(LIBSCALER): $(ANALYZER)/Makefile
$(USERDICT).cxx: $(RCHDR) $(HDR) $(LINKDEF) $(USERDICT).cxx: $(RCHDR) $(HDR) $(LINKDEF)
@echo "Generating dictionary $(USERDICT)..." @echo "Generating dictionary $(USERDICT)..."
$(ROOTBIN)/rootcint -f $@ -c $(INCLUDES) $^ $(ROOTBIN)/rootcint -f $@ -c $(INCLUDES) $(CCDBFLAGS) $^
install: all install: all
cp -p $(USERLIB) $(HOME)/cue/SRC/ana cp -p $(USERLIB) $(HOME)/cue/SRC/ana
...@@ -211,7 +219,7 @@ srcdist: ...@@ -211,7 +219,7 @@ srcdist:
.SUFFIXES: .c .cc .cpp .cxx .C .o .d .SUFFIXES: .c .cc .cpp .cxx .C .o .d
%.o: %.cxx %.o: %.cxx
$(CXX) $(CXXFLAGS) -o $@ -c $< $(CXX) $(CXXFLAGS) $(CCDBFLAGS) -o $@ -c $<
# FIXME: this only works with gcc # FIXME: this only works with gcc
%.d: %.cxx %.d: %.cxx
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "TObjArray.h" #include "TObjArray.h"
#include "TObjString.h" #include "TObjString.h"
#include "TSystem.h"
#include "THcParmList.h" #include "THcParmList.h"
#include "THaVar.h" #include "THaVar.h"
...@@ -17,7 +18,6 @@ ...@@ -17,7 +18,6 @@
#include "TMath.h" #include "TMath.h"
/* #incluce <algorithm> include <fstream> include <cstring> */ /* #incluce <algorithm> include <fstream> include <cstring> */
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
...@@ -579,3 +579,91 @@ void THcParmList::PrintFull( Option_t* option ) const ...@@ -579,3 +579,91 @@ void THcParmList::PrintFull( Option_t* option ) const
THaVarList::PrintFull(option); THaVarList::PrintFull(option);
TextList->Print(); TextList->Print();
} }
#ifdef WITH_CCDB
//_____________________________________________________________________________
Int_t THcParmList::OpenCCDB(Int_t runnum)
{
// Use the Environment variable "CCDB_CONNECTION" as the
// connection string
const char* connection_string = gSystem->Getenv("CCDB_CONNECTION");
return(OpenCCDB(runnum,connection_string));
}
Int_t THcParmList::OpenCCDB(Int_t runnum, const char* connection_string)
{
// Connect to a CCDB database pointed to by connection_string
std::string s (connection_string);
CCDB_obj = new SQLiteCalibration(runnum);
Int_t result = CCDB_obj->Connect(s);
if(!result) return -1; // Need some error codes
cout << "Opened " << s << " for run " << runnum << endl;
return 0;
}
Int_t THcParmList::CloseCCDB()
{
delete CCDB_obj;
return(0);
}
Int_t THcParmList::LoadCCDBDirectory(const char* directory,
const char* prefix)
{
// Load all parameters in directory
// Prepend prefix onto the name of each
std::string dirname (directory);
if(dirname[dirname.length()-1]!='/') {
dirname.append("/");
}
Int_t dirlen=dirname.length();
vector<string> namepaths;
CCDB_obj->GetListOfNamepaths(namepaths);
for(UInt_t iname=0;iname<namepaths.size();iname++) {
std::string varname (namepaths[iname]);
if(varname.compare(0,dirlen,dirname) == 0) {
varname.replace(0,dirlen,prefix);
// cout << namepaths[iname] << " -> " << varname << endl;
// To what extent is there duplication here with Load() method?
// Retrieve the data as floats
vector<vector<double> > data;
CCDB_obj->GetCalib(data, namepaths[iname]);
for(UInt_t row=0; row<data.size(); row++) {
for(UInt_t col=0;col<data[0].size(); col++) {
cout << data[row][col] << "\t";
}
cout << endl;
}
if(data[0].size()==1) { // Only handle single column tables
// Could stuff 2d arrays in, and assume that the application knows
// the number of columns. Then the matrix stuff would just need to
// see if the variable exists, then copy the data into the right kind
// of structure instead of reading from the recon files.
THaVar* existingvar=Find(varname.c_str());
if(existingvar) {
// Does the array of data need to deleted too?
RemoveName(varname.c_str());
}
Double_t* fp = new Double_t[data.size()];
for(UInt_t row=0;row<data.size(); row++) {
fp[row] = data[row][0];
}
// Need to append [size] to end of varname
char sizestring[20];
sprintf(sizestring,"[%d]",(Int_t) data.size());
std::string size_str (sizestring);
varname.append(size_str);
Define(varname.c_str(), "comment", *fp);
}
}
}
return 0;
}
#endif
...@@ -10,8 +10,20 @@ ...@@ -10,8 +10,20 @@
#include "THaVarList.h" #include "THaVarList.h"
#include "THaTextvars.h" #include "THaTextvars.h"
#ifdef WITH_CCDB
#ifdef __CINT__
struct pthread_cond_t;
struct pthread_mutex_t;
#endif
#include <CCDB/Calibration.h>
#include <CCDB/SQLiteCalibration.h>
using namespace ccdb;
#endif
using namespace std; using namespace std;
class THcParmList : public THaVarList { class THcParmList : public THaVarList {
public: public:
...@@ -39,10 +51,22 @@ public: ...@@ -39,10 +51,22 @@ public:
Int_t GetArray(const char* attr, Int_t* array, Int_t size); Int_t GetArray(const char* attr, Int_t* array, Int_t size);
Int_t GetArray(const char* attr, Double_t* array, Int_t size); Int_t GetArray(const char* attr, Double_t* array, Int_t size);
#ifdef WITH_CCDB
Int_t OpenCCDB(Int_t runnum);
Int_t OpenCCDB(Int_t runnum, const char* connection_string);
Int_t CloseCCDB();
Int_t LoadCCDBDirectory(const char* directory,
const char* prefix);
#endif
private: private:
THaTextvars* TextList; THaTextvars* TextList;
#ifdef WITH_CCDB
SQLiteCalibration* CCDB_obj;
#endif
template<class T> template<class T>
Int_t ReadArray(const char* attrC, T* array, Int_t size); Int_t ReadArray(const char* attrC, T* array, Int_t size);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment