forked from JeffersonLab/clas12root
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scaler reader and fix HipoChain to run sequntially through files with…
… clas12reader
- Loading branch information
Showing
10 changed files
with
538 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,81 @@ | ||
#include "scaler_reader.h" | ||
#include <algorithm> | ||
|
||
namespace clas12{ | ||
|
||
scaler_reader::scaler_reader(std::string filename){ | ||
_reader.setTags(1); | ||
_reader.open(filename.data()); //keep a pointer to the reader | ||
_reader.readDictionary(_factory); | ||
_factory.show(); | ||
_bscal.reset(new scaler{_factory.getSchema("RUN::scaler")}); | ||
_bscal->show(); | ||
while(_reader.next()){ | ||
_reader.read(_event); | ||
_event.getStructure(*_bscal.get()); | ||
if(filename.empty())return; | ||
hipo::reader reader_; | ||
hipo::event event_; | ||
hipo::dictionary factory_; | ||
|
||
reader_.setTags(1); | ||
reader_.open(filename.data()); //keep a pointer to the reader | ||
reader_.readDictionary(factory_); | ||
|
||
_bscal.reset(new scaler{factory_.getSchema("RUN::scaler")}); | ||
_brun.reset(new runconfig{factory_.getSchema("RUN::config")}); | ||
|
||
while(reader_.next()){ | ||
reader_.read(event_); | ||
event_.getStructure(*_bscal.get()); | ||
if(_bscal->getRows()==0)continue; //only RUN::scaler | ||
event_.getStructure(*_brun.get()); | ||
|
||
_nScalReads++; | ||
auto cup=_bscal->getFCupGated(); | ||
if(cup>_maxCup) _maxCup=cup; | ||
if(cup<_minCup) _minCup=cup; | ||
_beamCharges.push_back(std::make_pair(_brun->getEvent(),cup)); | ||
} | ||
std::sort(_beamCharges.begin(),_beamCharges.end()); | ||
|
||
// int ccc=0; | ||
_deltaCharges.resize(_nScalReads); | ||
for(int i=0;i<_nScalReads;i++){ | ||
if(i)_deltaCharges[i]=_beamCharges[i].second-_beamCharges[i-1].second; | ||
else _deltaCharges[i]=0; | ||
} | ||
std::cout<<"Number of scaler reads "<<_nScalReads<<" "<<getBeamCharge()<<std::endl; | ||
} | ||
|
||
size_t scaler_reader::addLongCounter(){ | ||
auto index=_longCounter.size(); | ||
std::vector<int64_t> vec(_nScalReads); | ||
_longCounter.push_back(std::move(vec)); | ||
return index; | ||
} | ||
size_t scaler_reader::addDoubleCounter(){ | ||
auto index=_doubleCounter.size(); | ||
std::vector<double> vec(_nScalReads); | ||
_doubleCounter.push_back(std::move(vec)); | ||
return index; | ||
} | ||
|
||
size_t scaler_reader::findPosition(size_t event){ | ||
|
||
if(event==_lastEvent) return _lastPosition; | ||
_lastEvent=event;//new event | ||
|
||
if(_lastPosition>0){ | ||
//beamCharges is sorted in event number | ||
if(event> _beamCharges[_lastPosition-1].first | ||
&& event<_beamCharges[_lastPosition].first) | ||
return _lastPosition; //still in the same scaler read | ||
} | ||
|
||
|
||
auto itr=std::upper_bound(_beamCharges.begin(),_beamCharges.end(), | ||
evch_pair(event,0), | ||
[](const evch_pair& entry,const evch_pair& rhs){ | ||
return entry.first<rhs.first; | ||
} | ||
); | ||
_lastPosition = std::distance(_beamCharges.begin(),itr); | ||
|
||
//For standard events this should not happen, may happen with tag!=0 | ||
if(_lastPosition>=_nScalReads) _lastPosition=_nScalReads-1; | ||
return _lastPosition; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.