diff --git a/src/libraries/JANA/Components/JBasicStorage.h b/src/libraries/JANA/Components/JBasicDataBundle.h similarity index 89% rename from src/libraries/JANA/Components/JBasicStorage.h rename to src/libraries/JANA/Components/JBasicDataBundle.h index c0f8d4da1..fe5053bc0 100644 --- a/src/libraries/JANA/Components/JBasicStorage.h +++ b/src/libraries/JANA/Components/JBasicDataBundle.h @@ -1,7 +1,7 @@ #pragma once -#include +#include #include #include @@ -9,14 +9,14 @@ #include #endif -class JBasicStorage : public JStorage { +class JBasicDataBundle : public JDataBundle { bool m_is_persistent = false; bool m_not_object_owner = false; bool m_write_to_output = true; public: - JBasicStorage() = default; - ~JBasicStorage() override = default; + JBasicDataBundle() = default; + ~JBasicDataBundle() override = default; void SetPersistentFlag(bool persistent) { m_is_persistent = persistent; } void SetNotOwnerFlag(bool not_owner) { m_not_object_owner = not_owner; } void SetWriteToOutputFlag(bool write_to_output) { m_write_to_output = write_to_output; } @@ -29,12 +29,12 @@ class JBasicStorage : public JStorage { template -class JBasicStorageT : public JBasicStorage { +class JBasicDataBundleT : public JBasicDataBundle { private: std::vector m_data; public: - JBasicStorageT(); + JBasicDataBundleT(); void ClearData() override; size_t GetSize() const override { return m_data.size();} @@ -55,7 +55,7 @@ class JBasicStorageT : public JBasicStorage { // Template definitions template -JBasicStorageT::JBasicStorageT() { +JBasicDataBundleT::JBasicDataBundleT() { SetTypeName(JTypeInfo::demangle()); EnableGetAs(); EnableGetAs( std::is_convertible() ); // Automatically add JObject if this can be converted to it @@ -65,7 +65,7 @@ JBasicStorageT::JBasicStorageT() { } template -void JBasicStorageT::ClearData() { +void JBasicDataBundleT::ClearData() { // ClearData won't do anything if Init() hasn't been called if (GetStatus() == Status::Empty) { @@ -87,7 +87,7 @@ void JBasicStorageT::ClearData() { template template -void JBasicStorageT::EnableGetAs() { +void JBasicDataBundleT::EnableGetAs() { auto upcast_lambda = [this]() { std::vector results; diff --git a/src/libraries/JANA/Components/JStorage.h b/src/libraries/JANA/Components/JDataBundle.h similarity index 87% rename from src/libraries/JANA/Components/JStorage.h rename to src/libraries/JANA/Components/JDataBundle.h index 2d76574db..c370076c0 100644 --- a/src/libraries/JANA/Components/JStorage.h +++ b/src/libraries/JANA/Components/JDataBundle.h @@ -17,7 +17,7 @@ class JFactory; -class JStorage { +class JDataBundle { public: // Typedefs enum class Status { Empty, Created, Inserted, InsertedViaGetObjects }; @@ -25,8 +25,8 @@ class JStorage { private: // Fields Status m_status = Status::Empty; - std::string m_collection_name; - JOptional m_collection_tag; + std::string m_unique_name; + JOptional m_short_name; std::string m_type_name; JFactory* m_factory = nullptr; JOptional m_inner_type_index; @@ -37,15 +37,15 @@ class JStorage { public: // Interface - JStorage() = default; - virtual ~JStorage() = default; + JDataBundle() = default; + virtual ~JDataBundle() = default; virtual size_t GetSize() const = 0; virtual void ClearData() = 0; // Getters Status GetStatus() const { return m_status; } - std::string GetCollectionName() const { return m_collection_name; } - JOptional GetCollectionTag() const { return m_collection_tag; } + std::string GetUniqueName() const { return m_unique_name; } + JOptional GetShortName() const { return m_short_name; } std::string GetTypeName() const { return m_type_name; } JOptional GetTypeIndex() const { return m_inner_type_index; } JCallGraphRecorder::JDataOrigin GetInsertOrigin() const { return m_insert_origin; } ///< If objects were placed here by JEvent::Insert() this records whether that call was made from a source or factory. @@ -53,12 +53,12 @@ class JStorage { // Setters void SetStatus(Status s) { m_status = s;} - void SetCollectionName(std::string collection_name) { m_collection_name = collection_name; } - void SetCollectionTag(std::string collection_tag) { m_collection_tag = collection_tag; } + void SetUniqueName(std::string unique_name) { m_unique_name = unique_name; } + void SetShortName(std::string short_name) { m_short_name = short_name; } void SetTypeName(std::string type_name) { m_type_name = type_name; } void SetInsertOrigin(JCallGraphRecorder::JDataOrigin origin) { m_insert_origin = origin; } ///< Called automatically by JEvent::Insert() to records whether that call was made by a source or factory. void SetFactory(JFactory* fac) { m_factory = fac; } - + // Templates // /// Generically access the encapsulated data, performing an upcast if necessary. This is useful for extracting data from @@ -86,7 +86,7 @@ class JStorage { // 3. The size of the vtable is expected to be very small (<10 elements, most likely 2) template -std::vector JStorage::GetAs() { +std::vector JDataBundle::GetAs() { std::vector results; auto ti = std::type_index(typeid(S)); auto search = mUpcastVTable.find(ti); diff --git a/src/libraries/JANA/Components/JHasFactoryOutputs.h b/src/libraries/JANA/Components/JHasFactoryOutputs.h index b6b85f5fd..c266ea773 100644 --- a/src/libraries/JANA/Components/JHasFactoryOutputs.h +++ b/src/libraries/JANA/Components/JHasFactoryOutputs.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include class JEvent; @@ -12,11 +12,11 @@ class JHasFactoryOutputs { public: struct OutputBase { protected: - std::vector> m_collections; + std::vector> m_databundles; bool m_is_variadic = false; public: - const std::vector>& GetCollections() const { return m_collections;} - virtual void PutCollections(const JEvent& event) = 0; + const std::vector>& GetDataBundles() const { return m_databundles; } + virtual void StoreData(const JEvent& event) = 0; virtual void Reset() = 0; }; diff --git a/src/libraries/JANA/Components/JPodioStorage.h b/src/libraries/JANA/Components/JPodioDataBundle.h similarity index 90% rename from src/libraries/JANA/Components/JPodioStorage.h rename to src/libraries/JANA/Components/JPodioDataBundle.h index ae16c0a03..d27e20de7 100644 --- a/src/libraries/JANA/Components/JPodioStorage.h +++ b/src/libraries/JANA/Components/JPodioDataBundle.h @@ -3,12 +3,12 @@ #pragma once -#include +#include #include #include -class JPodioStorage : public JStorage { +class JPodioDataBundle : public JDataBundle { private: const podio::CollectionBase* m_collection = nullptr; @@ -23,7 +23,7 @@ class JPodioStorage : public JStorage { virtual void ClearData() override { m_collection = nullptr; - SetStatus(JStorage::Status::Empty); + SetStatus(JDataBundle::Status::Empty); // Podio clears the data itself when the frame is destroyed. // Until then, the collection is immutable. // diff --git a/src/libraries/JANA/Components/JPodioOutput.h b/src/libraries/JANA/Components/JPodioOutput.h index 5ccef6524..de4d6d476 100644 --- a/src/libraries/JANA/Components/JPodioOutput.h +++ b/src/libraries/JANA/Components/JPodioOutput.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include #include @@ -13,29 +13,27 @@ namespace jana::components { template class PodioOutput : public JHasFactoryOutputs::OutputBase { private: - std::unique_ptr m_data; - JPodioStorage* m_podio_storage; + std::unique_ptr m_transient_collection; + JPodioDataBundle* m_podio_databundle; public: PodioOutput(JHasFactoryOutputs* owner, std::string default_collection_name="") { owner->RegisterOutput(this); - auto storage = std::make_unique(); - storage->SetCollectionName(default_collection_name); - storage->SetTypeName(JTypeInfo::demangle()); - m_podio_storage = storage.get(); - m_collections.push_back(std::move(storage)); - m_data = std::move(std::make_unique()); + auto bundle = std::make_unique(); + bundle->SetUniqueName(default_collection_name); + bundle->SetTypeName(JTypeInfo::demangle()); + m_podio_databundle = bundle.get(); + m_databundles.push_back(std::move(bundle)); + m_transient_collection = std::move(std::make_unique()); } - std::unique_ptr& operator()() { return m_data; } + std::unique_ptr& operator()() { return m_transient_collection; } - const JStorage* GetCollection() const { return m_podio_storage; } + JPodioDataBundle* GetDataBundle() const { return m_podio_databundle; } protected: - //void CreateCollections() override { - //} - void PutCollections(const JEvent& event) override { + void StoreData(const JEvent& event) override { podio::Frame* frame; try { frame = const_cast(event.GetSingle()); @@ -49,13 +47,13 @@ class PodioOutput : public JHasFactoryOutputs::OutputBase { event.Insert(frame); } - frame->put(std::move(m_data), m_podio_storage->GetCollectionName()); - const auto* moved = &frame->template get(m_podio_storage->GetCollectionName()); - m_data = nullptr; - m_podio_storage->SetCollection(moved); + frame->put(std::move(m_transient_collection), m_podio_databundle->GetUniqueName()); + const auto* moved = &frame->template get(m_podio_databundle->GetUniqueName()); + m_transient_collection = nullptr; + m_podio_databundle->SetCollection(moved); } void Reset() override { - m_data = std::move(std::make_unique()); + m_transient_collection = std::move(std::make_unique()); } }; @@ -63,25 +61,26 @@ class PodioOutput : public JHasFactoryOutputs::OutputBase { template class VariadicPodioOutput : public JHasFactoryOutputs::OutputBase { private: - std::vector> m_data; + std::vector> m_collections; + std::vector m_databundles; public: VariadicPodioOutput(JHasFactoryOutputs* owner, std::vector default_collection_names={}) { owner->RegisterOutput(this); this->m_is_variadic = true; for (const std::string& name : default_collection_names) { - auto coll = std::make_unique(); - coll->SetCollectionName(name); + auto coll = std::make_unique(); + coll->SetUniqueName(name); coll->SetTypeName(JTypeInfo::demangle()); m_collections.push_back(std::move(coll)); } for (auto& coll_name : this->collection_names) { - m_data.push_back(std::make_unique()); + m_collections.push_back(std::make_unique()); } } - void PutCollections(const JEvent& event) override { - if (m_data.size() != this->collection_names.size()) { - throw JException("VariadicPodioOutput InsertCollection failed: Declared %d collections, but provided %d.", this->collection_names.size(), m_data.size()); + void StoreData(const JEvent& event) override { + if (m_collections.size() != this->collection_names.size()) { + throw JException("VariadicPodioOutput InsertCollection failed: Declared %d collections, but provided %d.", this->collection_names.size(), m_collections.size()); } podio::Frame* frame; @@ -98,22 +97,22 @@ class VariadicPodioOutput : public JHasFactoryOutputs::OutputBase { } size_t i = 0; - for (auto& datum : m_data) { - frame->put(std::move(std::move(datum)), m_collections[i]->GetCollectionName()); - const auto* moved = &frame->template get(m_collections[i]->GetCollectionName()); - datum = nullptr; - const auto &coll = dynamic_cast(m_collections[i]); - coll.SetCollection(moved); + for (auto& collection : m_collections) { + frame->put(std::move(std::move(collection)), m_databundles[i]->GetUniqueName()); + const auto* moved = &frame->template get(m_databundles[i]->GetUniqueName()); + collection = nullptr; + const auto &databundle = dynamic_cast(m_databundles[i]); + databundle->SetCollection(moved); i += 1; } } void Reset() override { - m_data.clear(); - for (auto& coll : this->m_collections) { + m_collections.clear(); + for (auto& coll : this->m_databundles) { coll->ClearData(); } for (auto& coll_name : this->collection_names) { - m_data.push_back(std::make_unique()); + m_collections.push_back(std::make_unique()); } } }; diff --git a/src/libraries/JANA/JEvent.h b/src/libraries/JANA/JEvent.h index 4b5593df7..f4699be3e 100644 --- a/src/libraries/JANA/JEvent.h +++ b/src/libraries/JANA/JEvent.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -25,7 +25,7 @@ #include #if JANA2_HAVE_PODIO -#include +#include #include #endif @@ -86,12 +86,12 @@ class JEvent : public std::enable_shared_from_this std::vector GetAllCollectionNames() const; const podio::CollectionBase* GetCollectionBase(std::string name, bool throw_on_missing=true) const; template const typename PodioT::collection_type* GetCollection(std::string name, bool throw_on_missing=true) const; - template JPodioStorage* InsertCollection(typename PodioT::collection_type&& collection, std::string name); - template JPodioStorage* InsertCollectionAlreadyInFrame(const podio::CollectionBase* collection, std::string name); + template JPodioDataBundle* InsertCollection(typename PodioT::collection_type&& collection, std::string name); + template JPodioDataBundle* InsertCollectionAlreadyInFrame(const podio::CollectionBase* collection, std::string name); #endif // EXPERIMENTAL NEW THING - JStorage* GetStorage(const std::string& name, bool create) const; + JDataBundle* GetDataBundle(const std::string& name, bool create) const; //SETTERS void SetRunNumber(int32_t aRunNumber){mRunNumber = aRunNumber;} @@ -526,16 +526,16 @@ JFactoryT* JEvent::GetSingle(const T* &t, const char *tag, bool exception_if_ return fac; } -inline JStorage* JEvent::GetStorage(const std::string& name, bool create) const { +inline JDataBundle* JEvent::GetDataBundle(const std::string& name, bool create) const { - auto* storage = mFactorySet->GetStorage(name); + auto* storage = mFactorySet->GetDataBundle(name); if (storage == nullptr) return nullptr; auto fac = storage->GetFactory(); if (fac != nullptr && create) { // The regenerate logic lives out here now - if ((storage->GetStatus() == JStorage::Status::Empty) || + if ((storage->GetStatus() == JDataBundle::Status::Empty) || (fac->TestFactoryFlag(JFactory::JFactory_Flags_t::REGENERATE))) { // If this was inserted, there would be no factory to run @@ -550,13 +550,13 @@ inline JStorage* JEvent::GetStorage(const std::string& name, bool create) const #if JANA2_HAVE_PODIO inline std::vector JEvent::GetAllCollectionNames() const { - return mFactorySet->GetAllCollectionNames(); + return mFactorySet->GetAllDataBundleNames(); } inline const podio::CollectionBase* JEvent::GetCollectionBase(std::string name, bool throw_on_missing) const { - auto* storage = GetStorage(name, true); + auto* storage = GetDataBundle(name, true); if (storage != nullptr) { - auto* podio_storage = dynamic_cast(storage); + auto* podio_storage = dynamic_cast(storage); if (podio_storage == nullptr) { throw JException("Not a podio collection: %s", name.c_str()); } @@ -572,9 +572,9 @@ inline const podio::CollectionBase* JEvent::GetCollectionBase(std::string name, template const typename T::collection_type* JEvent::GetCollection(std::string name, bool throw_on_missing) const { - auto* coll = GetStorage(name, true); + auto* coll = GetDataBundle(name, true); if (coll != nullptr) { - auto* podio_coll = dynamic_cast(coll); + auto* podio_coll = dynamic_cast(coll); if (podio_coll == nullptr) { throw JException("Not a podio collection: %s", name.c_str()); } @@ -595,7 +595,7 @@ const typename T::collection_type* JEvent::GetCollection(std::string name, bool template -JPodioStorage* JEvent::InsertCollection(typename PodioT::collection_type&& collection, std::string name) { +JPodioDataBundle* JEvent::InsertCollection(typename PodioT::collection_type&& collection, std::string name) { /// InsertCollection inserts the provided PODIO collection into both the podio::Frame and then a JFactoryPodioT podio::Frame* frame = nullptr; @@ -616,7 +616,7 @@ JPodioStorage* JEvent::InsertCollection(typename PodioT::collection_type&& colle template -JPodioStorage* JEvent::InsertCollectionAlreadyInFrame(const podio::CollectionBase* collection, std::string name) { +JPodioDataBundle* JEvent::InsertCollectionAlreadyInFrame(const podio::CollectionBase* collection, std::string name) { /// InsertCollection inserts the provided PODIO collection into a JPodioStorage. It assumes that the collection pointer /// is _already_ owned by the podio::Frame corresponding to this JEvent. This is meant to be used if you are starting out /// with a PODIO frame (e.g. a JEventSource that uses podio::ROOTFrameReader). @@ -634,14 +634,14 @@ JPodioStorage* JEvent::InsertCollectionAlreadyInFrame(const podio::CollectionBas } // Retrieve storage if it already exists, else create it - auto storage = mFactorySet->GetStorage(name); + auto storage = mFactorySet->GetDataBundle(name); if (storage == nullptr) { // No factories already registered this! E.g. from an event source - auto coll = new JPodioStorage; - coll->SetCollectionName(name); + auto coll = new JPodioDataBundle; + coll->SetUniqueName(name); coll->SetTypeName(JTypeInfo::demangle()); - coll->SetStatus(JStorage::Status::Inserted); + coll->SetStatus(JDataBundle::Status::Inserted); coll->SetInsertOrigin(mCallGraph.GetInsertDataOrigin()); coll->SetCollection(typed_collection); mFactorySet->Add(coll); @@ -650,12 +650,12 @@ JPodioStorage* JEvent::InsertCollectionAlreadyInFrame(const podio::CollectionBas else { // This is overriding a factory // Check that we only inserted this collection once - if (storage->GetStatus() != JStorage::Status::Empty) { + if (storage->GetStatus() != JDataBundle::Status::Empty) { throw JException("Collections can only be inserted once!"); } - auto typed_storage = dynamic_cast(storage); + auto typed_storage = dynamic_cast(storage); typed_storage->SetCollection(typed_collection); - typed_storage->SetStatus(JStorage::Status::Inserted); + typed_storage->SetStatus(JDataBundle::Status::Inserted); typed_storage->SetInsertOrigin(mCallGraph.GetInsertDataOrigin()); return typed_storage; } diff --git a/src/libraries/JANA/JFactory.cc b/src/libraries/JANA/JFactory.cc index 32f65008d..759591121 100644 --- a/src/libraries/JANA/JFactory.cc +++ b/src/libraries/JANA/JFactory.cc @@ -54,7 +54,7 @@ void JFactory::Create(const std::shared_ptr& event) { } CallWithJExceptionWrapper("JFactory::Process", [&](){ Process(event); }); for (auto& output : this->GetOutputs()) { - output->PutCollections(*event); + output->StoreData(*event); } mStatus = Status::Processed; mCreationStatus = CreationStatus::Created; diff --git a/src/libraries/JANA/JFactorySet.cc b/src/libraries/JANA/JFactorySet.cc index a85a41590..8f6053c71 100644 --- a/src/libraries/JANA/JFactorySet.cc +++ b/src/libraries/JANA/JFactorySet.cc @@ -3,11 +3,10 @@ // Subject to the terms in the LICENSE file found in the top-level directory. #include -#include #include #include -#include +#include #include "JFactorySet.h" #include "JFactory.h" #include "JMultifactory.h" @@ -41,7 +40,7 @@ JFactorySet::~JFactorySet() /// The only time mIsFactoryOwner should/can be set false is when a JMultifactory is using a JFactorySet internally /// to manage its JMultifactoryHelpers. if (mIsFactoryOwner) { - for (auto& s : mCollectionsFromName) { + for (auto& s : mDataBundlesFromName) { // Only delete _inserted_ collections. Collections are otherwise owned by their factories if (s.second->GetFactory() == nullptr) { delete s.second; @@ -57,22 +56,22 @@ JFactorySet::~JFactorySet() //--------------------------------- // Add //--------------------------------- -void JFactorySet::Add(JStorage* collection) { +void JFactorySet::Add(JDataBundle* databundle) { - if (collection->GetCollectionName().empty()) { - throw JException("Attempted to add a collection with no name"); + if (databundle->GetUniqueName().empty()) { + throw JException("Attempted to add a databundle with no unique_name"); } - auto named_result = mCollectionsFromName.find(collection->GetCollectionName()); - if (named_result != std::end(mCollectionsFromName)) { + auto named_result = mDataBundlesFromName.find(databundle->GetUniqueName()); + if (named_result != std::end(mDataBundlesFromName)) { // Collection is duplicate. Since this almost certainly indicates a user error, and // the caller will not be able to do anything about it anyway, throw an exception. // We show the user which factory is causing this problem, including both plugin names - auto ex = JException("Attempted to add duplicate collections"); + auto ex = JException("Attempted to add duplicate databundles"); ex.function_name = "JFactorySet::Add"; - ex.instance_name = collection->GetCollectionName(); + ex.instance_name = databundle->GetUniqueName(); - auto fac = collection->GetFactory(); + auto fac = databundle->GetFactory(); if (fac != nullptr) { ex.type_name = fac->GetTypeName(); ex.plugin_name = fac->GetPluginName(); @@ -83,7 +82,7 @@ void JFactorySet::Add(JStorage* collection) { throw ex; } // Note that this is agnostic to event level. We may decide to change this. - mCollectionsFromName[collection->GetCollectionName()] = collection; + mDataBundlesFromName[databundle->GetUniqueName()] = databundle; } //--------------------------------- @@ -140,9 +139,9 @@ bool JFactorySet::Add(JFactory* aFactory) else { // We have a new-style JFactory! for (const auto* output : aFactory->GetOutputs()) { - for (const auto& coll : output->GetCollections()) { - coll->SetFactory(aFactory); - Add(coll.get()); + for (const auto& bundle : output->GetDataBundles()) { + bundle->SetFactory(aFactory); + Add(bundle.get()); } } } @@ -168,14 +167,14 @@ bool JFactorySet::Add(JMultifactory *multifactory) { } //--------------------------------- -// GetCollection +// GetDataBundle //--------------------------------- -JStorage* JFactorySet::GetStorage(const std::string& collection_name) const { - auto it = mCollectionsFromName.find(collection_name); - if (it != std::end(mCollectionsFromName)) { +JDataBundle* JFactorySet::GetDataBundle(const std::string& name) const { + auto it = mDataBundlesFromName.find(name); + if (it != std::end(mDataBundlesFromName)) { auto fac = it->second->GetFactory(); if (fac != nullptr && fac->GetLevel() != mLevel) { - throw JException("Collection belongs to a different level on the event hierarchy!"); + throw JException("Data bundle belongs to a different level on the event hierarchy!"); } return it->second; } @@ -235,7 +234,7 @@ std::vector JFactorySet::GetAllFactories(std::type_index object_type, // This returns all factories which _directly_ produce objects of type object_type, i.e. they don't use a JStorage. // This is what all of its callers already expect anyhow. Obviously we'd like to migrate everything over to JStorage - // eventually. Rather than updating this to also check mCollectionsFromName, it probably makes more sense to create + // eventually. Rather than updating this to also check mDataBundlesFromName, it probably makes more sense to create // a JFactorySet::GetAllStorages(type_index, object_name) instead, and migrate all callers to use that. std::vector results; @@ -255,11 +254,11 @@ std::vector JFactorySet::GetAllMultifactories() const { } //--------------------------------- -// GetAllCollectionNames +// GetAllDataBundleNames //--------------------------------- -std::vector JFactorySet::GetAllCollectionNames() const { +std::vector JFactorySet::GetAllDataBundleNames() const { std::vector results; - for (const auto& it : mCollectionsFromName) { + for (const auto& it : mDataBundlesFromName) { results.push_back(it.first); } return results; @@ -294,7 +293,7 @@ void JFactorySet::Release() { for (auto* fac : mAllFactories) { fac->ClearData(); } - for (auto& it : mCollectionsFromName) { + for (auto& it : mDataBundlesFromName) { // fac->ClearData() only clears JFactoryT's, because that's how it always worked. // Clearing is fundamentally an operation on the data bundle, not on the factory itself. // Furthermore, "clearing" the factory is misleading because factories can cache arbitrary diff --git a/src/libraries/JANA/JFactorySet.h b/src/libraries/JANA/JFactorySet.h index ce96db52d..46b58d178 100644 --- a/src/libraries/JANA/JFactorySet.h +++ b/src/libraries/JANA/JFactorySet.h @@ -15,7 +15,7 @@ class JFactoryGenerator; class JFactory; class JMultifactory; -class JStorage; +class JDataBundle; class JFactorySet { @@ -24,7 +24,7 @@ class JFactorySet { std::vector mAllFactories; std::map, JFactory*> mFactories; // {(typeid, tag) : factory} std::map, JFactory*> mFactoriesFromString; // {(objname, tag) : factory} - std::map mCollectionsFromName; + std::map mDataBundlesFromName; std::vector mMultifactories; bool mIsFactoryOwner = true; JEventLevel mLevel = JEventLevel::PhysicsEvent; @@ -36,12 +36,12 @@ class JFactorySet { bool Add(JFactory* aFactory); bool Add(JMultifactory* multifactory); - void Add(JStorage* storage); + void Add(JDataBundle* storage); void Print() const; void Release(); - std::vector GetAllCollectionNames() const; - JStorage* GetStorage(const std::string& collection_name) const; + std::vector GetAllDataBundleNames() const; + JDataBundle* GetDataBundle(const std::string& collection_name) const; JFactory* GetFactory(const std::string& object_name, const std::string& tag="") const; JFactory* GetFactory(std::type_index object_type, const std::string& object_name, const std::string& tag = "") const; diff --git a/src/libraries/JANA/JMultifactory.h b/src/libraries/JANA/JMultifactory.h index 2569a56df..763fca62e 100644 --- a/src/libraries/JANA/JMultifactory.h +++ b/src/libraries/JANA/JMultifactory.h @@ -51,7 +51,7 @@ class JMultifactoryHelperPodio : public JFactory { JMultifactoryHelperPodio(JMultifactory* parent, std::string collection_name) : mMultiFactory(parent) { mObjectName = JTypeInfo::demangle(); mTag = collection_name; - m_output.GetCollections().at(0)->SetCollectionName(collection_name); + m_output.GetDataBundle()->SetUniqueName(collection_name); } virtual ~JMultifactoryHelperPodio() = default; @@ -193,8 +193,8 @@ void JMultifactory::DeclarePodioOutput(std::string coll_name, bool) { } template -void JMultifactory::SetCollection(std::string tag, typename T::collection_type&& collection) { - JFactory* helper = mHelpers.GetStorage(tag)->GetFactory(); +void JMultifactory::SetCollection(std::string name, typename T::collection_type&& collection) { + JFactory* helper = mHelpers.GetDataBundle(name)->GetFactory(); if (helper == nullptr) { auto ex = JException("JMultifactory: Attempting to SetData() without corresponding DeclareOutput()"); ex.function_name = "JMultifactory::SetCollection"; @@ -217,8 +217,8 @@ void JMultifactory::SetCollection(std::string tag, typename T::collection_type&& } template -void JMultifactory::SetCollection(std::string tag, std::unique_ptr collection) { - JFactory* helper = mHelpers.GetStorage(tag)->GetFactory(); +void JMultifactory::SetCollection(std::string name, std::unique_ptr collection) { + JFactory* helper = mHelpers.GetDataBundle(name)->GetFactory(); if (helper == nullptr) { auto ex = JException("JMultifactory: Attempting to SetData() without corresponding DeclareOutput()"); ex.function_name = "JMultifactory::SetCollection"; diff --git a/src/libraries/JANA/Podio/JFactoryPodioT.h b/src/libraries/JANA/Podio/JFactoryPodioT.h index cbd198dc7..7db5ad5cf 100644 --- a/src/libraries/JANA/Podio/JFactoryPodioT.h +++ b/src/libraries/JANA/Podio/JFactoryPodioT.h @@ -24,7 +24,7 @@ class JFactoryPodioT : public JFactory { void SetTag(std::string tag) { mTag = tag; - m_output.GetCollections().at(0)->SetCollectionName(tag); + m_output.GetDataBundle()->SetUniqueName(tag); } void Init() override {} @@ -34,7 +34,7 @@ class JFactoryPodioT : public JFactory { void EndRun() override {} void Finish() override {} - std::size_t GetNumObjects() const final { return m_output.GetCollection()->GetSize(); } + std::size_t GetNumObjects() const final { return m_output.GetDataBundle()->GetSize(); } void SetCollection(CollectionT&& collection); void SetCollection(std::unique_ptr collection); diff --git a/src/programs/unit_tests/Components/PodioTests.cc b/src/programs/unit_tests/Components/PodioTests.cc index 6aae53718..faa0f54c6 100644 --- a/src/programs/unit_tests/Components/PodioTests.cc +++ b/src/programs/unit_tests/Components/PodioTests.cc @@ -3,15 +3,16 @@ #include -#include #include #include #include #include -#include +#include #include #include +#include +#include namespace podiotests { @@ -163,7 +164,7 @@ TEST_CASE("JFactoryPodioT::Init gets called") { REQUIRE(res != nullptr); REQUIRE((*res)[0].energy() == 16.0); - auto fac_untyped = event->GetStorage("clusters", false)->GetFactory(); + auto fac_untyped = event->GetDataBundle("clusters", false)->GetFactory(); REQUIRE(fac_untyped != nullptr); auto fac = dynamic_cast(fac_untyped); REQUIRE(fac != nullptr); @@ -250,7 +251,7 @@ TEST_CASE("PodioTests_InsertMultiple") { auto storage = event->InsertCollection(std::move(coll1), "clusters"); REQUIRE(storage->GetSize() == 1); - REQUIRE(storage->GetStatus() == JStorage::Status::Inserted); + REQUIRE(storage->GetStatus() == JDataBundle::Status::Inserted); // Retrieve and validate cluster @@ -261,9 +262,9 @@ TEST_CASE("PodioTests_InsertMultiple") { event->GetFactorySet()->Release(); // Simulate a trip to the JEventPool - // After clearing, the JStorage will still exist, but it will be empty - auto storage2 = event->GetStorage("clusters", false); - REQUIRE(storage2->GetStatus() == JStorage::Status::Empty); + // After clearing, the JDataBundle will still exist, but it will be empty + auto storage2 = event->GetDataBundle("clusters", false); + REQUIRE(storage2->GetStatus() == JDataBundle::Status::Empty); REQUIRE(storage2->GetSize() == 0); // Insert a cluster. If event isn't being cleared correctly, this will throw @@ -271,7 +272,7 @@ TEST_CASE("PodioTests_InsertMultiple") { auto coll2 = ExampleClusterCollection(); auto cluster2 = coll2.create(33.0); auto storage3 = event->InsertCollection(std::move(coll2), "clusters"); - REQUIRE(storage3->GetStatus() == JStorage::Status::Inserted); + REQUIRE(storage3->GetStatus() == JDataBundle::Status::Inserted); REQUIRE(storage3->GetSize() == 1); // Retrieve and validate cluster @@ -313,9 +314,9 @@ TEST_CASE("PodioTests_OmniFacMultiple") { event->SetEventNumber(22); // Check that storage is already present - auto storage = event->GetStorage("clusters", false); + auto storage = event->GetDataBundle("clusters", false); REQUIRE(storage != nullptr); - REQUIRE(storage->GetStatus() == JStorage::Status::Empty); + REQUIRE(storage->GetStatus() == JDataBundle::Status::Empty); // Retrieve triggers factory auto coll = event->GetCollection("clusters"); @@ -327,9 +328,9 @@ TEST_CASE("PodioTests_OmniFacMultiple") { event->SetEventNumber(1010); // Check that storage has been reset - storage = event->GetStorage("clusters", false); + storage = event->GetDataBundle("clusters", false); REQUIRE(storage != nullptr); - REQUIRE(storage->GetStatus() == JStorage::Status::Empty); + REQUIRE(storage->GetStatus() == JDataBundle::Status::Empty); REQUIRE(storage->GetFactory() != nullptr); @@ -342,6 +343,48 @@ TEST_CASE("PodioTests_OmniFacMultiple") { } // namespace omnifacmultiple +namespace omnifacreadinsert { + +struct RWClusterFac : public JOmniFactory { + + PodioInput m_clusters_in{this}; + PodioOutput m_clusters_out{this}; + + void Configure() {} + void ChangeRun(int32_t /*run_nr*/) {} + void Execute(int32_t /*run_nr*/, uint64_t evt_nr) { + + auto cs = std::make_unique(); + for (const auto& cluster_in : *m_clusters_in()) { + auto cluster = MutableExampleCluster(1.0 + cluster_in.energy()); + cs->push_back(cluster); + } + m_clusters_out() = std::move(cs); + } +}; + +TEST_CASE("PodioTests_OmniFacReadInsert") { + + JApplication app; + app.SetParameterValue("jana:loglevel", "error"); + app.Add(new JOmniFactoryGeneratorT("cluster_fac", {"protoclusters"}, {"clusters"})); + app.Initialize(); + auto event = std::make_shared(&app); + app.GetService()->configure_event(*event); + + auto coll1 = ExampleClusterCollection(); + auto cluster1 = coll1.create(22.0); + auto storage = event->InsertCollection(std::move(coll1), "protoclusters"); + + REQUIRE(storage->GetSize() == 1); + REQUIRE(storage->GetStatus() == JDataBundle::Status::Inserted); + // Retrieve triggers factory + auto coll = event->GetCollection("clusters"); + REQUIRE(coll->size() == 1); + REQUIRE(coll->at(0).energy() == 23.0); + +} +} // namespace omnifacreadinsert } // namespace podiotests