/** * @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. * @remarks The implementation of this module is based on the ROOTObjectReader module of the Allpix Squared project */ #include "FileReader.h" #include #include #include #include #include #include #include #include #include "core/utils/file.h" #include "core/utils/log.h" #include "core/utils/type.h" #include "objects/Object.hpp" #include "objects/objects.h" using namespace corryvreckan; FileReader::FileReader(Configuration config, std::vector> detectors) : Module(std::move(config), std::move(detectors)) {} /** * @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; } } /** * 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) { map[typeid(T)] = [&](std::vector objects, std::string detector, std::shared_ptr clipboard) { std::vector data; // Copy the objects to data vector for(auto& object : objects) { data.push_back(new T(*static_cast(object))); } // 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]; // Only update the reference for objects that have been referenced before if(prev_obj.TestBit(kIsReferenced)) { auto pid = TProcessID::GetProcessWithUID(new_obj); if(pid->GetObjectWithID(prev_obj.GetUniqueID()) != &prev_obj) { LOG(ERROR) << "Duplicate object IDs, cannot correctly resolve previous history!"; } prev_obj.ResetBit(kIsReferenced); new_obj->SetBit(kIsReferenced); pid->PutObjectWithID(new_obj); } } // 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); } }; } /** * 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