Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
gallery::Event Class Reference

#include <Event.h>

Public Types

template<typename T >
using HandleT = Handle< T >
 

Public Member Functions

 Event (std::vector< std::string > const &fileNames, bool useTTreeCache=true, unsigned int eventsToLearnUsedBranches=7)
 
template<typename PROD >
gallery::ValidHandle< PROD > getValidHandle (art::InputTag const &) const
 
template<typename PROD >
bool getByLabel (art::InputTag const &, Handle< PROD > &result) const
 
template<typename PROD >
void getManyByType (std::vector< Handle< PROD >> &result) const
 
template<typename PROD >
std::vector< art::InputTaggetInputTags () const
 
template<typename PROD >
std::vector< art::ProductToken< PROD > > getProductTokens () const
 
art::EventAuxiliary const & eventAuxiliary () const
 
art::History const & history () const
 
art::ProcessHistoryID const & processHistoryID () const
 
art::ProcessHistory const & processHistory () const
 
art::BranchDescription const & getProductDescription (art::ProductID) const
 
long long numberOfEventsInFile () const
 
long long eventEntry () const
 
long long fileEntry () const
 
void goToEntry (long long entry)
 
bool isValid () const
 
bool atEnd () const
 
void toBegin ()
 
void first ()
 
Eventoperator++ ()
 
void next ()
 
Eventoperator-- ()
 
void previous ()
 
TFile * getTFile () const
 
TTree * getTTree () const
 

Private Member Functions

ProductWithID getByLabel (std::type_info const &typeInfoOfWrapper, art::InputTag const &inputTag) const
 
std::vector< ProductWithIDgetManyByType (std::type_info const &typeInfoOfWrapper) const
 
void throwProductNotFoundException (std::type_info const &typeInfo, art::InputTag const &tag) const
 
std::shared_ptr< art::Exception const > makeProductNotFoundException (std::type_info const &typeInfo, art::InputTag const &tag) const
 
void checkForEnd () const
 
void updateAfterEventChange (long long oldFileEntry)
 

Private Attributes

bool randomAccessOK_
 
std::unique_ptr< EventNavigatoreventNavigator_
 
std::unique_ptr< DataGetterHelperdataGetterHelper_
 
bool useTTreeCache_
 
unsigned int eventsToLearnUsedBranches_
 
unsigned int eventsProcessed_ {}
 

Detailed Description

Definition at line 42 of file Event.h.

Member Typedef Documentation

template<typename T >
using gallery::Event::HandleT = Handle<T>

Definition at line 124 of file Event.h.

Constructor & Destructor Documentation

gallery::Event::Event ( std::vector< std::string > const &  fileNames,
bool  useTTreeCache = true,
unsigned int  eventsToLearnUsedBranches = 7 
)
explicit

Definition at line 12 of file Event.cc.

15  : randomAccessOK_{fileNames.size() == 1}
16  , eventNavigator_{std::make_unique<EventNavigator>(fileNames)}
17  , dataGetterHelper_{std::make_unique<DataGetterHelper>(
18  eventNavigator_.get(),
19  std::make_shared<EventHistoryGetter>(eventNavigator_.get()))}
20  , useTTreeCache_{useTTreeCache}
21  , eventsToLearnUsedBranches_{eventsToLearnUsedBranches}
22  {
23 
26  if (!atEnd()) {
27  bool constexpr initializeTheCache{false};
28  dataGetterHelper_->updateFile(eventNavigator_->getTFile(),
29  eventNavigator_->getTTree(),
30  initializeTheCache);
31  }
32  }
std::unique_ptr< DataGetterHelper > dataGetterHelper_
Definition: Event.h:146
bool atEnd() const
Definition: Event.cc:101
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
bool useTTreeCache_
Definition: Event.h:148
unsigned int eventsToLearnUsedBranches_
Definition: Event.h:149
bool randomAccessOK_
Definition: Event.h:144

Member Function Documentation

bool gallery::Event::atEnd ( ) const

Definition at line 101 of file Event.cc.

