evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StructureFinder.h
Go to the documentation of this file.
1 //
2 // Copyright 2020, Jefferson Science Associates, LLC.
3 // Subject to the terms in the LICENSE file found in the top-level directory.
4 //
5 // EPSCI Group
6 // Thomas Jefferson National Accelerator Facility
7 // 12000, Jefferson Ave, Newport News, VA 23606
8 // (757)-269-7100
9 
10 
11 #ifndef EVIO_6_0_STRUCTUREFINDER_H
12 #define EVIO_6_0_STRUCTUREFINDER_H
13 
14 
15 #include "vector"
16 #include "memory"
17 
18 
19 #include "IEvioFilter.h"
20 #include "IEvioListener.h"
21 #include "EvioXMLDictionary.h"
22 #include "BaseStructure.h"
23 #include "StructureType.h"
24 
25 
26 namespace evio {
27 
28 
40 
41  public:
42 
49  static void getMatchingStructures(std::shared_ptr<BaseStructure> structure,
50  std::shared_ptr<IEvioFilter> filter,
51  std::vector<std::shared_ptr<BaseStructure>> & vec) {
52  if (structure == nullptr) {
53  std::cout << "getMatchingStructures: returning null list" << std::endl;
54  vec.clear();
55  return;
56  }
57  return structure->getMatchingStructures(filter, vec);
58  }
59 
68  static void getMatchingBanks(std::shared_ptr<BaseStructure> structure,
69  uint16_t tag, uint8_t num,
70  std::vector<std::shared_ptr<BaseStructure>> & vec) {
71 
72  class myFilter : public IEvioFilter {
73  uint16_t tag; uint8_t num;
74  public:
75  myFilter(uint16_t tag, uint8_t num) : tag(tag), num(num) {}
76  bool accept(StructureType const & type, std::shared_ptr<BaseStructure> struc) override {
77  return ((type == StructureType::STRUCT_BANK) &&
78  (tag == struc->getHeader()->getTag()) &&
79  (num == struc->getHeader()->getNumber()));
80  }
81  };
82 
83  auto filter = std::make_shared<myFilter>(tag, num);
84  return getMatchingStructures(structure, filter, vec);
85  }
86 
93  static void getMatchingStructures(std::shared_ptr<BaseStructure> structure, uint16_t tag,
94  std::vector<std::shared_ptr<BaseStructure>> & vec) {
95 
96  class myFilter : public IEvioFilter {
97  uint16_t tag;
98  public:
99  myFilter(uint16_t tag) : tag(tag) {}
100  bool accept(StructureType const & structureType, std::shared_ptr<BaseStructure> struc) override {
101  return (tag == struc->getHeader()->getTag());
102  }
103  };
104 
105  auto filter = std::make_shared<myFilter>(tag);
106  return getMatchingStructures(structure, filter, vec);
107  }
108 
116  static void getMatchingNonBanks(std::shared_ptr<BaseStructure> structure, uint16_t tag,
117  std::vector<std::shared_ptr<BaseStructure>> & vec) {
118 
119  class myFilter : public IEvioFilter {
120  uint16_t tag;
121  public:
122  myFilter(uint16_t tag) : tag(tag) {}
123  bool accept(StructureType const & type, std::shared_ptr<BaseStructure> struc) override {
124  return ((type != StructureType::STRUCT_BANK) &&
125  (tag == struc->getHeader()->getTag()));
126  }
127  };
128 
129  auto filter = std::make_shared<myFilter>(tag);
130  return getMatchingStructures(structure, filter, vec);
131  }
132 
133 
143  static void getMatchingStructures(std::shared_ptr<BaseStructure> structure,
144  std::string name,
145  EvioXMLDictionary & dictionary,
146  std::vector<std::shared_ptr<BaseStructure>> & vec) {
147 
148  // This IEvioFilter selects structures that match the given dictionary name
149  class myFilter : public IEvioFilter {
150  std::string name;
151  EvioXMLDictionary & dict;
152  public:
153  myFilter(std::string const & name, EvioXMLDictionary & dict) :
154  name(name), dict(dict) {}
155 
156  bool accept(StructureType const & structureType,
157  std::shared_ptr<BaseStructure> struc) override {
158  // If this structure matches the name, add it to the list
159  return (name == dict.getName(struc));
160  }
161  };
162 
163  auto filter = std::make_shared<myFilter>(name, dictionary);
164  return getMatchingStructures(structure, filter, vec);
165  }
166 
167 
177  static void getMatchingParent(std::shared_ptr<BaseStructure> structure,
178  std::string parentName,
179  EvioXMLDictionary & dictionary,
180  std::vector<std::shared_ptr<BaseStructure>> & vec) {
181 
182  // This IEvioFilter selects structures whose parent has the given dictionary name
183  class myFilter : public IEvioFilter {
184  std::string name;
185  EvioXMLDictionary & dict;
186  public:
187  myFilter(std::string const & name, EvioXMLDictionary & dict) :
188  name(name), dict(dict) {}
189 
190  bool accept(StructureType const & structureType,
191  std::shared_ptr<BaseStructure> struc) override {
192 
193  auto parent = struc->getParent();
194  if (parent == nullptr) {
195  return false;
196  }
197 
198  // If this parent matches the name, add it to the list
199  return (name == dict.getName(parent));
200  }
201  };
202 
203  auto filter = std::make_shared<myFilter>(parentName, dictionary);
204  return getMatchingStructures(structure, filter, vec);
205  }
206 
207 
217  static void getMatchingChild(std::shared_ptr<BaseStructure> structure,
218  std::string childName,
219  EvioXMLDictionary & dictionary,
220  std::vector<std::shared_ptr<BaseStructure>> & vec) {
221 
222  // This IEvioFilter selects structures who have a child with the given dictionary name
223  class myFilter : public IEvioFilter {
224  std::string name;
225  EvioXMLDictionary & dict;
226  public:
227  myFilter(std::string const & name, EvioXMLDictionary & dict) :
228  name(name), dict(dict) {}
229 
230  bool accept(StructureType const & structureType,
231  std::shared_ptr<BaseStructure> struc) override {
232 
233  auto children = struc->getChildren();
234  if (children.empty()) {
235  return false;
236  }
237 
238  for (auto child : children) {
239  if (name == dict.getName(child)) {
240  // If this child matches the name, add it to the list
241  return true;
242  }
243  }
244 
245  return false;
246  }
247  };
248 
249  auto filter = std::make_shared<myFilter>(childName, dictionary);
250  return getMatchingStructures(structure, filter, vec);
251  }
252 
253  };
254 
255 
256 }
257 
258 #endif //EVIO_6_0_STRUCTUREFINDER_H
This is a set of convenient static methods used to find lists of structures within an event...
Definition: StructureFinder.h:39
static void getMatchingStructures(std::shared_ptr< BaseStructure > structure, std::string name, EvioXMLDictionary &dictionary, std::vector< std::shared_ptr< BaseStructure >> &vec)
Collect all structures in an event that match the given dictionary name.
Definition: StructureFinder.h:143
static const StructureType STRUCT_BANK
Bank.
Definition: StructureType.h:41
static void getMatchingBanks(std::shared_ptr< BaseStructure > structure, uint16_t tag, uint8_t num, std::vector< std::shared_ptr< BaseStructure >> &vec)
Collect all the banks in an event that match a provided tag and number in their header.
Definition: StructureFinder.h:68
static void getMatchingNonBanks(std::shared_ptr< BaseStructure > structure, uint16_t tag, std::vector< std::shared_ptr< BaseStructure >> &vec)
Collect all the non-banks (i.e., Segments and TagSegments) in an event that match a provided tag in t...
Definition: StructureFinder.h:116
std::string getName(std::shared_ptr< BaseStructure > &structure)
Returns the name of a given evio structure.
Definition: EvioXMLDictionary.cpp:849
This interface allows applications to create filters so that they only receive certain structures whe...
Definition: IEvioFilter.h:40
static void getMatchingChild(std::shared_ptr< BaseStructure > structure, std::string childName, EvioXMLDictionary &dictionary, std::vector< std::shared_ptr< BaseStructure >> &vec)
Collect all structures in an event who has a child with the given dictionary name.
Definition: StructureFinder.h:217
static void getMatchingStructures(std::shared_ptr< BaseStructure > structure, std::shared_ptr< IEvioFilter > filter, std::vector< std::shared_ptr< BaseStructure >> &vec)
Collect all the structures in an event that pass a filter.
Definition: StructureFinder.h:49
Numerical values associated with evio structure types.
Definition: StructureType.h:34
This was developed to read the xml dictionary that Maurizio uses for GEMC.
Definition: EvioXMLDictionary.h:55
static void getMatchingParent(std::shared_ptr< BaseStructure > structure, std::string parentName, EvioXMLDictionary &dictionary, std::vector< std::shared_ptr< BaseStructure >> &vec)
Collect all structures in an event whose parent has the given dictionary name.
Definition: StructureFinder.h:177
static void getMatchingStructures(std::shared_ptr< BaseStructure > structure, uint16_t tag, std::vector< std::shared_ptr< BaseStructure >> &vec)
Collect all the structures in an event that match a provided tag in their header. ...
Definition: StructureFinder.h:93