Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:19

0001 
0002 // Copyright 2023, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 
0006 #include "PodioExampleProcessor.h"
0007 #include <PodioDatamodel/ExampleHitCollection.h>
0008 #include <PodioDatamodel/ExampleClusterCollection.h>
0009 
0010 /*
0011 struct PrintingVisitor {
0012 
0013     template <typename T>
0014     void operator() (const podio::CollectionBase* collection, std::string collection_name) {
0015 
0016         auto* typed_collection = static_cast<const typename T::collection_type*>(collection);
0017 
0018         std::cout << collection_name << " :: " << collection->getValueTypeName() << " = [";
0019         for (const T& object : *typed_collection) {
0020             std::cout << object.id() << ", ";
0021         }
0022         std::cout << "]" << std::endl;
0023     }
0024 
0025     template <>
0026     void operator()<ExampleCluster>(const podio::CollectionBase* collection, std::string collection_name) {
0027 
0028         std::cout << collection_name << " :: " << collection->getValueTypeName() << std::endl;
0029         auto* typed_collection = static_cast<const ExampleClusterCollection*>(collection);
0030         for (const ExampleCluster& cluster : *typed_collection) {
0031             std::cout << "    " << cluster.id() << ": energy=" << cluster.energy() << ", hits=" << std::endl;
0032             for (const ExampleHit& hit : cluster.Hits()) {
0033                 std::cout << "        " << hit.id() << ": energy=" << hit.energy() << std::endl;
0034             }
0035         }
0036     }
0037 
0038 };
0039 */
0040 
0041 
0042 // TODO: C++20 visitor using a lambda overload set
0043 // TODO: Less generic visitor, e.g. VisitCollection
0044 
0045 PodioExampleProcessor::PodioExampleProcessor() {
0046     SetTypeName(NAME_OF_THIS);
0047     SetCallbackStyle(CallbackStyle::ExpertMode);
0048 }
0049 
0050 void PodioExampleProcessor::Process(const JEvent& event) {
0051 
0052     // Obtain a typed collection just like you would in a JFactory
0053     auto hits = event.GetCollection<ExampleHit>("hits");
0054     auto hits_filtered = event.GetCollection<ExampleHit>("hits_filtered");
0055     auto clusters = event.GetCollection<ExampleCluster>("clusters");
0056     auto clusters_filtered = event.GetCollection<ExampleCluster>("clusters_filtered");
0057     auto clusters_from_hits_filtered = event.GetCollection<ExampleCluster>("clusters_from_hits_filtered");
0058 
0059     std::cout << "========================" << std::endl;
0060     std::cout << "Event nr: " << event.GetEventNumber() << ", Cluster count: " << clusters->size() << std::endl;
0061 
0062     std::cout << "hits:" << std::endl;
0063     for (const ExampleHit& hit : *hits) {
0064         std::cout << "    " << hit.id() << ": energy=" << hit.energy() << ", x=" << hit.x() << ", y=" << hit.y() << std::endl;
0065     }
0066     std::cout << "hits_filtered:" << std::endl;
0067     for (const ExampleHit& hit : *hits_filtered) {
0068         std::cout << "    " << hit.id() << ": energy=" << hit.energy() << ", x=" << hit.x() << ", y=" << hit.y() << std::endl;
0069     }
0070 
0071     std::cout << "clusters:" << std::endl;
0072     for (const ExampleCluster& cluster : *clusters) {
0073         std::cout << "    " << cluster.id() << ": energy=" << cluster.energy() << ", hits=" << std::endl;
0074         for (const ExampleHit& hit : cluster.Hits()) {
0075             std::cout << "        " << hit.id() << ": energy=" << hit.energy() << ", x=" << hit.x() << ", y=" << hit.y() << std::endl;
0076         }
0077     }
0078     std::cout << "clusters_filtered:" << std::endl;
0079     for (const ExampleCluster& cluster : *clusters_filtered) {
0080         std::cout << "    " << cluster.id() << ": energy=" << cluster.energy() << ", hits=" << std::endl;
0081         for (const ExampleHit& hit : cluster.Hits()) {
0082             std::cout << "        " << hit.id() << ": energy=" << hit.energy() << ", x=" << hit.x() << ", y=" << hit.y() << std::endl;
0083         }
0084     }
0085     std::cout << "clusters_from_hits_filtered:" << std::endl;
0086     for (const ExampleCluster& cluster : *clusters_from_hits_filtered) {
0087         std::cout << "    " << cluster.id() << ": energy=" << cluster.energy() << ", hits=" << std::endl;
0088         for (const ExampleHit& hit : cluster.Hits()) {
0089             std::cout << "        " << hit.id() << ": energy=" << hit.energy() << ", x=" << hit.x() << ", y=" << hit.y() << std::endl;
0090         }
0091     }
0092 }