diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d68acec..b0e8623 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,8 +2,12 @@ name: C++ CI Testing on: pull_request +defaults: + run: + shell: bash + jobs: -build_and_test: + build_and_test: runs-on: ubuntu-latest container: rootproject/root:${{ matrix.version }} strategy: @@ -11,16 +15,17 @@ build_and_test: version: [6.28.12-ubuntu22.04] steps: - - name: system dependancies + - name: system dependencies run: | - apt update - apt -y install git scons python2 + apt -y update + apt -y upgrade + apt -y install git python3-pip + python -m pip install scons meson ninja - name: checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive - path: . - name: set env vars run: | @@ -36,25 +41,18 @@ build_and_test: echo "PATH=$PWD/bin:$CCDB_HOME:$CCDB_HOME/bin:$RCDB_HOME/bin:$RCDB_HOME/cpp/bin:$PATH" >> $GITHUB_ENV echo "LD_LIBRARY_PATH=$RCDB_HOME/cpp/lib:$CCDB_HOME/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV - - - name: checkout hipo - uses: actions/checkout@v4 - with: - repository: gavalian/hipo - ref: 4.0.1 # if you want to use a fixed tag; remove if you want to use `main` - path: ${HIPO} + - name: Create hipo folder + run: | + mkdir -p $HIPO - name: build hipo - run: | - cd $HIPO - cmake -DCMAKE_INSTALL_PREFIX=$HIPO - cmake --build . --target install + run: ./installHIPO $HIPO - name: build ccdb run: | cd $CCDB_HOME - bash environment.bash - /usr/bin/env python2 $(which scons) + source environment.bash + python $(which scons) - name: build clas12root run: | diff --git a/.gitignore b/.gitignore index 33280fc..ba54cd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,13 @@ # diff between stock checkout and after ./installC12Root bin build -hipo4 lib man +# dependency installations +############## +/hipo + # hipo source ############## ExtraPackages/rhipo/chipo/ diff --git a/.gitmodules b/.gitmodules index e9d8d51..138455f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,15 @@ [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 "clas12-qadb"] path = clas12-qadb url = https://github.com/JeffersonLab/clas12-qadb +[submodule "ccdb"] + path = ccdb + url = https://github.com/baltzell/ccdb.git +[submodule "hipo_src"] + path = hipo_src + url = https://github.com/gavalian/hipo.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fad631..ebc5492 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ if (DEFINED ENV{HIPO}) set(HIPOEXT $ENV{HIPO}) set(HIPO_INCLUDE_DIR ${HIPOEXT}/include/) - set(HIPO_LIBS -L${HIPOEXT}/ -lhipo4) + set(HIPO_LIBS "-L${HIPOEXT}/lib -lhipo4") MESSAGE( STATUS "HIPO INCLUDE_DIR : " ${HIPO_INCLUDE_DIR} ) MESSAGE( STATUS "HIPO LIBRARIES : " ${HIPO_LIBS} ) @@ -52,10 +52,14 @@ ENDIF (DEFINED ENV{QADB}) +set(HIPOROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/hipo4) set(CLAS12ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Clas12Root) set(CLAS12BANKS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Clas12Banks) +include_directories(${HIPOROOT_DIR}) +add_subdirectory (${HIPOROOT_DIR}) + include_directories(${CLAS12BANKS_DIR}) add_subdirectory (${CLAS12BANKS_DIR}) diff --git a/Clas12Banks/clas12databases.cpp b/Clas12Banks/clas12databases.cpp index 4e7d469..8b01267 100644 --- a/Clas12Banks/clas12databases.cpp +++ b/Clas12Banks/clas12databases.cpp @@ -41,10 +41,12 @@ namespace clas12 { _myRcdbPath=other._myRcdbPath; _myCcdbPath=other._myCcdbPath; //_myQadbPath=other._myQadbPath; - + _pass = other._pass; + initDBs(); - if(_qadb.get()){ + if(other._qadb.get()){ + initQA(); qadb_requireOkForAsymmetry(other._qadbReqOKAsymmetry); qadb_requireGolden(other._qadbReqGolden); qadb_setQARequirements(other._qadbReqsQA); @@ -57,11 +59,12 @@ namespace clas12 { _myRcdbPath=other._myRcdbPath; _myCcdbPath=other._myCcdbPath; //_myQadbPath=other._myQadbPath; - + _pass = other._pass; initDBs(); - if(_qadb.get()){ + if(other._qadb.get()){ + initQA(); qadb_requireOkForAsymmetry(other._qadbReqOKAsymmetry); qadb_requireGolden(other._qadbReqGolden); qadb_setQARequirements(other._qadbReqsQA); @@ -86,10 +89,10 @@ namespace clas12 { } - _qadb.reset( new qadb_reader{0} ); - 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 @@ -105,8 +108,11 @@ namespace clas12 { if(_ccdb.get()!=nullptr){ _ccdb->setRun(runNb); _ccdb->updateTables(); - } - if(_qadb.get()!=nullptr)_qadb->setRun(runNb); + } + if(_qadb.get()!=nullptr){ + // _qadb->setRun(runNb); + initQA(); + } if(_rcdb.get()!=nullptr)_rcdb->readRun(runNb); close(); diff --git a/Clas12Banks/clas12databases.h b/Clas12Banks/clas12databases.h index 1eb1a46..82ae714 100644 --- a/Clas12Banks/clas12databases.h +++ b/Clas12Banks/clas12databases.h @@ -64,7 +64,12 @@ namespace clas12 { //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_addQARequirement(string req){ + if(_qadb.get()==nullptr){ + throw std::runtime_error("clas12databases::qadb_addQARequirement - Need to call clas12reader::applyQA(cook) first"); + } + _qadb->addQARequirement(req);_qadbReqsQA.push_back(req); + } void qadb_setQARequirements( std::vector reqs){_qadb->setQARequirements(reqs); _qadbReqsQA = reqs;}; void qadb_requireOkForAsymmetry(bool ok){_qadb->requireOkForAsymmetry(ok);_qadbReqOKAsymmetry=ok;}; @@ -75,6 +80,18 @@ namespace clas12 { void turnOffQADB(){_qadb.reset();} void turnOffRCDB(){_rcdb.reset();} void turnOffCCDB(){_ccdb.reset();} + + void setPass(const string& pass){ + _pass = pass; + initQA(); + } + void initQA(){ + std::cout<<"clas12databases::initQA pass = "<<_pass<<" run ="<<_runNb< _rcdb;//! diff --git a/Clas12Banks/clas12reader.h b/Clas12Banks/clas12reader.h index d6f7ce3..bb83fba 100644 --- a/Clas12Banks/clas12reader.h +++ b/Clas12Banks/clas12reader.h @@ -146,6 +146,29 @@ namespace clas12 { int getBankOrder(int ibank,std::string itemname ) const{ return getBank(ibank)->getSchema().getEntryOrder(itemname.data()); } + + const std::vector getBanksPtrs(std::vector names) const{ + std::vector blist; + for(const auto& name:names){ + //Find this bank in all banks + auto it = std::find_if( + _allBanks.begin(), + _allBanks.end(), + [&name](auto* bank) + { return bank->getSchema().getName() == name; }); + if(it == _allBanks.end()) { + cerr<<"clas12reader::getBanks : bank "<(*it); + blist.push_back(cpBank); + + } + cout<<"clas12reader::getBanks got "<& getDetParticles(){return _detParticles;} @@ -153,7 +176,7 @@ namespace clas12 { std::vector getByID(int id); std::vector getByRegion(int ir); std::vector getByCharge(int ch); - + const std::vector& preCheckPids(); const std::vector& preCheckPidsOrCharge(); @@ -347,14 +370,9 @@ namespace clas12 { clas12databases* db(){return _db;}; //clas12-qadb - void applyQA() { - // if(_db) - if( _db->qa() ) - _applyQA=true; - - if( _applyQA==false){ - std::cout<<"Warning, clas12reader applyQA() not valid"<setPass(pass); } //double sumChargeFromQA(); diff --git a/Clas12Banks/covmatrix.h b/Clas12Banks/covmatrix.h index a51ec51..dd85094 100644 --- a/Clas12Banks/covmatrix.h +++ b/Clas12Banks/covmatrix.h @@ -40,8 +40,8 @@ namespace clas12 { int getPindex() { return getInt(_pindex_order,_index);} int getIndex() const {return _index;} int getIndex(int pindex); - void setIndex(int ind){_index=ind;} - void setEntry(int ind){_index=ind;} + void setIndex(int ind) const{_index=ind;} + void setEntry(int ind) const{_index=ind;} void setBankEntry(int ind){_index=ind;} const CovMatrix* matrix(); @@ -79,7 +79,7 @@ namespace clas12 { CovMatrix _matrix={5,std::vector(5,0)}; IndMatrix _morder={5,std::vector(5,-1)}; int _pindex_order=-1; - int _index=-1; + mutable int _index=-1; //std::map _rmap; std::vector _rvec; }; diff --git a/Clas12Banks/event.h b/Clas12Banks/event.h index 96182cd..a57a4f6 100644 --- a/Clas12Banks/event.h +++ b/Clas12Banks/event.h @@ -51,7 +51,7 @@ namespace clas12 { void notify() final{ bank::notify(); } - void setEntry(int ind){} + void setEntry(int ind) const{} void setBankEntry(int ind){} private : diff --git a/Clas12Banks/ftbevent.h b/Clas12Banks/ftbevent.h index d2942d3..ce3e12e 100644 --- a/Clas12Banks/ftbevent.h +++ b/Clas12Banks/ftbevent.h @@ -32,7 +32,7 @@ namespace clas12 { long getCategory() const noexcept{ return getLong(_cat_order,0); } float getStartTime() const noexcept{ return getFloat(_st_order,0); } - void setEntry(int ind){} + void setEntry(int ind) const {} void setBankEntry(int ind){} /** diff --git a/Clas12Banks/ftbparticle.h b/Clas12Banks/ftbparticle.h index 4aa3e63..cea5c04 100644 --- a/Clas12Banks/ftbparticle.h +++ b/Clas12Banks/ftbparticle.h @@ -33,7 +33,7 @@ namespace clas12 { int _py_order{-1}; int _pz_order{-1}; - short _entry{0}; + mutable short _entry{0}; public: @@ -67,7 +67,7 @@ namespace clas12 { float getPz() const noexcept{ return getFloat(_pz_order,_entry);} - void setEntry(short i){ + void setEntry(short i) const{ if( isetEntry(_matched_pindex); @@ -105,7 +105,7 @@ namespace clas12 { _matched_pindex=-1; bank::notify(); } - int match_to(int pindex){//pindex is index of reconstructed particle + int match_to(int pindex) const{//pindex is index of reconstructed particle _matched_pindex=pindex; return _match.get()!=nullptr ? _entry=_match->getMCindex(pindex) : _entry=-1 ; @@ -136,8 +136,8 @@ namespace clas12 { int _parent_order{-1}; int _daughter_order{-1}; - short _entry={0}; - short _matched_pindex; + mutable short _entry={0}; + mutable short _matched_pindex; mcmatch_uptr _match; }; diff --git a/Clas12Banks/particle.h b/Clas12Banks/particle.h index 28d5f2e..8c8f598 100644 --- a/Clas12Banks/particle.h +++ b/Clas12Banks/particle.h @@ -40,7 +40,7 @@ namespace clas12 { int _st_order{-1}; int _chi2pid_order{-1}; - short _entry={0}; + mutable short _entry={0}; public: @@ -101,7 +101,7 @@ namespace clas12 { return sqrt(x*x+y*y+z*z); } - void setEntry(short i){ _entry=i;if(_ftbpar)_ftbpar->setEntry(i);} + void setEntry(short i) const { _entry=i;if(_ftbpar)_ftbpar->setEntry(i);} void setBankEntry(short i){ _entry=i;} //faster for BankHist short getEntry() const noexcept{return _entry;} /** diff --git a/Clas12Banks/particle_detector.h b/Clas12Banks/particle_detector.h index 46fccd8..0b29255 100644 --- a/Clas12Banks/particle_detector.h +++ b/Clas12Banks/particle_detector.h @@ -57,9 +57,9 @@ namespace clas12 { int getIndex() const noexcept{return _index;} int getIndex(int pindex, int detector=0, int layer=0); - virtual void setIndex(int ind){_index=ind;} + virtual void setIndex(int ind) const{_index=ind;} void setBankEntry(short i){ _index=i;} //faster for BankHist - void setEntry(int ind){_index=ind;} + void setEntry(int ind) const{_index=ind;} //////////////////////////////////////////////////////////////// //virtual functions can be overridden in derived class @@ -80,7 +80,7 @@ namespace clas12 { int _detector_id_order=-1; int _pindex_order=-1; - int _index=-1; + mutable int _index=-1; // std::map _rmap; std::vector _rvec{}; diff --git a/Clas12Banks/qadb_reader.cpp b/Clas12Banks/qadb_reader.cpp index a91aedd..5ffdf58 100644 --- a/Clas12Banks/qadb_reader.cpp +++ b/Clas12Banks/qadb_reader.cpp @@ -4,7 +4,7 @@ namespace clas12 { #ifdef CLAS_QADB - qadb_reader::qadb_reader(int runNb):_qa{}{_runNb=runNb;}; + qadb_reader::qadb_reader(const string& pass,int runNb):_qa{pass}{_runNb=runNb;}; /////////////////////////////////////////////////////// /// Add masks for all QA requirements @@ -18,13 +18,13 @@ namespace clas12 { /////////////////////////////////////////////////////// ///Checks if an event passes all the QA requirements bool qadb_reader::passQAReqs(int evNb){ - // std::cout<<"DEBUG qadb_reader::passQAReqs "<<_runNb<<" "<setIndex(_ptof); return _scint->getTime(); } - double getPath() final{ + double getPath() const final{ _scint->setIndex(_ptof); return _scint->getPath(); } - double getDetEnergy() final{ + double getDetEnergy() const final{ _scint->setIndex(_ptof); return _scint->getEnergy(); } - double getDeltaEnergy() final{ + double getDeltaEnergy() const final{ _scint->setIndex(_pveto); return _scint->getEnergy(); } - short getSector() final{return 0;} + short getSector() const final{return 0;} private: diff --git a/Clas12Banks/region_cdet.h b/Clas12Banks/region_cdet.h index 60093e2..1268479 100644 --- a/Clas12Banks/region_cdet.h +++ b/Clas12Banks/region_cdet.h @@ -43,7 +43,7 @@ namespace clas12 { - double getTime() final{ + double getTime() const final{ if(_ptof>-1){ _scint->setIndex(_ptof); return _scint->getTime(); @@ -52,7 +52,7 @@ namespace clas12 { return _scint->getTime(); } - double getPath() final{ + double getPath() const final{ if(_ptof>-1){ _scint->setIndex(_ptof); return _scint->getPath(); @@ -61,7 +61,7 @@ namespace clas12 { return _scint->getPath(); } - double getDetEnergy() final{ + double getDetEnergy() const final{ //sum of cnd layers _scint->setIndex(_pcnd1); double energy=_scint->getEnergy(); @@ -72,12 +72,12 @@ namespace clas12 { return energy; } - double getDeltaEnergy() final{ + double getDeltaEnergy() const final{ _scint->setIndex(_ptof); return _scint->getEnergy(); } - short getSector() final{ + short getSector() const final{ return 0; } diff --git a/Clas12Banks/region_fdet.h b/Clas12Banks/region_fdet.h index 32bc8cc..c274796 100644 --- a/Clas12Banks/region_fdet.h +++ b/Clas12Banks/region_fdet.h @@ -50,7 +50,7 @@ namespace clas12 { rich_ptr rich() const final; - double getTime() final{ + double getTime() const final{ if(_ptof>-1 && par()->getCharge()!=0){ _scint->setIndex(_ptof); return _scint->getTime(); @@ -58,7 +58,7 @@ namespace clas12 { _cal->setIndex(_pcal); return _cal->getTime(); } - double getPath() final{ + double getPath() const final{ if(_ptof>-1 && par()->getCharge()!=0){ _scint->setIndex(_ptof); return _scint->getPath(); @@ -67,7 +67,7 @@ namespace clas12 { return _cal->getPath(); } - double getDetEnergy() final{ + double getDetEnergy() const final{ _cal->setIndex(_ppre); double energy=_cal->getEnergy(); _cal->setIndex(_pin); @@ -77,12 +77,12 @@ namespace clas12 { return energy; } - double getDeltaEnergy() final{ + double getDeltaEnergy() const final{ _scint->setIndex(_ptof); return _scint->getEnergy(); } - short getSector() final{ + short getSector() const final{ if(_ptrck>-1){ _trck->setIndex(_ptrck); return _trck->getSector(); diff --git a/Clas12Banks/region_ft.cpp b/Clas12Banks/region_ft.cpp index 003739b..3b1e690 100644 --- a/Clas12Banks/region_ft.cpp +++ b/Clas12Banks/region_ft.cpp @@ -20,7 +20,7 @@ namespace clas12 { /////////////////////////////////////////////////////// /// Temporary until FT banks updated - double region_ft::getPath(){ + double region_ft::getPath() const { if(_pcal>=0){ //currently no FT path reported if(_ft)_ft->setIndex(_pcal); double ftx=_ft->getX(); diff --git a/Clas12Banks/region_ft.h b/Clas12Banks/region_ft.h index ffb6a16..8ccddb1 100644 --- a/Clas12Banks/region_ft.h +++ b/Clas12Banks/region_ft.h @@ -38,23 +38,23 @@ namespace clas12 { traj_ptr traj(ushort det,ushort layer=0) const final; - double getTime() final{ + double getTime() const final{ _ft->setIndex(_pcal); return _ft->getTime(); } - double getPath() final; + double getPath() const final; - double getDetEnergy() final{ + double getDetEnergy() const final{ _ft->setIndex(_pcal); return _ft->getEnergy(); } - double getDeltaEnergy() final{ + double getDeltaEnergy() const final{ _ft->setIndex(_phod); return _ft->getEnergy(); } - short getSector() final{return 0;} + short getSector() const final{return 0;} private: diff --git a/Clas12Banks/region_particle.cpp b/Clas12Banks/region_particle.cpp index e48a619..e432fd9 100644 --- a/Clas12Banks/region_particle.cpp +++ b/Clas12Banks/region_particle.cpp @@ -59,7 +59,7 @@ namespace clas12 { } - double region_particle::getTheta() { + double region_particle::getTheta() const { _parts->setEntry(_pentry); double x=getPx(); double y=getPy(); @@ -67,13 +67,13 @@ namespace clas12 { return x == 0.0 && y == 0.0 && z == 0.0 ? 0.0 : atan2(sqrt(x*x+y*y),z); } - double region_particle::getPhi() { + double region_particle::getPhi() const { _parts->setEntry(_pentry); double x=getPx(); double y=getPy(); return atan2(y,x); } - double region_particle::getCalcMass() { + double region_particle::getCalcMass() const { double p=getP(); double t=getTime()-getStartTime(); double d=getPath()/100; @@ -93,23 +93,23 @@ namespace clas12 { // float beta= d/t/2.9979246e+08*1E9; // return beta; // } - double region_particle::getGamma() { + double region_particle::getGamma() const{ double beta=getBeta(); double gamma= sqrt(1/(1-beta*beta)); return gamma; } - double region_particle::getDeltaTime() { + double region_particle::getDeltaTime() const{ _parts->setEntry(_pentry); double t=getTime()-getVt(); double d=getPath()/100; return t-d/getBetaFromP()/2.99792e+08*1E9; } - double region_particle::getBetaFromP() { + double region_particle::getBetaFromP() const{ double pp=getP(); auto mass=getPdgMass(); return pp/sqrt(pp*pp+mass*mass); } - double region_particle::getPdgMass() { + double region_particle::getPdgMass() const { switch (getPid()) { diff --git a/Clas12Banks/region_particle.h b/Clas12Banks/region_particle.h index 984d6a2..f0882c1 100644 --- a/Clas12Banks/region_particle.h +++ b/Clas12Banks/region_particle.h @@ -68,43 +68,43 @@ namespace clas12 { } //solve FTB ambiguity at this stage - int getPid(){ + int getPid() const{ _parts->setEntry(_pentry); if(_ftbparts==nullptr) return _parts->getPid(); return _useFTBPid*_ftbparts->getRows()?_ftbparts->getPid():_parts->getPid(); } - float getVt(){ + float getVt() const{ _parts->setEntry(_pentry); if(_ftbparts==nullptr) return _parts->getVt(); auto vt = _useFTBPid*_ftbparts->getRows()?_ftbparts->getVt():_parts->getVt(); if(vt==-1)return getStartTime(); else return vt; } - int getStatus(){ + int getStatus() const{ _parts->setEntry(_pentry); if(_ftbparts==nullptr) return _parts->getStatus(); return _useFTBPid*_ftbparts->getRows()?_ftbparts->getStatus():_parts->getStatus(); } - float getChi2Pid(){ + float getChi2Pid() const{ _parts->setEntry(_pentry); if(_ftbparts==nullptr) return _parts->getChi2Pid(); return _useFTBPid*_ftbparts->getRows()?_ftbparts->getChi2Pid():_parts->getChi2Pid(); } - float getBeta(){ + float getBeta() const{ _parts->setEntry(_pentry); if(_ftbparts==nullptr) return _parts->getBeta(); return _useFTBPid*_ftbparts->getRows()?_ftbparts->getBeta():_parts->getBeta(); } - virtual double getTime()=0; - virtual double getPath()=0; - virtual double getDetEnergy()=0; - virtual double getDeltaEnergy()=0; - virtual short getSector() =0; + virtual double getTime() const=0; + virtual double getPath() const=0; + virtual double getDetEnergy() const=0; + virtual double getDeltaEnergy() const=0; + virtual short getSector() const=0; event_ptr event() const{return _event;}; - par_ptr par() const{_parts->setEntry(_pentry);return _parts;}; + const par_ptr par() const{_parts->setEntry(_pentry);return _parts;}; ftbpar_ptr ftbpar() const{_ftbparts->setEntry(_pentry);return _ftbparts;}; covmat_ptr covmat() const{_covmat->setIndex(_pcmat);return _covmat;}; virtual cal_ptr cal(ushort lay) const{_cal->setIndex(-1);return _cal;}; @@ -124,39 +124,39 @@ namespace clas12 { short getIndex()const {return _pentry;} short getRegion() const {return _region;} - double getTheta() ; - double getPhi() ; - double getP(){ + double getTheta() const; + double getPhi() const; + double getP() const{ _parts->setEntry(_pentry); if(_ftbparts==nullptr) return _parts->getP(); return _useFTBPid*_ftbparts->getRows()?_parts->getFTBP():_parts->getP(); } - double getPx(){ + double getPx() const{ _parts->setEntry(_pentry); if(_ftbparts==nullptr) return _parts->getPx(); return _useFTBPid*_ftbparts->getRows()?_parts->getFTBPx():_parts->getPx(); } - double getPy(){ + double getPy() const{ _parts->setEntry(_pentry); if(_ftbparts==nullptr) return _parts->getPy(); return _useFTBPid*_ftbparts->getRows()?_parts->getFTBPy():_parts->getPy(); } - double getPz(){ + double getPz() const{ _parts->setEntry(_pentry); if(_ftbparts==nullptr) return _parts->getPz(); return _useFTBPid*_ftbparts->getRows()?_parts->getFTBPz():_parts->getPz(); } - double getStartTime(){ + double getStartTime() const{ if(_ftbparts==nullptr) return _event->getStartTime(); return _useFTBPid*_event->getFTBStartTime()?_event->getFTBStartTime():_event->getStartTime(); } - double getCalcMass(); - double getGamma(); - double getDeltaTime(); - double getBetaFromP(); - double getPdgMass(); + double getCalcMass() const; + double getGamma() const; + double getDeltaTime() const; + double getBetaFromP() const; + double getPdgMass() const; void useFTBPid(){if(_ftbparts)_useFTBPid=1;} - double getMCThetaDiff() {return getTheta()-mc()->getTheta();} - double getMCPhiDiff() {return getPhi()-mc()->getPhi();} - double getMCPDiff() {return getP()-mc()->getP();} + double getMCThetaDiff() const {return getTheta()-mc()->getTheta();} + double getMCPhiDiff() const {return getPhi()-mc()->getPhi();} + double getMCPDiff() const {return getP()-mc()->getP();} //if(_parts->getCharge()) protected: diff --git a/Clas12Banks/rich.cpp b/Clas12Banks/rich.cpp index b62ae4f..ccc7c24 100644 --- a/Clas12Banks/rich.cpp +++ b/Clas12Banks/rich.cpp @@ -14,7 +14,9 @@ namespace clas12 { clas12::particle_detector(aschema), _ring{new richring(ringschema)} { - + // std::cout<<"DEBUG "<<"rich::rich()"<< std::endl; + //aschema.show(); + _detector_id_order=0; //dont have a detector bank, but getDetector is fixed _id_order = aschema.getEntryOrder("id"); _hindex_order = aschema.getEntryOrder("hindex"); _pindex_order = aschema.getEntryOrder("pindex"); @@ -40,10 +42,11 @@ namespace clas12 { } rich::rich(hipo::schema aschema): clas12::particle_detector(aschema) { - + + _detector_id_order=0; //dont have a detector bank, but getDetector is fixed _id_order = aschema.getEntryOrder("id"); - _hindex_order = aschema.getEntryOrder("hindex"); - _pindex_order = aschema.getEntryOrder("pindex"); + _hindex_order = aschema.getEntryOrder("hindex"); + _pindex_order = aschema.getEntryOrder("pindex"); _emilay_order = aschema.getEntryOrder("emilay"); _emico_order = aschema.getEntryOrder("emico"); _enico_order = aschema.getEntryOrder("enico"); diff --git a/Clas12Banks/rich.h b/Clas12Banks/rich.h index 7c1df02..9d58e15 100644 --- a/Clas12Banks/rich.h +++ b/Clas12Banks/rich.h @@ -89,7 +89,7 @@ namespace clas12 { return 0; } - + private: friend clas12::rich; diff --git a/Clas12Banks/runconfig.h b/Clas12Banks/runconfig.h index 3e5f3fb..8cc5bc4 100644 --- a/Clas12Banks/runconfig.h +++ b/Clas12Banks/runconfig.h @@ -49,7 +49,7 @@ namespace clas12 { void notify() final{ bank::notify(); } - void setEntry(int i){} + void setEntry(int i) const{} void setBankEntry(int ind){} private : diff --git a/Clas12Banks/vtp.h b/Clas12Banks/vtp.h index 8158e3f..c5552ad 100644 --- a/Clas12Banks/vtp.h +++ b/Clas12Banks/vtp.h @@ -41,13 +41,13 @@ namespace clas12 { void addVTPTriggerToEvent(long pattern); void setBankEntry(short i){ _index=i;} //faster for BankHist - void setEntry(int ind){_index=ind;} + void setEntry(int ind) const {_index=ind;} private : int cr_order{-1}; int wo_order{-1}; - int _index{0}; + mutable int _index{0}; std::bitset<32> _VTPBitSet; }; diff --git a/Clas12Root/HipoChain.h b/Clas12Root/HipoChain.h index 52061a6..6a5c751 100644 --- a/Clas12Root/HipoChain.h +++ b/Clas12Root/HipoChain.h @@ -56,6 +56,7 @@ namespace clas12root { clas12::clas12reader* GetC12Reader(); const std::unique_ptr& C12ref()const {return _c12;} + const std::unique_ptr* C12ptr()const {return &_c12;} Double_t TotalBeamCharge() noexcept{ diff --git a/Clas12Root/HipoSelector.cpp b/Clas12Root/HipoSelector.cpp index f4d0236..f51678f 100644 --- a/Clas12Root/HipoSelector.cpp +++ b/Clas12Root/HipoSelector.cpp @@ -58,6 +58,14 @@ namespace clas12root{ fInput->Add(_chain);//make chain of files avaialbel on slaves + + //copy database paths for proof. Previous method stopped working around Root 6.28 + + _rcdbPath = TNamed("RCDBPATH",_chain->db()->rcdbPath()); + _ccdbPath = TNamed("CCDBPATH",_chain->db()->ccdbPath()); + fInput->Add(&_rcdbPath); + fInput->Add(&_ccdbPath); + } void HipoSelector::SlaveBegin(TTree * /*tree*/) @@ -68,7 +76,12 @@ namespace clas12root{ fInput->Print(); TString option = GetOption(); _chain=dynamic_cast(fInput->FindObject("HIPOFILES")); - + //retrieve db paths + _rcdbPath=*(dynamic_cast(fInput->FindObject("RCDBPATH"))); + _ccdbPath=*(dynamic_cast(fInput->FindObject("CCDBPATH"))); + _chain->db()->SetRCDBRootConnection(_rcdbPath.GetTitle()); + _chain->db()->SetCCDBLocalConnection(_ccdbPath.GetTitle()); + _chain->db()->initDBs(); } Bool_t HipoSelector::Notify() { // Called at the start of a new file diff --git a/Clas12Root/HipoSelector.h b/Clas12Root/HipoSelector.h index a218d8f..6e8b51b 100644 --- a/Clas12Root/HipoSelector.h +++ b/Clas12Root/HipoSelector.h @@ -59,7 +59,9 @@ namespace clas12root{ Int_t GetCurrentRecord()const noexcept{return _iRecord;} Int_t GetCurrentFileNum()const noexcept{return _iFile;} Int_t GetCurrentFileRecords()const noexcept{return _NcurrRecords;} - + + HipoChain* GetChain() const{return _chain;} + protected: std::unique_ptr _c12;//! @@ -75,7 +77,10 @@ namespace clas12root{ } clas12::rcdb_reader* rcdb()const {return _chain->db()->rc();} clas12::qadb_reader* qadb()const {return _chain->db()->qa();} - + + TNamed _rcdbPath; + TNamed _ccdbPath; + private: HipoChain* _chain={nullptr};//! diff --git a/README.md b/README.md index 622423e..4b2911b 100644 --- a/README.md +++ b/README.md @@ -5,26 +5,14 @@ Data Analysis Tools for hipo4 data format. Examples are given for running in interactive ROOT sessions and ROOT-Jupyter notebooks. +## New : from version 1.9.0 an external `hipo` install is required before building clas12root -## Clas12Banks -> Clas12Root +We now use an external `hipo` repository. This must be pointed at with the environment variable `$HIPO` when installing. -We now use an external hipo4 repository. This must be pointed at with the variable HIPO when installing. The files from hipo/hipo4 will be copied here to Hipo4. +For convenience, the `hipo` source code is included here in `hipo_src/` as a submodule, and you may compile and install it with `./installHIPO`; +the default installation location is the top-level directory `hipo/`. - -A default hipo implementation is now packed with clas12root. If you prefer to use this do not set the enviroment variable HIPO. If you would like to use a different version of the hipo library set HIPO. You may get the most up to data hipo library from - - -For Hipo library see https://github.com/gavalian/hipo - -## New : from version 1.9.0 an external hipo install is required before building clas12root - - git clone --recurse-submodules https://github.com/gavalian/hipo - cd hipo/ - git checkout 4.0.1 - cmake -DCMAKE_INSTALL_PREFIX=$PWD/ - cmake --build . --target install - -The environment variable HIPO must be set to the path of the hipo install. +You may get the most up to date `hipo` source code from ## Clas12Banks and Clas12Root @@ -80,6 +68,12 @@ source ${CCDB_HOME}/environment.csh setenv QADB /Where/Is/clas12-qadb (e.g. setenv QADB ${CLAS12ROOT}/clas12-qadb ) #Preinstalled hipo is a requirement setenv HIPO /Where/Is/hipo +#If you wish to use, you should set a link to iguana +setenv IGUANA /Where/Is/Iguana +#We now also need root include path to support these pacakges +setenv ROOT_INCLUDE_PATH ${HIPO}/include:${IGUANA}/include:${ROOT_INCLUDE_PATH} +#and if you are using clas12root in other programmes it may help to include it +setenv ROOT_INCLUDE_PATH ${CLAS12ROOT}/Clas12Banks:${CLAS12ROOT}/Clas12Root:${CLAS12ROOT}/hipo4:${ROOT_INCLUDE_PATH} ``` or for bash @@ -87,14 +81,20 @@ or for bash export CLAS12ROOT=$PWD export PATH="$PATH":"$CLAS12ROOT/bin" #To use the RCDB interface -export RCDB_HOME /Where/Is/rcdb +export RCDB_HOME=/Where/Is/rcdb #To use the CCDB interface -export CCDB_HOME /Where/Is/ccdb +export CCDB_HOME=/Where/Is/ccdb source ${CCDB_HOME}/environment.csh #To use clas12-qadb interface -export QADB /Where/Is/clas12-qadb +export QADB=/Where/Is/clas12-qadb #Preinstalled hipo is a requirement -export HIPO /Where/Is/hipo +export HIPO=/Where/Is/hipo +#If you wish to use, you should set a link to iguana +export IGUANA=/Where/Is/Iguana +#We now also need root include path to support these pacakges +export ROOT_INCLUDE_PATH=${HIPO}/include:${IGUANA}/include:${ROOT_INCLUDE_PATH} +#and if you are using clas12root in other programmes it may help to include it +export ROOT_INCLUDE_PATH=${CLAS12ROOT}/Clas12Banks:${CLAS12ROOT}/Clas12Root:${CLAS12ROOT}/hipo4:${ROOT_INCLUDE_PATH} ``` ## To install @@ -480,24 +480,27 @@ Where ccdbElSF is a std::vector> and so you can access the e clas12root can use the Quality Assurance database .json files found at https://github.com/c-dilks/clas12-qadb/tree/master to reject events that have been identified as failing to meet certain requirements. This is implemented in an analysis using the clas12reader with the functions - c12.db()->qadb_requireOkForAsymmetry(true); - c12.db()->qadb_requireGolden(true); - c12.db()->qadb_addQARequirement("MarginalOutlier"); - c12.db()->qadb_addQARequirement("TotalOutlier"); - c12.applyQA(); + c12.db().applyQA(GETPASSSTRINGHERE);//GETPASSSTRINGHERE="latest", "pass1, "pass2",... + c12.db().qadb_addQARequirement("MarginalOutlier"); + c12.db().qadb_addQARequirement("TotalOutlier"); + c12.db().qadb_addQARequirement("TerminalOutlier"); + c12.db().qadb_addQARequirement("MarginalOutlier"); + c12.db().qadb_addQARequirement("SectorLoss"); + c12.db().qadb_addQARequirement("LowLiveTime"); Or in case you use HipoChain (also for when running PROOF/HipoSelector) - auto c12=chain.GetC12Reader(); - - c12->db()->qadb_requireOkForAsymmetry(true); - c12->db()->qadb_requireGolden(true); - c12->db()->qadb_addQARequirement("MarginalOutlier"); - c12->db()->qadb_addQARequirement("TotalOutlier"); - c12->applyQA(); - -where requireOkForAsymmetry(true) requires only events that were identified as suitable for asymmetry calculations, and requireGolden(true) requires only events without any defects. addQARequirement("Requirement") allows to reject events that fail to meet the specified requirement. These can be: + auto config_c12=chain.GetC12Reader(); + config_c12->applyQA(GETPASSSTRINGHERE);//GETPASSSTRINGHERE="latest", "pass1, "pass2",... + config_c12->db()->qadb_addQARequirement("MarginalOutlier"); + config_c12->db()->qadb_addQARequirement("TotalOutlier"); + config_c12->db()->qadb_addQARequirement("TerminalOutlier"); + config_c12->db()->qadb_addQARequirement("MarginalOutlier"); + config_c12->db()->qadb_addQARequirement("SectorLoss"); + config_c12->db()->qadb_addQARequirement("LowLiveTime"); + +addQARequirement("Requirement") allows to reject events that fail to meet the specified requirement. These can be: TotalOutlier: outlier N/F, but not terminal, marginal, or sector loss TerminalOutlier: outlier N/F of first or last file of run @@ -566,3 +569,67 @@ To create a clas12reader and go straight o a particular event in the file, Note the event number is just its position in the file, not the DST RUN::Config::Event. + +## Ex 11 Iguana interface + +To run iguana routines in clas12root you should first set the environment to point to an +installed version of iguana, by setting the IGUANA variable to the INSTALLATION directory. + +There are 2 methods of using Iguana. For speed and simplicity both use just the iguana +action function and will not operate on the underlying banks structures. +In the first method, which can use any iguan algorithm, you just directly create the iguana +algorithm and run it yourself. See Ex11_Iguana_example_01_bank_rows.C + +The second method is though a higher level interface which simplifies the usage, but is not +garuanteed to be able to use all algorithms. In these cases you may revert to the first method +to apply any additional algorithms. The interface for this is in the $CLAS12ROOT/iguana/ directory +and an example is available at Ex11_Iguana_MomentumCorrection.C. + +These example use a HipoChain and you will need to set file paths yourself etc. +Using clas12root:region_particles means that information for +alogithms is readily available and so we can just pass these particle objects +into the action functions. + +Highlighting the iguana parts for method 2 : + + //clas12root-iguana interface + clas12root::Iguana ig; + + //choose some algorithms to apply + ig.GetTransformers().Use("clas12::MomentumCorrection"); + ig.GetFilters().Use("clas12::ZVertexFilter"); + ig.GetCreators().Use("physics::InclusiveKinematics"); + + ig.SetOptionAll("log", "debug"); + ig.Start(); + + + ... + // get particles by type + // note we applied a filter to ensure size of all ==1 + auto electron=c12->getByID(11)[0]; + auto pip=c12->getByID(211)[0]; + auto pim=c12->getByID(-211)[0]; + + ///Now do some iguana analysis!! + + //filter on z-vertices of the particles + //note I can pass a vector of clas12root particles + if( !(ig.GetFilters().doZVertexFilter({electron,pip,pim})) ) { + continue; + } + + + //correct momentum and get 4-vectors + //I pass a vector of clas12root particles and LorentzVectors + ig.GetTransformers().doMomentumCorrections({electron,pip,pim},{&p4el,&p4pip,&p4pim}); + + //calculate inclusive kinematics + //use original bank info + auto kine = ig.GetCreators().doInclusiveKinematics(electron); + //use momentum corrected momentum + auto corrkine = ig.GetCreators().doInclusiveKinematics(p4el); + + ... + + diff --git a/RunRoot/Ex10_clas12Databases.C b/RunRoot/Ex10_clas12Databases.C index d296ae9..e64fd5e 100644 --- a/RunRoot/Ex10_clas12Databases.C +++ b/RunRoot/Ex10_clas12Databases.C @@ -44,13 +44,26 @@ void Ex10_clas12Databases(){ cout<<"Beam current: "<Start("db"); diff --git a/RunRoot/Ex10_clas12DatabasesChain.C b/RunRoot/Ex10_clas12DatabasesChain.C index c7e2d86..3635539 100644 --- a/RunRoot/Ex10_clas12DatabasesChain.C +++ b/RunRoot/Ex10_clas12DatabasesChain.C @@ -42,9 +42,6 @@ void Ex10_clas12DatabasesChain(){ //configure qadb requirements /* - * Several quality assurance requirements can be specified. - * requireOkForAsymmetry requires that an event was deemed - * suitable for asymmetry measurements. * * addRequirement requires that the event was not identified * as, for example, a marginal outlier. Several requirements @@ -53,21 +50,14 @@ void Ex10_clas12DatabasesChain(){ * See RGA analysis note and clas12-qadb github repository for * additional information. */ - if(config_c12->qadb()!=nullptr){ - config_c12->db()->qadb_requireOkForAsymmetry(true); - config_c12->db()->qadb_requireGolden(true); - config_c12->db()->qadb_addQARequirement("MarginalOutlier"); - config_c12->db()->qadb_addQARequirement("TotalOutlier"); - /* - * applyQA specifies to the clas12reader that quality assurance - * cuts will be applied, based on the .json file given as an - * argument. This file should contain the Clas12 Quality Assurance - * database. - * i.e. clas12reader will only process events that pass quality assurance - * and ignore those which fail - */ - config_c12->applyQA(); - } + config_c12->applyQA(GETPASSSTRINGHERE);//GETPASSSTRINGHERE="latest", "pass1, "pass2",... + config_c12->db()->qadb_addQARequirement("MarginalOutlier"); + config_c12->db()->qadb_addQARequirement("TotalOutlier"); + config_c12->db()->qadb_addQARequirement("TerminalOutlier"); + config_c12->db()->qadb_addQARequirement("MarginalOutlier"); + config_c12->db()->qadb_addQARequirement("SectorLoss"); + config_c12->db()->qadb_addQARequirement("LowLiveTime"); + gBenchmark->Start("db"); diff --git a/RunRoot/Ex11_Iguana_MomentumCorrection.C b/RunRoot/Ex11_Iguana_MomentumCorrection.C new file mode 100644 index 0000000..260a2b7 --- /dev/null +++ b/RunRoot/Ex11_Iguana_MomentumCorrection.C @@ -0,0 +1,141 @@ +#include "clas12reader.h" +#include "region_particle.h" +#include "HipoChain.h" +#include "Iguana.h" +#include +#include +#include +#include +#include +#include +#include +#include + +void Ex11_Iguana_MomentumCorrection(){ + + using FourVector = ROOT::Math::PxPyPzMVector; + // clas12databases::SetRCDBRootConnection("rcdb.root"); + gBenchmark->Start("iguana"); + //create hipo chain for looping over events + clas12root::HipoChain chain; + chain.Add("/home/dglazier/Jlab/clas12/data/hipo/DVPipPimP_006733.hipo"); + chain.SetReaderTags({0}); //create clas12reader with just tag 0 events + //add some filters + auto config_c12=chain.GetC12Reader(); + config_c12->addAtLeastPid(11,1); //exactly 1 electron + config_c12->addAtLeastPid(211,1); //exactly 1 pi+ + config_c12->addAtLeastPid(-211,1); //exactly 1 pi- + config_c12->ignoreBank("REC::CovMat"); + + + // create the chosen algorithms + clas12root::Iguana ig; + ig.SetClas12(chain.C12ptr());//connect to clas12reader + ig.GetTransformers().Use("clas12::MomentumCorrection"); + ig.GetTransformers().Use("clas12::FTEnergyCorrection"); + ig.GetFilters().Use("clas12::ZVertexFilter"); + ig.GetCreators().Use("physics::InclusiveKinematics"); + + ig.SetOptionAll("log", "debug"); + ig.Start(); + + + //decalre 4-vector objects + auto db=TDatabasePDG::Instance(); + FourVector p4beam(0,0,10.6,10.6); + FourVector p4target(0,0,0,db->GetParticle(2212)->Mass()); + FourVector p4el(0,0,0,db->GetParticle(11)->Mass()); + FourVector p4pip(0,0,0,db->GetParticle(211)->Mass()); + FourVector p4pim(0,0,0,db->GetParticle(-211)->Mass()); + TLorentzVector tp4el(0,0,0,db->GetParticle(11)->Mass()); + + TH1D hQ2{"Q2","Q^{2}",100,0,10}; + TH1D hx{"x","x",100,0,1}; + TH1D hy{"y","y",100,0,1}; + TH1D hW{"W","W",100,0,6}; + TH1D hcQ2{"cQ2","corrected Q^{2}",100,0,10}; + TH1D hcx{"cx","corrected x",100,0,1}; + TH1D hcy{"cy","corrected y",100,0,1}; + TH1D hcW{"cW","corrected W",100,0,6}; + + + //get run clas12reader + auto& c12=chain.C12ref(); + while ( chain.Next() ){ + ig.PrepareEvent(c12->getRunNumber()); + + //auto ebeam = c12->rcdb()->current().beam_energy/1000; + //p4beam.SetXYZT(0,0,ebeam,ebeam); //approx. mass =0 + //filter on z-vertices of the particles + //filter on fiducial cuts + //filter on PhotonGBT + ig.GetFilters().doAllFilters(); + + + //Check if particles still exist after filters + //and if they do assign them + auto getFirstParticle=[&c12](short pdg)->clas12::region_particle*{ + auto particles=c12->getByID(pdg); + if(particles.size()>0){ + return particles[0]; + } + return nullptr; + }; + + auto electron=getFirstParticle(11); + if(electron==nullptr) continue; + auto pip=getFirstParticle(211); + if(pip==nullptr) continue; + auto pim=getFirstParticle(-211); + if(pim==nullptr) continue; + + //correct momentum and get 4-vectors + ig.GetTransformers().doAllCorrections({electron,pip,pim},{&p4el,&p4pip,&p4pim}); + + //calculate inclusive kinematics + auto kine = ig.GetCreators().doInclusiveKinematics(electron); + auto corrkine = ig.GetCreators().doInclusiveKinematics(p4el); + + hQ2.Fill(kine.Q2); + hx.Fill(kine.x); + hy.Fill(kine.y); + hW.Fill(kine.W); + + hcQ2.Fill(corrkine.Q2); + hcx.Fill(corrkine.x); + hcy.Fill(corrkine.y); + hcW.Fill(corrkine.W); + + //if you unfortunately prefer TLorentzVector, there is a transform function to help. + // ig.GoodToBad(p4el,tp4el); + // cout<<"check good to bad "<Stop("iguana"); + gBenchmark->Print("iguana"); + + auto* can = new TCanvas(); + can->Divide(2,2); + + can->cd(1); + hQ2.DrawCopy(); + hcQ2.SetLineColor(2); + hcQ2.DrawCopy("same"); + + can->cd(2); + hW.DrawCopy(); + hcW.SetLineColor(2); + hcW.DrawCopy("same"); + + can->cd(3); + hx.DrawCopy(); + hcx.SetLineColor(2); + hcx.DrawCopy("same"); + + can->cd(4); + hy.DrawCopy(); + hcy.SetLineColor(2); + hcy.DrawCopy("same"); + + std::cout<<"analysed "< +#include + +void Ex11_Iguana_example_01_bank_rows(){ + // clas12databases::SetRCDBRootConnection("rcdb.root"); + + clas12root::HipoChain chain; + chain.Add("/home/dglazier/Jlab/clas12/data/hipo/DVPipPimP_006733.hipo"); + chain.SetReaderTags({0}); //create clas12reader with just tag 0 events + auto config_c12=chain.GetC12Reader(); + config_c12->addExactPid(11,1); //exactly 1 electron + config_c12->addExactPid(211,1); //exactly 1 pi+ + config_c12->addExactPid(-211,1); //exactly 1 pi- + + // create the algorithms + iguana::clas12::MomentumCorrection algo_momentum_correction; + // set log levels + algo_momentum_correction.SetOption("log", "debug"); + // start the algorithms + algo_momentum_correction.Start(); + + //get run clas12reader + auto& c12=chain.C12ref(); + int counter =0; + + //decalre 4-vector objects + auto db=TDatabasePDG::Instance(); + TLorentzVector p4beam(0,0,10.6,10.6); + TLorentzVector p4target(0,0,0,db->GetParticle(2212)->Mass()); + TLorentzVector p4el(0,0,0,db->GetParticle(11)->Mass()); + TLorentzVector p4pip(0,0,0,db->GetParticle(211)->Mass()); + TLorentzVector p4pim(0,0,0,db->GetParticle(-211)->Mass()); + + //define mometnum correction function taking a region_particle and a lorentzvector + auto momCorrection = [&algo_momentum_correction,&c12](region_particle *p, TLorentzVector& p4){ + + auto [px, py, pz] = algo_momentum_correction.Transform(p->getPx(),p->getPy(),p->getPz(),p->getSector(),p->getPid(),c12->runconfig()->getTorus()); + + p4.SetXYZM(px,py,pz,p4.M()); + }; + + //loop over all events + + while (chain.Next()){ + //auto ebeam = c12->rcdb()->current().beam_energy/1000; + // p4beam.SetXYZT(0,0,ebeam,ebeam); //approx. mass =0 + // get particles by type + // note we applied a filter to ensure size of all ==1 + auto electron=c12->getByID(11)[0]; + auto pip=c12->getByID(211)[0]; + auto pim=c12->getByID(-211)[0]; + + momCorrection(electron,p4el); + momCorrection(pip,p4pip); + momCorrection(pim,p4pim); + cout<<"el px "<getPx()<<" to "<getPy()<<" to "<getPz()<<" to "<Getenv("HIPO"); gSystem->Load(HIPO+"/lib/libhipo4"); + gInterpreter->AddIncludePath(HIPO+"/include"); TString CLAS12ROOT=gSystem->Getenv("CLAS12ROOT"); TString LIB=CLAS12ROOT+"/lib/"; @@ -46,4 +47,9 @@ void LoadClas12Root(){ gSystem->SetFlagsOpt(optFlags.Data()); + TString IGUANA = gSystem->Getenv("IGUANA"); + if(IGUANA.Length()>0){ + gROOT->ProcessLine(".x $CLAS12ROOT/RunRoot/LoadIguana.C"); + } + } diff --git a/RunRoot/LoadIguana.C b/RunRoot/LoadIguana.C new file mode 100644 index 0000000..fb300a7 --- /dev/null +++ b/RunRoot/LoadIguana.C @@ -0,0 +1,28 @@ +//setenv FMT .....(/usr/local?) +//setenv IGUANA .... +//setenv ROOT_INCLUDE_PATH ${FMT}/include:${ROOT_INCLUDE_PATH} + +void LoadIguana(){ + + //external iguana linking + TString IGUANA = gSystem->Getenv("IGUANA"); + gInterpreter->AddIncludePath(IGUANA+"/include"); + + gROOT->ProcessLine("#include "); + gROOT->ProcessLine("#include "); + gROOT->ProcessLine("#include "); + + gSystem->Load("$IGUANA/lib/libIguanaServices.so"); + gSystem->Load("$IGUANA/lib/libIguanaAlgorithms.so"); + gSystem->Load("$IGUANA/lib/libIguanaValidators.so"); + + //clas12root iguana stuff + TString CLAS12ROOT = gSystem->Getenv("CLAS12ROOT"); + gInterpreter->AddIncludePath(Form("%s/iguana",CLAS12ROOT.Data())); + gROOT->ProcessLine(Form("#include \"%s/iguana/IguanaAlgo.h\" ",CLAS12ROOT.Data())); + gROOT->ProcessLine(Form("#include \"%s/iguana/Transformers.h\" ",CLAS12ROOT.Data())); + gROOT->ProcessLine(Form("#include \"%s/iguana/Filters.h\" ",CLAS12ROOT.Data())); + gROOT->ProcessLine(Form("#include \"%s/iguana/Creators.h\" ",CLAS12ROOT.Data())); + gROOT->ProcessLine(Form("#include \"%s/iguana/Iguana.h\" ",CLAS12ROOT.Data())); + +} diff --git a/ccdb b/ccdb index 39397d9..08d5e3f 160000 --- a/ccdb +++ b/ccdb @@ -1 +1 @@ -Subproject commit 39397d98b15de27d4ec8e707d39e416d584c65a5 +Subproject commit 08d5e3f40511f2135741d351815c74d33737e806 diff --git a/clas12-qadb b/clas12-qadb index 61b8449..4ce0809 160000 --- a/clas12-qadb +++ b/clas12-qadb @@ -1 +1 @@ -Subproject commit 61b8449cf2a7b88eae1f9dd840f6bf279a0b5918 +Subproject commit 4ce08098865b43b793d44ea0d58e60f9649b400a diff --git a/hipo4/CMakeLists.txt b/hipo4/CMakeLists.txt index d5e1421..79bd111 100644 --- a/hipo4/CMakeLists.txt +++ b/hipo4/CMakeLists.txt @@ -1,23 +1,18 @@ -#ROOT_GENERATE_DICTIONARY(G__Hipo4 reader.h bank.h writer.h ntuple_writer.h ntuple_reader.h LINKDEF HipoLinkDef.h) #cant' generate dictionary for ntuple_writer with ROOT 6.22.02 see https://sft.its.cern.ch/jira/browse/ROOT-11013 +include_directories(${HIPO_INCLUDE_DIR}) -ROOT_GENERATE_DICTIONARY(G__Hipo4 reader.h bank.h writer.h LINKDEF HipoLinkDef.h) - -add_library(Hipo4 SHARED utils.cpp dictionary.cpp event.cpp record.cpp recordbuilder.cpp reader.cpp bank.cpp writer.cpp ntuple_writer.cpp ntuple_reader.cpp G__Hipo4.cxx) +ROOT_GENERATE_DICTIONARY(G__Hipo4 ntuple_writer.h ntuple_reader.h LINKDEF HipoLinkDef.h) +add_library(Hipo4 SHARED ntuple_writer.cpp ntuple_reader.cpp G__Hipo4.cxx) if( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") target_link_libraries(Hipo4 ${ROOT_LIBRARIES} "-undefined dynamic_lookup") else() - target_link_libraries(Hipo4 ${ROOT_LIBRARIES} ${LZ4_LINK_LIBRARY}) + target_link_libraries(Hipo4 ${ROOT_LIBRARIES} ${HIPO_LIBS}) endif() install(TARGETS Hipo4 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") -#FILE(GLOB ROOT_HIPO_PCM ${CMAKE_BINARY_DIR}/hipo4/*pcm) - -#install (FILES ${ROOT_HIPO_PCM} -# DESTINATION "${CMAKE_INSTALL_LIBDIR}") install (FILES ${CMAKE_CURRENT_BINARY_DIR}/libHipo4_rdict.pcm DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/hipo4/HipoLinkDef.h b/hipo4/HipoLinkDef.h index b3ffd6d..d30d50f 100644 --- a/hipo4/HipoLinkDef.h +++ b/hipo4/HipoLinkDef.h @@ -8,11 +8,7 @@ #pragma link C++ namespace hipo; -//#pragma link C++ defined_in "utils.h"; -#pragma link C++ class hipo::bank+; -#pragma link C++ class hipo::reader+; -#pragma link C++ class hipo::writer+; -//#pragma link C++ class hipo::ntuple_writer+; -//#pragma link C++ class hipo::ntuple_reader+; +#pragma link C++ class hipo::ntuple_writer+; +#pragma link C++ class hipo::ntuple_reader+; #pragma link C++ class hipo::data_addrs_to_func+; #endif diff --git a/hipo4/bank.cpp b/hipo4/bank.cpp deleted file mode 100644 index fd8676a..0000000 --- a/hipo4/bank.cpp +++ /dev/null @@ -1,214 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ -/******************************************************************************* - * File: bank.cc - * Author: gavalian - * - * Created on April 12, 2017, 10:14 AM - */ - -#include "bank.h" -#include "utils.h" - -namespace hipo { - - //============================================================== - // Definition of class structure, this will class will be extended - // to represent different objects that will be appended to the event - //============================================================== - - structure::structure(int __group, int __item, std::string &str){ - int length = str.length(); - initStructureBySize(__group,__item, 6, length); - putStringAt(0,str); - } - - bool structure::allocate(int size){ - if(structureBuffer.size()(structureAddress) = (uint16_t) __group; - *reinterpret_cast(&structureAddress[2]) = (uint8_t) __item; - *reinterpret_cast(&structureAddress[3]) = (uint8_t) __type; - *reinterpret_cast(&structureAddress[4]) = __size; - } - - void structure::setSize(int size){ - *reinterpret_cast(structureAddress+4) = size; - } - // return the type of the structure - int structure::getType(){ - auto type = (int) (*reinterpret_cast(structureAddress+3)); - return type; - } - // returns the group number of the object - int structure::getGroup(){ - auto group = (int) (*reinterpret_cast(structureAddress)); - return group; - } - // returns the item number of the structure - int structure::getItem(){ - auto item = (int) (*reinterpret_cast(structureAddress+2)); - return item; - } - void structure::initNoCopy(const char *buffer, int size){ - structureAddress = const_cast(buffer); - } - - void structure::init(const char *buffer, int size){ - allocate(size); - memcpy(&structureBuffer[0],buffer,size); - structureAddress = &structureBuffer[0]; - } - - void structure::show(){ - printf("structure : [%5d,%5d] type = %4d, length = %6d\n", - getGroup(),getItem(),getType(),getSize()); - } - - std::string structure::getStringAt(int index){ - int length = getSize(); - auto *string_ch = (char *) malloc(length+1); - std::memcpy(string_ch, &structureBuffer[8],length); - string_ch[length] = '\0'; - std::string result = string_ch; - free(string_ch); - return result; - } - - void structure::putStringAt(int index, std::string &str){ - int strLen = str.length(); - std::memcpy(&structureBuffer[8],&str[0],strLen); - } - - const char *structure::getAddress(){ - return structureAddress; - } - - //==================================================================== - // END of structure class - //==================================================================== - -bank::bank()= default; - -bank::~bank()= default; - -void bank::setRows(int rows){ - bankRows = rows; - int size = bankSchema.getSizeForRows(bankRows); - initStructureBySize(bankSchema.getGroup(),bankSchema.getItem(), 11, size); - //allocate(size+12); -} - -void bank::reset(){ - setSize(0); - bankRows = 0; -} - -void bank::notify(){ - int size = bankSchema.getRowLength(); - bankRows = getSize()/size; - //printf("---> bank notify called structure size = %8d (size = %5d) rows = %d\n", - // getSize(),size, bankRows); -} - - -void bank::putInt(const char *name, int index, int32_t value){ - int item = bankSchema.getEntryOrder(name); - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - putIntAt(offset,value); -} -void bank::putShort(const char *name, int index, int16_t value){ - int item = bankSchema.getEntryOrder(name); - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - putShortAt(offset,value); -} -void bank::putByte(const char *name, int index, int8_t value){ - int item = bankSchema.getEntryOrder(name); - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - putByteAt(offset,value); -} -void bank::putFloat(const char *name, int index, float value){ - int item = bankSchema.getEntryOrder(name); - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - //printf("---- put float %f at position = %d\n",value,offset); - putFloatAt(offset,value); -} -void bank::putDouble(const char *name, int index, double value){ - int item = bankSchema.getEntryOrder(name); - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - putDoubleAt(offset,value); -} - -void bank::putLong(const char *name, int index, int64_t value){ - int item = bankSchema.getEntryOrder(name); - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - putLongAt(offset,value); -} - -void bank::show(){ - - printf("BANK :: NAME %24s , ROWS %6d \n",bankSchema.getName().c_str(),getRows()); - for(int i = 0; i < bankSchema.getEntries(); i++){ - //printf("%14d : ", i); - printf("%18s : ", bankSchema.getEntryName(i).c_str()); - for(int k = 0; k < bankRows; k++){ - if(bankSchema.getEntryType(i) < 4){ - printf("%8d ",getInt(i,k)); - } else { - if(bankSchema.getEntryType(i)==4) { - printf("%8.5f ",getFloat(i,k)); - } - if(bankSchema.getEntryType(i)==5) { - printf("%8.5f ",getDouble(i,k)); - } - if(bankSchema.getEntryType(i)==8){ - printf("%14ld ", getLong(i,k)); - } - - } - } - printf("\n"); - } -} - -} diff --git a/hipo4/bank.h b/hipo4/bank.h deleted file mode 100644 index 7139f9d..0000000 --- a/hipo4/bank.h +++ /dev/null @@ -1,377 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ -/******************************************************************************* - * File: bank.h - * Author: gavalian - * - * Created on April 12, 2017, 10:14 AM - */ - -#ifndef HIPO_BANK_H -#define HIPO_BANK_H -#include -#include -#include -#include -#include -#include -#include -#include "dictionary.h" - -namespace hipo { - - class structure { - - private: - - std::vector structureBuffer; - char *structureAddress{}; - void setAddress(const char *address); - - protected: - - void initStructureBySize(int __group, int __item, int __type, int __size); - std::vector &getStructureBuffer(){ return structureBuffer;} - int getStructureBufferSize(){ return 8+getSize();} - friend class tuple; - public: - - structure(){ structureAddress = nullptr;} - structure(int size){ allocate(size);} - structure(int __group, int __item, std::string &str); - - virtual ~structure()= default; - bool allocate(int size); - int getSize() const noexcept{ - return *reinterpret_cast(structureAddress+4); - } - int getType(); - int getGroup(); - int getItem(); - void init(const char *buffer, int size); - void initNoCopy(const char *buffer, int size); - - const char *getAddress(); - virtual void show(); - void setSize(int size); - - - int getIntAt ( int index) const noexcept { - return *reinterpret_cast(&structureAddress[index+8]); - } - int16_t getShortAt ( int index) const noexcept { - return *reinterpret_cast(&structureAddress[index+8]); - } - int8_t getByteAt ( int index) const noexcept { - return *reinterpret_cast(&structureAddress[index+8]); - } - float getFloatAt ( int index) const noexcept { - return *reinterpret_cast(&structureAddress[index+8]); - } - double getDoubleAt( int index) const noexcept { - return *reinterpret_cast(&structureAddress[index+8]); - } - long getLongAt ( int index) const noexcept { - return *reinterpret_cast(&structureAddress[index+8]); - } - - std::string getStringAt(int index); - - void putIntAt(int index, int value){ - *reinterpret_cast(&structureAddress[index+8]) = value; - } - - void putShortAt(int index, int16_t value){ - *reinterpret_cast(&structureAddress[index+8]) = value; - } - - void putByteAt(int index, int8_t value){ - *reinterpret_cast(&structureAddress[index+8]) = value; - } - - void putFloatAt(int index, float value){ - *reinterpret_cast(&structureAddress[index+8]) = value; - } - - void putDoubleAt(int index, double value){ - *reinterpret_cast(&structureAddress[index+8]) = value; - } - - void putLongAt(int index, int64_t value){ - *reinterpret_cast(&structureAddress[index+8]) = value; - } - - void putStringAt(int index, std::string &str); - - virtual void notify(){} - friend class event; - }; - - //typedef std::auto_ptr node_pointer; - - class bank : public hipo::structure { - - private: - - hipo::schema bankSchema; - int bankRows{-1}; - - protected: - void setBankRows(int rows){ bankRows = rows;} - - public: - - bank(); - // constructor initializes the nodes in the bank - // and they will be filled automatically by reader.next() - // method. - bank(const hipo::schema& __schema){ - bankSchema = __schema; - bankRows = -1; - } - - bank(const hipo::schema& __schema, int __rows){ - bankSchema = __schema; - bankRows = __rows; - int size = bankSchema.getSizeForRows(__rows); - initStructureBySize(bankSchema.getGroup(),bankSchema.getItem(), 11, size); - } - - ~bank() override; - // display the content of the bank - //void show(); - - hipo::schema &getSchema() { return bankSchema;} - - int getRows() const noexcept{ return bankRows;} - void setRows( int rows); - int getInt( int item, int index) const noexcept; - int getShort( int item, int index) const noexcept; - int getByte( int item, int index) const noexcept; - float getFloat( int item, int index) const noexcept; - double getDouble( int item, int index) const noexcept; - long getLong( int item, int index) const noexcept; - - int getInt( const char *name, int index) const noexcept; - int getShort( const char *name, int index) const noexcept; - int getByte( const char *name, int index) const noexcept; - float getFloat( const char *name, int index) const noexcept; - double getDouble( const char *name, int index) const noexcept; - long getLong( const char *name, int index) const noexcept; - - void putInt( const char *name, int index, int32_t value); - void putShort( const char *name, int index, int16_t value); - void putByte( const char *name, int index, int8_t value); - void putFloat( const char *name, int index, float value); - void putDouble( const char *name, int index, double value); - void putLong( const char *name, int index, int64_t value); - - void putInt(int item, int index, int32_t value); - void putShort(int item, int index, int16_t value); - void putByte(int item, int index, int8_t value); - void putFloat(int item, int index, float value); - void putDouble(int item, int index, double value); - void putLong(int item, int index, int64_t value); - - void show() override; - void reset(); - //virtual void notify(){ }; - - void notify() override; - - - - }; - ///////////////////////////////////// - //inlined getters - - inline float bank::getFloat(int item, int index) const noexcept{ - if(bankSchema.getEntryType(item)==4){ - int offset = bankSchema.getOffset(item, index, bankRows); - return getFloatAt(offset); - } - return 0.0; - } - - inline double bank::getDouble(int item, int index) const noexcept{ - if(bankSchema.getEntryType(item)==5){ - int offset = bankSchema.getOffset(item, index, bankRows); - return getDoubleAt(offset); - } - if(bankSchema.getEntryType(item)==4){ - int offset = bankSchema.getOffset(item, index, bankRows); - return getFloatAt(offset); - } - return 0.0; - } - - inline long bank::getLong(int item, int index) const noexcept{ - if(bankSchema.getEntryType(item)==8){ - int offset = bankSchema.getOffset(item, index, bankRows); - return getLongAt(offset); - } - return 0; - } - - inline int bank::getInt(int item, int index) const noexcept{ - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - switch(type){ - case 1: return (int) getByteAt(offset); - case 2: return (int) getShortAt(offset); - case 3: return getIntAt(offset); - default: printf("---> error : requested INT for [%s] type = %d\n", - bankSchema.getEntryName(item).c_str(),type); break; - } - return 0; - } - - inline int bank::getShort(int item, int index) const noexcept{ - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - switch(type){ - case 1: return (int) getByteAt(offset); - case 2: return (int) getShortAt(offset); - default: printf("---> error : requested SHORT for [%s] type = %d\n", - bankSchema.getEntryName(item).c_str(),type); break; - } - return 0; - } - - inline int bank::getByte(int item, int index) const noexcept{ - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - switch(type){ - case 1: return (int) getByteAt(offset); - default: printf("---> error : requested BYTE for [%s] type = %d\n", - bankSchema.getEntryName(item).c_str(),type); break; - } - return 0; - } - inline int bank::getInt(const char *name, int index) const noexcept{ - int item = bankSchema.getEntryOrder(name); - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - switch(type){ - case 1: return (int) getByteAt(offset); - case 2: return (int) getShortAt(offset); - case 3: return getIntAt(offset); - default: printf("---> error : requested INT for [%s] type = %d\n",name,type); break; - } - return 0; - } - - inline int bank::getShort(const char *name, int index) const noexcept{ - int item = bankSchema.getEntryOrder(name); - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - switch(type){ - case 1: return (int) getByteAt(offset); - case 2: return (int) getShortAt(offset); - default: printf("---> error : requested SHORT for [%s] type = %d\n", - bankSchema.getEntryName(item).c_str(),type); break; - } - return 0; - } - inline int bank::getByte(const char *name, int index) const noexcept{ - int item = bankSchema.getEntryOrder(name); - int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - switch(type){ - case 1: return (int) getByteAt(offset); - default: printf("---> error : requested BYTE for [%s] type = %d\n", - bankSchema.getEntryName(item).c_str(),type); break; - } - return 0; - } - - inline float bank::getFloat(const char *name, int index) const noexcept{ - int item = bankSchema.getEntryOrder(name); - if(bankSchema.getEntryType(item)==4){ - int offset = bankSchema.getOffset(item, index, bankRows); - return getFloatAt(offset); - } - return 0.0; - } - - inline double bank::getDouble(const char *name, int index) const noexcept{ - int item = bankSchema.getEntryOrder(name); - if(bankSchema.getEntryType(item)==5){ - int offset = bankSchema.getOffset(item, index, bankRows); - return getDoubleAt(offset); - } - if(bankSchema.getEntryType(item)==4){ - int offset = bankSchema.getOffset(item, index, bankRows); - return (double) getFloatAt(offset); - } - return 0.0; - } - - inline long bank::getLong(const char *name, int index) const noexcept{ - int item = bankSchema.getEntryOrder(name); - if(bankSchema.getEntryType(item)==8){ - int offset = bankSchema.getOffset(item, index, bankRows); - return getLongAt(offset); - } - return 0; - } - inline void bank::putInt(int item, int index, int32_t value){ - //int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - putIntAt(offset,value); - } - inline void bank::putShort(int item, int index, int16_t value){ - //int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - putShortAt(offset,value); - } - inline void bank::putByte(int item, int index, int8_t value){ - //int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - putByteAt(offset,value); - } - inline void bank::putFloat(int item, int index, float value){ - //int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - //printf("---- put float %f at position = %d\n",value,offset); - putFloatAt(offset,value); - } - inline void bank::putDouble(int item, int index, double value){ - //int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - putDoubleAt(offset,value); - } - inline void bank::putLong(int item, int index, int64_t value){ - //int type = bankSchema.getEntryType(item); - int offset = bankSchema.getOffset(item, index, bankRows); - putLongAt(offset,value); - } -} -#endif /* BANK_H */ diff --git a/hipo4/datastream.cpp b/hipo4/datastream.cpp deleted file mode 100644 index 55fd388..0000000 --- a/hipo4/datastream.cpp +++ /dev/null @@ -1,94 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ - /* - * File: datastream.cpp - * Author: gavalian - * - * Created on May 5, 2020, 9:24 PM - */ - -#include "datastream.h" - -#include - -namespace hipo { - /** - * The constructor for reader, printWarning routine - * will printout a warning message if the library - * was not compiled with compression libraries LZ4 or GZIP - */ - datastreamXrootd::datastreamXrootd(){ - - } - - /*datastreamXrootd::datastreamXrootd(const char *address){ - - }*/ - /** - * Default destructor. Does nothing - */ - datastreamXrootd::~datastreamXrootd(){ - #ifdef __XROOTD__ - if(cli!=NULL) delete cli; - #endif - } - - - void datastreamXrootd::open(const char *filename){ -#ifdef __XROOTD__ - printf("[datastream::xrootd] >>> open : %s\n" + filename); - XrdClient *cli = new new XrdClient(filename); - cli->Open(open_mode,open_opts); -#endif - } - - long datastreamXrootd::size(){ - #ifdef __XROOTD__ - XrdClientStatInfo stats; - cli->Stat(&stats); - return stats.size(); - #endif - #ifndef __XROOTD__ - return 0; - #endif - } - - long datastreamXrootd::position(){ return streamPosition;} - long datastreamXrootd::position(long pos){ streamPosition = pos; return streamPosition;} - int datastreamXrootd::read(char *s, int size){ - #ifdef __XROOTD__ - cli->Read(s,streamPosition,size); - return size; - #endif - #ifndef __XROOTD__ - return 0; - #endif - } -} diff --git a/hipo4/datastream.h b/hipo4/datastream.h deleted file mode 100644 index edf1513..0000000 --- a/hipo4/datastream.h +++ /dev/null @@ -1,137 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ -/* - * This class is generic class that is suppose to provide a data stream. - * it is implemented as a test case for xrootd, functionality to switch - * between the regular file and files provided by xrootd server. - * File: datastream.h - * Author: gavalian - * - * Created on May 5, 2020, 9:18 PM - */ - -#ifndef DATASTREAM_H -#define DATASTREAM_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __XROOTD__ -#include -#include "XrdClient/XrdClientEnv.hh" -#include "XrdSys/XrdSysHeaders.hh" -#endif - -namespace hipo { - - -class datastream { - - private: - - std::ifstream inputStream; - std::string remoteAddress; - int streamType = 1; - - - public: - - datastream(); - //datastream(const char *address); - virtual ~datastream(); - - virtual long size(){ return 0;} - virtual long position(){ return 0;} - virtual long position(long pos){ return 0;} - //virtual void setAdress(const char *address){} - virtual void open(const char *filename){} - virtual int read(char *s, int size){return 0;} - }; - -class datastreamLocalFile { - - private: - std::ifstream inputStream; - - public: - - datastreamLocalFile(); - ~datastreamLocalFile(){ - if(inputStream.is_open()==true){ - inputStream.close(); - } - } - - long size(){ - long pos = inputStream.tellg(); - inputStream.seekg(0,std::ios_base::end); - long lastpos = inputStream.tellg(); - inputStream.seekg(pos,std::ios_base::beg); - return lastpos; - } - - void open(const char *filename){ - inputStream.open(filename, std::ios::binary); - } - long position(){ return inputStream.tellg();} - long position(long pos){ inputStream.seekg(pos,std::ios_base::beg); return pos; } - int read(char *s, int size){inputStream.read(s,size); return size;} -}; - -class datastreamXrootd { - -private: - #ifdef __XROOTD__ - kXR_unt16 open_mode = (kXR_ur); - kXR_unt16 open_opts = (1); - XrdClient *cli = NULL; - #endif - long streamPosition = 0; - -public: - datastreamXrootd(); - ~datastreamXrootd(); - - - long size(); - long position(); - long position(long pos); - //virtual void setAdress(const char *address){} - void open(const char *filename); - int read(char *s, int size); -}; -} -#endif /* DATASTREAM_H */ diff --git a/hipo4/dictionary.cpp b/hipo4/dictionary.cpp deleted file mode 100644 index e65c735..0000000 --- a/hipo4/dictionary.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#include "dictionary.h" -#include "utils.h" -#include - -namespace hipo { - - void schema::parse(const std::string& schString){ - std::vector entries; - std::vector entry; - hipo::utils::tokenize(schString, entries, ","); - int offset = 0; - for(int i = 0; i < entries.size(); i++){ - entry.clear(); - hipo::utils::tokenize(entries[i],entry, "/"); - schemaEntry_t e; - e.name = hipo::utils::trim(entry[0]); - e.type = hipo::utils::trim(entry[1]); - e.typeId = getTypeByString(e.type); - e.typeSize = getTypeSize(e.typeId); - e.offset = offset; - offset += e.typeSize; - schemaEntries.push_back(e); - schemaEntriesMap[e.name] = i; - } - } - - int schema::getTypeByString(std::string &typeName){ - if(typeName=="B"){ - return 1; - } else if(typeName=="S") { - return 2; - } else if(typeName=="I") { - return 3; - } else if(typeName=="F") { - return 4; - } else if(typeName=="D") { - return 5; - } else if(typeName=="L") { - return 8; - } - return -1; - } - - int schema::getTypeSize(int id){ - switch(id){ - case 1: return 1; - case 2: return 2; - case 3: return 4; - case 4: return 4; - case 5: return 8; - case 8: return 8; - default: return 0; - } - return 0; - } - - void schema::show(){ - printf("schema : %14s , group = %6d, item = %3d\n", - schemaName.c_str(),groupid,itemid); - for(auto & schemaEntrie : schemaEntries){ - printf("%16s : (%3s) %5d %5d , offset = %3d --> [%s]\n", - schemaEntrie.name.c_str(),schemaEntrie.type.c_str(), - schemaEntrie.typeId,schemaEntrie.typeSize, schemaEntrie.offset, - schemaEntrie.name.c_str() - ); - } - } - - - int schema::getSizeForRows(int rows){ - int nentries = schemaEntries.size(); - int offset = getOffset(nentries-1,rows-1,rows) + schemaEntries[nentries-1].typeSize; - return offset; - } - - std::string schema::getSchemaString(){ - char parts[256]; - std::string result; - sprintf(parts,"{%s/%d/%d}{",schemaName.c_str(),groupid,itemid); - result.append(parts); - for(int loop = 0; loop < schemaEntries.size(); loop++){ - sprintf(parts,"%s/%s",schemaEntries[loop].name.c_str(), schemaEntries[loop].type.c_str()); - if(loop!=0) result.append(","); - result.append(parts); - } - result.append("}"); - return result; - } - - std::string schema::getSchemaStringJson(){ - char parts[256]; - std::string result; - sprintf(parts,"{ \"name\": \"%s\", \"group\": %d, \"item\": %d, \"info\": \" \",", - schemaName.c_str(),groupid,itemid); - result.append(parts); - result.append("\"entries\": [ "); - for(int loop = 0; loop < schemaEntries.size(); loop++){ - sprintf(parts,"{\"name\":\"%s\", \"type\":\"%s\", \"info\":\" \"}", - schemaEntries[loop].name.c_str(), schemaEntries[loop].type.c_str()); - if(loop!=0) result.append(","); - result.append(parts); - } - result.append("] }"); - return result; - } - - - //============================================= - // Implementation of dictionary class - //============================================= - std::vector dictionary::getSchemaList(){ - std::map::iterator it; - std::vector vec; - for ( it = factory.begin(); it != factory.end(); it++ ){ - vec.push_back(it->first); - } - return vec; - } - - bool dictionary::parse(const char *schemaString){ - std::vector tokens; - std::string schemahead = hipo::utils::substring(schemaString,"{","}",0); - hipo::utils::tokenize(schemahead, tokens, "/"); - int group = std::atoi(tokens[1].c_str()); - int item = std::atoi(tokens[2].c_str()); - hipo::schema schema (tokens[0].c_str(),group,item); - std::string schemabody = hipo::utils::substring(schemaString,"{","}",1); - schema.parse(schemabody.c_str()); - addSchema(schema); - return true; - } - - void dictionary::show(){ - std::vector list = getSchemaList(); - for(auto & i : list){ - schema sc = getSchema(i.c_str()); - printf("%24s : %5d %5d %5d\n", sc.getName().c_str(), - sc.getGroup(), sc.getItem(),sc.getEntries()); - } - } -} diff --git a/hipo4/dictionary.h b/hipo4/dictionary.h deleted file mode 100644 index 5fc8f74..0000000 --- a/hipo4/dictionary.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -/* - * File: dictionary.h - * Author: gavalian - * - * Created on April 27, 2017, 10:01 AM - */ - -#ifndef DICTIONARY_H -#define DICTIONARY_H - -#include -#include -#include -#include -#include -#include - -//#include "reader.h" - -namespace hipo { - - typedef struct schemaEntry_t { - std::string name; - std::string type; - int typeId{}; - int typeSize{}; - int offset{}; - } schemaEntry_t; - -class schema { - private: - - std::map schemaEntriesMap; - std::vector schemaEntries; - - int groupid{}; - int itemid{}; - int rowLength{}; - mutable int warningCount{10}; - - std::string schemaName; - - - int getTypeSize(int id); - int getTypeByString(std::string &typeName); - - - public: - - schema(){ groupid = 0; itemid = 0; rowLength = 0;} - schema(const char *name, int __group,int __item){ - schemaName = name; groupid = __group; itemid = __item; - } - schema(const schema &s) { - schemaName = s.schemaName; - schemaEntries = s.schemaEntries; - schemaEntriesMap = s.schemaEntriesMap; - groupid = s.groupid; - itemid = s.itemid; - } - - virtual ~schema()= default; - - void parse(const std::string& schString); - std::string getName(){ return schemaName;} - int getGroup(){ return groupid;} - int getItem(){ return itemid;} - int getSizeForRows(int rows); - - int getRowLength() const noexcept{ - const auto nentries = schemaEntries.size()-1; - const auto &sch=schemaEntries[nentries]; - return sch.offset + sch.typeSize; - } - - int getEntryOrder(const char *name) const; - - bool exists(const char *name) const{ - if(schemaEntriesMap.count(name)) return true; - return false; - } - - int getOffset(int item, int order, int rows) const { - const auto &sch=schemaEntries[item]; - return rows*sch.offset + order*sch.typeSize; - } - - int getOffset(const char *name, int order, int rows) const { - int item = schemaEntriesMap.at(name); - return getOffset(item,order,rows); - } - - int getEntryType(int item) const noexcept { - return schemaEntries[item].typeId; - } - std::string getEntryName(int item) const noexcept { return schemaEntries[item].name;} - int getEntries() const noexcept { return schemaEntries.size();} - void show(); - - std::string getSchemaString(); - std::string getSchemaStringJson(); - - void operator = (const schema &D ) { - schemaName = D.schemaName; - groupid = D.groupid; - itemid = D.itemid; - schemaEntries = D.schemaEntries; - schemaEntriesMap = D.schemaEntriesMap; - } -}; - - inline int schema::getEntryOrder(const char *name) const { - if(exists(name)) - return schemaEntriesMap.at(name);//at needed for const function - - if(warningCount>0 ) { warningCount--; std::cout<<"Warning , hipo::schema getEntryOrder(const char *name) item :" < factory; - public: - dictionary()= default;; - virtual ~dictionary()= default;; - - std::vector getSchemaList(); - void addSchema(schema sc){ factory[sc.getName()] = sc;} - bool hasSchema(const char *name) { return (factory.count(name)!=0);} - schema &getSchema(const char *name){ - if(factory.count(name)==0){ - printf("\n\nhipo::dictionary (ERROR) schema {%s} does not exist... exiting\n\n",name); - exit(0); - } - return factory[name]; - } - bool parse(const char *schemaString); - void show(); - }; - -} - -#endif /* NODE_H */ diff --git a/hipo4/event.cpp b/hipo4/event.cpp deleted file mode 100644 index c277f6f..0000000 --- a/hipo4/event.cpp +++ /dev/null @@ -1,224 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ - /* - * File: event.h - * Author: gavalian - * - * Created on April 12, 2017, 10:14 AM - */ - -#include "event.h" - -namespace hipo { - - - event::event(){ - #if __cplusplus > 199711L - //printf("\n*****>>>>> compiled with c++11 support.\n"); - #endif - // default allocation size for the event is 128 Kb - dataBuffer.resize(128*1024); - reset(); - } - - event::event(int size){ - dataBuffer.resize(size); - reset(); - } - - event::~event()= default; - - void event::getStructure(hipo::bank &b){ - getStructure(b,b.getSchema().getGroup(),b.getSchema().getItem()); - } - - void event::read(hipo::bank &b){ - getStructure(b,b.getSchema().getGroup(),b.getSchema().getItem()); - } - - - void event::getStructure(hipo::structure &str, int group, int item){ - std::pair index = getStructurePosition(group,item); - if(index.first>0){ - str.init(&dataBuffer[index.first], index.second + 8); - str.notify(); - } else { - str.initStructureBySize(group,item,1,0); - str.notify(); - //printf("*** error *** : structure (%5d,%5d) does not exist\n", group,item); - } - } - - void event::getStructureNoCopy(const char *buffer, hipo::structure &str, int group, int item){ - std::pair index = getStructurePosition(buffer,group,item); - if(index.first>0){ - str.initNoCopy(&buffer[index.first], index.second + 8); - str.notify(); - } else { - str.initStructureBySize(group,item,1,0); - str.notify(); - //printf("*** error *** : structure (%5d,%5d) does not exist\n", group,item); - } - } - void event::getStructure(const char *buffer, hipo::structure &str, int group, int item){ - std::pair index = getStructurePosition(buffer,group,item); - if(index.first>0){ - str.init(&buffer[index.first], index.second + 8); - str.notify(); - } else { - str.initStructureBySize(group,item,1,0); - str.notify(); - //printf("*** error *** : structure (%5d,%5d) does not exist\n", group,item); - } - } - - void event::addStructure(hipo::structure &str){ - - int str_size = str.getStructureBufferSize(); - int data_size = str.getSize(); - int evt_size = getSize(); - int evt_capacity = dataBuffer.size(); - - //if(dataBuffer.size()<= () ){ - // dataBuffer.resize(size+1024); - //} - if(data_size>0){ - if((evt_size + str_size)(&dataBuffer[4])) = (evt_size + str_size + 24); - *(reinterpret_cast(&dataBuffer[4])) = (evt_size + str_size); - } else { - printf("event::add : error adding structure with size = %5d (capacity = %5d, size = %5d)\n", - str_size,evt_capacity, evt_size); - } - } - } - - int event::getTag(){ - int eventTag = *(reinterpret_cast(&dataBuffer[8])); - return eventTag; - } - - void event::setTag(int tag){ - *(reinterpret_cast(&dataBuffer[8])) = tag; - } - - void event::init(std::vector &buffer){ - dataBuffer.resize(buffer.size()); - std::memcpy(&dataBuffer[0],&buffer[0],buffer.size()); - } - - std::pair event::getStructurePosition(const char *buffer, int group, int item){ - int position = 16; - int eventSize = *(reinterpret_cast(&buffer[4])); - while(position+8 (&buffer[position ])); - uint8_t iid = *(reinterpret_cast (&buffer[position+2])); - uint8_t type = *(reinterpret_cast (&buffer[position+3])); - int length = *(reinterpret_cast (&buffer[position+4])); - //printf("group = %4d , item = %4d\n",(unsigned int) gid, (unsigned int) iid); - if(gid==group&&iid==item) return std::make_pair(position,length); - position += (length + 8); - } - return std::make_pair(-1,0); - } - - std::pair event::getStructurePosition(int group, int item){ - int position = 16; - int eventSize = *(reinterpret_cast(&dataBuffer[4])); - while(position+8(&dataBuffer[position])); - uint8_t iid = *(reinterpret_cast(&dataBuffer[position+2])); - uint8_t type = *(reinterpret_cast(&dataBuffer[position+3])); - int length = *(reinterpret_cast(&dataBuffer[position+4])); - //printf("group = %4d , item = %4d\n",(unsigned int) gid, (unsigned int) iid); - if(gid==group&&iid==item) return std::make_pair(position,length); - position += (length + 8); - } - return std::make_pair(-1,0); - } -/* - std::pair event::getStructurePosition(const char *buffer, int group, int item){ - int position = 16; - int eventSize = *(reinterpret_cast(&buffer[4])); - while(position+8(&buffer[position])); - uint8_t iid = *(reinterpret_cast(&buffer[position+2])); - uint8_t type = *(reinterpret_cast(&buffer[position+3])); - int length = *(reinterpret_cast(&buffer[position+4])); - //printf("group = %4d , item = %4d\n",(unsigned int) gid, (unsigned int) iid); - if(gid==group&&iid==item) return std::make_pair(position,length); - position += (length + 8); - } - return std::make_pair(-1,0); - } -*/ - void event::init(const char *buffer, int size){ - if(dataBuffer.size()<=size){ - dataBuffer.resize(size+1024); - } - std::memcpy(&dataBuffer[0],buffer,size); - *(reinterpret_cast(&dataBuffer[4])) = size; - } - - int event::getSize(){ - return *(reinterpret_cast(&dataBuffer[4])); - } - - void event::reset(){ - dataBuffer[0] = 'E'; dataBuffer[1] = 'V'; - dataBuffer[2] = 'N'; dataBuffer[3] = 'T'; - *(reinterpret_cast(&dataBuffer[ 4])) = 16; - *(reinterpret_cast(&dataBuffer[ 8])) = 0; - *(reinterpret_cast(&dataBuffer[12])) = 0; - } - std::vector &event::getEventBuffer(){ return dataBuffer;} - /* - template node event::getNode(){ - node en; - en.setLength(4); - en.setAddress(NULL); - } */ - void event::show(){ - printf(" EVENT SIZE = %d\n",getSize()); - int position = 16; - int eventSize = *(reinterpret_cast(&dataBuffer[4])); - while(position+8(&dataBuffer[position])); - uint8_t iid = *(reinterpret_cast(&dataBuffer[position+2])); - uint8_t type = *(reinterpret_cast(&dataBuffer[position+3])); - int length = *(reinterpret_cast(&dataBuffer[position+4])); - //printf("group = %4d , item = %4d\n",(unsigned int) gid, (unsigned int) iid); - //if(gid==group&&iid==item) return std::make_pair(position,length); - printf("%12s %9d %4d %12d %12d\n"," ",gid,iid,type,length); - position += (length + 8); - } - } -} diff --git a/hipo4/event.h b/hipo4/event.h deleted file mode 100644 index 1f04282..0000000 --- a/hipo4/event.h +++ /dev/null @@ -1,102 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ -/* - * File: event.h - * Author: gavalian - * - * Created on April 12, 2017, 10:14 AM - */ - -#ifndef HIPO_EVENT_H -#define HIPO_EVENT_H - -#include -#include -#include -#include -#include -#include -#include -#include "bank.h" - -// if the library is compiled with C++11 -// support we will use unordered map which -// is faster than standard map -#if __cplusplus > 199711L -#include -#endif - - -namespace hipo { - - //typedef std::auto_ptr node_pointer; - - class event { - - private: - std::vector dataBuffer; - public: - - event(); - event(int size); - virtual ~event(); - - void show(); - void init(std::vector &buffer); - void init(const char *buffer, int size); - void getStructure(hipo::structure &str, int group, int item); - int getTag(); - void setTag(int tag); - void getStructure(hipo::bank &b); - void read(hipo::bank &b); - void addStructure(hipo::structure &str); - - std::pair getStructurePosition(int group, int item); - - std::vector &getEventBuffer(); - int getSize(); - void reset(); - - //******************************************************************* - //** static methods for reading structures from event structure - //** from the memory. It does not have to copy event into separate - //** buffer. - //******************************************************************* - static std::pair - getStructurePosition(const char *buffer, int group, int item); - //static std::pair getStructurePosition(const char *buffer, int group, int item); - static void - getStructure(const char *buffer, hipo::structure &str, int group, int item); - static void - getStructureNoCopy(const char *buffer, hipo::structure &str, int group, int item); - }; -} - -#endif /* EVENT_H */ diff --git a/hipo4/fusion.cpp b/hipo4/fusion.cpp deleted file mode 100644 index 243a8ab..0000000 --- a/hipo4/fusion.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/*---------------------------------------------------------------------- - * This is the implementation of fusion class which is used in - * interfacing HIPO library from python. - * author: G.Gavalian (June, 2022) - * --------------------------------------------------------------------- - */ - -#include "fusion.h" - - -namespace hipo { - - void inputSource::open(const char *filename){ - reader.open(filename); - reader.readDictionary(factory); - } - - void inputSource::define(const char *bank){ - banks[std::string(bank)] = hipo::bank(factory.getSchema(bank)); - } - bool inputSource::next(){ - bool status = reader.next(); - if(status==true){ - reader.read(event); - std::map::iterator it; - for (it = banks.begin(); it != banks.end(); it++) - { - event.getStructure(it->second); - //How do I access each element? - } - } - return status; - } - -int inputSource::getSize(const char *bank){ - return banks[bank].getRows(); -} - - -int inputSource::getInt( const char *bank, const char *entry, int row){ - return banks[bank].getInt(entry,row); -} -double inputSource::getFloat( const char *bank, const char *entry, int row){ - return banks[bank].getFloat(entry,row); -} - - - int fusion::open(const char *filename){ - int number = sources.size() + 1; - sources.insert(std::make_pair(number, new inputSource(filename))); - return number; - } - - void fusion::define(int fid, const char *bank){ - sources[fid]->define(bank); - } - - int fusion::getSize(int fid, const char *bank){ - return sources[fid]->getSize(bank); - } - -bool fusion::next(int handle){ - return sources[handle]->next(); -} - -int fusion::getInt( int handle, const char *bank, const char *entry, int row){ - return sources[handle]->getInt(bank,entry,row); -} - -float fusion::getFloat( int handle, const char *bank, const char *entry, int row){ - //double result = sources[handle]->getFloat(bank,entry,row); - //printf("reuslt = %f\n",result); - return sources[handle]->getFloat(bank,entry,row); -} - -int fusion::getType( int handle, const char *bank, const char *entry){ - hipo::bank b = sources[handle]->get(bank); - return b.getSchema().getEntryType(b.getSchema().getEntryOrder(entry)); -} -} diff --git a/hipo4/fusion.h b/hipo4/fusion.h deleted file mode 100644 index 00ed1db..0000000 --- a/hipo4/fusion.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -/* - * File: fusion.h - * Author: gavalian - * - * Created on April 27, 2017, 10:01 AM - */ - -#ifndef FUSION_H -#define FUSION_H - -#include -#include -#include -#include -#include -#include -#include "reader.h" -#include - -namespace hipo { - - class inputSource { - - private: - - hipo::reader reader; - std::map banks; - hipo::dictionary factory; - hipo::event event; - - public: - - inputSource(){} - inputSource(const char *filename){ open(filename); } - ~inputSource(){} - - void open(const char *filename); - void define(const char *bank); - bool next(); - - hipo::bank &get(const char *bank){ return banks[bank];} - int getSize(const char *bank); - - int getInt( const char *bank, const char *entry, int row); - double getFloat( const char *bank, const char *entry, int row); - - }; - - class fusion { - - private: - - std::map sources; - - public: - fusion(){} - ~fusion(){} - - - int open(const char *filename); - bool next(int handle); - void define(int fid, const char *bank); - int getSize(int fid, const char *bank); - - int getInt( int handle, const char *bank, const char *entry, int row); - float getFloat( int handle, const char *bank, const char *entry, int row); - int getType( int handle, const char *bank, const char *entry); - }; -} - -#endif /* FUSION_H */ diff --git a/hipo4/hipoexceptions.h b/hipo4/hipoexceptions.h deleted file mode 100644 index 75dfb43..0000000 --- a/hipo4/hipoexceptions.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -/* - * File: hipoexceptions.h - * Author: gavalian - * - * Created on April 11, 2017, 2:06 PM - */ - -#ifndef HIPOEXCEPTIONS_H -#define HIPOEXCEPTIONS_H - -#include - -class HipoWrongFile : public std::exception { - virtual const char* what() const throw(){ - return "exception: wrong Hipo File format."; - } -}; - -class HipoRecordError : public std::exception { - virtual const char* what() const throw(){ - return "exception: error parsing record"; - } -}; - - -#endif /* HIPOEXCEPTIONS_H */ - diff --git a/hipo4/ntuple_reader.h b/hipo4/ntuple_reader.h index f4360c5..d009711 100644 --- a/hipo4/ntuple_reader.h +++ b/hipo4/ntuple_reader.h @@ -1,7 +1,7 @@ #pragma once -#include "reader.h" -#include "bank.h" +#include +#include #include "ntuple_writer.h" namespace hipo { diff --git a/hipo4/ntuple_writer.h b/hipo4/ntuple_writer.h index 2f44546..bcd9e6d 100644 --- a/hipo4/ntuple_writer.h +++ b/hipo4/ntuple_writer.h @@ -1,7 +1,7 @@ #pragma once -#include "writer.h" -#include "bank.h" +#include +#include #include #include diff --git a/hipo4/reader.cpp b/hipo4/reader.cpp deleted file mode 100644 index 0a1d4c0..0000000 --- a/hipo4/reader.cpp +++ /dev/null @@ -1,556 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ - /* - * File: reader.cpp - * Author: gavalian - * - * Additions by: dglazier - * Created on April 11, 2017, 2:07 PM - */ - -#include "reader.h" -#include "hipoexceptions.h" -#include "record.h" - -#include -/** - * HIPO namespace is used for the classes that read/write - * files and records. - */ -namespace hipo { - /** - * The constructor for reader, printWarning routine - * will printout a warning message if the library - * was not compiled with compression libraries LZ4 or GZIP - */ - reader::reader(){ - printWarning(); - //hipoutils.printLogo(); - } - - /** - * Default destructor. Does nothing - */ - reader::~reader(){ - if(inputStream.is_open()==true){ - inputStream.close(); - } - } - - void reader::about(){ - hipoutils.printLogo(); - } - /** - * Open file, if file stream is open, it is closed first. - * At open time verification of file structure is performed. - * If the signature does not match EVIO/HIPO template, the - * file will be closed and warning message is printed. - * @param filename - name of the file to open - */ - void reader::open(const char *filename){ - - if(inputStream.is_open()==true){ - inputStream.close(); - - } - - inputStream.open(filename, std::ios::binary); - inputStream.seekg(0,std::ios_base::end); - inputStreamSize = inputStream.tellg(); - inputStream.seekg(0,std::ios_base::beg); - if(inputStream.is_open()==false){ - printf("[ERROR] something went wrong with openning file : %s\n", - filename); - return; - } - readHeader(); - readIndex(); -} - -/** - * Reads the file header. The endiannes is determined for bytes - * swap. The header structure will be filled with file parameters. - */ - void reader::readHeader(){ - - std::vector headerBuffer; - headerBuffer.resize(80); - inputStream.read(&headerBuffer[0],80); - - header.uniqueid = *(reinterpret_cast(&headerBuffer[0])); - header.filenumber = *(reinterpret_cast(&headerBuffer[4])); - header.headerLength = *(reinterpret_cast(&headerBuffer[8])); - header.recordCount = *(reinterpret_cast(&headerBuffer[12])); - - header.indexArrayLength = *(reinterpret_cast(&headerBuffer[16])); - int word_8 = *(reinterpret_cast(&headerBuffer[20])); - - header.userHeaderLength = *(reinterpret_cast(&headerBuffer[24])); - header.magicNumber = *(reinterpret_cast(&headerBuffer[28])); - header.userRegister = *(reinterpret_cast(&headerBuffer[32])); - header.trailerPosition = *(reinterpret_cast(&headerBuffer[40])); - // If magic word is reversed, then the file was written in BIG_ENDIAN - // format, the bytes have to be swapped - if(header.magicNumber==0x0001dac0){ - printf(" THIS FILE IS BIG ENDIAN: SWAPPING BYTES\n"); - header.uniqueid = __builtin_bswap32(header.uniqueid); - header.filenumber = __builtin_bswap32(header.filenumber); - header.headerLength = __builtin_bswap32(header.headerLength); - header.recordCount = __builtin_bswap32(header.recordCount); - header.userHeaderLength = __builtin_bswap32(header.userHeaderLength); - header.indexArrayLength = __builtin_bswap32(header.indexArrayLength); - word_8 = __builtin_bswap32(word_8); - header.userRegister = __builtin_bswap64(header.userRegister); - header.trailerPosition = __builtin_bswap64(header.trailerPosition); - } - - header.version = word_8&0x000000FF; - header.bitInfo = (word_8>>8)&0x00FFFFFF; - header.firstRecordPosition = 4*header.headerLength + header.userHeaderLength; - if(_verbose){ - printf("----------------------------------------\n"); - printf("**** reader:: header version : %d \n",header.version); - printf("**** reader:: header length : %d \n",header.headerLength*4); - printf("**** reader:: first record pos : %lu\n",header.firstRecordPosition); - printf("**** reader:: trailer position : %lu\n",header.trailerPosition); - printf("**** reader:: file size : %lu\n",inputStreamSize); - printf("----------------------------------------\n"); - } - //int *signature = reinterpret_cast(&headerBuffer[0]); - //printf("signature = %X\n",(unsigned int) *signature); - //std::cout << "signature = " << std::ios::hex << (*signature) << '\n'; -} - -/** - * Reads run index from the file. The index is in the last record of the - * file, and the pointer to that record is contained in the File Header. - * If the file was not properly closed event index will not be loaded - * then file has to be opened in sequential more, to read record by record. - * in sequential mode the random access is not avilable. - */ -void reader::readIndex(){ - - inputRecord.readRecord(inputStream,header.trailerPosition,0); - if(_verbose)printf("*** reader:: trailer record event count : %d\n",inputRecord.getEventCount()); - - //a catch for broken files - //can use hiporeader.getNRecords() to see if succesfull (=-1 if not) - if(inputRecord.getEventCount()==0) return;//dglazier - - hipo::event event; - inputRecord.readHipoEvent(event,0); - if(_verbose)event.show(); - hipo::structure base; - event.getStructure(base,32111,1); - if(_verbose)base.show(); - readerEventIndex.clear(); - int rows = base.getSize()/32; - - //printf(" number of rows = %d\n",rows); - for(int i = 0; i < rows; i++){ - long position = base.getLongAt( i*8); - int length = base.getIntAt ( rows*8 + i*4); - int entries = base.getIntAt ( rows*12 + i*4); - long uid1 = base.getLongAt( rows*16 + i*8); - long uid2 = base.getLongAt( rows*24 + i*8); - if(tagsToRead.size()==0){ - readerEventIndex.addSize(entries); - readerEventIndex.addPosition(position); - } else { - bool accept = false; - for(long jr : tagsToRead){ - if(jr==uid1) accept = true; - } - if(accept==true){ - readerEventIndex.addSize(entries); - readerEventIndex.addPosition(position); - } - } - } - readerEventIndex.rewind(); - //printf("**** reader:: header version : %d \n",readerEventIndex.getMaxEvents()); - if(_verbose)printf("**** reader:: # of events : %d \n",readerEventIndex.getMaxEvents()); -} -/** - * Checks if there are more events in the file to advance to. - * @return true if there are events left to read, false - otherwise - */ -bool reader::hasNext(){ return readerEventIndex.canAdvance();} - -/** - * Reads next event from the file, the event pointer is automatically - * advanced to the next event. - * @param reference to the event object to be filled from the record. - * @return true if the event was successfully read, and false otherwise - */ -bool reader::next(hipo::event &dataevent){ - if(readerEventIndex.canAdvance()==false) return false; - int recordNumber = readerEventIndex.getRecordNumber(); - readerEventIndex.advance(); - int recordToBeRead = readerEventIndex.getRecordNumber(); - if(recordToBeRead!=recordNumber){ - long position = readerEventIndex.getPosition(recordToBeRead); - inputRecord.readRecord(inputStream,position,0); - /*printf(" record changed from %d to %d at event %d total event # %d\n", - recordNumber, recordToBeRead,readerEventIndex.getEventNumber(), - readerEventIndex.getMaxEvents());*/ - } - int eventNumberInRecord = readerEventIndex.getRecordEventNumber(); - inputRecord.readHipoEvent(dataevent,eventNumberInRecord); - return true; -} -/** - * Reads current event from the record without advancing the current event - * position. Multiple reads can be performed on the same event. - * @param reference to the event object to be read - */ -void reader::read(hipo::event &dataevent){ - int eventNumberInRecord = readerEventIndex.getRecordEventNumber(); - inputRecord.readHipoEvent(dataevent,eventNumberInRecord); -} -/** - * Reads the structure from the current event without copying the event - * buffer. - * @param structure - reference to the stucture object - * @param group - the group is for the structure. - * @param item - item id for the structure. - */ -void reader::getStructure(hipo::structure &structure,int group, int item){ - hipo::data data; - int eventNumberInRecord = readerEventIndex.getRecordEventNumber(); - inputRecord.getData(data,eventNumberInRecord); - event::getStructure(data.getDataPtr(),structure,group,item); -} -/** - * Reads the structure from the current event without copying the event - * buffer and without copying the structure buffer. This should be used - * very carefully, since it sets the pointer of the structure directly - * to the buffer owned by the record. If new record is loaded this - * structure will be pointing to the wrong part of the buffer. - * @param structure - reference to the stucture object - * @param group - the group is for the structure. - * @param item - item id for the structure. - */ -void reader::getStructureNoCopy(hipo::structure &structure,int group, int item){ - hipo::data data; - int eventNumberInRecord = readerEventIndex.getRecordEventNumber(); - inputRecord.getData(data,eventNumberInRecord); - event::getStructureNoCopy(data.getDataPtr(),structure,group,item); -} - - void reader::readUserConfig(std::map &mapConfig){ - - if(inputStream.is_open()==false){ - printf("\n\nhipo::reader (ERROR) file is not open.... exiting...\n\n"); - exit(0); - } - long position = header.headerLength*4; - hipo::record dictRecord; - dictRecord.readRecord(inputStream,position,0); - int nevents = dictRecord.getEventCount(); - /* printf(" reading record at position %8lu, number of entries = %5d\n", - position,dictRecord.getEventCount()); */ - hipo::structure sKey; - hipo::structure sConfig; - hipo::event event; - for(int i = 0; i < nevents; i++){ - dictRecord.readHipoEvent(event,i); - event.getStructure(sKey,32555,1); - event.getStructure(sConfig,32555,2); - if(sKey.getSize()>0){ - mapConfig[std::string(sKey.getStringAt(0).c_str())] = std::string(sConfig.getStringAt(0).c_str()); - } - //printf("schema : %s\n",schemaStructure.getStringAt(0).c_str()); - //dict.parse(schemaStructure.getStringAt(0).c_str()); - } -} - -/** - * Reads the dictionary for the file. C++ API is reading packed dictionary - * format from node (120,2), parses each schema and creates schema dictionary. - * @param dict - reference to dictionary object. - */ -void reader::readDictionary(hipo::dictionary &dict){ - if(inputStream.is_open()==false){ - printf("\n\nhipo::reader (ERROR) file is not open.... exiting...\n\n"); - exit(0); - } - long position = header.headerLength*4; - hipo::record dictRecord; - dictRecord.readRecord(inputStream,position,0); - int nevents = dictRecord.getEventCount(); - /* printf(" reading record at position %8lu, number of entries = %5d\n", - position,dictRecord.getEventCount()); */ - hipo::structure schemaStructure; - hipo::event event; - for(int i = 0; i < nevents; i++){ - dictRecord.readHipoEvent(event,i); - event.getStructure(schemaStructure,120,2); - //printf("schema : %s\n",schemaStructure.getStringAt(0).c_str()); - dict.parse(schemaStructure.getStringAt(0).c_str()); - } -} -/** - * Advances the event pointer to the next event. This does not read an - * event, but if the event goes beyond boundary of the record the next - * record is loaded into the memody. - * @return returns true - if the are events available in the file, false - otherwise - */ -bool reader::next(){ - if(readerEventIndex.canAdvance()==false) return false; - int recordNumber = readerEventIndex.getRecordNumber(); - readerEventIndex.advance(); - int recordToBeRead = readerEventIndex.getRecordNumber(); - if(recordToBeRead!=recordNumber){ - long position = readerEventIndex.getPosition(recordToBeRead); - inputRecord.readRecord(inputStream,position,0); - /*printf(" record changed from %d to %d at event %d total event # %d\n", - recordNumber, recordToBeRead,readerEventIndex.getEventNumber(), - readerEventIndex.getMaxEvents());*/ - } - return true; -} -/** - * Moves the pointer of the event to the event number provided. If the event - * number is within the same record no reading is done, otherwise the appropriate - * record is loaded and event indicies are updated. - * @param eventNumber - number of event to jump to - * @return true if event is available, false - otherwise - */ -bool reader::gotoEvent(int eventNumber){ - int recordNumber = readerEventIndex.getRecordNumber(); - - //goto event in index if exists, if not return - if(readerEventIndex.gotoEvent(eventNumber)==false){ - printf("[WARNING] hipo::reader::gotoEvent event %d greater than max events = %d, will stay at current event\n", - eventNumber, readerEventIndex.getMaxEvents()); - return false; - } - - int recordToBeRead = readerEventIndex.getRecordNumber(); - - if(recordToBeRead!=recordNumber){ - //readerEventIndex.show(); - commented out by gg, this was for debugging - long position = readerEventIndex.getPosition(recordToBeRead); - inputRecord.readRecord(inputStream,position,0); - /*printf(" record changed from %d to %d at event %d total event # %d\n", - recordNumber, recordToBeRead,readerEventIndex.getEventNumber(), - readerEventIndex.getMaxEvents());*/ - } - return true; -} -/** - * Moves the current event pointer to the new record # irec. The readerIndex - * is updated so current event is the first event in loaded record. - * @param irec - record number to jump to - * @return true - if the record exists, false - otherwise - */ -bool reader::gotoRecord(int irec){ - bool status = readerEventIndex.gotoRecord(irec); - if(status==false) return false; - long position = readerEventIndex.getPosition(irec); - inputRecord.readRecord(inputStream,position,0); - return true; -} - -//dglazier -// Added by Derek - for some reason -// Use gotoRecord instead, since it checks first if record exists. -bool reader::loadRecord(int irec){ - long position = readerEventIndex.getPosition(irec); - inputRecord.readRecord(inputStream,position,0); - return readerEventIndex.loadRecord(irec); -} - - bool reader::loadRecord(hipo::record &record, int irec){ - long position = readerEventIndex.getPosition(irec); - record.readRecord(inputStream,position,0); - return true; -} -//dglazier -bool reader::nextInRecord(){ - if(readerEventIndex.canAdvanceInRecord()==false) return false; - readerEventIndex.advance(); - return true; -} -/** - * Prints out warning if the LZ4 library was not linked to the compiled - * library. In that case only uncompressed files can be read and written. - */ -void reader::printWarning(){ - #ifndef __LZ4__ - std::cout << "******************************************************" << std::endl; - std::cout << "* WARNING: *" << std::endl; - std::cout << "* This library war compiled without LZ4 support. *" << std::endl; - std::cout << "* Reading and writing compressed buffers will not *" << std::endl; - std::cout << "* work. However un-compressed file I/O will work. *" << std::endl; - std::cout << "******************************************************" << std::endl; - #endif - } -} - -//***************************************************************************** -//* Implementation of reader index class to keep track of events and records -//***************************************************************************** -//-- -namespace hipo { -/** - * Adds record size (number of events) to the list of records. - */ -void readerIndex::addSize(int size){ - if(recordEvents.size()==0){ - recordEvents.push_back(0); - recordEvents.push_back(size); - } else { - int cz = recordEvents[recordEvents.size()-1] + size; - recordEvents.push_back(cz); - } -} -/** - * Checks to determine if there are events left in the index buffer - * @return true - if there are available events, false - otherwise - */ -bool readerIndex::canAdvance(){ - return (currentEvent=getMaxEvents()) return false; - // The proper record number is found by binary search through records array - //------ - // G.Gavalian (July 25/2022) - // Changed the eventNumber -> eventNumber+1 in binary search. Now it changes the - // record number properly and starts with record event number from 0 - // I think this was a bug. - - std::vector::iterator l_bound = - std::lower_bound(recordEvents.begin(), recordEvents.end(), eventNumber+1); - std::vector::iterator u_bound = - std::lower_bound(recordEvents.begin(), recordEvents.end(), eventNumber+1); - - - long position = (l_bound - recordEvents.begin()) - 1; - //printf("event # %d , lbound = %ld\n",eventNumber,position); - currentRecord = position; - currentRecordEvent = eventNumber - recordEvents[currentRecord]; - currentEvent = eventNumber; - return true; -} - - void readerIndex::show(){ - for(int i = 0; i < recordEvents.size(); i++){ - printf("record = %8d, %8d\n",i,recordEvents[i]); - } - } -/** - * Returns maximum number of events available to read. - * @return maximum number of events. - */ -int readerIndex::getMaxEvents(){ - if(recordEvents.size()==0) return 0; - return recordEvents[recordEvents.size()-1]; -} -/** - * Sets the event pointer to the first even of provided record. - * Originally implemenet by Derek as loadRecord(), I changed the - * name to keep naming consistent, but left the old one not to break - * clas12root code. - * @param irec - the record number to jump to - * @return true - if the provided record is valid, false - otherwise - */ -bool readerIndex::gotoRecord(int irec){ - if(irec==0){ - currentEvent=-1; currentRecord=0; currentRecordEvent = -1; - return true; - } - if(irec+1>(int)recordEvents.size()) - return false; - currentEvent = recordEvents[irec]-1; currentRecord=irec; - currentRecordEvent = -1; - return true; -} -//dglazier -/** -* Implemented by Derek for clas12tool purposes (I think - therefore I am) -*/ -bool readerIndex::loadRecord(int irec){ - if(irec==0){ - currentEvent=-1; - currentRecord=0; - currentRecordEvent = -1; - return true; - } - if(irec+1>(int)recordEvents.size()) - return false; - - currentEvent = recordEvents[irec]-1; - currentRecord=irec; - currentRecordEvent = -1; - return true; -} -//dglazier -/** - * Checks to verify if the next event is in the same record as current one. - * Not sure why Derek needed it ;-), but may be it's useful - * @return true - if the next event is in the same record, false - otherwise - */ -bool readerIndex::canAdvanceInRecord(){ - return (currentEvent - * - * FILE HEADER STRUCTURE ( 56 bytes, 14 integers (32 bit) ) - * - * +----------------------------------+ - * 1 | ID | // HIPO: 0x43455248, Evio: 0x4556494F - * +----------------------------------+ - * 2 + File Number | // split file # - * +----------------------------------+ - * 3 + Header Length | // 14 (words) - * +----------------------------------+ - * 4 + Record (Index) Count | - * +----------------------------------+ - * 5 + Index Array Length | // bytes - * +-----------------------+----------+ - * 6 + Bit Info | Version | // version (8 bits) - * +-----------------------+----------+ - * 7 + User Header Length | // bytes - * +----------------------------------+ - * 8 + Magic Number | // 0xc0da0100 - * +----------------------------------+ - * 9 + User Register | - * +-- --+ - * 10 + | - * +----------------------------------+ - * 11 + Trailer Position | // File offset to trailer head (64 bits). - * +-- --+ // 0 = no offset available or no trailer exists. - * 12 + | - * +----------------------------------+ - * 13 + User Integer 1 | - * +----------------------------------+ - * 14 + User Integer 2 | - * +----------------------------------+ - * - * ------------------- - * Bit Info Word - * ------------------- - * 0-7 = version - * 8 = true if dictionary is included (relevant for first record only) - * 9 = true if this file has "first" event (in every split file) - * 10 = File trailer with index array exists - * 11-19 = reserved - * 20-21 = pad 1 - * 22-23 = pad 2 - * 24-25 = pad 3 (always 0) - * 26-27 = reserved - * 28-31 = general header type: 1 = Evio file - * 2 = Evio extended file - * 5 = HIPO file - * 6 = HIPO extended file - * - * - * - * @version 6.0 - * @since 6.0 9/6/17 - */ -/* - * File: reader.h - * Author: gavalian - * - * Created on April 11, 2017, 2:07 PM - */ - -#ifndef HIPOREADER_H -#define HIPOREADER_H - - -#define HIPO_FILE_HEADER_SIZE 72 -/* Constants for endianness of the file */ -#ifndef BIG_ENDIAN -#define BIG_ENDIAN 0 -#endif -#ifndef LITTLE_ENDIAN -#define LITTLE_ENDIAN 1 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include "record.h" -#include "utils.h" -#include "bank.h" - -namespace hipo { - - // typedef struct fileHeader_t { - struct fileHeader_t { - int uniqueid{}; - int filenumber{}; - int headerLength{}; // in words (usually 14) - int recordCount{}; - int indexArrayLength{}; // in bytes - int bitInfo{}; - int version{}; - int userHeaderLength{}; - int magicNumber{}; - long userRegister{}; - long trailerPosition{}; - long firstRecordPosition{}; - };// fileHeader_t; - - - // typedef struct recordInfo_t { - struct recordInfo_t { - long recordPosition{}; - int recordLength{}; - int recordEntries{}; - long userWordOne{}; - long userWordTwo{}; - };// recordInfo_t; - - - /** - * READER index class is used to construct entire events - * sequence from all records, and provides ability to canAdvance - * through events where record number is automatically calculated - * and triggers reading of the next record when events in the current - * record are exhausted. - */ - - class readerIndex { - - private: - std::vector recordEvents; - std::vector recordPosition; - - int currentRecord{}; - int currentEvent{}; - int currentRecordEvent{}; - - public: - - readerIndex()= default;; - ~readerIndex()= default;; - - bool canAdvance(); - bool advance(); - - //dglazier - bool canAdvanceInRecord(); - bool loadRecord(int irec); - bool gotoEvent(int eventNumber); - bool gotoRecord(int irec); - - int getEventNumber() { return currentEvent;} - int getRecordNumber() { return currentRecord;} - int getRecordEventNumber() { return currentRecordEvent;} - int getMaxEvents(); - void addSize(int size); - void addPosition(long position){ recordPosition.push_back(position);} - long getPosition(int index) { return recordPosition[index];} - - //dglazier - int getNRecords() const {return recordEvents.size();} - void show(); - void rewind(){ - currentRecord = -1; currentEvent = -1; currentRecordEvent = -1; - } - void clear(){ - recordEvents.clear(); recordPosition.clear(); - } - void reset(){ - currentRecord = 0; currentEvent = 0; currentRecordEvent = 0; - } -}; - - class reader { - - private: - - fileHeader_t header{}; - hipo::utils hipoutils; - std::ifstream inputStream; - long inputStreamSize{}; - - hipo::record inputRecord; - hipo::readerIndex readerEventIndex; - std::vector tagsToRead; - short _verbose = {0} ; - - std::map userConfig; - - void readHeader(); - void readIndex(); - - public: - - reader(); - reader(const reader &r){} - - ~reader(); - - void about(); - void readDictionary(hipo::dictionary &dict); - void getStructure(hipo::structure &structure,int group, int item); - void getStructureNoCopy(hipo::structure &structure,int group, int item); - - void readUserConfig(std::map &mapConfig); - //std::string getUserConfig(const char *key); - - void open(const char *filename); - void setTags(int tag){ tagsToRead.push_back(tag);} - void setTags(std::vector tags){ tagsToRead=std::move(tags);} - void setVerbose(short level=1){_verbose=level;} - - bool hasNext(); - bool next(); - bool gotoEvent(int eventNumber); - bool gotoRecord(int irec); - bool next(hipo::event &dataevent); - void read(hipo::event &dataevent); - void printWarning(); - //void showUserConfig(); - int getNRecords() const {return readerEventIndex.getNRecords()-1;} - bool nextInRecord(); - bool loadRecord(int irec); - bool loadRecord(hipo::record &record, int irec); - int getEntries(){return readerEventIndex.getMaxEvents();} - }; -} -#endif /* HIPOREADER_H */ diff --git a/hipo4/record.cpp b/hipo4/record.cpp deleted file mode 100644 index e8f9400..0000000 --- a/hipo4/record.cpp +++ /dev/null @@ -1,546 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ - - /* - * File: record.cpp - * Author: gavalian - * - * Created on April 11, 2017, 4:47 PM - */ - -#include "record.h" -//#include "hipoexceptions.h" - -#ifdef __LZ4__ -#include -#endif - -namespace hipo { - - - record::record()= default; - - - record::~record()= default; - - /** - * Read - */ - void record::readRecord(std::ifstream &stream, long position, int dataOffset){ - - recordHeaderBuffer.resize(80); - stream.seekg(position,std::ios::beg); - - stream.read( (char *) &recordHeaderBuffer[0],80); - recordHeader.recordLength = *(reinterpret_cast(&recordHeaderBuffer[ 0])); - recordHeader.headerLength = *(reinterpret_cast(&recordHeaderBuffer[ 8])); - recordHeader.numberOfEvents = *(reinterpret_cast(&recordHeaderBuffer[12])); - recordHeader.bitInfo = *(reinterpret_cast(&recordHeaderBuffer[20])); - recordHeader.signatureString = *(reinterpret_cast(&recordHeaderBuffer[28])); - recordHeader.recordDataLength = *(reinterpret_cast(&recordHeaderBuffer[32])); - recordHeader.userHeaderLength = *(reinterpret_cast(&recordHeaderBuffer[24])); - int compressedWord = *(reinterpret_cast(&recordHeaderBuffer[36])); - - if(recordHeader.signatureString==0xc0da0100) recordHeader.dataEndianness = 0; - if(recordHeader.signatureString==0x0001dac0) recordHeader.dataEndianness = 1; - - if(recordHeader.signatureString==0x0001dac0){ - recordHeader.recordLength = __builtin_bswap32(recordHeader.recordLength); - recordHeader.headerLength = __builtin_bswap32(recordHeader.headerLength); - recordHeader.numberOfEvents = __builtin_bswap32(recordHeader.numberOfEvents); - recordHeader.recordDataLength = __builtin_bswap32(recordHeader.recordDataLength); - recordHeader.userHeaderLength = __builtin_bswap32(recordHeader.userHeaderLength); - recordHeader.bitInfo = __builtin_bswap32(recordHeader.bitInfo); - compressedWord = __builtin_bswap32(compressedWord); - } - - int compressedDataLengthPadding = (recordHeader.bitInfo>>24)&0x00000003; - int headerLengthBytes = recordHeader.headerLength*4; - int dataBufferLengthBytes = recordHeader.recordLength * 4 - headerLengthBytes; - - recordHeader.userHeaderLengthPadding = (recordHeader.bitInfo>>20)&0x00000003; - recordHeader.recordDataLengthCompressed = compressedWord&0x0FFFFFFF; - recordHeader.compressionType = (compressedWord>>28)&0x0000000F; - recordHeader.indexDataLength = 4*recordHeader.numberOfEvents; - - /*printf(" allocating buffer for record, size = %d, padding = %d length = %d type = %d nevents = %d data length = %d\n", - dataBufferLengthBytes, - compressedDataLengthPadding, recordHeader.recordDataLengthCompressed*4, - recordHeader.compressionType, recordHeader.numberOfEvents, recordHeader.recordDataLength); - */ - //char *compressedBuffer = (char*) malloc(dataBufferLengthBytes); - - if(dataBufferLengthBytes>recordCompressedBuffer.size()){ - int newSize = dataBufferLengthBytes + 5*1024; - //printf("---> resizing internal compressed buffer size to from %ld to %d\n", - // recordCompressedBuffer.size(), newSize); - recordCompressedBuffer.resize(newSize); - } - //dataBufferLengthBytes -= compressedDataLengthPadding; - long dataposition = position + headerLengthBytes; - //printf("position = %ld data position = %ld\n",position, dataposition); - stream.seekg(dataposition,std::ios::beg); - //stream.read( compressedBuffer, dataBufferLengthBytes); - stream.read( (&recordCompressedBuffer[0]), dataBufferLengthBytes); - //showBuffer(compressedBuffer, 10, 200); - //printf("position = %ld data position = %ld \n",position, dataposition); - int decompressedLength = recordHeader.indexDataLength + - recordHeader.userHeaderLength + - recordHeader.userHeaderLengthPadding + - recordHeader.recordDataLength; - - if(recordBuffer.size()(&recordBuffer[i*4]); - int size = *ptr; - if(recordHeader.dataEndianness==1) size = __builtin_bswap32(size); - eventPosition += size; - *ptr = eventPosition; - } - //printf("final position = %d\n",eventPosition); - } - - bool record::readRecord(std::ifstream &stream, long position, int dataOffset, long inputSize){ - - readBenchmark.resume(); - if((position+80)>=inputSize) return false; - - recordHeaderBuffer.resize(80); - stream.seekg(position,std::ios::beg); - - stream.read( (char *) &recordHeaderBuffer[0],80); - recordHeader.recordLength = *(reinterpret_cast(&recordHeaderBuffer[0])); - recordHeader.headerLength = *(reinterpret_cast(&recordHeaderBuffer[8])); - recordHeader.numberOfEvents = *(reinterpret_cast(&recordHeaderBuffer[12])); - recordHeader.bitInfo = *(reinterpret_cast(&recordHeaderBuffer[20])); - recordHeader.signatureString = *(reinterpret_cast(&recordHeaderBuffer[28])); - recordHeader.recordDataLength = *(reinterpret_cast(&recordHeaderBuffer[32])); - recordHeader.userHeaderLength = *(reinterpret_cast(&recordHeaderBuffer[24])); - int compressedWord = *(reinterpret_cast(&recordHeaderBuffer[36])); - - if(recordHeader.signatureString==0xc0da0100) recordHeader.dataEndianness = 0; - if(recordHeader.signatureString==0x0001dac0) recordHeader.dataEndianness = 1; - - if(recordHeader.signatureString==0x0001dac0){ - recordHeader.recordLength = __builtin_bswap32(recordHeader.recordLength); - recordHeader.headerLength = __builtin_bswap32(recordHeader.headerLength); - recordHeader.numberOfEvents = __builtin_bswap32(recordHeader.numberOfEvents); - recordHeader.recordDataLength = __builtin_bswap32(recordHeader.recordDataLength); - recordHeader.userHeaderLength = __builtin_bswap32(recordHeader.userHeaderLength); - recordHeader.bitInfo = __builtin_bswap32(recordHeader.bitInfo); - compressedWord = __builtin_bswap32(compressedWord); - } - - int compressedDataLengthPadding = (recordHeader.bitInfo>>24)&0x00000003; - int headerLengthBytes = recordHeader.headerLength*4; - int dataBufferLengthBytes = recordHeader.recordLength * 4 - headerLengthBytes; - - recordHeader.userHeaderLengthPadding = (recordHeader.bitInfo>>20)&0x00000003; - recordHeader.recordDataLengthCompressed = compressedWord&0x0FFFFFFF; - recordHeader.compressionType = (compressedWord>>28)&0x0000000F; - recordHeader.indexDataLength = 4*recordHeader.numberOfEvents; - - /*printf(" allocating buffer for record, size = %d, padding = %d length = %d type = %d nevents = %d data length = %d\n", - dataBufferLengthBytes, - compressedDataLengthPadding, recordHeader.recordDataLengthCompressed*4, - recordHeader.compressionType, recordHeader.numberOfEvents, recordHeader.recordDataLength); - */ - //char *compressedBuffer = (char*) malloc(dataBufferLengthBytes); - - if(dataBufferLengthBytes>recordCompressedBuffer.size()){ - //-- resize the buffer extending it by 500kB. hopefully - //-- will be enough not to resize too many times. - int newSize = dataBufferLengthBytes + 500*1024; - // printout commented out --- by G.G. - /* printf("---> resizing internal compressed buffer size to from %ld to %d\n", - recordCompressedBuffer.size(), newSize); */ - recordCompressedBuffer.resize(newSize); - } - - long dataposition = position + headerLengthBytes; - stream.seekg(dataposition,std::ios::beg); - - if(position+dataBufferLengthBytes+recordHeader.headerLength>inputSize){ - printf("**** warning : record at position %ld is incomplete.",position); - return false; - } - - stream.read( (&recordCompressedBuffer[0]), dataBufferLengthBytes); - - int decompressedLength = recordHeader.indexDataLength + - recordHeader.userHeaderLength + - recordHeader.userHeaderLengthPadding + - recordHeader.recordDataLength; - - if(recordBuffer.size()(&recordBuffer[i*4]); - int size = *ptr; - if(recordHeader.dataEndianness==1) size = __builtin_bswap32(size); - eventPosition += size; - *ptr = eventPosition; - } - indexBenchmark.pause(); - return true; - } - - int record::getRecordSizeCompressed(){ - return recordHeader.recordLength; - } - - void record::readRecord__(std::ifstream &stream, long position, long recordLength){ - - stream.seekg(position,std::ios::beg); - - if(recordLength>recordCompressedBuffer.size()){ - int newSize = recordLength + 5*1024; - //printf("---> resizing internal compressed buffer size to from %ld to %d\n", - //recordCompressedBuffer.size(), newSize); - //printf("---> after printout\n"); - recordCompressedBuffer.resize(newSize); - } - //printf(" trying seeksg\n"); - stream.seekg( position,std::ios::beg); - //printf(" trying read\n"); - stream.read( (&recordCompressedBuffer[0]), recordLength); - //printf(" readin was successfull....\n"); - //stream.read( (char *) &recordHeaderBuffer[0],80); - recordHeader.recordLength = *(reinterpret_cast(&recordCompressedBuffer[0])); - recordHeader.headerLength = *(reinterpret_cast(&recordCompressedBuffer[8])); - recordHeader.numberOfEvents = *(reinterpret_cast(&recordCompressedBuffer[12])); - recordHeader.bitInfo = *(reinterpret_cast(&recordCompressedBuffer[20])); - recordHeader.signatureString = *(reinterpret_cast(&recordCompressedBuffer[28])); - recordHeader.recordDataLength = *(reinterpret_cast(&recordCompressedBuffer[32])); - recordHeader.userHeaderLength = *(reinterpret_cast(&recordCompressedBuffer[24])); - int compressedWord = *(reinterpret_cast(&recordCompressedBuffer[36])); - - if(recordHeader.signatureString==0xc0da0100) recordHeader.dataEndianness = 0; - if(recordHeader.signatureString==0x0001dac0) recordHeader.dataEndianness = 1; - - if(recordHeader.signatureString==0x0001dac0){ - recordHeader.recordLength = __builtin_bswap32(recordHeader.recordLength); - recordHeader.headerLength = __builtin_bswap32(recordHeader.headerLength); - recordHeader.numberOfEvents = __builtin_bswap32(recordHeader.numberOfEvents); - recordHeader.recordDataLength = __builtin_bswap32(recordHeader.recordDataLength); - recordHeader.userHeaderLength = __builtin_bswap32(recordHeader.userHeaderLength); - recordHeader.bitInfo = __builtin_bswap32(recordHeader.bitInfo); - compressedWord = __builtin_bswap32(compressedWord); - } - - int compressedDataLengthPadding = (recordHeader.bitInfo>>24)&0x00000003; - int headerLengthBytes = recordHeader.headerLength*4; - int dataBufferLengthBytes = recordHeader.recordLength * 4 - headerLengthBytes; - - recordHeader.userHeaderLengthPadding = (recordHeader.bitInfo>>20)&0x00000003; - recordHeader.recordDataLengthCompressed = compressedWord&0x0FFFFFFF; - recordHeader.compressionType = (compressedWord>>28)&0x0000000F; - recordHeader.indexDataLength = 4*recordHeader.numberOfEvents; - - /*printf(" allocating buffer for record, size = %d, padding = %d length = %d type = %d nevents = %d data length = %d\n", - dataBufferLengthBytes, - compressedDataLengthPadding, recordHeader.recordDataLengthCompressed*4, - recordHeader.compressionType, recordHeader.numberOfEvents, recordHeader.recordDataLength); - */ - //char *compressedBuffer = (char*) malloc(dataBufferLengthBytes); - - - //dataBufferLengthBytes -= compressedDataLengthPadding; - //printf(" record header intialized....\n"); - long dataposition = position + headerLengthBytes; - //printf("position = %ld data position = %ld\n",position, dataposition); - //stream.seekg(dataposition,std::ios::beg); - //stream.read( compressedBuffer, dataBufferLengthBytes); - //stream.read( (&recordCompressedBuffer[0]), dataBufferLengthBytes); - //showBuffer(compressedBuffer, 10, 200); - //printf("position = %ld data position = %ld \n",position, dataposition); - int decompressedLength = recordHeader.indexDataLength + - recordHeader.userHeaderLength + - recordHeader.userHeaderLengthPadding + - recordHeader.recordDataLength; - //printf(" decompressed length = %d\n",decompressedLength); - if(recordBuffer.size()(&recordBuffer[i*4]); - int size = *ptr; - if(recordHeader.dataEndianness==1) size = __builtin_bswap32(size); - eventPosition += size; - *ptr = eventPosition; - } - //printf("final position = %d\n",eventPosition); - } - /** - * returns number of events in the record. - */ - int record::getEventCount(){ - return recordHeader.numberOfEvents; - } - /** - * reads content of the event with given index into a vector - * vector will be resized to fit the data. The resulting - * size of the vector can be used to veryfy the successfull read. - */ - void record::readEvent( std::vector &vec, int index){ - - } - - /** - * returns a data object that points to the event inside of the - * record. For given index the data object will be filled with the - * pointer to the position in the buffer where the event starts and - * with the size indicating length of the event. - */ - void record::getData(hipo::data &data, int index){ - int first_position = 0; - if(index > 0){ - first_position = *(reinterpret_cast(&recordBuffer[(index -1)*4])); - } - int last_position = *(reinterpret_cast(&recordBuffer[index*4])); - int offset = recordHeader.indexDataLength - + recordHeader.userHeaderLength - + recordHeader.userHeaderLengthPadding; - data.setDataPtr(&recordBuffer[first_position+offset]); - data.setDataSize(last_position-first_position); - data.setDataOffset(first_position + offset); - } -void record::read(hipo::bank &b, int event){ - hipo::data event_data; - getData(event_data,event); - hipo::event::getStructure(event_data.getDataPtr(),b,b.getSchema().getGroup(),b.getSchema().getItem()); -} - -void record::getColumn(hipo::data &data,const char* column, hipo::bank &bank, int event){ - int order = bank.getSchema().getEntryOrder(column); - getColumn(data,order,bank,event); -} - -void record::getColumn(hipo::data &data,int column, hipo::bank &bank, int event){ - hipo::data event_data; - getData(event_data,event); - std::pair pos = hipo::event::getStructurePosition(event_data.getDataPtr(), - bank.getSchema().getGroup(), bank.getSchema().getItem()); - - //printf(" returned position = %8d, %8d\n",pos.first,pos.second); - - if(pos.second<=0) { - data.setDataPtr(NULL); - data.setDataSize(0); - data.setDataType(0); - return; - } - //printf("----- hok ---- we are here now ----\n"); - int size = *reinterpret_cast(&event_data.getDataPtr()[pos.first+4]); - //printf("----- hok ---- one more step ----\n"); - int bankRows = size/bank.getSchema().getRowLength(); - //printf(" returned sizes = %8d, %8d\n",size,bankRows); - data.setDataSize(bankRows); - data.setDataType(bank.getSchema().getEntryType(column)); - - //printf(" returned type = %d\n",data.getDataType()); - int offset = bank.getSchema().getOffset(column,0,bankRows); - //printf("============ offset = %8d\n",offset); - data.setDataPtr(&(event_data.getDataPtr()[pos.first+offset+8])); -} - -void record::getEventsMap(std::vector> &emap){ - emap.clear(); - int offset = recordHeader.indexDataLength - + recordHeader.userHeaderLength - + recordHeader.userHeaderLengthPadding; - /* - printf(" offset for the record = %8d, %8d, %8d, %8d\n",offset, - recordHeader.indexDataLength - , recordHeader.userHeaderLength - , recordHeader.userHeaderLengthPadding - );*/ - - int nevents = recordHeader.numberOfEvents; - for(int index = 0; index < nevents; index++){ - int first_position = 0; - if(index > 0){ - first_position = *(reinterpret_cast(&recordBuffer[(index -1)*4])); - } - int last_position = *(reinterpret_cast(&recordBuffer[index*4])); - emap.push_back(std::make_pair(first_position+offset,last_position+offset)); - } -} - void record::readHipoEvent(hipo::event &event, int index){ - hipo::data event_data; - getData(event_data,index); - event.init(event_data.getDataPtr(), event_data.getDataSize()); - } - /** - * prints the content of given buffer in HEX format. Used for debugging. - */ - void record::showBuffer(const char *data, int wrapping, int maxsize) - { - for(int i = 0; i < maxsize; i++){ - printf("%X ", 0x000000FF&((unsigned int) data[i])); - if( (i+1)%wrapping==0) printf("\n"); - } - printf("\n"); - } - /** - * decompresses the buffer given with pointed *data, into a destination array - * provided. The arguments indicate the compressed data length (dataLength), - * and maximum decompressed length. - * returns the number of bytes that were decompressed by LZ4 - */ - int record::getUncompressed(const char *data, char *dest, int dataLength, int dataLengthUncompressed){ - #ifdef __LZ4__ - int result = LZ4_decompress_safe(data,dest,dataLength,dataLengthUncompressed); - //int result = LZ4_decompress_fast(data,dest,dataLengthUncompressed); - return result; - #endif - - #ifndef __LZ4__ - printf("\n >>>>> LZ4 compression is not supported."); - printf("\n >>>>> check if libz4 is installed on your system."); - printf("\n >>>>> recompile the library with liblz4 installed.\n"); - return NULL; - #endif - - } - /** - * deompresses the content of given buffer ( *data), into a newly allocated - * memory. User is responsible for free-ing the allocated memory. - */ - char *record::getUncompressed(const char *data, int dataLength, - int dataLengthUncompressed){ - - #ifdef __LZ4__ - char *output = (char *) malloc(dataLengthUncompressed); - int result = LZ4_decompress_safe(data,output,dataLength,dataLengthUncompressed); - //int result = LZ4_decompress_fast(data,output,dataLengthUncompressed); - return output; - //printf(" FIRST (%d) = %x %x %x %x\n",result);//,destUnCompressed[0],destUnCompressed[1], - //destUnCompressed[2],destUnCompressed[3]); - //LZ4_decompress_fast(buffer,destUnCompressed,decompressedLength); - //LZ4_uncompress(buffer,destUnCompressed,decompressedLength); - #endif - - #ifndef __LZ4__ - printf("\n >>>>> LZ4 compression is not supported."); - printf("\n >>>>> check if libz4 is installed on your system."); - printf("\n >>>>> recompile the library with liblz4 installed.\n"); - return nullptr; - #endif - - } - - -} diff --git a/hipo4/record.h b/hipo4/record.h deleted file mode 100644 index bde7d23..0000000 --- a/hipo4/record.h +++ /dev/null @@ -1,143 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ - -/* - * File: record.h - * Author: gavalian - * - * Created on April 11, 2017, 4:47 PM - */ - -#ifndef HIPORECORD_H -#define HIPORECORD_H - -#include -#include -#include -#include -#include -#include -#include - -#include "event.h" -#include "utils.h" - -namespace hipo { - - typedef struct recordHeader_t { - int signatureString{}; // 1) identifier string is HREC (int = 0x43455248 - int recordLength{}; // 2) TOTAL Length of the RECORD, includes INDEX array - int recordDataLength{}; // 3) Length of the DATA uncompressed - int recordDataLengthCompressed{}; // 4) compressed length of the DATA buffer - int numberOfEvents{} ; // 5) number of event, data buckets in DATA buffer - int headerLength{} ; // 6) Length of the buffer represengin HEADER for the record - int indexDataLength{} ; // 7) Length of the index buffer (in bytes) - int userHeaderLength{}; // user header length in bytes - int userHeaderLengthPadding{}; // the padding added to user header Length - int bitInfo{}; - int compressionType{}; - int compressedLengthPadding{}; - int dataEndianness{}; - } recordHeader_t; - - class data { - private: - const char *data_ptr{}; - int data_size{}; - int data_endianness{}; - int data_offset{}; - int data_type; - - public: - data(){ data_ptr = nullptr; data_size = 0;} - ~data()= default; - - void setDataPtr(const char *__ptr){ data_ptr = __ptr;} - void setDataSize(int __size){ data_size = __size;} - void setDataOffset(int __offset) { data_offset = __offset;} - void setDataEndianness(int __endianness) { data_endianness = __endianness;} - void setDataType(int __type){ data_type = __type;} - const uint32_t *getEvioPtr(){ return reinterpret_cast(data_ptr);} - int getEvioSize(){ return (int) data_size/4 ;} - const char *getDataPtr(){ return data_ptr;} - int getDataSize(){ return data_size;} - int getDataType(){ return data_type;} - int getDataEndianness(){ return data_endianness;} - int getDataOffset(){ return data_offset;} - }; - - class record { - - private: - - //std::vector< std::vector > eventBuffer; - std::vector recordHeaderBuffer; - recordHeader_t recordHeader{}; - - std::vector recordBuffer; - std::vector recordCompressedBuffer; - - hipo::benchmark readBenchmark; - hipo::benchmark unzipBenchmark; - hipo::benchmark indexBenchmark; - - char *getUncompressed(const char *data, int dataLength, int dataLengthUncompressed); - int getUncompressed(const char *data, char *dest, int dataLength, int dataLengthUncompressed); - void showBuffer(const char *data, int wrapping, int maxsize); - - public: - - record(); - ~record(); - - void read(hipo::bank &b, int event); - void readRecord(std::ifstream &stream, long position, int dataOffset); - void readRecord__(std::ifstream &stream, long position, long recordLength); - bool readRecord(std::ifstream &stream, long position, int dataOffset, long inputSize); - int getEventCount(); - int getRecordSizeCompressed(); - - void getColumn(hipo::data &data,int column, hipo::bank &bank, int event); - void getColumn(hipo::data &data,const char* column, hipo::bank &bank, int event); - - void readEvent( std::vector &vec, int index); - void readHipoEvent(hipo::event &event, int index); - - void getData( hipo::data &data, int index); - //void getBank( hipo::bank &bank, int index); - - void getEventsMap(std::vector> &emap); - - hipo::benchmark &getReadBenchmark(){ return readBenchmark;} - hipo::benchmark &getUnzipBenchmark(){ return unzipBenchmark;} - hipo::benchmark &getIndexBenchmark(){ return indexBenchmark;} - }; -} -#endif /* HIPORECORD_H */ diff --git a/hipo4/recordbuilder.cpp b/hipo4/recordbuilder.cpp deleted file mode 100644 index 39e9e57..0000000 --- a/hipo4/recordbuilder.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#include "recordbuilder.h" -//#include "hipoexceptions.h" - -#ifdef __LZ4__ -#include -#endif - -namespace hipo { - /** - * Default constructor sets number of max events to 100000 - * and the buffer size to 8MB. - */ - recordbuilder::recordbuilder(){ - bufferIndex.resize(4*defaultNumberOfEvents); - bufferEvents.resize(defaultRecordSize); - bufferData.resize(defaultRecordSize+4*defaultNumberOfEvents); - bufferRecord.resize(defaultRecordSize+4*defaultNumberOfEvents+512*1024); - bufferIndexEntries = 0; - bufferEventsPosition = 0; - } - /** - * Constructor with custom max event size and maximum record - * size provided by user. - */ - recordbuilder::recordbuilder(int maxEvents, int maxLength){ - bufferIndex.resize(4*maxEvents); - bufferEvents.resize(maxLength); - bufferData.resize( maxLength+4*maxEvents + 1024); - bufferRecord.resize(maxLength+4*maxEvents+512*1024); - bufferIndexEntries = 0; - bufferEventsPosition = 0; - } - - /** - * add event object to the record builder buffer. - */ - bool recordbuilder::addEvent(hipo::event &evnt){ - return addEvent(evnt.getEventBuffer(),0,evnt.getSize()); - } - /** - * add a content of a vector to the record builder buffer. - * offset in the buffer and number of bytes to add provided - * by user. - */ - bool recordbuilder::addEvent(std::vector &vec, int start, int length){ - if((bufferEventsPosition+length)>=bufferEvents.size()) return false; - if((bufferIndexEntries+1)*4>=bufferIndex.size()) return false; - *reinterpret_cast(&bufferIndex[bufferIndexEntries*4]) = length; - bufferIndexEntries++; - memcpy(&bufferEvents[bufferEventsPosition],&vec[start],length); - bufferEventsPosition += length; - return true; - } - /** - * Resets the counters for number of events and sets the - * position for writing new events to the begining of the - * event buffer. - */ - void recordbuilder::reset(){ - bufferIndexEntries = 0; - bufferEventsPosition = 0; - } - /** - * returns record length in bytes rounded to first integer. - * the length comes out divisible by 4. - */ - int recordbuilder::getRecordLengthRounding(int bufferSize){ - if(bufferSize%4==0) return 0; - int nwords = bufferSize/4; - int nbytes = 4*(nwords+1); - return (nbytes-bufferSize); - } - /** - * Returns number of events in the record. - */ - int recordbuilder::getEntries(){ - int nentries = *reinterpret_cast(&bufferRecord[12]); - return nentries; - } - /** - * returns the size of the record. - */ - int recordbuilder::getRecordSize(){ - int size = *reinterpret_cast(&bufferRecord[0]); - return size*4; - } - - long recordbuilder::getUserWordOne(){ - long wOne = *reinterpret_cast(&bufferRecord[40]); - return wOne; - } - - long recordbuilder::getUserWordTwo(){ - long wTwo = *reinterpret_cast(&bufferRecord[48]); - return wTwo; - } - - void recordbuilder::setUserWordOne(long userWordOne){ - bufferUserWordOne = userWordOne; - } - - void recordbuilder::setUserWordTwo(long userWordTwo){ - bufferUserWordTwo = userWordTwo; - } - - void recordbuilder::build(){ - int indexSize = bufferIndexEntries*4; - int eventsSize = bufferEventsPosition; - memcpy(&bufferData[0],&bufferIndex[0],indexSize); - memcpy(&bufferData[indexSize],&bufferEvents[0],eventsSize); - int uncompressedSize = indexSize+eventsSize; - int compressedSize = compressRecord(uncompressedSize); - int rounding = getRecordLengthRounding(compressedSize); - int compressedSizeToWrite = compressedSize + rounding; - int compressedSizeToWriteWords = compressedSizeToWrite/4; - int recordLength = compressedSizeToWrite/4+14; - - hipo::utils::writeInt(&bufferRecord[0], 0, recordLength); // (1) - record length in words (includes header) - hipo::utils::writeInt(&bufferRecord[0], 4, 0); // (2) - record # - hipo::utils::writeInt(&bufferRecord[0], 8, 14); // (3) - record header lenght (in words) - hipo::utils::writeInt(&bufferRecord[0], 12, bufferIndexEntries); // (4) event count in the record - hipo::utils::writeInt(&bufferRecord[0], 16, bufferIndexEntries*4); // (5) length of index array in bytes - int versionWord = (rounding<<24)|(6); - hipo::utils::writeInt(&bufferRecord[0], 20, versionWord); // (6) record version number - hipo::utils::writeInt(&bufferRecord[0], 24, 0); // (7) user header length bytes - hipo::utils::writeInt(&bufferRecord[0], 28, 0xc0da0100); // (8) magic word - hipo::utils::writeInt(&bufferRecord[0], 32, eventsSize); // (9) magic word - int compressionWord = (1<<28)|(0x0FFFFFFF&compressedSizeToWriteWords); - hipo::utils::writeInt(&bufferRecord[0], 36, compressionWord); - hipo::utils::writeLong(&bufferRecord[0], 40, bufferUserWordOne); - hipo::utils::writeLong(&bufferRecord[0], 48, bufferUserWordTwo); - - //printf("record::build uncompressed size = %8d, compressed size = %8d, rounding = %4d , compressed FULL = %6d, record size = %6d, version = %X, size = %5X\n", - // uncompressedSize,compressedSize, rounding,compressedSizeToWrite, recordLength*4,versionWord,compressionWord); - } - /** - * Compresses the constructed buffer with LZ4 into internal buffer that - * will be written to the output. - */ - int recordbuilder::compressRecord(int src_size){ - - #ifdef __LZ4__ - //(const char* src, char* dst, int srcSize, int dstCapacity, int acceleration); - int result = LZ4_compress_fast(&bufferData[0],&bufferRecord[56],src_size,bufferRecord.size(),1); - - //int result = LZ4_decompress_safe(data,output,dataLength,dataLengthUncompressed); - //int result = LZ4_decompress_fast(data,output,dataLengthUncompressed); - return result; - //printf(" FIRST (%d) = %x %x %x %x\n",result);//,destUnCompressed[0],destUnCompressed[1], - //destUnCompressed[2],destUnCompressed[3]); - //LZ4_decompress_fast(buffer,destUnCompressed,decompressedLength); - //LZ4_uncompress(buffer,destUnCompressed,decompressedLength); - #endif - - #ifndef __LZ4__ - printf("\n >>>>> LZ4 compression is not supported."); - printf("\n >>>>> check if libz4 is installed on your system."); - printf("\n >>>>> recompile the library with liblz4 installed.\n"); - return 0; - #endif - } -} diff --git a/hipo4/recordbuilder.h b/hipo4/recordbuilder.h deleted file mode 100644 index d2f13db..0000000 --- a/hipo4/recordbuilder.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -/* - * File: recordbuilder.h - * Author: gavalian - * - * Created on April 11, 2017, 4:47 PM - */ - -#ifndef HIPORECORDBUILDER_H -#define HIPORECORDBUILDER_H - -#include -#include -#include -#include -#include -#include -#include - -#include "event.h" -#include "utils.h" - -namespace hipo { - - class recordbuilder { - - private: - const int defaultNumberOfEvents = 100000; - const int defaultRecordSize = 8*1024*1024; - //std::vector< std::vector > eventBuffer; - std::vector bufferIndex; - std::vector bufferEvents; - std::vector bufferData; - std::vector bufferRecord; - - int bufferIndexEntries; - int bufferEventsPosition; - long bufferUserWordOne = 0; - long bufferUserWordTwo = 0; - - int compressRecord(int src_size); - int getRecordLengthRounding(int bufferSize); - - public: - - recordbuilder(int maxEvents, int maxLength); - recordbuilder(); - virtual ~recordbuilder(){}; - - bool addEvent(std::vector &vec, int start, int length); - bool addEvent(hipo::event &evnt); - - long getUserWordOne(); - long getUserWordTwo(); - void setUserWordOne(long userWordOne); - void setUserWordTwo(long userWordTwo); - - int getRecordSize(); - int getEntries(); - std::vector &getRecordBuffer(){ return bufferRecord;}; - void reset(); - void build(); - }; -} -#endif /* HIPORECORD_H */ diff --git a/hipo4/tuple.cpp b/hipo4/tuple.cpp deleted file mode 100644 index e1bf98c..0000000 --- a/hipo4/tuple.cpp +++ /dev/null @@ -1,81 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ - /* - * File: event.h - * Author: gavalian - * - * Created on August 15, 2022, 17:04 PM - */ - -#include "tuple.h" - -namespace hipo { - - - tuple::tuple(){ - - } - - tuple::tuple(const char *format){ - } - - tuple::~tuple()= default; - - void tuple::initBranches(int size){ - for(int i = 0; i < size; i++) branches.push_back(new hipo::structure()); - for(int i = 0; i < branches.size(); i++) branches[i]->initStructureBySize(120,1,4,800); - currentPosition = 0; - } - - void tuple::fill(const float *array){ - for(int i = 0; i < branches.size(); i++) branches[i]->putFloatAt(currentPosition*4,array[i]); - currentPosition++; - if(currentPosition>=200){ - writeAndUpdate(); currentPosition = 0; - } - } - - void tuple::open(const char *file){ - writer.open(file); - } - - void tuple::close(){ - writer.close(); - } - - void tuple::writeAndUpdate(){ - for(int i = 0; i < branches.size(); i++){ - event.reset(); - event.setTag(i+1); - event.addStructure(*branches[i]); - writer.addEvent(event); - } - } -} diff --git a/hipo4/tuple.h b/hipo4/tuple.h deleted file mode 100644 index 4c1790d..0000000 --- a/hipo4/tuple.h +++ /dev/null @@ -1,87 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ -/* - * File: event.h - * Author: gavalian - * - * Created on August 15, 2022, 17:04 PM - */ - -#ifndef HIPO_TUPLE_H -#define HIPO_TUPLE_H - -#include -#include -#include -#include -#include -#include -#include -#include "writer.h" - -// if the library is compiled with C++11 -// support we will use unordered map which -// is faster than standard map -#if __cplusplus > 199711L -#include -#endif - - -namespace hipo { - - //typedef std::auto_ptr node_pointer; - - class tuple { - - private: - std::vector branches; - int currentPosition = 0; - hipo::writer writer; - hipo::event event; - - protected: - - void writeAndUpdate(); - - public: - - tuple(); - tuple(const char *format); - virtual ~tuple(); - - void open(const char *file); - void initBranches(int size); - void setVerbose(int level){ writer.setVerbose(level);} - void fill(const float *array); - void close(); - }; -} - -#endif /* TUPLE_H */ diff --git a/hipo4/utils.cpp b/hipo4/utils.cpp deleted file mode 100644 index 19d733e..0000000 --- a/hipo4/utils.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#include "utils.h" - - -namespace hipo { - - utils::utils(){ } - utils::~utils(){} - - void utils::tokenize(const std::string& str, std::vector& tokens, - const std::string& delimiters) - { - // Skip delimiters at beginning. - std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); - // Find first "non-delimiter". - std::string::size_type pos = str.find_first_of(delimiters, lastPos); - - - while (std::string::npos != pos || std::string::npos != lastPos) - { - // Found a token, add it to the vector. - tokens.push_back(str.substr(lastPos, pos - lastPos)); - // Skip delimiters. Note the "not_of" - lastPos = str.find_first_not_of(delimiters, pos); - // Find next "non-delimiter" - pos = str.find_first_of(delimiters, lastPos); - } - } - /** - * finds postion of the dalim in the string, while skipping "order" times. - */ - int utils::findposition(const std::string &str, const char *delim, int order){ - int found = 0; - int position = 0; - std::string::size_type firstPos = str.find_first_of(delim,position); - if(firstPos==std::string::npos) return -1; - position = firstPos; - while(found!=order){ - firstPos = str.find_first_of(delim,position+1); - if(firstPos==std::string::npos) return -1; - position = firstPos; - found++; - } - return position; - } - /** - * returns a substring from a string that is enclosed between - * start_delim and end_delim. order variable decides which enclosed - * string to return as and order of occurance. 0 - first one. 1 - second one. - */ - std::string utils::substring(const std::string &str, - const char *start_delim, const char *end_delim, int order){ - int position = 0; - int firstPos = hipo::utils::findposition(str,start_delim,order); - if(firstPos<0) return std::string(); - std::string::size_type lastPos = str.find_first_of(end_delim,firstPos+1); - if(lastPos==std::string::npos) return std::string(); - int length = lastPos - firstPos - 1; - return str.substr(firstPos+1, length); - } - - void utils::writeInt(char *buffer, int position, int value){ - int *ptr = reinterpret_cast(&buffer[position]); - *ptr = value; - } - - void utils::writeLong( char *buffer, int position, long value){ - int64_t *ptr = reinterpret_cast(&buffer[position]); - *ptr = value; - } - - void utils::writeByte( char *buffer, int position, uint8_t value ){ - int8_t *ptr = reinterpret_cast(&buffer[position]); - *ptr = value; - } - - void utils::printLogo(){ - std::cout << "************************************************" << std::endl; - std::cout << "* >=< : --------------------- *" << std::endl; - std::cout << "* ,.--' ''-. : HIPO 4.0 I/O Library *" << std::endl; - std::cout << "* ( ) ',_.' : Jefferson National Lab *" << std::endl; - std::cout << "* Xx'xX : Date: 01/24/2019 *" << std::endl; - std::cout << "************************************************" << std::endl; - std::cout << std::endl; - } - - std::string utils::getHeader(){ - std::string header; - header.append("//***********************************************************************\n"); - header.append("//***********************************************************************\n"); - header.append("// ____ ____ _____ _______ ___ ______ __ \n"); - header.append("// |_ || _||_ _||_ __ \\ .' `. / ____ `. / | \n"); - header.append("// | |__| | | | | |__) |/ .-. \\ `' __) | `| | \n"); - header.append("// | __ | | | | ___/ | | | | _ |__ '. | | \n"); - header.append("// _| | | |_ _| |_ _| |_ \\ `-' / | \\____) | _ _| |_ \n"); - header.append("// |____||____||_____||_____| `.___.' \\______.'(_)|_____| \n"); - header.append("// \n"); - header.append("//======================================================================= \n"); - header.append("// Autogenerated code by HIPO 3.1 io library\n"); - header.append("// Modify the main loop to suite your needs\n"); - header.append("// Date: \n"); - header.append("//***********************************************************************\n"); - return header; - } - - std::string utils::getFileHeader(){ - std::string file_header; - std::string comments = hipo::utils::getHeader(); - file_header.append(comments); - file_header.append("#include \n#include \n\n"); - file_header.append("#include \"reader.h\"\n#include \"node.h\"\n"); - file_header.append("\nint main(int argc, char** argv) {\n"); - file_header.append(" std::cout << \" reading file example program (HIPO) \" << std::endl;\n"); - file_header.append(" char inputFile[256];\n\n" ); - file_header.append(" if(argc>1) {\n sprintf(inputFile,\"%s\",argv[1]);\n } else {\n " ); - file_header.append(" std::cout << \" *** please provide a file name...\" << std::endl;\n" ); - file_header.append(" exit(0);\n }\n\n"); - file_header.append(" hipo::reader reader;\n"); - file_header.append(" reader.open(inputFile);\n\n" ); - return file_header; - } - std::string utils::getFileTrailer(const char *code){ - std::string file_trailer; - file_trailer.append("\n"); - file_trailer.append(" //----------------------------------------------------\n"); - file_trailer.append(" //-- Main LOOP running through events and printing\n"); - file_trailer.append(" //-- values of the first decalred branch\n"); - file_trailer.append(" //----------------------------------------------------\n"); - file_trailer.append(" int entry = 0;\n"); - file_trailer.append(" while(reader.next()==true){\n"); - file_trailer.append(" entry++;\n"); - file_trailer.append(" std::cout << \"event # \" << entry << std::endl;\n"); - file_trailer.append(code); - file_trailer.append(" }\n"); - file_trailer.append(" //----------------------------------------------------\n"); - file_trailer.append("}\n"); - file_trailer.append("//###### ENF OF GENERATED FILE #######\n"); - return file_trailer; - } - std::string utils::getSConstruct(){ - std::string std__string; - std__string.append("#=================================================\n"); - std__string.append("# The SCONSTRUCT file for building HIPO project.\n"); - std__string.append("# \n"); - std__string.append("#=================================================\n"); - std__string.append("import glob\n"); - std__string.append("import os\n"); - std__string.append("import sys\n"); - std__string.append("#=================================================\n"); - std__string.append("# LOADING THE ENVIRONMENT\n"); - std__string.append("#=================================================\n"); - std__string.append("env = Environment(CPPPATH=[\"include\",\".\",\"/usr/include\",\"/usr/local/include\",\"/opt/local/include\",\"/group/clas12/packages/lz4/lib\",\"/group/clas12/packages/hipo-io/libcpp\"])\n"); - std__string.append("env.Append(ENV = os.environ)\n"); - std__string.append("env.Append(CPPPATH=[\"src/root\",\"src/evio\"])\n"); - std__string.append("env.Append(CCFLAGS=[\"-O2\",\"-fPIC\",\"-m64\",\"-fmessage-length=0\",\"-g\"])\n"); - std__string.append("env.Append(LIBPATH=[\"/opt/local/lib\",\"/usr/lib\",\"/usr/local/lib\",\"/group/clas12/packages/lz4/lib\",\"lib\",\"/group/clas12/packages/hipo-io/lib\"])\n"); - std__string.append("env.Append(CONFIGUREDIR=[\"/group/clas12/packages/lz4/lib\",\"/group/clas12/packages/hipo-io/lib\"])\n"); - std__string.append("#=================================================\n"); - std__string.append("# Check for compression libraries.\n"); - std__string.append("#=================================================\n"); - std__string.append("conf = Configure(env)\n"); - std__string.append("\n"); - std__string.append("if conf.CheckLib('libhipo'):\n"); - std__string.append(" print '\\n\\033[32m[**] >>>>> found library : HIPO'\n"); - std__string.append(" print ''\n"); - std__string.append(" env.Append(CCFLAGS=\"-D__HIPO__\")\n"); - std__string.append(" \n"); - std__string.append("if conf.CheckLib('liblz4'):\n"); - std__string.append(" print '\\n\\033[32m[**] >>>>> found library : LZ4'\n"); - std__string.append(" print '[**] >>>>> enabling lz4 compression. \\033[0m'\n"); - std__string.append(" print ''\n"); - std__string.append(" env.Append(CCFLAGS=\"-D__LZ4__\")\n"); - std__string.append("\n"); - std__string.append("if conf.CheckLib('libz'):\n"); - std__string.append(" print '\\n\\033[32m[**] >>>>> found library : libz'\n"); - std__string.append(" print '[**] >>>>> enabling gzip compression. \\033[0m'\n"); - std__string.append(" print ''\n"); - std__string.append(" env.Append(CCFLAGS=\"-D__LIBZ__\")\n"); - std__string.append("#=================================================\n"); - std__string.append("# BUILDING EXECUTABLE PROGRAM\n"); - std__string.append("#=================================================\n"); - std__string.append("runFileLoop = env.Program(target=\"runFileLoop\",source=[\"runFileLoop.cc\"])\n"); - return std__string; - } - - - - void benchmark::resume(){ - first = clock.now(); - //auto start = clock.now(); - counter++; - } - - void benchmark::show(){ - printf("[benchmark] %24s : time = %12.4f \n", benchmarkName.c_str(),getTimeSec()); - } - - void benchmark::pause(){ - - second = clock.now(); - std::chrono::nanoseconds diff_ms = - std::chrono::duration_cast< std::chrono::nanoseconds >( second-first ); - //printf(" count = %lld\n",diff_ms.count()); - running_time += diff_ms.count(); - } - - long benchmark::getTime(){ - return running_time; - } - - double benchmark::getTimeSec(){ - return running_time*1e-9; - } - - int benchmark::getCounter(){ return counter;} -} diff --git a/hipo4/utils.h b/hipo4/utils.h deleted file mode 100644 index 2cdaef7..0000000 --- a/hipo4/utils.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -/* - * File: utils.h - * Author: gavalian - * - * Created on April 27, 2017, 10:01 AM - */ - -#ifndef UTILS_H -#define UTILS_H - -#include -#include -#include -#include -#include -#include - -namespace hipo { - - class utils { - private: - - public: - utils(); - ~utils(); - static void tokenize(const std::string& str, - std::vector& tokens, - const std::string& delimiters = " "); - - static std::string substring(const std::string &str, - const char *start_delim, - const char *end_delim, int order); - - static int findposition(const std::string &str, - const char *delim, int order); - - static std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r "){ - str.erase(0, str.find_first_not_of(chars));return str; - } - static std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r "){ - str.erase(str.find_last_not_of(chars) + 1);return str; - } - static std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r "){ - return ltrim(rtrim(str, chars), chars); - } - - static void printLogo(); - - static std::string getHeader(); - static std::string getFileHeader(); - static std::string getFileTrailer(const char *code); - static std::string getSConstruct(); - - static void writeInt( char *buffer, int position, int value); - static void writeLong( char *buffer, int position, long value); - static void writeByte( char *buffer, int position, uint8_t value ); - }; - - class benchmark { - private: - - std::chrono::high_resolution_clock clock; - std::chrono::time_point first, second; - std::string benchmarkName; - - long running_time; - int counter; - int printoutFrequency; - - public: - - benchmark(const char *name){ - benchmarkName = name; - running_time = 0;counter = 0; printoutFrequency = -1; - } - benchmark(){ running_time = 0;counter = 0; printoutFrequency = -1;} - benchmark(int freq){ running_time = 0;counter = 0; printoutFrequency = freq;} - ~benchmark(){} - - void setName(const char *name){ benchmarkName = name;} - void resume(); - void pause(); - long getTime(); - double getTimeSec(); - int getCounter(); - void show(); - }; -} - -#endif /* UTILS_H */ diff --git a/hipo4/wrapper.cpp b/hipo4/wrapper.cpp deleted file mode 100644 index a1f2998..0000000 --- a/hipo4/wrapper.cpp +++ /dev/null @@ -1,262 +0,0 @@ -#include -#include "reader.h" -#include "event.h" -#include "fusion.h" - -hipo::reader hipo_FORT_Reader; -hipo::event hipo_FORT_Event; -hipo::dictionary hipo_FORT_Dictionary; - -std::map eventStore; - - -hipo::fusion hFusion; - -extern "C" { - - void hipo_file_open_( const char *filename, int length){ - char *buffer = (char *) malloc(length+1); - memcpy(buffer,filename,length); - buffer[length] = '\0'; - printf("[FORTRAN] opening file : %s\n", buffer); - hipo_FORT_Reader.open(buffer); - hipo_FORT_Reader.readDictionary(hipo_FORT_Dictionary); - free(buffer); - } - - void hipo_file_open(const char *filename){ - hipo_FORT_Reader.open(filename); - hipo_FORT_Reader.readDictionary(hipo_FORT_Dictionary); - } - - int hipo_file_next_(int* fstatus){ - bool status = hipo_FORT_Reader.next(); - if(status==false){ - *fstatus = 12; - return 12; - } - hipo_FORT_Reader.read(hipo_FORT_Event); - std::map::iterator it; - for ( it = eventStore.begin(); it != eventStore.end(); it++ ) - { - it->second->reset(); // string's value - } - *fstatus = 0; - return 0; - } - - void hipo_read_bank_(const char *bankname, int *bankRows, int banknameLength){ - char *buffer = (char * ) malloc(banknameLength+1); - memcpy(buffer,bankname,banknameLength); - buffer[banknameLength] = '\0'; - if(eventStore.count(std::string(buffer))==0){ - if(hipo_FORT_Dictionary.hasSchema(buffer)==true){ - hipo::bank *bank_ptr = new hipo::bank(hipo_FORT_Dictionary.getSchema(buffer)); - eventStore[buffer] = bank_ptr; - printf("---> map : initializing bank \"%24s\" (%6d, %5d) to the store\n", - buffer,hipo_FORT_Dictionary.getSchema(buffer).getGroup(), - hipo_FORT_Dictionary.getSchema(buffer).getItem() ); - } else { - *bankRows = 0; - free(buffer); - return; - } - } - - hipo_FORT_Event.getStructure(*eventStore[buffer]); - *bankRows = eventStore[buffer]->getRows(); - free(buffer); - } -/* - void hipo_read_bank_byid_(int *group, int *item){ - int igroup = *group; - int iitem = *item; - - if(eventStore.count(igroup)==0){ - printf("********* bank does not exist %d\n",igroup); - std::vector schemaList = hipo_FORT_Dictionary.getSchemaList(); - for(int i = 0; i < schemaList.size(); i++){ - int schGroup = hipo_FORT_Dictionary.getSchema(schemaList[i].c_str()).getGroup(); - if(schGroup==igroup){ - printf(" found group = %d\n",schGroup); - printf("---> map : initializing bank \"%24s\" (%6d) to the store\n", - schemaList[i].c_str(),schGroup); - hipo::bank *bank_ptr = new hipo::bank(hipo_FORT_Dictionary.getSchema(schemaList[i].c_str())); - eventStore[schGroup] = bank_ptr; - } - } - } - }*/ - - void get_bank_rows_(int *group, int *bankRows){ - /*int igroup = *group; - if(eventStore.count(igroup)==0) *bankRows = 0; - *bankRows = eventStore[igroup]->getRows();*/ - } - - void hipo_read_float_(const char *group, const char *item, int *nread, float *buffer, int *maxRows, - int length_group, int length_item){ - - char *buffer_group = (char * ) malloc(length_group+1); - memcpy(buffer_group,group,length_group); - buffer_group[length_group] = '\0'; - - char *buffer_item = (char * ) malloc(length_item+1); - memcpy(buffer_item,item,length_item); - buffer_item[length_item] = '\0'; - - //printf("---->>>>> reading float (%s) (%s)\n",buffer_group,buffer_item); - /*int id_g = *group; - int id_i = ; - int max = *maxRows; - //printf("READIN FLOAT %d %d \n",*group,*item); - //std::vector vec = hipo_FORT_Reader.getEvent()->getFloat(id_g,id_i); - //printf("RESULT SIZE = %d \n",vec.size()); - for(int i = 0; i < vec.size(); i++){ - if(igetRows(); - if(nrows>(*maxRows)) nrows = *(maxRows); - //printf("---->>>>> reading float (%s) (%s) (%d)\n",buffer_group,buffer_item,nrows); - for(int i = 0; i < nrows; i++){ - buffer[i] = bank->getFloat(buffer_item, i); - } - *nread = nrows; - - free(buffer_group); - free(buffer_item); - } - - void hipo_read_double_(const char *group, const char *item, int *nread, double *buffer, int *maxRows, - int length_group, int length_item){ - - char *buffer_group = (char * ) malloc(length_group+1); - memcpy(buffer_group,group,length_group); - buffer_group[length_group] = '\0'; - - char *buffer_item = (char * ) malloc(length_item+1); - memcpy(buffer_item,item,length_item); - buffer_item[length_item] = '\0'; - - - if(eventStore.count(buffer_group)==0){ - *nread = 0; - free(buffer_group); - free(buffer_item); - return; - } - - hipo::bank *bank = eventStore[buffer_group]; - int nrows = bank->getRows(); - if(nrows>(*maxRows)) nrows = *(maxRows); - //printf("---->>>>> reading float (%s) (%s) (%d)\n",buffer_group,buffer_item,nrows); - for(int i = 0; i < nrows; i++){ - buffer[i] = bank->getDouble(buffer_item, i); - } - *nread = nrows; - - free(buffer_group); - free(buffer_item); - } - - void hipo_read_int_(const char *group, const char *item, int *nread, int *buffer, int *maxRows, - int length_group, int length_item){ - - char *buffer_group = (char * ) malloc(length_group+1); - memcpy(buffer_group,group,length_group); - buffer_group[length_group] = '\0'; - - char *buffer_item = (char * ) malloc(length_item+1); - memcpy(buffer_item,item,length_item); - buffer_item[length_item] = '\0'; - - if(eventStore.count(buffer_group)==0){ - *nread = 0; - free(buffer_group); - free(buffer_item); - return; - } - - hipo::bank *bank = eventStore[buffer_group]; - int nrows = bank->getRows(); - if(nrows>(*maxRows)) nrows = *(maxRows); - //printf("---->>>>> reading float (%s) (%s) (%d)\n",buffer_group,buffer_item,nrows); - for(int i = 0; i < nrows; i++){ - buffer[i] = bank->getInt(buffer_item, i); - } - *nread = nrows; - free(buffer_group); - free(buffer_item); - } - - void hipo_read_long_(const char *group, const char *item, int *nread, int64_t *buffer, int *maxRows, - int length_group, int length_item){ - - char *buffer_group = (char * ) malloc(length_group+1); - memcpy(buffer_group,group,length_group); - buffer_group[length_group] = '\0'; - - char *buffer_item = (char * ) malloc(length_item+1); - memcpy(buffer_item,item,length_item); - buffer_item[length_item] = '\0'; - - if(eventStore.count(buffer_group)==0){ - *nread = 0; - free(buffer_group); - free(buffer_item); - return; - } - - hipo::bank *bank = eventStore[buffer_group]; - int nrows = bank->getRows(); - if(nrows>(*maxRows)) nrows = *(maxRows); - //printf("---->>>>> reading float (%s) (%s) (%d)\n",buffer_group,buffer_item,nrows); - for(int i = 0; i < nrows; i++){ - buffer[i] = bank->getLong(buffer_item, i); - } - *nread = nrows; - free(buffer_group); - free(buffer_item); - } - /*void hipo_read_int_(int *group, int *item, int *nread, int *buffer, int *maxRows){ - - }*/ - - - int fusion_open(const char *filename){ - int handle = hFusion.open(filename); return handle; - } - - bool fusion_next(int handle){ return hFusion.next(handle);} - void fusion_define(int handle, const char *bank){ hFusion.define(handle,bank);} - int fusion_bankSize(int handle, const char *bank){ return hFusion.getSize(handle,bank);} - - int fusion_get_int(int handle, const char *bank, const char *entry, int row){ - return hFusion.getInt(handle,bank,entry,row); - } - - float fusion_get_float(int handle, const char *bank, const char *entry, int row){ - float value = hFusion.getFloat(handle,bank,entry,row); - //printf(" result from wrapper = %f\n",value); - return value; - } - - int fusion_entry_type(int handle, const char *bank, const char *entry){ - return hFusion.getType(handle,bank,entry); - } - - float *fusion_create_array(int size){ - float *array = new float[size]; - for(int i = 0; i < size; i++) array[i]=(i+1)*2; - return array; - } -} diff --git a/hipo4/writer.cpp b/hipo4/writer.cpp deleted file mode 100644 index e262399..0000000 --- a/hipo4/writer.cpp +++ /dev/null @@ -1,245 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ - -#include "writer.h" -#include - -namespace hipo { - -/** -* Open a File for writing, it includes the dictionary -* in the file. -*/ - void writer::open(const char *filename){ - outputStream.open(filename); - - std::vector schemaList = writerDictionary.getSchemaList(); - - recordbuilder builder; - event schemaEvent; - - for(int i = 0; i < schemaList.size(); i++){ - std::string schemaString = writerDictionary.getSchema(schemaList[i].c_str()).getSchemaString(); - std::string schemaStringJson = writerDictionary.getSchema(schemaList[i].c_str()).getSchemaStringJson(); - //---> Can open after debug level is introduced in the class - //printf("STR : %s\n",schemaString.c_str()); - //printf("JSON : %s\n",schemaStringJson.c_str()); - schemaEvent.reset(); - structure schemaNode(120,2,schemaString); - structure schemaNodeJson(120,1,schemaStringJson); - schemaEvent.addStructure(schemaNodeJson); - schemaEvent.addStructure(schemaNode); - schemaEvent.show(); - builder.addEvent(schemaEvent); - } - - //------------------------------------------------------------------------- - // This section is added on April-28-2022, it will store user provided - // configurations along with the schema in the record that goes into - // HIPO header. G^2 - //------------------------------------------------------------------------- - std::map::iterator it; - event configEvent; - - for( it = userConfig.begin(); it != userConfig.end(); it++){ - printf("::: adding user configuration (key): %s\n",it->first.c_str()); - - std::string wKey = std::string(it->first.c_str()); - std::string wConfig = std::string(it->second.c_str()); - - structure configKey(32555,1,wKey); - structure configString(32555,2,wConfig); - - configEvent.reset(); - configEvent.addStructure(configKey); - configEvent.addStructure(configString); - builder.addEvent(configEvent); - } - - //printf(" RECORD SIZE BEFORE BUILD = %d\n",builder.getRecordSize()); - builder.build(); - //printf(" RECORD SIZE AFTER BUILD = %d, NENTRIES = %d\n", - // builder.getRecordSize(),builder.getEntries()); - - int dictionarySize = builder.getRecordSize(); - - hipoFileHeader_t header; - - //header.uniqueid = 0x43455248; - header.uniqueid = 0x4F504948;// 4849504F; - header.filenumber = 1; - header.headerLength = 14; - header.recordCount = 0; - header.indexArrayLength = 0; - header.bitInfoVersion = (0x000000FF&6); - header.userHeaderLength = dictionarySize;// will change with the dictionary - header.magicNumber = 0xc0da0100; - header.userRegister = 0; - header.trailerPosition = 0; - header.userIntegerOne = 0; - header.userIntegerTwo = 0; - - outputStream.write( reinterpret_cast (&header),sizeof(header)); - long position = outputStream.tellp(); - - printf("writing header:: position = %ld\n",position); - outputStream.write( reinterpret_cast (&builder.getRecordBuffer()[0]),dictionarySize); - position = outputStream.tellp(); - printf("writing dictionary:: position = %ld\n",position); - } - -void writer::addDictionary(hipo::dictionary &dict){ - std::vector schemaList = dict.getSchemaList(); - for(int i = 0; i < schemaList.size(); i++){ - writerDictionary.addSchema(dict.getSchema(schemaList[i].c_str())); - } -} - - void writer::addEvent(hipo::event &hevent){ - if(hevent.getTag()==0){ - bool status = recordBuilder.addEvent(hevent); - if(status==false){ - writeRecord(recordBuilder); - recordBuilder.addEvent(hevent); - } - } else { - int tag = hevent.getTag(); - extendedBuilder[tag].setUserWordOne(tag); - bool status = extendedBuilder[tag].addEvent(hevent); - if(status==false){ - writeRecord(extendedBuilder[tag]); - extendedBuilder[tag].addEvent(hevent); - } - } - } - -void writer::addEvent(std::vector &vec, int size ){ - int transferSize = size; - if(size<0){ transferSize = vec.size(); } - bool status = recordBuilder.addEvent(vec,0,transferSize); - if(status==false){ - writeRecord(recordBuilder); - recordBuilder.addEvent(vec,0,transferSize); - } -} - - void writer::writeRecord(recordbuilder &builder){ - builder.build(); - recordInfo_t recordInfo; - recordInfo.recordPosition = outputStream.tellp(); - recordInfo.recordEntries = builder.getEntries(); - recordInfo.recordLength = builder.getRecordSize(); - recordInfo.userWordOne = builder.getUserWordOne(); - recordInfo.userWordTwo = builder.getUserWordTwo(); - if(recordInfo.recordEntries>0){ - outputStream.write( reinterpret_cast (&builder.getRecordBuffer()[0]),recordInfo.recordLength); - writerRecordInfo.push_back(recordInfo); - if(verbose>0) printf("%6ld : writing::record : size = %8d, entries = %8d, position = %12ld word = %12ld %12ld\n", - writerRecordInfo.size(), recordInfo.recordLength,recordInfo.recordEntries, - recordInfo.recordPosition,recordInfo.userWordOne,recordInfo.userWordTwo); - } else { - if(verbose>0) printf(" write::record : empty record will not be written.....\n"); - } - builder.reset(); - } - -void writer::showSummary(){ - for(int loop = 0; loop < writerRecordInfo.size(); loop++){ - recordInfo_t recordInfo = writerRecordInfo[loop]; - printf(" %6d : record INFO : size = %8d, entries = %8d, position = %12ld word = %12ld %12ld\n", loop, - recordInfo.recordLength,recordInfo.recordEntries,recordInfo.recordPosition, - recordInfo.userWordOne,recordInfo.userWordTwo); - } -} - - -void writer::writeIndexTable(){ - hipo::schema indexSchema("file::index",32111,1); - indexSchema.parse("position/L,length/I,entries/I,userWordOne/L,userWordTwo/L"); - int nEntries = writerRecordInfo.size(); - long indexPosition = outputStream.tellp(); - printf("\n\n-----> writing file index : entries = %d, position = %ld\n", - nEntries,indexPosition); - hipo::bank indexBank(indexSchema,nEntries); - for(int i = 0; i < nEntries; i++){ - recordInfo_t recordInfo = writerRecordInfo[i]; - indexBank.putLong("position",i,recordInfo.recordPosition); - indexBank.putInt("length",i,recordInfo.recordLength); - indexBank.putInt("entries",i,recordInfo.recordEntries); - indexBank.putLong("userWordOne",i,recordInfo.userWordOne); - indexBank.putLong("userWordTwo",i,recordInfo.userWordTwo); - } - - int eventSize = 32*nEntries + 1024; - - hipo::event indexEvent(eventSize); - indexEvent.addStructure(indexBank); - recordBuilder.reset(); - recordBuilder.addEvent(indexEvent); - writeRecord(recordBuilder); - outputStream.seekp(40); - outputStream.write(reinterpret_cast (&indexPosition), 8); -} - -void writer::close(){ - writeRecord(recordBuilder); - - std::map::iterator it; - for(it = extendedBuilder.begin(); it != extendedBuilder.end(); it++){ - writeRecord(it->second); - } - - writeIndexTable(); - outputStream.close(); - writerRecordInfo.clear(); -} - -/*** -* Function to change the record builder user word one -*/ -void writer::setUserIntegerOne(long userIntOne){ - recordBuilder.setUserWordOne(userIntOne); -} - -/*** -*Function to change the record builder user word two -*/ -void writer::setUserIntegerTwo(long userIntTwo){ - recordBuilder.setUserWordTwo(userIntTwo); -} - -/*** -*Function to write buffer. -*/ -void writer::flush(){ - writeRecord(recordBuilder); -} - -} diff --git a/hipo4/writer.h b/hipo4/writer.h deleted file mode 100644 index 5b0cf41..0000000 --- a/hipo4/writer.h +++ /dev/null @@ -1,180 +0,0 @@ -//****************************************************************************** -//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ * -//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ * -//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ * -//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ * -//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ * -//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ * -//************************ Jefferson National Lab (2017) *********************** -/* - * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission - * to use, copy, modify, and distribute this software and its documentation - * for educational, research, and not-for-profit purposes, without fee and - * without a signed licensing agreement. - * - * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF - * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * This software was developed under the United States Government license. - * For more information contact author at gavalian@jlab.org - * Department of Experimental Nuclear Physics, Jefferson Lab. - */ -/* - *This sowftware was developed at Jefferson National Laboratory. - */ - /** - *
-  *
-  * FILE HEADER STRUCTURE ( 56 bytes, 14 integers (32 bit) )
-  *
-  *    +----------------------------------+
-  *  1 |              ID                  | // HIPO: 0x43455248, Evio: 0x4556494F
-  *    +----------------------------------+
-  *  2 +          File Number             | // split file #
-  *    +----------------------------------+
-  *  3 +         Header Length            | // 14 (words)
-  *    +----------------------------------+
-  *  4 +      Record (Index) Count        |
-  *    +----------------------------------+
-  *  5 +      Index Array Length          | // bytes
-  *    +-----------------------+----------+
-  *  6 +       Bit Info        | Version  | // version (8 bits)
-  *    +-----------------------+----------+
-  *  7 +      User Header Length          | // bytes
-  *    +----------------------------------+
-  *  8 +          Magic Number            | // 0xc0da0100
-  *    +----------------------------------+
-  *  9 +          User Register           |
-  *    +--                              --+
-  * 10 +                                  |
-  *    +----------------------------------+
-  * 11 +         Trailer Position         | // File offset to trailer head (64 bits).
-  *    +--                              --+ // 0 = no offset available or no trailer exists.
-  * 12 +                                  |
-  *    +----------------------------------+
-  * 13 +          User Integer 1          |
-  *    +----------------------------------+
-  * 14 +          User Integer 2          |
-  *    +----------------------------------+
-  *
-  * -------------------
-  *   Bit Info Word
-  * -------------------
-  *     0-7  = version
-  *     8    = true if dictionary is included (relevant for first record only)
-  *     9    = true if this file has "first" event (in every split file)
-  *    10    = File trailer with index array exists
-  *    11-19 = reserved
-  *    20-21 = pad 1
-  *    22-23 = pad 2
-  *    24-25 = pad 3 (always 0)
-  *    26-27 = reserved
-  *    28-31 = general header type: 1 = Evio file
-  *                                 2 = Evio extended file
-  *                                 5 = HIPO file
-  *                                 6 = HIPO extended file
-  *
-  * 
- * - * @version 6.0 - * @since 6.0 9/6/17 - */ -/* - * File: writer.h - * Author: gavalian - * - * Created on April 11, 2017, 2:07 PM - */ - -#ifndef HIPOWRITER_H -#define HIPOWRITER_H - - -#define HIPO_FILE_HEADER_SIZE 72 -/* Constants for endianness of the file */ -#ifndef BIG_ENDIAN -#define BIG_ENDIAN 0 -#endif -#ifndef LITTLE_ENDIAN -#define LITTLE_ENDIAN 1 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "recordbuilder.h" -#include "reader.h" - -namespace hipo { - - typedef struct { - int uniqueid; - int filenumber; - int headerLength; // in words (usually 14) - int recordCount; - int indexArrayLength; // in bytes - int bitInfoVersion; - int userHeaderLength; - int magicNumber; - long userRegister; - long trailerPosition; - int userIntegerOne; - int userIntegerTwo; - } hipoFileHeader_t; - - /** -* READER index class is used to construct entire events -* sequence from all records, and provides ability to canAdvance -* through events where record number is automatically calculated -* and triggers reading of the next record when events in the current -* record are exhausted. -*/ -class writer { - - private: - std::ofstream outputStream; - hipo::recordbuilder recordBuilder; - hipo::dictionary writerDictionary; - std::vector writerRecordInfo; - std::map userConfig; - - std::map extendedBuilder; - - void writeIndexTable(); - int verbose = 0; - - public: - - writer(){}; - virtual ~writer(){}; - - void addEvent(hipo::event &hevent); - void addEvent(std::vector &vec, int size = -1); - void addUserConfig(std::string key, std::string value){ userConfig[key] = value;} - void addUserConfig(const char *key, const char *value){ userConfig[std::string(key)] = std::string(value);} - void writeRecord(recordbuilder &builder); - void open(const char *filename); - void close(); - void showSummary(); - void addDictionary(hipo::dictionary &dict); - hipo::dictionary &getDictionary(){ return writerDictionary;} - void setUserIntegerOne(long userIntOne); - void setUserIntegerTwo(long userIntTwo); - void flush(); - void setVerbose(int level){ verbose = level;} -}; - -}; -#endif /* HIPOFILE_H */ diff --git a/hipo_src b/hipo_src new file mode 160000 index 0000000..2009487 --- /dev/null +++ b/hipo_src @@ -0,0 +1 @@ +Subproject commit 20094876df040ec234dd376fa527cf58442b775a diff --git a/iguana/Creators.h b/iguana/Creators.h new file mode 100644 index 0000000..3a66e6a --- /dev/null +++ b/iguana/Creators.h @@ -0,0 +1,55 @@ +#pragma once + +#include "IguanaAlgo.h" +#include + +namespace clas12root{ + + + class Creators : public IguanaAlgo { + + public: + + iguana::physics::InclusiveKinematics* InclusiveKinematics(){return _incKin.get();} + + + void Use(const string& name){ + //Initialise the inclusive kinemtics algorithm + if(name=="physics::InclusiveKinematics"){ + _incKin.reset(new iguana::physics::InclusiveKinematics ); + AddAlgo(_incKin.get()); + } + + + } + + //Inclusive Kinematics + iguana::physics::InclusiveKinematicsVars doInclusiveKinematics(const clas12::region_particle *electron){ + return _incKin->ComputeFromLepton(electron->getPx(),electron->getPy(),electron->getPz(),_concurrent_key); //0 => concurrent key + } + + iguana::physics::InclusiveKinematicsVars doInclusiveKinematics(const FourVector& electron){ + return _incKin->ComputeFromLepton(electron.X(),electron.Y(),electron.Z(),_concurrent_key); //0 => concurrent key + } + iguana::physics::InclusiveKinematicsVars doInclusiveKinematics(const TLorentzVector& electron){ + return _incKin->ComputeFromLepton(electron.X(),electron.Y(),electron.Z(),_concurrent_key); //0 => concurrent key + } + //Reload + void Reload() const{ + auto run = C12()->runconfig()->getRun(); + if(_runNb==run) return; + _runNb=run; + + if(_incKin.get())_concurrent_key=_incKin->PrepareEvent(run); + } + + private: + + std::unique_ptr _incKin; + + mutable Long64_t _runNb =-1; + mutable int _concurrent_key=0; + + }; + +} diff --git a/iguana/Filters.h b/iguana/Filters.h new file mode 100644 index 0000000..6d9d5eb --- /dev/null +++ b/iguana/Filters.h @@ -0,0 +1,151 @@ +#pragma once + +#include "IguanaAlgo.h" +#include +//#include +//#include +#include + +namespace clas12root{ + + + class Filters : public IguanaAlgo { + + public: + + iguana::clas12::ZVertexFilter* ZVertexFilter(){return _zVer.get();} + // iguana::clas12::FiducialFilter* FiducialFilter(){return _Fid.get();} + //iguana::clas12::PhotonGBTFilter* PhotonGBTFilter(){return _PhotGBT.get();} + + void Use(const string& name){ + + //Initialise the z-vertex filter algorithm + if(name=="clas12::ZVertexFilter"){ + _zVer.reset(new iguana::clas12::ZVertexFilter); + AddAlgo(_zVer.get()); + } + // if(name=="clas12::FiducialFilter"){ + // _Fid.reset(new iguana::clas12::FiducialFilter); + // AddAlgo(_Fid.get()); + // } + /* + if(name=="clas12::PhotonGBTFilter"){ + _PhotGBT.reset(new iguana::clas12::PhotonGBTFilter); + AddAlgo(_PhotGBT.get()); + } + */ + } + + //interface to vector transforms + void doFilters(std::function< bool ( const clas12::region_particle *p ) > fun) const{ + // bool filt = true; + // for(auto* p:parts) filt*=fun(p); + // return filt; + + //get the clas12root region particles vector for the event + auto& particles = C12()->getDetParticles(); + //save particles to delete + //(cannot to it actively when looping over same vector) + std::vector to_delete; + for(auto* pa:particles){ + if(fun(pa)==false){//failed filter must remove + to_delete.push_back(pa); + } + } + //remove failed particles from clas12root vector + if(to_delete.empty()==false){ + for(auto* pa:to_delete){ + //remove this particle pointer from detParticles + particles.erase(find(particles.begin(), particles.end(), pa)); + } + } + //all done + } + + ///////////////// + //specific filters + //zvertex filter + bool doZVertexFilter(const clas12::region_particle *p) const{ + return _zVer->Filter(p->par()->getVz(),p->par()->getPid(),p->par()->getStatus(),_concurrent_key);// 0 => concurrent key + } + void doZVertexFilter() const{ + doFilters([this](const clas12::region_particle *p){return doZVertexFilter(p);}); + } + /* + //////////////// + //fiducial filter + bool doFiducialFilter(const clas12::region_particle *p) const + { + iguana::clas12::FiducialFilter::traj_row_data traj; + auto c12=C12(); + traj.x1 = p->traj(clas12::DC,6)->getX(); + traj.x1 = p->traj(clas12::DC,6)->getY(); + traj.z1 = p->traj(clas12::DC,6)->getZ(); + traj.x2 = p->traj(clas12::DC,18)->getX(); + traj.x2 = p->traj(clas12::DC,18)->getY(); + traj.z2 = p->traj(clas12::DC,18)->getZ(); + traj.x3 = p->traj(clas12::DC,36)->getX(); + traj.x3 = p->traj(clas12::DC,36)->getY(); + traj.z3 = p->traj(clas12::DC,36)->getZ(); + traj.sector = p->getSector(); + + //Need FiducialFitler to be public! + // return _Fid->Filter(traj,c12->runconfig()->getTorus(),p->par()->getPid()); + return true; + } + void doFiducialFilter() const{ + doFilters([this](const clas12::region_particle *p){return doFiducialFilter(p);}); + } + */ + ////////////////// + //PhotonGBT filter + /* + bool doPhotonGBTFilter(const clas12::region_particle *p, const std::map& calo) const{ + + if(p->getPid()!=22) return true; + + //Need FiducialFitler to be public! + + //return _PhotGBT->Filter(*(p->par()),*(p->cal()),calo,p->getIndex(),C12()->getRunNumber() ); + + return true; + + } + void doPhotonGBTFilter() const{ + if(getNParticles()==0) return; + auto calo = _PhotGBT->GetCaloMap(*(C12()->getDetParticles(0)->cal(-1))); + doFilters([this,&calo](const clas12::region_particle *p){return doPhotonGBTFilter(p,calo);}); + } + */ + /////////////////////////////////////////////// + void doAllFilters(){ + + if(_zVer.get())doZVertexFilter(); + // if(_Fid.get())doFiducialFilter(); + // if(_PhotGBT.get())doPhotonGBTFilter(); + } + + + //Reload + void Reload() const{ + auto run = C12()->runconfig()->getRun(); + if(_runNb==run) return; + _runNb=run; + + if(_zVer.get())_concurrent_key=_zVer->PrepareEvent(run); + + } + + private: + + std::unique_ptr _zVer; + //std::unique_ptr _Fid; + //std::unique_ptr _PhotGBT; + + mutable Long64_t _runNb =-1; + mutable int _concurrent_key=0; + + }; + +} + diff --git a/iguana/Iguana.h b/iguana/Iguana.h new file mode 100644 index 0000000..50ba7ea --- /dev/null +++ b/iguana/Iguana.h @@ -0,0 +1,107 @@ +#pragma once + +#include "clas12reader.h" + +#include "Transformers.h" +#include "Filters.h" +#include "Creators.h" + + +namespace clas12root{ + + + class Iguana { + + public: + + void SetClas12( const std::unique_ptr* c12 ){ + _transform.SetClas12(c12); + _filter.SetClas12(c12); + _creator.SetClas12(c12); + } + + template + OPTION_TYPE SetOptionAll(std::string const& key, const OPTION_TYPE val){ + + _transform.SetOptionAll(key,val); + _filter.SetOptionAll(key,val); + _creator.SetOptionAll(key,val); + + return val; + } + + void Start(){ + + _transform.Start(); + _filter.Start(); + _creator.Start(); + + } + + void Stop(){ + + _transform.Stop(); + _filter.Stop(); + _creator.Stop(); + + } + + + Transformers& GetTransformers(){return _transform;} + Filters& GetFilters(){return _filter;} + Creators& GetCreators(){return _creator;} + + + void GoodToBad(const ROOT::Math::PxPyPzMVector& good, TLorentzVector &bad){ + bad.SetXYZT(good.X(),good.Y(),good.Z(),good.T()); + } + + //multithreading + concurrent_key_t PrepareEvent(int const runnum) const{ + /* + if(o_runnum->NeedsHashing()) { + std::hash hash_ftn; + auto hash_key = hash_ftn(runnum); + + if(!o_runnum->HasKey(hash_key)){ + _concurrent_key=hash_key; + // Reload(runnum, hash_key); + Reload(); + } + } else { + if(o_runnum->IsEmpty() || o_runnum->Load(0) != runnum){ + //Reload(runnum, 0); + _concurrent_key=0; + Reload(); + } + } + */ + Reload(); + return 0; + } + int GetKey()const {return _concurrent_key;} + + void Reload() const{ + //_transforms->Reload(GetKey()); + //_filter->Reload(GetKey()); + _filter.Reload(); + _creator.Reload(); + } + private: + + clas12root::Transformers _transform; + clas12root::Filters _filter; + clas12root::Creators _creator; + + int _concurrent_key=0; + // mutable std::unique_ptr> o_runnum = {ConcurrentParamFactory::Create()}; + + + }; + + + + + + +} diff --git a/iguana/IguanaAlgo.h b/iguana/IguanaAlgo.h new file mode 100644 index 0000000..b12c2d4 --- /dev/null +++ b/iguana/IguanaAlgo.h @@ -0,0 +1,68 @@ +#pragma once + +#include "clas12reader.h" +#include "region_particle.h" + +#include +#include + +#include +#include +#include + +namespace clas12root{ + + using FourVector = ROOT::Math::PxPyPzMVector; + using concurrent_key_t = std::size_t; + + class IguanaAlgo{ + + public: + + void SetClas12( const std::unique_ptr* c12){_c12=c12;} + + void Start(){ + + for(auto* algo: _algos){ + std::cout<<" start "<GetName()<Start(); + } + + } + void Stop(){ + + for(auto* algo: _algos){ + algo->Stop(); + } + + } + + + protected : + + friend class Iguana; + + void AddAlgo(iguana::Algorithm* algo){ + _algos.push_back(algo); + } + + template + OPTION_TYPE SetOptionAll(std::string const& key, const OPTION_TYPE val){ + + for(auto* algo: _algos){ + algo->SetOption(key,val); + } + return val; + } + + clas12::clas12reader* C12() const {return _c12->get();} + + private: + + std::vector _algos; + const std::unique_ptr* _c12=nullptr; + + + }; + +} diff --git a/iguana/Transformers.h b/iguana/Transformers.h new file mode 100644 index 0000000..97425f2 --- /dev/null +++ b/iguana/Transformers.h @@ -0,0 +1,137 @@ +#pragma once + +#include "IguanaAlgo.h" +#include +#include +#include + +namespace clas12root{ + + + class Transformers : public IguanaAlgo { + + public: + + iguana::clas12::MomentumCorrection* MomentumCorrection(){return _momCorr.get();} + + void Use(const string& name){ + + //Initialise the momentum corrections algorithm + if(name=="clas12::MomentumCorrection"){ + _momCorr.reset(new iguana::clas12::MomentumCorrection); + AddAlgo(_momCorr.get()); + } + else if(name=="clas12::FTEnergyCorrection"){ + _ftECorr.reset(new iguana::clas12::FTEnergyCorrection); + AddAlgo(_ftECorr.get()); + } + else{ + std::cerr<<"Iguana -> clas12root::Transformers routine "<Transform(p->getPx(),p->getPy(),p->getPz(),p->getSector(),p->getPid(),C12()->runconfig()->getTorus()); + + //set the FourVector X,Y,Z,M + p4.SetCoordinates(px,py,pz,p4.M()); + + } + + //FT momentum corrections + void doFTEnergyCorrection(const clas12::region_particle *p, FourVector& p4) const{ + + auto [px, py, pz, en] = _ftECorr->Transform(p->getPx(),p->getPy(),p->getPz(),p->getSector()); + //set the FourVector X,Y,Z,T + p4.SetXYZT(px,py,pz,en); + + } + + + + //Configure to automate the right correction for the particle + void doAllCorrections(std::vector parts, + std::vector p4s) const{ + + if(parts.size()!=p4s.size()){ + std::cerr<<"Iguana-> clas12root::Transformers::doCorrections : Different number of particles, "<getRegion() ){ + //Forward tagger corrections + case clas12::FT : + if(_ftECorr.get()){ + doFTEnergyCorrection(parts[i],*p4s[i]); + } + + break; + + case clas12::FD : + //Forward detector corrections + if(_momCorr.get()){ + doMomentumCorrection(parts[i],*p4s[i]); + } + + break; + + case clas12::CD : + + break; + + default: + break; + }//end region switch + }//particle loop + + } + + + + + //interface to vector transforms + /*void doCorrections(std::vector parts, + std::vector p4s, + std::function< void (const clas12::region_particle *p, TLorentzVector& p4) > fun) const{ + + for(uint i=0;iTransform(p->getPx(),p->getPy(),p->getPz(),p->getSector(),p->getPid(),C12()->runconfig()->getTorus()); + + p4.SetXYZM(px,py,pz,p4.M()); + + } + + void doMomentumCorrections(std::vector parts, + std::vector p4s){ + + return doCorrections(parts,p4s, + [this](const clas12::region_particle *p,TLorentzVector& p4){ + return doMomentumCorrection(p,p4); + }); + } + */ + + private: + + std::unique_ptr _momCorr; + std::unique_ptr _ftECorr; + + + }; + +} + diff --git a/installHIPO b/installHIPO new file mode 100755 index 0000000..454e5a4 --- /dev/null +++ b/installHIPO @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# install HIPO locally + +set -eou pipefail + +# set the installation prefix: the default is clas12root/hipo, and it may be overriden by user argument +top_dir=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) && pwd -P) +[ $# -ge 1 ] && prefix=$1 || prefix=$top_dir/hipo + +# check for meson and ninja +if ! type meson; then + echo "ERROR: 'meson' is needed to build HIPO; you can install it with your package manager or with 'pip'." >&2 + exit 1 +fi +if ! type ninja; then + echo "WARNING: 'ninja' may be needed for 'meson', unless you prefer a different default backend; building HIPO may fail." >&2 +fi + +# compile and install +source_dir=$top_dir/hipo_src +build_dir=$source_dir/build +echo """================================================================================== +source directory: $source_dir +build directory: $build_dir +installation directory: $prefix +================================================================================== +""" +meson setup --wipe $build_dir $source_dir --prefix=$prefix # use --wipe to force a 'clean' build +meson install -C $build_dir +echo """================================================================================== +Done installing HIPO. +You may now set your environment to point to this installation: +- for bash or zsh: export HIPO=$prefix +- for csh or tcsh: setenv HIPO $prefix +""" diff --git a/tests/Ex11_Iguana_MomentumCorrection.C b/tests/Ex11_Iguana_MomentumCorrection.C new file mode 100644 index 0000000..c507dac --- /dev/null +++ b/tests/Ex11_Iguana_MomentumCorrection.C @@ -0,0 +1,127 @@ +#include "clas12reader.h" +#include "region_particle.h" +#include "HipoChain.h" +#include "Iguana.h" +#include +#include +#include +#include +#include +#include +#include +#include + +void Ex11_Iguana_MomentumCorrection(){ + + using FourVector = ROOT::Math::PxPyPzMVector; + // clas12databases::SetRCDBRootConnection("rcdb.root"); + gBenchmark->Start("iguana"); + //create hipo chain for looping over events + clas12root::HipoChain chain; + chain.Add("/cache/clas12/rg-a/production/recon/spring2019/torus-1/pass2/dst/recon/006616/rec_clas_006616.evio.00000-00004.hipo"); + chain.SetReaderTags({0}); //create clas12reader with just tag 0 events + //add some filters + auto config_c12=chain.GetC12Reader(); + config_c12->addExactPid(11,1); //exactly 1 electron + config_c12->addExactPid(211,1); //exactly 1 pi+ + config_c12->addExactPid(-211,1); //exactly 1 pi- + config_c12->ignoreBank("REC::CovMat"); + + + // create the chosen algorithms + clas12root::Iguana ig; + ig.SetClas12(chain.C12ptr());//connect to clas12reader + ig.GetTransformers().Use("clas12::MomentumCorrection"); + ig.GetTransformers().Use("clas12::FTEnergyCorrection"); + ig.GetFilters().Use("clas12::ZVertexFilter"); + ig.GetCreators().Use("physics::InclusiveKinematics"); + + ig.SetOptionAll("log", "debug"); + ig.Start(); + + + //decalre 4-vector objects + auto db=TDatabasePDG::Instance(); + FourVector p4beam(0,0,10.6,10.6); + FourVector p4target(0,0,0,db->GetParticle(2212)->Mass()); + FourVector p4el(0,0,0,db->GetParticle(11)->Mass()); + FourVector p4pip(0,0,0,db->GetParticle(211)->Mass()); + FourVector p4pim(0,0,0,db->GetParticle(-211)->Mass()); + TLorentzVector tp4el(0,0,0,db->GetParticle(11)->Mass()); + + TH1D hQ2{"Q2","Q^{2}",100,0,10}; + TH1D hx{"x","x",100,0,1}; + TH1D hy{"y","y",100,0,1}; + TH1D hW{"W","W",100,0,6}; + TH1D hcQ2{"cQ2","corrected Q^{2}",100,0,10}; + TH1D hcx{"cx","corrected x",100,0,1}; + TH1D hcy{"cy","corrected y",100,0,1}; + TH1D hcW{"cW","corrected W",100,0,6}; + + + //get run clas12reader + auto& c12=chain.C12ref(); + while ( chain.Next() ){ + + //auto ebeam = c12->rcdb()->current().beam_energy/1000; + //p4beam.SetXYZT(0,0,ebeam,ebeam); //approx. mass =0 + // get particles by type + // note we applied a filter to ensure size of all ==1 + auto electron=c12->getByID(11)[0]; + auto pip=c12->getByID(211)[0]; + auto pim=c12->getByID(-211)[0]; + //filter on z-vertices of the particles + // if( !(ig.GetFilters().doZVertexFilter({electron,pip,pim})) ) { + if( !(ig.GetFilters().doAllFilters({electron,pip,pim})) ) { + continue; + } + + //correct momentum and get 4-vectors + ig.GetTransformers().doAllCorrections({electron,pip,pim},{&p4el,&p4pip,&p4pim}); + + //calculate inclusive kinematics + auto kine = ig.GetCreators().doInclusiveKinematics(electron); + auto corrkine = ig.GetCreators().doInclusiveKinematics(p4el); + + hQ2.Fill(kine.Q2); + hx.Fill(kine.x); + hy.Fill(kine.y); + hW.Fill(kine.W); + + hcQ2.Fill(corrkine.Q2); + hcx.Fill(corrkine.x); + hcy.Fill(corrkine.y); + hcW.Fill(corrkine.W); + + //if you unfortunately prefer TLorentzVector, there is a transform function to help. + // ig.GoodToBad(p4el,tp4el); + // cout<<"check good to bad "<Stop("iguana"); + gBenchmark->Print("iguana"); + + auto* can = new TCanvas(); + can->Divide(2,2); + + can->cd(1); + hQ2.DrawCopy(); + hcQ2.SetLineColor(2); + hcQ2.DrawCopy("same"); + + can->cd(2); + hW.DrawCopy(); + hcW.SetLineColor(2); + hcW.DrawCopy("same"); + + can->cd(3); + hx.DrawCopy(); + hcx.SetLineColor(2); + hcx.DrawCopy("same"); + + can->cd(4); + hy.DrawCopy(); + hcy.SetLineColor(2); + hcy.DrawCopy("same"); + +} diff --git a/tests/db.C b/tests/db.C new file mode 100644 index 0000000..420717c --- /dev/null +++ b/tests/db.C @@ -0,0 +1,96 @@ +#include "clas12databases.h" +#include "clas12reader.h" + +#include + +using namespace clas12; +using namespace std; + +void db(){ + + /*For a database to be created you must specify the path to + its database connection. In the case of ccdb this can be a + a local sqlite file or a web link to the jlab clasdb account + It is recommended to download a local copy to reduce connections + It is recommended to edit and run the script PrepareDatabases.C + for this purpose*/ + clas12databases::SetCCDBLocalConnection("/scigroup/cvmfs/hallb/clas12/soft/noarch/data/ccdb/ccdb_latest.sqlite"); + //clas12databases::SetRCDBRootConnection("rcdb.root"); + + clas12root::HipoChain chain; + chain.Add("/cache/clas12/rg-a/production/recon/spring2019/torus-1/pass2/dst/train/InclusivePositron/InclusivePositron_006666.hipo"); + + chain.SetReaderTags({0}); //create clas12reader with just tag 0 events + + auto config_c12=chain.GetC12Reader(); + + /*make a request for ccdb information (&=> reference, will update for next file) + for list of tables , https://clasweb.jlab.org/cgi-bin/ccdb/objects*/ + auto& ccdbElSF=config_c12->ccdb()->requestTableDoubles("/calibration/eb/electron_sf"); + + /*Get some data from the ccdb for this run + rcdb info,(&=> reference, will update for next file) + see Clas12Banks/rcdb_vals for full list of data + this should match https://clasweb.jlab.org/rcdb/conditions*/ + //auto& rcdbData= config_c12->rcdb()->current();//struct with all relevent rcdb values + + //configure qadb requirements + /* + * Several quality assurance requirements can be specified. + * requireOkForAsymmetry requires that an event was deemed + * suitable for asymmetry measurements. + * + * addRequirement requires that the event was not identified + * as, for example, a marginal outlier. Several requirements + * can be assigned at the same time. + * + * See RGA analysis note and clas12-qadb github repository for + * additional information. + */ + if(config_c12->qadb()!=nullptr){ + config_c12->db()->qadb_requireOkForAsymmetry(true); + config_c12->db()->qadb_requireGolden(true); + config_c12->db()->qadb_addQARequirement("MarginalOutlier"); + config_c12->db()->qadb_addQARequirement("TotalOutlier"); + /* + * applyQA specifies to the clas12reader that quality assurance + * cuts will be applied, based on the .json file given as an + * argument. This file should contain the Clas12 Quality Assurance + * database. + * i.e. clas12reader will only process events that pass quality assurance + * and ignore those which fail + */ + config_c12->applyQA(); + } + + gBenchmark->Start("db"); + + //now get reference to (unique)ptr for accessing data in loop + //this will point to the correct place when file changes + auto& c12=chain.C12ref(); + while (chain.Next()){ + + //The following run conditions can be returned directly by c12 + //cout<<"Event count: "<ccdb()){ + cout<< ccdbElSF.size()<Stop("db"); + gBenchmark->Print("db"); +}