Skip to content

Commit

Permalink
Merge pull request #30 from dglazier/master
Browse files Browse the repository at this point in the history
mcmatch
  • Loading branch information
dglazier authored Feb 3, 2021
2 parents f0deb61 + 4f52d8d commit da7457a
Show file tree
Hide file tree
Showing 72 changed files with 2,238 additions and 592 deletions.
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[submodule "lz4"]
path = lz4
url = https://github.com/lz4/lz4.git
[submodule "ccdb"]
path = ccdb
url = https://github.com/JeffersonLab/ccdb.git
[submodule "rcdb"]
path = rcdb
url = https://github.com/JeffersonLab/rcdb
[submodule "clasqaDB"]
path = clasqaDB
url = https://github.com/JeffersonLab/clasqaDB
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ add_definitions(-D__LZ4__)
set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

#include clasqaDB c++ library and rapidjson library
IF (DEFINED ENV{CLASQADB_HOME})
IF (DEFINED ENV{QADB})

include_directories($ENV{CLASQADB_HOME}/srcC/rapidjson/include)
include_directories($ENV{CLASQADB_HOME}/srcC/include)
include_directories($ENV{QADB}/srcC/rapidjson/include)
include_directories($ENV{QADB}/srcC/include)
#clasqaDB header contains function definitions which are not inlined
#including this header causes multiple definitions of these functions
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--allow-multiple-definition")
add_definitions(-DCLAS_QADB)
ENDIF (DEFINED ENV{CLASQADB_HOME})
ENDIF (DEFINED ENV{QADB})



Expand Down
18 changes: 10 additions & 8 deletions Clas12Banks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@



set(CLASS_LIST_CPP helflip.cpp helonline.cpp runconfig.cpp event.cpp ftbevent.cpp particle.cpp ftbparticle.cpp mcparticle.cpp scaler.cpp vtp.cpp particle_detector.cpp scintillator.cpp tracker.cpp traj.cpp forwardtagger.cpp cherenkov.cpp calorimeter.cpp covmatrix.cpp region_particle.cpp region_ft.cpp region_fdet.cpp region_cdet.cpp region_band.cpp clas12writer.cpp clas12reader.cpp mesonex_trigger.cpp scaler_reader.cpp clas12databases.cpp qadb_reader.cpp ccdb_reader.cpp rcdb_reader.cpp)
set(CLASS_LIST_CPP helflip.cpp helonline.cpp runconfig.cpp event.cpp ftbevent.cpp particle.cpp ftbparticle.cpp mcparticle.cpp mcevent.cpp mcmatch.cpp scaler.cpp vtp.cpp particle_detector.cpp scintillator.cpp scintextras.cpp tracker.cpp traj.cpp forwardtagger.cpp cherenkov.cpp calorimeter.cpp covmatrix.cpp region_particle.cpp region_ft.cpp region_fdet.cpp region_cdet.cpp region_band.cpp clas12writer.cpp clas12reader.cpp mesonex_trigger.cpp scaler_reader.cpp clas12databases.cpp qadb_reader.cpp ccdb_reader.cpp rcdb_reader.cpp)

set(CLASS_LIST_H helflip.h helonline.h runconfig.h event.h ftbevent.h particle.h ftbparticle.h mcparticle.h scaler.h vtp.h particle_detector.h scintillator.h tracker.h traj.h forwardtagger.h cherenkov.h calorimeter.h covmatrix.h region_particle.h region_ft.h region_fdet.h region_cdet.h region_band.h clas12writer.h clas12reader.h mesonex_trigger.h scaler_reader.h clas12databases.h qadb_reader.h ccdb_reader.h rcdb_reader.h)
set(CLASS_LIST_H helflip.h helonline.h runconfig.h event.h ftbevent.h particle.h ftbparticle.h mcparticle.h mcevent.h mcmatch.h scaler.h vtp.h particle_detector.h scintillator.h scintextras.h tracker.h traj.h forwardtagger.h cherenkov.h calorimeter.h covmatrix.h region_particle.h region_ft.h region_fdet.h region_cdet.h region_band.h clas12writer.h clas12reader.h mesonex_trigger.h scaler_reader.h clas12databases.h qadb_reader.h ccdb_reader.h rcdb_reader.h)