102  {
103  return eventNavigator_->atEnd();
104  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
void gallery::Event::checkForEnd ( ) const
private

Definition at line 220 of file Event.cc.

221  {
222  if (atEnd()) {
224  << "You have requested data past the last event\n";
225  }
226  }
bool atEnd() const
Definition: Event.cc:101
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
art::EventAuxiliary const & gallery::Event::eventAuxiliary ( ) const

Definition at line 35 of file Event.cc.

36  {
37  return eventNavigator_->eventAuxiliary();
38  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
long long gallery::Event::eventEntry ( ) const

Definition at line 71 of file Event.cc.

72  {
73  return eventNavigator_->eventEntry();
74  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
long long gallery::Event::fileEntry ( ) const

Definition at line 77 of file Event.cc.

78  {
79  return eventNavigator_->fileEntry();
80  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
void gallery::Event::first ( )
inline

Definition at line 237 of file Event.h.

238 {
239  return toBegin();
240 }
void toBegin()
Definition: Event.cc:107
template<typename PROD >
bool gallery::Event::getByLabel ( art::InputTag const &  inputTag,
Handle< PROD > &  result 
) const
inline

Definition at line 174 of file Event.h.

176 {
177  checkForEnd();
178  if (inputTag.empty()) {
179  result = Handle<PROD>{makeProductNotFoundException(typeid(PROD), inputTag)};
180  return false;
181  }
182 
183  std::type_info const& typeInfoOfWrapper{typeid(art::Wrapper<PROD>)};
184  auto res = getByLabel(typeInfoOfWrapper, inputTag);
185  auto edProduct = res.first;
186 
187  auto ptrToWrapper = dynamic_cast<art::Wrapper<PROD> const*>(edProduct);
188 
189  if (ptrToWrapper == nullptr) {
190  result = Handle<PROD>{makeProductNotFoundException(typeid(PROD), inputTag)};
191  return false;
192  }
193  auto product = ptrToWrapper->product();
194  result = Handle<PROD>{product, res.second};
195  return true;
196 }
static QCString result
std::shared_ptr< art::Exception const > makeProductNotFoundException(std::type_info const &typeInfo, art::InputTag const &tag) const
Definition: Event.cc:206
bool getByLabel(art::InputTag const &, Handle< PROD > &result) const
Definition: Event.h:174
void checkForEnd() const
Definition: Event.cc:220
ProductWithID gallery::Event::getByLabel ( std::type_info const &  typeInfoOfWrapper,
art::InputTag const &  inputTag 
) const
private

Definition at line 185 of file Event.cc.

187  {
188  return dataGetterHelper_->getByLabel(typeInfoOfWrapper, inputTag);
189  }
std::unique_ptr< DataGetterHelper > dataGetterHelper_
Definition: Event.h:146
template<typename PROD >
std::vector< art::InputTag > gallery::Event::getInputTags ( ) const
inline

Definition at line 218 of file Event.h.

219 {
220  std::type_info const& typeInfoOfWrapper{typeid(art::Wrapper<PROD>)};
221  return dataGetterHelper_->getInputTags(typeInfoOfWrapper);
222 }
std::unique_ptr< DataGetterHelper > dataGetterHelper_
Definition: Event.h:146
template<typename PROD >
void gallery::Event::getManyByType ( std::vector< Handle< PROD >> &  result) const
inline

Definition at line 200 of file Event.h.

201 {
202  std::type_info const& typeInfoOfWrapper{typeid(art::Wrapper<PROD>)};
203  auto products = getManyByType(typeInfoOfWrapper);
204  std::vector<Handle<PROD>> tmp;
205  cet::transform_all(products, back_inserter(tmp), [](auto const& pr) {
206  auto product = pr.first;
207  auto wrapped_product = dynamic_cast<art::Wrapper<PROD> const*>(product);
208  assert(wrapped_product != nullptr);
209  auto user_product = wrapped_product->product();
210  assert(user_product != nullptr);
211  return Handle<PROD>{user_product, pr.second};
212  });
213  swap(tmp, result);
214 }
void swap(Handle< T > &a, Handle< T > &b)
string tmp
Definition: languages.py:63
auto transform_all(Container &, OutputIt, UnaryOp)
void getManyByType(std::vector< Handle< PROD >> &result) const
Definition: Event.h:200
std::vector< ProductWithID > gallery::Event::getManyByType ( std::type_info const &  typeInfoOfWrapper) const
private

Definition at line 192 of file Event.cc.

193  {
194  return dataGetterHelper_->getManyByType(typeInfoOfWrapper);
195  }
std::unique_ptr< DataGetterHelper > dataGetterHelper_
Definition: Event.h:146
art::BranchDescription const & gallery::Event::getProductDescription ( art::ProductID  pid) const

Definition at line 59 of file Event.cc.

60  {
61  return dataGetterHelper_->getProductDescription(pid);
62  }
std::unique_ptr< DataGetterHelper > dataGetterHelper_
Definition: Event.h:146
template<typename PROD >
std::vector< art::ProductToken< PROD > > gallery::Event::getProductTokens ( ) const
inline

Definition at line 226 of file Event.h.

227 {
228  std::vector<art::ProductToken<PROD>> result;
229  auto const tags = getInputTags<PROD>();
230  cet::transform_all(tags, back_inserter(result), [](auto const& tag) {
232  });
233  return result;
234 }
static QCString result
auto transform_all(Container &, OutputIt, UnaryOp)
TFile * gallery::Event::getTFile ( ) const

Definition at line 173 of file Event.cc.

174  {
175  return eventNavigator_->getTFile();
176  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
TTree * gallery::Event::getTTree ( ) const

Definition at line 179 of file Event.cc.

180  {
181  return eventNavigator_->getTTree();
182  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
template<typename PROD >
gallery::ValidHandle< PROD > gallery::Event::getValidHandle ( art::InputTag const &  inputTag) const
inline

Definition at line 156 of file Event.h.

157 {
158  checkForEnd();
159  std::type_info const& typeInfoOfWrapper{typeid(art::Wrapper<PROD>)};
160  auto res = getByLabel(typeInfoOfWrapper, inputTag);
161  auto edProduct = res.first;
162 
163  auto ptrToWrapper = dynamic_cast<art::Wrapper<PROD> const*>(edProduct);
164  if (ptrToWrapper == nullptr) {
165  throwProductNotFoundException(typeid(PROD), inputTag);
166  }
167 
168  auto product = ptrToWrapper->product();
169  return ValidHandle<PROD>{product, res.second};
170 }
bool getByLabel(art::InputTag const &, Handle< PROD > &result) const
Definition: Event.h:174
void throwProductNotFoundException(std::type_info const &typeInfo, art::InputTag const &tag) const
Definition: Event.cc:198
void checkForEnd() const
Definition: Event.cc:220
void gallery::Event::goToEntry ( long long  entry)

Definition at line 83 of file Event.cc.

84  {
85  if (!randomAccessOK_)
87  if (entry < 0)
89  if (entry >= numberOfEventsInFile())
91  eventNavigator_->goToEntry(entry);
92  }
QList< Entry > entry
void throwIllegalRandomAccess()
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
long long numberOfEventsInFile() const
Definition: Event.cc:65
bool randomAccessOK_
Definition: Event.h:144
art::History const & gallery::Event::history ( ) const

Definition at line 41 of file Event.cc.

42  {
43  return eventNavigator_->history();
44  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
bool gallery::Event::isValid ( ) const

Definition at line 95 of file Event.cc.

96  {
97  return eventNavigator_->isValid();
98  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
std::shared_ptr< art::Exception const > gallery::Event::makeProductNotFoundException ( std::type_info const &  typeInfo,
art::InputTag const &  tag 
) const
private

Definition at line 206 of file Event.cc.

208  {
209  auto e = std::make_shared<art::Exception>(art::errors::ProductNotFound);
210  *e << "Failed to find product for \n type = '"
211  << art::TypeID{typeInfo}.className() << "'\n module = '" << tag.label()
212  << "'\n productInstance = '"
213  << ((!tag.instance().empty()) ? tag.instance().c_str() : "")
214  << "'\n process='"
215  << ((!tag.process().empty()) ? tag.process().c_str() : "") << "'\n";
216  return e;
217  }
const double e
std::string className() const
Definition: TypeID.cc:48
void gallery::Event::next ( )

Definition at line 161 of file Event.cc.

162  {
163  operator++();
164  }
Event & operator++()
Definition: Event.cc:119
long long gallery::Event::numberOfEventsInFile ( ) const

Definition at line 65 of file Event.cc.

66  {
67  return eventNavigator_->entriesInCurrentFile();
68  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
Event & gallery::Event::operator++ ( )

Definition at line 119 of file Event.cc.

120  {
121  auto const oldFileEntry = fileEntry();
122  eventNavigator_->next();
123  updateAfterEventChange(oldFileEntry);
124  return *this;
125  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
long long fileEntry() const
Definition: Event.cc:77
void updateAfterEventChange(long long oldFileEntry)
Definition: Event.cc:141
Event & gallery::Event::operator-- ( )

Definition at line 128 of file Event.cc.

129  {
130  if (!randomAccessOK_)
132  if (atEnd())
134  auto const oldFileEntry = fileEntry();
135  eventNavigator_->previous();
136  updateAfterEventChange(oldFileEntry);
137  return *this;
138  }
void throwIllegalRandomAccess()
void throwIllegalDecrement()
bool atEnd() const
Definition: Event.cc:101
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
long long fileEntry() const
Definition: Event.cc:77
void updateAfterEventChange(long long oldFileEntry)
Definition: Event.cc:141
bool randomAccessOK_
Definition: Event.h:144
void gallery::Event::previous ( )

Definition at line 167 of file Event.cc.

168  {
169  operator--();
170  }
Event & operator--()
Definition: Event.cc:128
art::ProcessHistory const & gallery::Event::processHistory ( ) const

Definition at line 53 of file Event.cc.

54  {
55  return eventNavigator_->processHistory();
56  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
art::ProcessHistoryID const & gallery::Event::processHistoryID ( ) const

Definition at line 47 of file Event.cc.

48  {
49  return eventNavigator_->processHistoryID();
50  }
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
void gallery::Event::throwProductNotFoundException ( std::type_info const &  typeInfo,
art::InputTag const &  tag 
) const
private

Definition at line 198 of file Event.cc.

200  {
201  auto e = makeProductNotFoundException(typeInfo, tag);
202  throw *e;
203  }
const double e
std::shared_ptr< art::Exception const > makeProductNotFoundException(std::type_info const &typeInfo, art::InputTag const &tag) const
Definition: Event.cc:206
void gallery::Event::toBegin ( )

Definition at line 107 of file Event.cc.

108  {
109  long long const oldEventEntry = eventEntry();
110  long long const oldFileEntry = fileEntry();
111  eventNavigator_->toBegin();
112  if (oldEventEntry == eventEntry() && oldFileEntry == fileEntry()) {
113  return;
114  }
115  updateAfterEventChange(oldFileEntry);
116  }
long long eventEntry() const
Definition: Event.cc:71
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
long long fileEntry() const
Definition: Event.cc:77
void updateAfterEventChange(long long oldFileEntry)
Definition: Event.cc:141
void gallery::Event::updateAfterEventChange ( long long  oldFileEntry)
private

Definition at line 141 of file Event.cc.

142  {
144  if (atEnd())
145  return;
146  if (oldFileEntry != fileEntry()) {
147  bool initializeTheCache =
149  dataGetterHelper_->updateFile(eventNavigator_->getTFile(),
150  eventNavigator_->getTTree(),
151  initializeTheCache);
152  } else {
153  dataGetterHelper_->updateEvent();
154  if (useTTreeCache_ && eventsProcessed_ == eventsToLearnUsedBranches_) {
155  dataGetterHelper_->initializeTTreeCache();
156  }
157  }
158  }
std::unique_ptr< DataGetterHelper > dataGetterHelper_
Definition: Event.h:146
bool atEnd() const
Definition: Event.cc:101
std::unique_ptr< EventNavigator > eventNavigator_
Definition: Event.h:145
long long fileEntry() const
Definition: Event.cc:77
unsigned int eventsProcessed_
Definition: Event.h:150
bool useTTreeCache_
Definition: Event.h:148
unsigned int eventsToLearnUsedBranches_
Definition: Event.h:149

Member Data Documentation

std::unique_ptr<DataGetterHelper> gallery::Event::dataGetterHelper_
private

Definition at line 146 of file Event.h.

std::unique_ptr<EventNavigator> gallery::Event::eventNavigator_
private

Definition at line 145 of file Event.h.

unsigned int gallery::Event::eventsProcessed_ {}
private

Definition at line 150 of file Event.h.

unsigned int gallery::Event::eventsToLearnUsedBranches_
private

Definition at line 149 of file Event.h.

bool gallery::Event::randomAccessOK_
private

Definition at line 144 of file Event.h.

bool gallery::Event::useTTreeCache_
private

Definition at line 148 of file Event.h.


The documentation for this class was generated from the following files: