Simon Spannagel committed Aug 23, 2019 1 2 3 4 5 6 7 /** * @file * @brief Implementation of ROOT data file reader module * @copyright Copyright (c) 2017-2019 CERN and the Corryvreckan authors. * This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md". * In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an * Intergovernmental Organization or submit itself to any jurisdiction.  Simon Spannagel committed Aug 27, 2019 8  * @remarks The implementation of this module is based on the ROOTObjectReader module of the Allpix Squared project  Simon Spannagel committed Aug 23, 2019 9 10  */  Daniel Hynds committed Jan 29, 2016 11 12 #include "FileReader.h"  Simon Spannagel committed Aug 23, 2019 13 14 15 #include #include #include  16   Simon Spannagel committed Aug 23, 2019 17 18 19 20 21 #include #include #include #include #include  Daniel Hynds committed Jan 29, 2016 22   Simon Spannagel committed Aug 23, 2019 23 24 25 #include "core/utils/file.h" #include "core/utils/log.h" #include "core/utils/type.h"  Simon Spannagel committed Oct 06, 2017 26   Simon Spannagel committed Aug 23, 2019 27 28 #include "objects/Object.hpp" #include "objects/objects.h"  Simon Spannagel committed Oct 06, 2017 29   Simon Spannagel committed Aug 23, 2019 30 using namespace corryvreckan;  Simon Spannagel committed Oct 06, 2017 31   Simon Spannagel committed Aug 23, 2019 32 33 FileReader::FileReader(Configuration config, std::vector> detectors) : Module(std::move(config), std::move(detectors)) {}  Daniel Hynds committed Jan 29, 2016 34   Simon Spannagel committed Aug 23, 2019 35 36 37 38 39 40 /** * @note Objects cannot be stored in smart pointers due to internal ROOT logic */ FileReader::~FileReader() { for(auto object_inf : object_info_array_) { delete object_inf.objects;  Simon Spannagel committed Dec 06, 2017 41  }  Simon Spannagel committed Aug 23, 2019 42 }  Simon Spannagel committed Oct 06, 2017 43   Simon Spannagel committed Aug 23, 2019 44 45 46 47 48 /** * Adds lambda function map to convert a vector of generic objects to a templated vector of objects containing this * particular type of object from its typeid. */ template static void add_creator(FileReader::ObjectCreatorMap& map) {  Simon Spannagel committed Aug 24, 2019 49  map[typeid(T)] = [&](std::vector objects, std::string detector, std::shared_ptr clipboard) {  Simon Spannagel committed Aug 23, 2019 50  std::vector data;  Simon Spannagel committed Aug 23, 2019 51 52  // Copy the objects to data vector for(auto& object : objects) {  Simon Spannagel committed Aug 25, 2019 53  data.push_back(new T(*static_cast(object)));  Simon Spannagel committed Aug 23, 2019 54  }  Simon Spannagel committed Oct 06, 2017 55   Simon Spannagel committed Aug 23, 2019 56 57 58 59  // Fix the object references (NOTE: we do this after insertion as otherwise the objects could have been relocated) for(size_t i = 0; i < objects.size(); ++i) { auto& prev_obj = *objects[i]; auto& new_obj = data[i];  Daniel Hynds committed Feb 22, 2016 60   Simon Spannagel committed Aug 23, 2019 61 62  // Only update the reference for objects that have been referenced before if(prev_obj.TestBit(kIsReferenced)) {  Simon Spannagel committed Aug 23, 2019 63  auto pid = TProcessID::GetProcessWithUID(new_obj);  Simon Spannagel committed Aug 23, 2019 64 65  if(pid->GetObjectWithID(prev_obj.GetUniqueID()) != &prev_obj) { LOG(ERROR) << "Duplicate object IDs, cannot correctly resolve previous history!";  Simon Spannagel committed Oct 16, 2018 66  }  Simon Spannagel committed Aug 23, 2019 67  prev_obj.ResetBit(kIsReferenced);  Simon Spannagel committed Aug 23, 2019 68 69  new_obj->SetBit(kIsReferenced); pid->PutObjectWithID(new_obj);  Simon Spannagel committed Oct 09, 2017 70 71  } }  Simon Spannagel committed Oct 06, 2017 72   Simon Spannagel committed Aug 24, 2019 73 74 75 76 77 78  // Store the ojects on the clipboard: if(detector.empty()) { clipboard->put(std::make_shared>(std::move(data))); } else { clipboard->put(std::make_shared>(std::move(data)), detector); }  Simon Spannagel committed Aug 23, 2019 79  };  Daniel Hynds committed Jan 29, 2016 80 81 }  Simon Spannagel committed Aug 23, 2019 82 83 84 85 86 87 88 89 90 /** * Uses SFINAE trick to call the add_creator function for all template arguments of a container class. Used to add creators * for every object in a tuple of objects. */ template