00001 #ifndef DATASET_H_ 00002 #define DATASET_H_ 00003 00004 #include <cstdint> 00005 #include <filesystem> 00006 #include <string> 00007 #include <string_view> 00008 #include <vector> 00009 00010 #include <yaml-cpp/yaml.h> 00011 00012 #include <TChain.h> 00013 #include <TTreeReader.h> 00014 00015 #include <Options.h> 00016 00017 00034 class DatasetInfo { 00035 public: 00037 DatasetInfo(std::filesystem::path const &path, Options const &options); 00038 00040 std::filesystem::path const &DefinitionFile() const { 00041 return definitionFile_; 00042 } 00043 00049 double CrossSection() const { 00050 return crossSection_; 00051 } 00052 00058 std::vector<std::string> const &Files() const { 00059 return files_; 00060 } 00061 00063 bool IsSimulation() const { 00064 return isSimulation_; 00065 }; 00066 00072 double MeanWeight() const { 00073 return meanWeight_; 00074 } 00075 00077 std::string const &Name() const { 00078 return name_; 00079 } 00080 00086 int64_t NumEventsTotal() const { 00087 return numEventsTotal_; 00088 } 00089 00095 YAML::Node const &Parameters() const { 00096 return parameters_; 00097 } 00098 00099 private: 00101 YAML::Node const FindStem(std::string_view name) const; 00102 00104 YAML::Node const GetNode(YAML::Node const root, std::string const &key) const; 00105 00111 void ReadYaml(std::filesystem::path const &path); 00112 00119 void SpliceYaml(YAML::Node info) const; 00120 00126 std::vector<std::filesystem::path> stemsFiles_; 00127 00133 std::filesystem::path definitionFile_; 00134 00141 std::vector<std::string> files_; 00142 00148 YAML::Node parameters_; 00149 00151 std::string name_; 00152 00154 bool isSimulation_; 00155 00161 double crossSection_; 00162 00168 int64_t numEventsTotal_; 00169 00175 double meanWeight_; 00176 }; 00177 00178 00192 class Dataset { 00193 public: 00204 Dataset(DatasetInfo info, int skipFiles = 0, int maxFiles = -1); 00205 00207 DatasetInfo const &Info() const { 00208 return info_; 00209 } 00210 00217 bool NextEntry() { 00218 return reader_.Next(); 00219 } 00220 00222 int64_t NumEntries() { 00223 return reader_.GetEntries(true); 00224 } 00225 00227 TTreeReader &Reader() { 00228 return reader_; 00229 } 00230 00232 std::vector<std::string> const &SelectedFiles() const { 00233 return selectedFiles_; 00234 } 00235 00237 void SetEntry(int64_t index) { 00238 reader_.SetEntry(index); 00239 } 00240 00241 private: 00243 DatasetInfo info_; 00244 00246 std::vector<std::string> selectedFiles_; 00247 00249 TChain chain_; 00250 00252 TTreeReader reader_; 00253 }; 00254 00255 #endif // DATASET_H_ 00256