IF (DEFINED ENV{CLASQADB_HOME})
IF (DEFINED ENV{QADB})
set(CLASS_LIST_CPP ${CLASS_LIST_CPP} jsonFileMerger.cpp)
set(CLASS_LIST_H ${CLASS_LIST_H} jsonFileMerger.h)
add_definitions(-DCLAS_QADB)
ENDIF (DEFINED ENV{CLASQADB_HOME})
ENDIF (DEFINED ENV{QADB})

#include rcdb c++ header library
IF (DEFINED ENV{CCDB_HOME})
# CCDB related
include_directories($ENV{CCDB_HOME}/include)
link_libraries($ENV{CCDB_HOME}/lib/libccdb.so)
link_libraries($ENV{CCDB_HOME}/lib/libccdb${CMAKE_SHARED_LIBRARY_SUFFIX})
add_definitions(-DCLAS_CCDB)
ENDIF (DEFINED ENV{CCDB_HOME})

Expand Down Expand Up @@ -69,9 +69,11 @@ target_link_libraries(Clas12Banks ${ROOT_LIBRARIES} Hipo4)
install(TARGETS Clas12Banks
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")

FILE(GLOB ROOT_CLAS12_PCM ${CMAKE_BINARY_DIR}/Clas12Banks/*pcm)
#FILE(GLOB ROOT_CLAS12_PCM ${CMAKE_BINARY_DIR}/Clas12Banks/*pcm)

install (FILES ${ROOT_CLAS12_PCM}
DESTINATION "${CMAKE_INSTALL_LIBDIR}")
#install (FILES ${ROOT_CLAS12_PCM}
# DESTINATION "${CMAKE_INSTALL_LIBDIR}")


install (FILES ${CMAKE_CURRENT_BINARY_DIR}/libClas12Banks_rdict.pcm
DESTINATION "${CMAKE_INSTALL_LIBDIR}")
38 changes: 38 additions & 0 deletions Clas12Banks/ccdb_reader.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ccdb_reader.h"
#include <iostream>
#include <algorithm>

namespace clas12 {


Expand All @@ -16,6 +18,7 @@ namespace clas12 {

ccdb::CalibrationGenerator gen;
_calib.reset( gen.MakeCalibration(_path, 0, "default", 0 ) );

#endif

}
Expand Down Expand Up @@ -46,6 +49,41 @@ namespace clas12 {

#endif

double ccdb_reader::requestTableValueFor(int row,const std::string& item,const std::string& tableName){

const TableOfDoubles_t* table=nullptr;

//Find the requested table
auto it = std::find_if(_localTable.begin(),_localTable.end(),
[&tableName](const TableRecord_t& element)
{ return element.first == tableName;} );
if(it==_localTable.end()){
//need to create table
table = &requestTableDoubles(tableName);
}

else table=&(it->second);

//Find the column index for this item in this table
auto ipos=requestTableEntryFor(item,tableName);
if(ipos<0){
std::cerr<<" ccdb_reader::requestTableValueFor no "<<item<<" in row "<<row<< " of "<<tableName<<std::endl;
return 0.;
}
return table->at(row)[ipos];

}
int ccdb_reader::requestTableEntryFor(const std::string& item,const std::string& tableName){

int entry=-1;
#ifdef CLAS_CCDB
const auto& columns = _calib->GetAssignment(tableName)->GetTypeTable()->GetColumnNames();
entry= std::distance(
columns.begin(),
std::find(columns.begin(), columns.end(), item) );
#endif
return entry;
}
const TableOfDoubles_t& ccdb_reader::requestTableDoubles(std::string tableName){
/*
Get a table from the database, will reconnect to database automatically
Expand Down
4 changes: 2 additions & 2 deletions Clas12Banks/ccdb_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace clas12 {
public:
const TableOfDoubles_t& requestTableDoubles(std::string tableName);
void updateTables();
int requestTableEntryFor(const std::string& item,const std::string& tableName);
double requestTableValueFor(int row,const std::string& item,const std::string& tableName);

private:

Expand All @@ -55,8 +57,6 @@ namespace clas12 {
#ifdef CLAS_CCDB

std::unique_ptr<ccdb::Calibration> _calib ={nullptr};



#endif

Expand Down
94 changes: 19 additions & 75 deletions Clas12Banks/clas12databases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace clas12 {

string clas12databases::_RcdbPath="";
string clas12databases::_CcdbPath="";
string clas12databases::_QadbPath="";
//string clas12databases::_QadbPath="";

void clas12databases::SetQADBConnection(const string& name){_QadbPath=FullPath(name);}
//void clas12databases::SetQADBConnection(const string& name){_QadbPath=FullPath(name);}
void clas12databases::SetCCDBLocalConnection(const string& name){_CcdbPath="sqlite://"+FullPath(name);}
void clas12databases::SetCCDBRemoteConnection(){_CcdbPath="mysql://clas12reader@clasdb.jlab.org/clas12";}
void clas12databases::SetRCDBLocalConnection(const string& name){_RcdbPath="sqlite://"+FullPath(name);}
Expand All @@ -24,13 +24,14 @@ namespace clas12 {

clas12databases::clas12databases()
{
std::cout<<"clas12databases() rcdb path "<<_RcdbPath<<" "<<_myRcdbPath<<std::endl;
std::cout<<"clas12databases() ccdb path "<<_CcdbPath<<std::endl;
std::cout<<"clas12databases() qadb path "<<_QadbPath<<std::endl;

if(_verbose){
std::cout<<"clas12databases() rcdb path "<<_RcdbPath<<" "<<_myRcdbPath<<std::endl;
std::cout<<"clas12databases() ccdb path "<<_CcdbPath<<std::endl;
//std::cout<<"clas12databases() qadb path "<<_QadbPath<<std::endl;
}
_myRcdbPath=_RcdbPath;
_myCcdbPath=_CcdbPath;
_myQadbPath=_QadbPath;
//_myQadbPath=_QadbPath;

initDBs();
}
Expand All @@ -39,15 +40,14 @@ namespace clas12 {

_myRcdbPath=other._myRcdbPath;
_myCcdbPath=other._myCcdbPath;
_myQadbPath=other._myQadbPath;
//_myQadbPath=other._myQadbPath;

initDBs();

if(_qadb.get()){
qadb_requireOkForAsymmetry(other._qadbReqOKAsymmetry);
qadb_requireGolden(other._qadbReqGolden);
qadb_setQARequirements(other._qadbReqsQA);

}

return *this;
Expand All @@ -56,7 +56,7 @@ namespace clas12 {

_myRcdbPath=other._myRcdbPath;
_myCcdbPath=other._myCcdbPath;
_myQadbPath=other._myQadbPath;
//_myQadbPath=other._myQadbPath;


initDBs();
Expand All @@ -70,9 +70,9 @@ namespace clas12 {
}

void clas12databases::initDBs(){
std::cout<<"clas12databases() rcdb path "<<_myRcdbPath<<std::endl;
std::cout<<"clas12databases() ccdb path "<<_myCcdbPath<<std::endl;
std::cout<<"clas12databases() qadb path "<<_myQadbPath<<std::endl;
//std::cout<<"clas12databases() rcdb path "<<_myRcdbPath<<std::endl;
//std::cout<<"clas12databases() ccdb path "<<_myCcdbPath<<std::endl;
//std::cout<<"clas12databases() qadb path "<<_myQadbPath<<std::endl;


if(_myCcdbPath.empty()==false)
Expand All @@ -85,12 +85,11 @@ namespace clas12 {
_rcdb.reset( new rcdb_reader{_myRcdbPath.data()} );
}

if(_myQadbPath.empty()==false){
_qadb.reset( new qadb_reader{_myQadbPath.data()} );
qadb_requireOkForAsymmetry(_qadbReqOKAsymmetry);
qadb_requireGolden(_qadbReqGolden);
qadb_setQARequirements(_qadbReqsQA);
}

_qadb.reset( new qadb_reader{0} );
qadb_requireOkForAsymmetry(_qadbReqOKAsymmetry);
qadb_requireGolden(_qadbReqGolden);
qadb_setQARequirements(_qadbReqsQA);

}
//update run number to each database
Expand All @@ -100,8 +99,7 @@ namespace clas12 {
open();


std::cout<<"clas12databases::notifyRun "<<runNb<<" ccdb = "<<(_ccdb.get()!=nullptr) <<" rcdb = "<<(_qadb.get()!=nullptr)<<" qadb = "<<(_rcdb.get()!=nullptr)<<std::endl;
if(_ccdb.get()!=nullptr){
if(_ccdb.get()!=nullptr){
_ccdb->setRun(runNb);
_ccdb->updateTables();
}
Expand All @@ -121,58 +119,4 @@ namespace clas12 {
if(_rcdb.get()!=nullptr)_rcdb->open();

}
/////////////////////////////////////////////////////
/// Get the rcdb info for all the files in the chain
// void clas12databases::writeRcdbData(TString filename,const clas12root::HipoChain& chain){
/*
void clas12databases::writeRcdbData(TString filename){
if(_rcdb.get()==nullptr){
std::cout<<"clas12databases::writeRcdbData no rcdb intiated with clas12databases::SetRCDB... "<<std::endl;
return;
}
auto rcdbFile=std::unique_ptr<TFile>{TFile::Open(filename,"recreate")};
auto nfiles=chain.GetNFiles();
//loop over files and get the rcdb data
for(auto i=0;i<nfiles;++i){
auto runNb=clas12reader::readQuickRunConfig(chain.GetFileName(i).Data());
auto runName = Form("%d",runNb);
auto vals=std::unique_ptr<clas12root::TRcdbVals>{new clas12root::TRcdbVals(_rcdb->readAll(runNb,runName))};
vals->Write();
}
rcdbFile->ls();
}
*/
/*
////////////////////////////////////////////////////////////
///Get a copy of the rcdb values for run number runNb,
///from file fname created previously by WriteRcdbData
clas12::rcdb_vals HipoChain::fetchRunRcdb(const TString& datafile){
//make file and list unique_ptr so deleted when we return
auto rcdbFile=std::unique_ptr<TFile>{TFile::Open(_rcdbFileName)};
if(rcdbFile.get()==nullptr){
Warning("HipoChain::FetchRunRcdb ",Form("No rcdb root file provided to the chain : %s",_rcdbFileName.Data()),"");
return rcdb_vals();
}
auto keys= rcdbFile->GetListOfKeys();
for(const auto& key:*keys){
//the rcdb_vals Title is mapped to the data file name
auto baseName = gSystem->BaseName(datafile);//use base name in case user copies data to temp directory
if(TString(key->GetTitle())==TString(baseName)){
auto vals=std::unique_ptr<TRcdbVals>{dynamic_cast<TRcdbVals*>(rcdbFile->Get(key->GetName()))};
if(vals.get())
return vals.get()->_data;
}
}
Warning("HipoChain::FetchRunRcdb ",Form("run file %s not found in list in file %s",datafile.Data(),_rcdbFileName.Data()),"");
//no rcdb
return rcdb_vals();
}
*/
}
14 changes: 8 additions & 6 deletions Clas12Banks/clas12databases.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace clas12 {
//where to make database connections
static string _RcdbPath;//!
static string _CcdbPath;//!
static string _QadbPath;//!
//static string _QadbPath;//!

public:

Expand All @@ -40,7 +40,7 @@ namespace clas12 {
void notifyRun(int runNb);


static void SetQADBConnection(const string& name);
//static void SetQADBConnection(const string& name);
static void SetCCDBLocalConnection(const string& name);
static void SetCCDBRemoteConnection();
static void SetRCDBLocalConnection(const string& name);
Expand All @@ -57,26 +57,27 @@ namespace clas12 {

const string& ccdbPath() const {return _myCcdbPath;}
const string& rcdbPath() const {return _myRcdbPath;}
const string& qadbPath() const {return _myQadbPath;}
//const string& qadbPath() const {return _myQadbPath;}



//qadb stuff
//I would rather this was not needed here
//but it is to make sure it gets passed to PROOF
void qadb_addQARequirement(string req){ _qadb->addQARequirement(req);_qadbReqsQA.push_back(req);};
void qadb_setQARequirements( std::vector<string> reqs){_qadb->setQARequirements(reqs); _qadbReqsQA = reqs; };
void qadb_setQARequirements( std::vector<string> reqs){_qadb->setQARequirements(reqs); _qadbReqsQA = reqs;};

void qadb_requireOkForAsymmetry(bool ok){_qadb->requireOkForAsymmetry(ok);_qadbReqOKAsymmetry=ok;};
void qadb_requireGolden(bool ok){_qadb->requireGolden(ok);_qadbReqGolden=ok;};


void setVerbose(short level=1){_verbose=level;}

private:

//names for copying to ROOT file for selector
string _myRcdbPath;
string _myCcdbPath;
string _myQadbPath;
//string _myQadbPath;

int _runNb={0};//!

Expand All @@ -92,6 +93,7 @@ namespace clas12 {
bool _qadbReqOKAsymmetry{false};
bool _qadbReqGolden{false};

short _verbose={0};
};


Expand Down
Loading

0 comments on commit da7457a

Please sign in to comment.