12#include <hipo4/reader.h>
40#include <hipo4/dictionary.h>
81 clas12reader(std::string filename,std::vector<long> tags=std::vector<long>());
88 cerr<<
"hipo::reader& getReader() clas12reader must be created with valid filename, currently we have "<<
getFilename()<<endl;
106 region_fdet_uptr reg{
new region_fdet{_bparts.get(),_bftbparts.get(),_bcovmat.get(),_bcal.get(),_bscint.get(),_btrck.get(),_butrck.get(),_btraj.get(),_bcher.get(),_bft.get(),_bevent.get(),_brich.get(),_bmcparts.get()}};
107 if(_useFTBased)reg->useFTBPid();
108 _rfdets.push_back(std::move(reg));
113 region_cdet_uptr reg{
new region_cdet{_bparts.get(),_bftbparts.get(),_bcovmat.get(),_bcal.get(),_bscint.get(),_btrck.get(),_butrck.get(),_btraj.get(),_bcher.get(),_bft.get(),_bevent.get(),_brich.get(),_bmcparts.get()}};
114 if(_useFTBased)reg->useFTBPid();
115 _rcdets.push_back(std::move(reg));
119 region_ft_uptr reg{
new region_ft{_bparts.get(),_bftbparts.get(),_bcovmat.get(),_bcal.get(),_bscint.get(),_btrck.get(),_butrck.get(),_btraj.get(),_bcher.get(),_bft.get(),_bevent.get(),_brich.get(),_bmcparts.get()}};
120 if(_useFTBased)reg->useFTBPid();
121 _rfts.push_back(std::move(reg));
125 region_band_uptr reg{
new region_band{_bparts.get(),_bftbparts.get(),_bcovmat.get(),_bcal.get(),_bscint.get(),_btrck.get(),_butrck.get(),_btraj.get(),_bcher.get(),_bft.get(),_bevent.get(),_brich.get(),_bmcparts.get()}};
126 if(_useFTBased)reg->useFTBPid();
127 _rbands.push_back(std::move(reg));
217 cerr<<
"clas12reader::addBank reader not opened, exiting..."<<endl;
218 cerr<<
" in case using HipoChain, call NextFile() first"<<endl;
221 std::unique_ptr<hipo::bank> bnk{
new hipo::bank{_factory.getSchema(name.data())}};
222 _addBanks.push_back(std::move(bnk));
223 _allBanks.push_back(_addBanks.back().get());
224 _addBankNames.push_back(name);
225 return _addBanks.size()-1;
228 hipo::bank*
getBank(uint index)
const {
return _addBanks.at(index).get();}
230 return getBank(ibank)->getSchema().getEntryOrder(itemname.data());
233 const std::vector<hipo::bank*>
getBanksPtrs(std::vector<std::string> names)
const{
234 std::vector<hipo::bank*> blist;
235 for(
const auto& name:names){
237 auto it = std::find_if(
241 { return bank->getSchema().getName() == name; });
242 if(it == _allBanks.end()) {
243 cerr<<
"clas12reader::getBanks : bank "<<name<<
" does not exist"<<endl;
247 auto cpBank =
dynamic_cast<hipo::bank*
>(*it);
248 blist.push_back(cpBank);
251 cout<<
"clas12reader::getBanks got "<<blist.size()<<endl;
283 std::vector<region_part_ptr>
getDetParticles(
bool const& applyBankFilter)
const;
293 std::vector<region_part_ptr>
getByID(
int id,
bool const& applyBankFilter=
false)
const;
303 std::vector<region_part_ptr>
getByRegion(
int ir,
bool const& applyBankFilter=
false)
const;
313 std::vector<region_part_ptr>
getByCharge(
int ch,
bool const& applyBankFilter=
false)
const;
320 short getNPid(
short pid)
const noexcept{
return std::count(_pids.begin(),_pids.end(), pid);};
323 _givenPids.push_back(pid);
326 _pidSelectExact[pid]=n;
327 _givenPids.push_back(pid);
341 const std::vector<short> &
getPids() const noexcept{
return _pids;}
344 long pattern = _brunconfig->getTrigger();
345 return ( pattern & (1<<k)) != 0;
348 long pattern = _bvtp->makeVTPTriggers();
349 return ( pattern & (1<<k)) != 0;
353 if(_scalReader.get())
return _scalReader.get();
356 return _scalReader.get();
361 return _runBeamCharge;
370 std::cout<<
"for file "<<_filename<<
"\n\t read "<<_nevent<<
" events from which "<<_nselected<<
" passed filtering conditions."<<std::endl;
379 cout<<
"\t accumulated charge past QA: "<<charge<<
" nC"<<endl;
386 _event.getStructure(*bank);
400 _reader.setVerbose(level);
408 _readEventUserAction = readEventUserAction;
419 void makeListBanks();
422 _reader.read(_event);
426 std::string _filename;
429 hipo::reader _reader;
431 hipo::dictionary _factory;
459 std::vector<std::unique_ptr<hipo::bank> > _addBanks;
460 std::vector<hipo::bank* > _allBanks;
465 std::vector<region_fdet_uptr> _rfdets;
466 std::vector<region_cdet_uptr> _rcdets;
467 std::vector<region_ft_uptr> _rfts;
468 std::vector<region_band_uptr> _rbands;
471 std::vector<region_part_ptr> _detParticles;
474 double _runBeamCharge{0};
477 long _nToProcess{-1};
486 std::vector<short> _pids;
492 std::vector<short> _givenPids;
493 std::map<short,short> _pidSelect;
494 std::map<short,short> _pidSelectExact;
495 bool _zeroOfRestPid{
false};
496 bool _useFTBased{
false};
498 std::vector<std::string> _addBankNames;
506 std::set<int> _runNumbers;
507 clas12databases *_db={
nullptr};
510 bool _connectDB=
false;
534 if(_bankInUse.at(bnk))
535 (*_bankInUse[bnk])=
false;
539 _justParticleAna=
true;
558 std::map<string,bool*> _bankInUse;
559 bool _useCovmat={
false};
560 bool _useEvent={
false};
561 bool _useRunconfig={
false};
562 bool _useFTBEvent={
false};
563 bool _useCal={
false};
564 bool _useCalExtras={
false};
565 bool _useScint={
false};
566 bool _useScintExtras={
false};
567 bool _useTrck={
false};
568 bool _useUTrck={
false};
569 bool _useTraj={
false};
570 bool _useCher={
false};
571 bool _useRich={
false};
573 bool _useVTP={
false};
574 bool _useHelonline={
false};
575 bool _useVertdoca={
false};
576 bool _useMCparts={
false};
577 bool _useMCevent={
false};
578 bool _justParticleAna={
false};
586 template <
typename Cont,
typename Pred>
589 std::copy_if(container.begin(),container.end(),std::back_inserter(result), predicate);
Definition calorimeter.h:24
Definition ccdb_reader.h:19
Definition cherenkov.h:22
Definition clas12databases.h:23
qadb_reader * qa() const
Definition clas12databases.h:53
void SetReadAction(std::function< bool(clas12reader *)> readEventUserAction)
Set a "read action", a custom lambda function that is executed for every event within readEvent().
Definition clas12reader.h:407
mcpar_ptr mcparts() const
get a pointer to the MC::Lund bank
Definition clas12reader.h:192
class tracker & getRECTrack() const
get the REC::Track bank
Definition clas12reader.h:158
bool const usingFTBased() const
Definition clas12reader.h:339
std::vector< region_part_ptr > & getDetParticles()
Get the full list of region_particles.
Definition clas12reader.h:267
std::vector< region_part_ptr > getByRegion(int ir, bool const &applyBankFilter=false) const
Get the list of region_particles, filtered by region.
Definition clas12reader.cpp:665
class rich & getRICHParticle() const
get the RICH::Particle bank
Definition clas12reader.h:168
ccdb_reader * ccdb() const
Definition clas12reader.h:520
hipo::dictionary & getDictionary()
Definition clas12reader.h:100
hipo::reader & getReader()
Definition clas12reader.h:86
class particle & getRECParticle() const
get the REC::Particle bank
Definition clas12reader.h:135
bool next()
initialise next event from the reader
Definition clas12reader.cpp:471
void getStructure(hipo::bank *bank)
Definition clas12reader.h:383
class runconfig & getRUNconfig() const
get the RUN::config bank
Definition clas12reader.h:144
hipo::bank * getBank(uint index) const
Definition clas12reader.h:228
event_ptr event() const
get a pointer to the REC::Event bank
Definition clas12reader.h:184
qadb_reader * qadb() const
Definition clas12reader.h:522
std::vector< region_part_ptr > * getDetParticlesPtr()
Get the full list of region_particles.
Definition clas12reader.h:273
clas12databases * db()
Definition clas12reader.h:524
uint addBank(const std::string &name)
Definition clas12reader.h:215
void SetRecParticleOnly()
Definition clas12reader.h:538
short getNPid(short pid) const noexcept
Definition clas12reader.h:320
void addExactPid(short pid, short n)
Definition clas12reader.h:325
bool checkTriggerBit(uint k)
Definition clas12reader.h:343
const std::vector< short > & preCheckPids()
Definition clas12reader.cpp:289
class event & getRECEvent() const
get the REC::Event bank
Definition clas12reader.h:146
class ftbevent & getRECFTEvent() const
get the REC::FTEvent bank
Definition clas12reader.h:148
void addARegionFDet()
Definition clas12reader.h:103
vtp_ptr vtp() const
get a pointer to the RAW::vtp bank
Definition clas12reader.h:188
scalerreader_ptr scalerReader()
Definition clas12reader.h:352
std::set< int > getRunNumbers() const
Definition clas12reader.h:365
bool nextInRecord()
initialise next event from the reader
Definition clas12reader.cpp:500
class mcparticle & getMCLund() const
get the MC::Lund bank
Definition clas12reader.h:172
const std::vector< short > & preCheckPidsOrCharge()
Definition clas12reader.cpp:322
bool readEvent()
Definition clas12reader.cpp:409
bool passPidSelect()
Definition clas12reader.cpp:612
class cherenkov & getRECCherenkov() const
get the REC::Cherenkov bank
Definition clas12reader.h:166
class vtp & getRAWvtp() const
get the RAW::vtp bank
Definition clas12reader.h:150
void sort()
Definition clas12reader.cpp:522
bool checkVTPTriggerBit(uint k)
Definition clas12reader.h:347
mcevt_ptr mcevent() const
get a pointer to the MC::Event bank
Definition clas12reader.h:194
ftbevent_ptr ftbevent() const
get a pointer to the REC::FTEvent bank
Definition clas12reader.h:186
bool grabEvent(Long64_t Nev)
Definition clas12reader.cpp:754
class vertdoca & getRECVertDoca() const
get the REC::VertDoca bank
Definition clas12reader.h:152
void clearEvent()
read the data
Definition clas12reader.cpp:273
std::vector< region_part_ptr > getByCharge(int ch, bool const &applyBankFilter=false) const
Get the list of region_particles, filtered by charge.
Definition clas12reader.cpp:672
const std::vector< short > & getPids() const noexcept
Definition clas12reader.h:341
class mcevent & getMCEvent() const
get the MC::Event bank
Definition clas12reader.h:174
runconfig_ptr runconfig() const
get a pointer to the RUN::config bank
Definition clas12reader.h:182
std::string getFilename()
Definition clas12reader.h:101
class forwardtagger & getRECForwardTagger() const
get the REC::ForwardTagger bank
Definition clas12reader.h:170
void summary()
Definition clas12reader.h:369
const std::vector< hipo::bank * > getBanksPtrs(std::vector< std::string > names) const
Definition clas12reader.h:233
class calorimeter & getRECCalorimeter() const
get the REC::Calorimeter bank
Definition clas12reader.h:154
class scintillator & getRECScintillator() const
get the REC::Scintillator bank
Definition clas12reader.h:156
void setVerbose(short level=1)
Definition clas12reader.h:398
hipo::bank & getParticleBank() const
get the particle bank, depending on your configuration
Definition clas12reader.h:207
void addARegionBAND()
Definition clas12reader.h:123
rcdb_reader * rcdb() const
Definition clas12reader.h:521
void addZeroOfRestPid()
Definition clas12reader.h:329
class helflip & getHELflip() const
get the HEL::flip bank
Definition clas12reader.h:142
helonline_ptr helonline() const
get a pointer to the HEL::online bank
Definition clas12reader.h:178
int getBankOrder(int ibank, std::string itemname) const
Definition clas12reader.h:229
void addARegionFT()
Definition clas12reader.h:117
class helonline & getHELonline() const
get the HEL::online bank
Definition clas12reader.h:140
helflip_ptr helflip() const
get a pointer to the HEL::flip bank
Definition clas12reader.h:180
void setEntries(long n)
Definition clas12reader.h:397
void ignoreBank(const string &bnk)
Definition clas12reader.h:533
static int readQuickRunConfig(const std::string &filename)
Definition clas12reader.cpp:215
int getNParticles() const noexcept
Get the number of region_particles.
Definition clas12reader.h:261
static int tryTaggRunConfig(const std::string &filename, int tag)
Definition clas12reader.cpp:226
void useFTBased()
use FT-based PID, rather than the default
Definition clas12reader.h:335
virtual ~clas12reader()=default
void applyQA(const string &pass)
Definition clas12reader.h:527
void addARegionCDet()
Definition clas12reader.h:110
std::vector< region_part_ptr > getByID(int id, bool const &applyBankFilter=false) const
Get the list of region_particles, filtered by PDG.
Definition clas12reader.cpp:658
void connectDataBases(clas12databases *db)
Enable QA skimming.
Definition clas12reader.cpp:701
bool isOpen()
Definition clas12reader.h:395
double getCurrApproxCharge()
Definition clas12reader.h:367
std::vector< hipo::bank * > getAllBanksPtrs()
Definition clas12reader.h:99
int getRunNumber() const
Definition clas12reader.h:364
double getRunBeamCharge()
Definition clas12reader.h:358
void initReader()
Definition clas12reader.cpp:62
class covmatrix & getRECCovMat() const
get the REC::CovMat bank
Definition clas12reader.h:160
void addAtLeastPid(short pid, short n)
Definition clas12reader.h:321
class utracker & getRECUTrack() const
get the REC::UTrack bank
Definition clas12reader.h:162
vertdoca_ptr vertdoca() const
get a pointer to the REC::VertDoca bank
Definition clas12reader.h:190
class ftbparticle & getRECFTParticle() const
get the REC::FTParticle bank
Definition clas12reader.h:138
class traj & getRECTraj() const
get the REC::Traj bank
Definition clas12reader.h:164
Definition covmatrix.h:27
Definition forwardtagger.h:23
Definition ftbparticle.h:23
Definition mcparticle.h:23
Definition qadb_reader.h:16
double getPreviousCharge() const
Definition qadb_reader.h:96
void setPreviousCharge(double val)
Definition qadb_reader.h:97
double getAccCharge()
Definition qadb_reader.h:89
Definition rcdb_reader.h:25
Definition region_band.h:23
Definition region_cdet.h:24
Definition region_fdet.h:23
Definition region_ft.h:23
Definition scaler_reader.h:12
double getBeamCharge() const noexcept
Definition scaler_reader.h:17
Definition scintillator.h:23
Definition calextras.cpp:10
std::unique_ptr< clas12::forwardtagger > ft_uptr
Definition forwardtagger.h:116
clas12::scaler_reader * scalerreader_ptr
Definition scaler_reader.h:48
std::unique_ptr< clas12::rich > rich_uptr
Definition rich.h:256
std::unique_ptr< clas12::vertdoca > vertdoca_uptr
Definition vertdoca.h:104
std::unique_ptr< clas12::helonline > helonline_uptr
Definition helonline.h:57
std::unique_ptr< clas12::ftbevent > ftbevent_uptr
Definition ftbevent.h:56
clas12::helonline * helonline_ptr
Definition helonline.h:56
std::unique_ptr< clas12::scaler_reader > scalerreader_uptr
Definition scaler_reader.h:49
std::unique_ptr< clas12::cherenkov > cher_uptr
Definition cherenkov.h:100
std::unique_ptr< clas12::calorimeter > cal_uptr
Definition calorimeter.h:226
clas12::vertdoca * vertdoca_ptr
Definition vertdoca.h:103
std::unique_ptr< clas12::region_ft > region_ft_uptr
Definition region_ft.h:67
std::unique_ptr< clas12::vtp > vtp_uptr
Definition vtp.h:56
std::unique_ptr< clas12::event > event_uptr
Definition event.h:75
std::unique_ptr< clas12::particle > par_uptr
Definition particle.h:119
clas12::mcparticle * mcpar_ptr
Definition mcparticle.h:144
std::unique_ptr< clas12::region_cdet > region_cdet_uptr
Definition region_cdet.h:103
clas12::vtp * vtp_ptr
Definition vtp.h:55
std::unique_ptr< clas12::mcparticle > mcpar_uptr
Definition mcparticle.h:145
std::unique_ptr< clas12::scintillator > scint_uptr
Definition scintillator.h:134
std::unique_ptr< clas12::traj > traj_uptr
Definition traj.h:94
std::unique_ptr< clas12::helflip > helflip_uptr
Definition helflip.h:72
clas12::mcevent * mcevt_ptr
Definition mcevent.h:78
clas12::event * event_ptr
Definition event.h:74
std::unique_ptr< clas12::covmatrix > covmat_uptr
Definition covmatrix.h:88
clas12::runconfig * runconfig_ptr
Definition runconfig.h:71
Cont container_filter(const Cont &container, Pred predicate)
Definition clas12reader.h:587
std::unique_ptr< clas12::tracker > trck_uptr
Definition tracker.h:74
std::unique_ptr< clas12::runconfig > runconfig_uptr
Definition runconfig.h:72
std::unique_ptr< clas12::mcevent > mcevt_uptr
Definition mcevent.h:79
std::unique_ptr< clas12::utracker > utrck_uptr
Definition utracker.h:104
std::unique_ptr< clas12::region_band > region_band_uptr
Definition region_band.h:75
std::unique_ptr< clas12::region_fdet > region_fdet_uptr
Definition region_fdet.h:126
clas12::helflip * helflip_ptr
Definition helflip.h:71
clas12::ftbevent * ftbevent_ptr
Definition ftbevent.h:55
std::unique_ptr< clas12::ftbparticle > ftbpar_uptr
Definition ftbparticle.h:88