diff --git a/FWCore/CMakeLists.txt b/FWCore/CMakeLists.txt deleted file mode 100644 index 5ddac21d7a011994871cbc5e43fdb535dd2afb1f..0000000000000000000000000000000000000000 --- a/FWCore/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -################################################################################ -# Package: FWCore -################################################################################ -gaudi_subdir(FWCore v0r1) - -find_package(podio REQUIRED) -find_package(plcio REQUIRED) -find_package(LCIO REQUIRED) - -# this declaration will not be needed in the future -gaudi_depends_on_subdirs(GaudiAlg GaudiKernel) -# gaudi_install_scripts() -gaudi_install_python_modules() - -gaudi_add_library(FWCore - src/*.cpp - INCLUDE_DIRS podio ${LCIO_INCLUDE_DIRS} ${plcio_INCLUDE_DIRS} ROOT - LINK_LIBRARIES GaudiAlgLib GaudiKernel podio::podioRootIO ${LCIO_LIBRARIES} ${plcio_LIBRARIES} ROOT - PUBLIC_HEADERS FWCore) - -gaudi_add_module(FWCorePlugins - src/components/*.cpp - LINK_LIBRARIES GaudiAlgLib GaudiKernel FWCore ROOT) - diff --git a/FWCore/FWCore/DataHandle.h b/FWCore/FWCore/DataHandle.h deleted file mode 100644 index 642d082380a708cbe88a2becbf74fc98418a47a9..0000000000000000000000000000000000000000 --- a/FWCore/FWCore/DataHandle.h +++ /dev/null @@ -1,157 +0,0 @@ -#ifndef FWCORE_DATAHANDLE_H -#define FWCORE_DATAHANDLE_H - -#include "FWCore/DataWrapper.h" -#include "FWCore/PodioDataSvc.h" - -#include "GaudiKernel/AlgTool.h" -#include "GaudiKernel/Algorithm.h" -#include <GaudiKernel/DataObjectHandle.h> -#include <GaudiKernel/GaudiException.h> -#include <GaudiKernel/Property.h> -#include <GaudiKernel/ServiceLocatorHelper.h> - -#include "TTree.h" - -#include <type_traits> - -template <typename T> -class DataHandle : public DataObjectHandle<DataWrapper<T>> { - -public: - friend class Algorithm; - friend class AlgTool; - -public: - DataHandle(); - - /// Initialises mother class - DataHandle(DataObjID& descriptor, Gaudi::DataHandle::Mode a, IDataHandleHolder* fatherAlg); - - DataHandle(const std::string& k, Gaudi::DataHandle::Mode a, IDataHandleHolder* fatherAlg); - /** - * Retrieve object from transient data store - */ - const T* get(); - - /** - * Register object in transient store - */ - void put(T* object); - - /** - * Create and register object in transient store - */ - T* createAndPut(); - -private: - ServiceHandle<IDataProviderSvc> m_eds; - bool m_isGoodType{false}; - bool m_isCollection{false}; - T* m_dataPtr; -}; - -//--------------------------------------------------------------------------- -template <typename T> -DataHandle<T>::DataHandle(DataObjID& descriptor, Gaudi::DataHandle::Mode a, IDataHandleHolder* fatherAlg) - : DataObjectHandle<DataWrapper<T>>(descriptor, a, fatherAlg), m_eds("EventDataSvc", "DataHandle") { - -} -//--------------------------------------------------------------------------- -template <typename T> -DataHandle<T>::DataHandle(const std::string& descriptor, Gaudi::DataHandle::Mode a, IDataHandleHolder* fatherAlg) - : DataObjectHandle<DataWrapper<T>>(descriptor, a, fatherAlg), m_eds("EventDataSvc", "DataHandle") { - - if (a > 15) { // Gaudi::DataHandle::Mode is 'writer' - m_eds.retrieve(); - PodioDataSvc* pds; - pds = dynamic_cast<PodioDataSvc*>( m_eds.get()); - m_dataPtr = 0; - if (nullptr != pds) { - if (std::is_convertible<T*,podio::CollectionBase*>::value) { - // still handled in PodioOutput - } else { - TTree* tree = pds->eventDataTree(); - tree->Branch(descriptor.c_str(), &m_dataPtr); - } - } - } -} - -/** - * Try to retrieve from the transient store. If the retrieval succeded and - * this is the first time we retrieve, perform a dynamic cast to the desired - * object. Then finally set the handle as Read. - * If this is not the first time we cast and the cast worked, just use the - * static cast: we do not need the checks of the dynamic cast for every access! - */ -template <typename T> -const T* DataHandle<T>::get() { - DataObject* dataObjectp = nullptr; - auto sc = m_eds->retrieveObject(DataObjectHandle<DataWrapper<T>>::fullKey().key(), dataObjectp); - - if (LIKELY(sc.isSuccess())) { - if (UNLIKELY(!m_isGoodType && !m_isCollection)) { - // only do this once (if both are false after this, we throw exception) - m_isGoodType = nullptr != dynamic_cast<DataWrapper<T>*>(dataObjectp); - if (!m_isGoodType) { - auto tmp = dynamic_cast<DataWrapper<podio::CollectionBase>*>(dataObjectp); - if (tmp != nullptr) { - m_isCollection = nullptr != dynamic_cast<T*>(tmp->collectionBase()); - } - } - } - if (LIKELY(m_isGoodType)) { - DataObjectHandle<DataWrapper<T>>::setRead(); - return static_cast<DataWrapper<T>*>(dataObjectp)->getData(); - } else if (m_isCollection) { - // The reader does not know the specific type of the collection. So we need a reinterpret_cast if the handle was - // created by the reader. - DataWrapper<podio::CollectionBase>* tmp = static_cast<DataWrapper<podio::CollectionBase>*>(dataObjectp); - DataObjectHandle<DataWrapper<T>>::setRead(); - return reinterpret_cast<const T*>(tmp->collectionBase()); - } else { - std::string errorMsg("The type provided for " + DataObjectHandle<DataWrapper<T>>::toString() + - " is different from the one of the object in the store."); - throw GaudiException(errorMsg, "wrong product type", StatusCode::FAILURE); - } - } - std::string msg("Could not retrieve product " + DataObjectHandle<DataWrapper<T>>::toString()); - throw GaudiException(msg, "wrong product name", StatusCode::FAILURE); -} - -//--------------------------------------------------------------------------- -template <typename T> -void DataHandle<T>::put(T* objectp) { - DataWrapper<T>* dw = new DataWrapper<T>(); - m_dataPtr = objectp; - dw->setData(objectp); - DataObjectHandle<DataWrapper<T>>::put(dw); - -} -//--------------------------------------------------------------------------- -/** - * Create the collection, put it in the DataObjectHandle and return the - * pointer to the data. Call this function if you create a collection and - * want to save it. - */ -template <typename T> -T* DataHandle<T>::createAndPut() { - T* objectp = new T(); - this->put(objectp); - return objectp; -} - -// temporary to allow property declaration -namespace Gaudi { -template <class T> -class Property<::DataHandle<T>&> : public ::DataObjectHandleProperty { -public: - Property(const std::string& name, ::DataHandle<T>& value) : ::DataObjectHandleProperty(name, value) {} - - /// virtual Destructor - virtual ~Property() {} -}; -} - -#endif diff --git a/FWCore/FWCore/DataWrapper.h b/FWCore/FWCore/DataWrapper.h deleted file mode 100644 index a6ec7a48d1628767e94b527a875495ad720426c3..0000000000000000000000000000000000000000 --- a/FWCore/FWCore/DataWrapper.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef FWCORE_DATAWRAPPER_H -#define FWCORE_DATAWRAPPER_H - -#include <type_traits> - -// Include files -#include "GaudiKernel/DataObject.h" -#include "podio/CollectionBase.h" - -class GAUDI_API DataWrapperBase : public DataObject { -public: - // ugly hack to circumvent the usage of boost::any yet - // DataSvc would need a templated register method - virtual podio::CollectionBase* collectionBase() = 0; - virtual ~DataWrapperBase(){}; -}; - -template <class T> -class GAUDI_API DataWrapper : public DataWrapperBase { -public: - DataWrapper() : DataWrapperBase(), m_data(nullptr){}; - virtual ~DataWrapper(); - - const T* getData() { return m_data; } - void setData(T* data) { m_data = data; } - /// try to cast to collectionBase; may return nullptr; - virtual podio::CollectionBase* collectionBase(); - -private: - T* m_data; -}; - -template <class T> -DataWrapper<T>::~DataWrapper<T>() { - if (m_data != nullptr) delete m_data; -} - -template <class T> -podio::CollectionBase* DataWrapper<T>::collectionBase() { - if (std::is_base_of<podio::CollectionBase, T>::value) { - return reinterpret_cast<podio::CollectionBase*>(m_data); - } - return nullptr; -} - -#endif diff --git a/FWCore/FWCore/KeepDropSwitch.h b/FWCore/FWCore/KeepDropSwitch.h deleted file mode 100644 index d4bd4c0bc2d7525056b18d6f34914a7faa7a488e..0000000000000000000000000000000000000000 --- a/FWCore/FWCore/KeepDropSwitch.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef EXAMPLES_KEEPDROPSWITCH_H -#define EXAMPLES_KEEPDROPSWITCH_H - -#include <map> -#include <string> -#include <vector> - -std::vector<std::string> split(const std::string& s, char delim); - -int wildcmp(const char* wild, const char* string); - -class KeepDropSwitch { -public: - enum Cmd { KEEP, DROP, UNKNOWN }; - typedef std::vector<std::string> CommandLines; - KeepDropSwitch() {} - explicit KeepDropSwitch(const CommandLines& cmds) { m_commandlines = cmds; } - bool isOn(const std::string& astring) const; - -private: - bool getFlag(const std::string& astring) const; - Cmd extractCommand(const std::string cmdLine) const; - CommandLines m_commandlines; - mutable std::map<std::string, bool> m_cache; -}; - -#endif diff --git a/FWCore/FWCore/LCIODataSvc.h b/FWCore/FWCore/LCIODataSvc.h deleted file mode 100644 index 74bf958bf2987b048192bb1031bbb40987ad4bf0..0000000000000000000000000000000000000000 --- a/FWCore/FWCore/LCIODataSvc.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef FWCORE_LCIODATASVC_H -#define FWCORE_LCIODATASVC_H - -#include "GaudiKernel/DataSvc.h" -#include "GaudiKernel/IConversionSvc.h" -// LCIO -#include "podio/CollectionBase.h" -#include "podio/CollectionIDTable.h" -#include "podio/EventStore.h" -#include "podio/ROOTReader.h" - -#include "IO/LCReader.h" -#include "EVENT/LCCollection.h" -#include "EVENT/MCParticle.h" -#include "plcio/MCParticleCollection.h" -#include "plcio/MCParticle.h" -#include "plcio/EventHeaderCollection.h" - -#include "src/components/LCIO2Plcio.h" -#include <utility> -// Forward declarations - -/** @class LCIOEvtSvc EvtDataSvc.h - * - * An EvtDataSvc for LCIO classes - * - * @author B. Hegner - */ -class LCIODataSvc : public DataSvc { -public: - - typedef std::vector<std::pair<std::string, podio::CollectionBase*>> CollRegistry; - - virtual StatusCode initialize(); - virtual StatusCode reinitialize(); - virtual StatusCode finalize(); - virtual StatusCode clearStore(); - - /// Standard Constructor - LCIODataSvc(const std::string& name, ISvcLocator* svc); - - /// Standard Destructor - virtual ~LCIODataSvc(); - - // Use DataSvc functionality except where we override - using DataSvc::registerObject; - /// Overriding standard behaviour of evt service - /// Register object with the data store. - virtual StatusCode registerObject(const std::string& fullPath, DataObject* pObject) final; - - StatusCode readCollection(const std::string& collectionName, int collectionID); - - virtual const CollRegistry& getCollections() const { return m_collections; } - virtual const CollRegistry& getReadCollections() const { return m_readCollections; } - virtual podio::CollectionIDTable* getCollectionIDs() { return m_collectionIDs; } - - /// Set the collection IDs (if reading a file) - void setCollectionIDs(podio::CollectionIDTable* collectionIds); - /// Resets caches of reader and event store, increases event counter - void endOfRead(); - - - TTree* eventDataTree() {return m_eventDataTree;} - -private: - - EVENT::LCEvent* evt = nullptr; - // eventDataTree - TTree* m_eventDataTree; - /// LCIO reader for ROOT files - IO::LCReader* m_reader; - /// LCIO reader for ROOT files - plcio::EventHeaderCollection* pl_evtcol; - /// the handle of DataProvider - IDataProviderSvc* m_pIDP{nullptr}; - /// podio::ROOTReader m_reader; - /// LCIO EventStore, used to initialise collections - /// podio::EventStore m_provider; - /// Counter of the event number - int m_eventNum{0}; - /// Number of events in the file / to process - int m_eventMax{-1}; - /// the current file index in the m_filenames vector - int m_fileIndex{0}; - - - SmartIF<IConversionSvc> m_cnvSvc; - - // special members for podio handling - std::vector<std::pair<std::string, podio::CollectionBase*>> m_collections; - std::vector<std::pair<std::string, podio::CollectionBase*>> m_readCollections; - podio::CollectionIDTable* m_collectionIDs; - -protected: -// bool exist_MCP = false; - LCIO2Plcio cvtor; -// EVENT::LCCollection* mcpcol_lc; -// plcio::MCParticleCollection* mcpcol_pl; - - /// ROOT file name the input is read from. Set by option filename - std::vector<std::string> m_filenames; - std::string m_filename; -}; -#endif // CORE_LCIODATASVC_H diff --git a/FWCore/FWCore/PodioDataSvc.h b/FWCore/FWCore/PodioDataSvc.h deleted file mode 100644 index 54d9bc830bc3bd228a526a9aca1b7ea871478347..0000000000000000000000000000000000000000 --- a/FWCore/FWCore/PodioDataSvc.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef FWCORE_PODIODATASVC_H -#define FWCORE_PODIODATASVC_H - -#include "GaudiKernel/DataSvc.h" -#include "GaudiKernel/IConversionSvc.h" -// PODIO -#include "podio/CollectionBase.h" -#include "podio/CollectionIDTable.h" -#include "podio/EventStore.h" -#include "podio/ROOTReader.h" - -#include <utility> -// Forward declarations - -/** @class PodioEvtSvc EvtDataSvc.h - * - * An EvtDataSvc for PODIO classes - * - * @author B. Hegner - */ -class PodioDataSvc : public DataSvc { -public: - typedef std::vector<std::pair<std::string, podio::CollectionBase*>> CollRegistry; - - virtual StatusCode initialize(); - virtual StatusCode reinitialize(); - virtual StatusCode finalize(); - virtual StatusCode clearStore(); - - /// Standard Constructor - PodioDataSvc(const std::string& name, ISvcLocator* svc); - - /// Standard Destructor - virtual ~PodioDataSvc(); - - // Use DataSvc functionality except where we override - using DataSvc::registerObject; - /// Overriding standard behaviour of evt service - /// Register object with the data store. - virtual StatusCode registerObject(std::string_view parentPath, std::string_view fullPath, DataObject* pObject) override final; - - StatusCode readCollection(const std::string& collectionName, int collectionID); - - virtual const CollRegistry& getCollections() const { return m_collections; } - virtual const CollRegistry& getReadCollections() const { return m_readCollections; } - virtual podio::CollectionIDTable* getCollectionIDs() { return m_collectionIDs; } - - /// Set the collection IDs (if reading a file) - void setCollectionIDs(podio::CollectionIDTable* collectionIds); - /// Resets caches of reader and event store, increases event counter - void endOfRead(); - - - TTree* eventDataTree() {return m_eventDataTree;} - - -private: - - // eventDataTree - TTree* m_eventDataTree; - /// PODIO reader for ROOT files - podio::ROOTReader m_reader; - /// PODIO EventStore, used to initialise collections - podio::EventStore m_provider; - /// Counter of the event number - int m_eventNum{0}; - /// Number of events in the file / to process - int m_eventMax{-1}; - - - SmartIF<IConversionSvc> m_cnvSvc; - - // special members for podio handling - std::vector<std::pair<std::string, podio::CollectionBase*>> m_collections; - std::vector<std::pair<std::string, podio::CollectionBase*>> m_readCollections; - podio::CollectionIDTable* m_collectionIDs; - -protected: - /// ROOT file name the input is read from. Set by option filename - std::vector<std::string> m_filenames; - std::string m_filename; -}; -#endif // CORE_PODIODATASVC_H diff --git a/FWCore/python/FWCore/__init__.py b/FWCore/python/FWCore/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/FWCore/python/FWCore/dump_joboptions.py b/FWCore/python/FWCore/dump_joboptions.py deleted file mode 100644 index eaf71c9aa02ca604f7c25c2777ed3f9e7cd00246..0000000000000000000000000000000000000000 --- a/FWCore/python/FWCore/dump_joboptions.py +++ /dev/null @@ -1,30 +0,0 @@ -from __future__ import print_function -import argparse -import ROOT - -parser = argparse.ArgumentParser(description='Job Options Dumper') -parser.add_argument( dest='fname', type=str, help="name of file to read") - - -def dump_joboptions(filename): - """ Simple and straightforward dump of the output of Gaudi's JobOptionsSvc - to stdout. - - Parameters - ---------- - - filename: str - The name of the CEPCSW output file containing joboptions to print - """ - f = ROOT.TFile(filename) - t = f.metadata - for event in t: - s = event.gaudiConfigOptions - for e in s: - print(e) - -if __name__ == "__main__": - args = parser.parse_args() - dump_joboptions(args.fname) - - diff --git a/FWCore/python/FWCore/joboptions.py b/FWCore/python/FWCore/joboptions.py deleted file mode 100644 index 47f8173d837c452551803be2690acb6d5e513ff2..0000000000000000000000000000000000000000 --- a/FWCore/python/FWCore/joboptions.py +++ /dev/null @@ -1,15 +0,0 @@ -import argparse - -def parse_standard_job_options(scriptname=""): - """ - Returns the parsed arguments, adding a parser with commonly needed opts: - - args.nevents -- number of events (int), specify with --nevents - - args.inputfile -- the input file (string), specify with --inputfile - - args.outputfile -- the output file (string), specify with --outputfile - """ - parser = argparse.ArgumentParser() - parser.add_argument('--inputfile', type=str, default='', help='specify an input file') - parser.add_argument('--outputfile', type=str, default='', help='specify an output file') - parser.add_argument('--nevents', type=int, default=None, help='specify number of events to process') - args, _ = parser.parse_known_args() - return args diff --git a/FWCore/src/KeepDropSwitch.cpp b/FWCore/src/KeepDropSwitch.cpp deleted file mode 100644 index 6617c03208e39556e2594ebe48d7bf0c29796b8b..0000000000000000000000000000000000000000 --- a/FWCore/src/KeepDropSwitch.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "FWCore/KeepDropSwitch.h" - -#include <iostream> -#include <sstream> -#include <stdexcept> - -int wildcmp(const char* wild, const char* string) { - // Written by Jack Handy - <A href="mailto:jakkhandy@hotmail.com">jakkhandy@hotmail.com</A> - const char *cp = nullptr, *mp = nullptr; - while ((*string) && (*wild != '*')) { - if ((*wild != *string) && (*wild != '?')) { - return 0; - } - wild++; - string++; - } - while (*string) { - if (*wild == '*') { - if (!*++wild) { - return 1; - } - mp = wild; - cp = string + 1; - } else if ((*wild == *string) || (*wild == '?')) { - wild++; - string++; - } else { - wild = mp; - string = cp++; - } - } - while (*wild == '*') { - wild++; - } - return !*wild; -} - -std::vector<std::string> split(const std::string& s, char delim) { - std::vector<std::string> elems; - std::stringstream ss(s); - std::string item; - while (std::getline(ss, item, delim)) { - if (item != "") elems.push_back(item); - } - return elems; -} - -bool KeepDropSwitch::isOn(const std::string& astring) const { - typedef std::map<std::string, bool>::const_iterator MIter; - MIter im = m_cache.find(astring); - if (im != m_cache.end()) - return im->second; - else { - bool val = getFlag(astring); - m_cache.insert(std::pair<std::string, bool>(astring, val)); - return val; - } -} - -bool KeepDropSwitch::getFlag(const std::string& astring) const { - bool flag = true; - for (const auto& cmdline : m_commandlines) { - std::vector<std::string> words = split(cmdline, ' '); - if (words.size() != 2) { - std::ostringstream msg; - msg << "malformed command string : " << cmdline; - throw std::invalid_argument(msg.str()); - } - std::string cmd = words[0]; - std::string pattern = words[1]; - Cmd theCmd = UNKNOWN; - if (cmd == "keep") - theCmd = KEEP; - else if (cmd == "drop") - theCmd = DROP; - else { - std::ostringstream msg; - msg << "malformed command in line: " << std::endl; - msg << cmdline << std::endl; - msg << "should be keep or drop, lower case" << std::endl; - throw std::invalid_argument(msg.str()); - } - bool match = wildcmp(pattern.c_str(), astring.c_str()); - if (not match) - continue; - else if (theCmd == KEEP) - flag = true; - else - flag = false; - } - return flag; -} - -KeepDropSwitch::Cmd KeepDropSwitch::extractCommand(const std::string cmdline) const { - std::vector<std::string> words = split(cmdline, ' '); - for (auto& word : words) - std::cout << "'" << word << "' "; - std::cout << std::endl; - return UNKNOWN; -} diff --git a/FWCore/src/PodioDataSvc.cpp b/FWCore/src/PodioDataSvc.cpp deleted file mode 100644 index c2920e12f90f95a147d03d9480c5ab805881b88d..0000000000000000000000000000000000000000 --- a/FWCore/src/PodioDataSvc.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include "FWCore/PodioDataSvc.h" -#include "GaudiKernel/IConversionSvc.h" -#include "GaudiKernel/IEventProcessor.h" -#include "GaudiKernel/ISvcLocator.h" - -#include "FWCore/DataWrapper.h" - -#include "TTree.h" - -/// Service initialisation -StatusCode PodioDataSvc::initialize() { - // Nothing to do: just call base class initialisation - StatusCode status = DataSvc::initialize(); - ISvcLocator* svc_loc = serviceLocator(); - - - // Attach data loader facility - m_cnvSvc = svc_loc->service("EventPersistencySvc"); - status = setDataLoader(m_cnvSvc); - - if (m_filename != "") { - m_filenames.push_back(m_filename); - } - - if (m_filenames.size() > 0) { - if (m_filenames[0] != "") { - m_reader.openFiles(m_filenames); - m_eventMax = m_reader.getEntries(); - auto idTable = m_reader.getCollectionIDTable(); - - setCollectionIDs(idTable); - m_provider.setReader(&m_reader); - } - } - return status; -} -/// Service reinitialisation -StatusCode PodioDataSvc::reinitialize() { - // Do nothing for this service - return StatusCode::SUCCESS; -} -/// Service finalization -StatusCode PodioDataSvc::finalize() { - m_cnvSvc = 0; // release - DataSvc::finalize().ignore(); - return StatusCode::SUCCESS; -} - -StatusCode PodioDataSvc::clearStore() { - for (auto& collNamePair : m_collections) { - if (collNamePair.second != nullptr) { - collNamePair.second->clear(); - } - } - for (auto& collNamePair : m_readCollections) { - if (collNamePair.second != nullptr) { - collNamePair.second->clear(); - } - } - DataSvc::clearStore().ignore(); - m_collections.clear(); - m_readCollections.clear(); - return StatusCode::SUCCESS; -} - -void PodioDataSvc::endOfRead() { - if (m_eventMax != -1) { - m_provider.clearCaches(); - m_reader.endOfEvent(); - if ( ++m_eventNum >= m_eventMax ) { - info() << "Reached end of file with event " << m_eventMax << endmsg; - IEventProcessor* eventProcessor; - service("ApplicationMgr", eventProcessor); - eventProcessor->stopRun(); - } - } -} - -void PodioDataSvc::setCollectionIDs(podio::CollectionIDTable* collectionIds) { - if (m_collectionIDs != nullptr) { - delete m_collectionIDs; - } - m_collectionIDs = collectionIds; -} - -/// Standard Constructor -PodioDataSvc::PodioDataSvc(const std::string& name, ISvcLocator* svc) - : DataSvc(name, svc), m_collectionIDs(new podio::CollectionIDTable()) { - - m_eventDataTree = new TTree("events", "Events tree"); - } - -/// Standard Destructor -PodioDataSvc::~PodioDataSvc() {} - -StatusCode PodioDataSvc::readCollection(const std::string& collName, int collectionID) { - podio::CollectionBase* collection(nullptr); - m_provider.get(collectionID, collection); - auto wrapper = new DataWrapper<podio::CollectionBase>; - int id = m_collectionIDs->add(collName); - collection->setID(id); - wrapper->setData(collection); - m_readCollections.emplace_back(std::make_pair(collName, collection)); - return DataSvc::registerObject("/Event", "/" + collName, wrapper); -} - -StatusCode PodioDataSvc::registerObject(std::string_view parentPath, std::string_view fullPath, DataObject* pObject) { - DataWrapperBase* wrapper = dynamic_cast<DataWrapperBase*>(pObject); - if (wrapper != nullptr) { - podio::CollectionBase* coll = wrapper->collectionBase(); - if (coll != nullptr) { - size_t pos = fullPath.find_last_of("/"); - std::string shortPath(fullPath.substr(pos + 1, fullPath.length())); - int id = m_collectionIDs->add(shortPath); - coll->setID(id); - m_collections.emplace_back(std::make_pair(shortPath, coll)); - } - } - return DataSvc::registerObject(parentPath, fullPath, pObject); -} diff --git a/FWCore/src/components/CEPCDataSvc.cpp b/FWCore/src/components/CEPCDataSvc.cpp deleted file mode 100644 index 0325578c04befbdc4f25235749a85c6f94883814..0000000000000000000000000000000000000000 --- a/FWCore/src/components/CEPCDataSvc.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "CEPCDataSvc.h" - -#include "GaudiKernel/IConversionSvc.h" -#include "GaudiKernel/ISvcLocator.h" -#include "GaudiKernel/SvcFactory.h" - -// Instantiation of a static factory class used by clients to create -// instances of this service -DECLARE_COMPONENT(CEPCDataSvc) - -/// Standard Constructor -CEPCDataSvc::CEPCDataSvc(const std::string& name, ISvcLocator* svc) - : PodioDataSvc(name, svc) -{ - declareProperty("inputs", m_filenames = {}, "Names of the files to read"); - declareProperty("input", m_filename = "", "Name of the file to read"); -} - -/// Standard Destructor -CEPCDataSvc::~CEPCDataSvc() {} diff --git a/FWCore/src/components/CEPCDataSvc.h b/FWCore/src/components/CEPCDataSvc.h deleted file mode 100644 index ff3878d76ac3f2d5d4dab236eb26ceab22149fd4..0000000000000000000000000000000000000000 --- a/FWCore/src/components/CEPCDataSvc.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef FWCORE_CEPCDATASVC_H -#define FWCORE_CEPCDATASVC_H - -#include "FWCore/PodioDataSvc.h" - -class CEPCDataSvc : public PodioDataSvc -{ - -public: - /// Standard Constructor - CEPCDataSvc(const std::string& name, ISvcLocator* svc); - - /// Standard Destructor - virtual ~CEPCDataSvc(); -}; - -#endif // FWCORE_CEPCDATASVC_H diff --git a/FWCore/src/components/LCIO2Plcio.cpp b/FWCore/src/components/LCIO2Plcio.cpp deleted file mode 100644 index 72cd688a9469a06c26113ec76aaf5be6df189d39..0000000000000000000000000000000000000000 --- a/FWCore/src/components/LCIO2Plcio.cpp +++ /dev/null @@ -1,610 +0,0 @@ -#include "LCIO2Plcio.h" - -#include "lcio.h" -#include "EVENT/LCCollection.h" -#include "plcio/MCParticle.h" -#include "plcio/MCParticleConst.h" -#include "plcio/MCParticleCollection.h" -#include "plcio/LCRunHeader.h" -#include "plcio/LCRunHeaderCollection.h" -#include "EVENT/MCParticle.h" - -typedef std::vector<EVENT::MCParticle*> MCParticleVec ; - -CollectionsMap LCIO2Plcio::map_cols; -std::string LCIO2Plcio::CollName; - -void lp_info(std::string s){ - printf("[LCIO2Plcio]:\t\t%s.\n", &s[0]); -} - -template<typename T> -static plcio::FloatThree FloatThreeFROMConstPtr(const T* vpos){ - float tmp[3]; - for(unsigned i=0; i<3; i++){ - tmp[i] = vpos[i]; - } - return plcio::FloatThree(tmp); -} - -template<typename T> -static plcio::FloatThree FloatThreeFROMFloatVec(std::vector<T> vec){ - float tmp[3]; - for(unsigned i=0; i<3; i++){ - tmp[i] = vec[i]; - } - return plcio::FloatThree(tmp); -} - -template<typename T> -static plcio::DoubleThree DoubleThreeFROMConstPtr(const T* vpos){ - double tmp[3]; - for(unsigned i=0; i<3; i++) - tmp[i] = vpos[i]; - return plcio::DoubleThree(tmp); -} - -std::array<float, 6> vec6_2_arr6(std::vector<float> vec){ - std::array<float, 6> arr; - for(unsigned i=0; i<6; i++){ - arr[i] = vec[i]; - } - return arr; -} - -LCIO2Plcio::LCIO2Plcio(){ - map_cvt.insert(std::make_pair<std::string, fptr>("MCParticle", Convertor_MCParticle)); - map_cvt.insert(std::make_pair<std::string, fptr>("LCRunHeader", Convertor_LCRunHeader)); - map_cvt.insert(std::make_pair<std::string, fptr>("SimTrackerHit", Convertor_SimTrackerHit)); - map_cvt.insert(std::make_pair<std::string, fptr>("SimCalorimeterHit", Convertor_SimCalorimeterHit)); - map_cvt.insert(std::make_pair<std::string, fptr>("Cluster", Convertor_Cluster)); - map_cvt.insert(std::make_pair<std::string, fptr>("Track", Convertor_Track)); - map_cvt.insert(std::make_pair<std::string, fptr>("TrackerHit", Convertor_TrackerHit)); - map_cvt.insert(std::make_pair<std::string, fptr>("TPCHit", Convertor_TPCHit)); - map_cvt.insert(std::make_pair<std::string, fptr>("ReconstructedParticle", Convertor_ReconstructedParticle)); - map_cvt.insert(std::make_pair<std::string, fptr>("ParticleID", Convertor_ParticleID)); -} -LCIO2Plcio::LCIO2Plcio(EVENT::LCCollection* collection){ - LCIO2Plcio(); -} - -podio::CollectionBase* LCIO2Plcio::Convertor_LCRunHeader(EVENT::LCCollection* lc_col){ - plcio::LCRunHeaderCollection* pl_col = new plcio::LCRunHeaderCollection(); - - // Convert basic info from LCIO to plcio; - for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::LCRunHeader* lc_var = (EVENT::LCRunHeader*) lc_col->getElementAt(i) ; - plcio::LCRunHeader pl_var = (plcio::LCRunHeader) pl_col->create(); - pl_var.setRunNumber( lc_var->getRunNumber() ); - pl_var.setDetectorName( lc_var->getDetectorName() ); - pl_var.setDescription( lc_var->getDescription() ); - - std::vector<std::string> vec_dct = *(lc_var->getActiveSubdetectors()); - for( unsigned j=0,N=vec_dct.size(); j<N; j++){ - pl_var.addActiveSubdetector( vec_dct[j] ); - } - } - return pl_col; -} - -void LCIO2Plcio::setMCParticle(EVENT::MCParticle* lc_var, plcio::MCParticle& pl_var){ - - pl_var.setPDG( lc_var->getPDG() ); - pl_var.setGeneratorStatus( lc_var->getGeneratorStatus() ); - pl_var.setSimulatorStatus( lc_var->getSimulatorStatus() ); - pl_var.setCharge( lc_var->getCharge() ); - pl_var.setTime( lc_var->getTime() ); - pl_var.setMass( lc_var->getMass() ); - pl_var.setStopped( lc_var->isStopped() ); - pl_var.setOverlay( lc_var->isOverlay() ); - pl_var.setBackscatter( lc_var->isBackscatter() ); - pl_var.setDecayedInTracker( lc_var->isDecayedInTracker() ); - pl_var.setDecayedInCalorimeter( lc_var->isDecayedInCalorimeter() ); - pl_var.setCreatedInSimulation( lc_var->isCreatedInSimulation() ); - pl_var.setVertexIsNotEndpointOfParent( lc_var->vertexIsNotEndpointOfParent() ); - pl_var.setHasLeftDetector( lc_var->hasLeftDetector() ); - - pl_var.setSpin( plcio::FloatThree( lc_var->getSpin() ) ); - pl_var.setColorFlow( plcio::IntTwo( lc_var->getColorFlow() ) ); - pl_var.setVertex( plcio::DoubleThree( lc_var->getVertex())); - pl_var.setEndpoint( plcio::DoubleThree( lc_var->getEndpoint() ) ); - pl_var.setMomentum( FloatThreeFROMConstPtr(lc_var->getMomentum()) ); - pl_var.setMomentumAtEndpoint( FloatThreeFROMConstPtr(lc_var->getMomentumAtEndpoint()) ); -} - -podio::CollectionBase* LCIO2Plcio::Convertor_MCParticle(EVENT::LCCollection* lc_col){ - plcio::MCParticleCollection* pl_col = new plcio::MCParticleCollection(); - - // Convert basic info from LCIO to plcio; - for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::MCParticle* lc_var = (EVENT::MCParticle*) lc_col->getElementAt(i) ; - plcio::MCParticle pl_var = (plcio::MCParticle) pl_col->create(); - - setMCParticle(lc_var, pl_var); - // dealing each of 'Parents' of lcio::MCParticle ; - const MCParticleVec& veclc = lc_var->getParents(); - for(unsigned j=0; j<veclc.size(); j++){ - EVENT::MCParticle* vlcreg = veclc[j]; - for(unsigned k=0; k<i; ++k){ - if(((EVENT::MCParticle*) lc_col->getElementAt(k)) == vlcreg){ - // A loop for plcio's MCParticleCollection to recover plcio's relationship; - plcio::MCParticle mcprt = pl_col->at(k); - pl_var.addParent(mcprt); - mcprt.addDaughter(pl_var); - } - } - } - } - return pl_col; -} - -podio::CollectionBase* LCIO2Plcio::Convertor_SimTrackerHit(EVENT::LCCollection* lc_col){ - plcio::SimTrackerHitCollection* pl_col = new plcio::SimTrackerHitCollection(); - - for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::SimTrackerHit* lc_var = (EVENT::SimTrackerHit*) lc_col->getElementAt(i) ; - plcio::SimTrackerHit pl_var = (plcio::SimTrackerHit) pl_col->create(); - - pl_var.setCellID0( lc_var->getCellID0() ); - pl_var.setCellID1( lc_var->getCellID1() ); - pl_var.setEDep( lc_var->getEDep() ); - pl_var.setTime( lc_var->getTime() ); - pl_var.setPathLength( lc_var->getPathLength() ); - pl_var.setQuality( lc_var->getQuality() ); - pl_var.setPosition( lc_var->getPosition() ); - pl_var.setMomentum( lc_var->getMomentum() ); - pl_var.setOverlay( lc_var->isOverlay() ); - pl_var.setProducedBySecondary( lc_var->isProducedBySecondary() ); - - // Looping the LCIO::MCParticleCollection to pick Particle for Hits; - CollectionsVec vec_mcp; - vec_mcp = map_cols["MCParticle"]; - EVENT::LCCollection* hitcol_lc = (EVENT::LCCollection*) vec_mcp[0].first; - plcio::MCParticleCollection* hitcol_pl = (plcio::MCParticleCollection*) vec_mcp[0].second; - - int index = -1; - // search corresponding MCParticleCollection*; - EVENT::MCParticle* mcptr_reg = lc_var->getMCParticle(); - for( unsigned j=0, M=hitcol_lc->getNumberOfElements(); j<M; ++j){ - EVENT::MCParticle* mcpin_lc = (EVENT::MCParticle*) hitcol_lc->getElementAt(j); - if( mcpin_lc == mcptr_reg ){ - index = j; - } - } -// if( index != -1) lp_info("Cedar: Convertor SimTrackerHit Success."); - bool is_empty = false; - if( index == -1){ - if(mcptr_reg == nullptr) is_empty = true; -// lp_info("Convertor SimTrackerHit Problem."); -// printf("LCCollection size: %d\n", hitcol_lc->getNumberOfElements()); -// printf("MCParticleCollection size: %d\n", hitcol_pl->size()); -// printf("Index: %d\n", index); - } - if( is_empty == false ) - pl_var.setMCParticle( hitcol_pl->at(index) ); - - } - return pl_col; -} - -podio::CollectionBase* LCIO2Plcio::Convertor_SimCalorimeterHit(EVENT::LCCollection* lc_col){ - plcio::SimCalorimeterHitCollection* pl_col = new plcio::SimCalorimeterHitCollection(); - - for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::SimCalorimeterHit* lc_var = (EVENT::SimCalorimeterHit*) lc_col->getElementAt(i); - plcio::SimCalorimeterHit pl_var = (plcio::SimCalorimeterHit) pl_col->create(); - - pl_var.setCellID0( lc_var->getCellID0() ); - pl_var.setCellID1( lc_var->getCellID1() ); - pl_var.setEnergy( lc_var->getEnergy() ); - pl_var.setPosition( FloatThreeFROMConstPtr(lc_var->getPosition()) ); - - // converting from lc_var to pl_var on the contribution variables; - for( unsigned j=0, N=lc_var->getNMCContributions(); j<N; j++){ - plcio::ConstCaloHitContribution tmp( - lc_var->getPDGCont(j), lc_var->getEnergyCont(j), - lc_var->getTimeCont(j), FloatThreeFROMConstPtr(lc_var->getStepPosition(j)) - ); - pl_var.addContribution( tmp ); - } - } - return pl_col; -} - -podio::CollectionBase* LCIO2Plcio::Convertor_Cluster(EVENT::LCCollection* lc_col){ - plcio::ClusterCollection* pl_col = new plcio::ClusterCollection(); - - for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::Cluster* lc_var = (EVENT::Cluster*) lc_col->getElementAt(i); - plcio::Cluster pl_var = (plcio::Cluster) pl_col->create(); - - pl_var.setType(lc_var->getType()); - pl_var.setEnergy(lc_var->getEnergy()); - pl_var.setEnergyError(lc_var->getEnergyError()); - pl_var.setPhi(lc_var->getIPhi()); - pl_var.setITheta(lc_var->getITheta()); - pl_var.setPosition( FloatThreeFROMConstPtr(lc_var->getPosition()) ); - pl_var.setPositionError( vec6_2_arr6(lc_var->getPositionError()) ); - pl_var.setDirectionError( FloatThreeFROMFloatVec(lc_var->getDirectionError()) ); - - std::vector<float> lcio_seq0 = lc_var->getShape(); - for(unsigned j=0; j<lcio_seq0.size(); j++){ - pl_var.addShap( lcio_seq0[j] ); - } - - lcio_seq0 = lc_var->getHitContributions(); - for(unsigned j=0; j<lcio_seq0.size(); j++){ - pl_var.addHitContribution( lcio_seq0[j] ); - } - - lcio_seq0 = lc_var->getSubdetectorEnergies(); - for(unsigned j=0; j<lcio_seq0.size(); j++){ - pl_var.addSubdetectorEnergie( lcio_seq0[j] ); - } - - EVENT::ParticleIDVec lcio_seq1 = lc_var->getParticleIDs(); - for(unsigned j=0; j<lcio_seq1.size(); j++){ - EVENT::ParticleID* lc_locx = lcio_seq1[j]; - - pl_var.addParticleID( plcio::ConstParticleID( - lc_locx->getType(), - lc_locx->getPDG(), - lc_locx->getAlgorithmType(), - lc_locx->getLikelihood() - ) ); - } - - EVENT::CalorimeterHitVec lcio_seq2 = lc_var->getCalorimeterHits(); - for(unsigned j=0; j<lcio_seq2.size(); j++){ - EVENT::CalorimeterHit* lc_locx = lcio_seq2[j]; - - podio::CollectionIDTable col2id; - plcio::ObjectID tmp; - tmp.index = i; - tmp.collectionID = col2id.collectionID(CollName); - - pl_var.addHit( plcio::ConstCalorimeterHit( - lc_locx->getCellID0(), - lc_locx->getCellID1(), - lc_locx->getEnergy(), - lc_locx->getEnergyError(), - lc_locx->getTime(), - FloatThreeFROMConstPtr(lc_locx->getPosition()), - lc_locx->getType(), - tmp - ) ); - } - } - - for(unsigned i=0,N=lc_col->getNumberOfElements(); i<N; i++){ - EVENT::Cluster* lc_var = (EVENT::Cluster*) lc_col->getElementAt(i); - plcio::Cluster pl_var = pl_col->at(i); - EVENT::ClusterVec lcio_seq3 = lc_var->getClusters(); - - for(unsigned j=0; j<lcio_seq3.size(); j++){ - for(unsigned k=0,K=lc_col->getNumberOfElements(); k<K; k++){ - if(lcio_seq3[j] == lc_col->getElementAt(k)){ - pl_var.addCluster(pl_col->at(k)); - break; - } - } - } - } - - return pl_col; -} - -// QUEST::isAvailable dows not analyze; -podio::CollectionBase* LCIO2Plcio::Convertor_ParticleID(EVENT::LCCollection* lc_col){ - plcio::ParticleIDCollection* pl_col = new plcio::ParticleIDCollection(); - - for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::ParticleID* lc_var = (EVENT::ParticleID*) lc_col->getElementAt(i); - plcio::ParticleID pl_var = (plcio::ParticleID) pl_col->create(); - - pl_var.setType( lc_var->getType() ); - pl_var.setPDG( lc_var->getPDG() ); - pl_var.setAlgorythmType( lc_var->getAlgorithmType() ); - pl_var.setLikelihood( lc_var->getLikelihood() ); - EVENT::FloatVec vec_float = lc_var->getParameters(); - for(unsigned j=0; j<vec_float.size(); j++){ - pl_var.addParameter(vec_float[j]); - } - } - return pl_col; -} - -podio::CollectionBase* LCIO2Plcio::Convertor_ReconstructedParticle(EVENT::LCCollection* lc_col){ - plcio::ReconstructedParticleCollection* pl_col = new plcio::ReconstructedParticleCollection(); - - for(unsigned i=0,N=lc_col->getNumberOfElements(); i<N; i++){ - EVENT::ReconstructedParticle* lc_var = (EVENT::ReconstructedParticle*) lc_col->getElementAt(i); - plcio::ReconstructedParticle pl_var = (plcio::ReconstructedParticle) pl_col->create(); - - pl_var.setType( lc_var->getType() ); - pl_var.setEnergy( lc_var->getEnergy() ); - pl_var.setCharge( lc_var->getCharge() ); - pl_var.setMass( lc_var->getMass() ); - pl_var.setGoodnessOfPID( lc_var->getGoodnessOfPID() ); - - pl_var.setMomentum( FloatThreeFROMConstPtr(lc_var->getMomentum()) ); - pl_var.setReferencePoint( FloatThreeFROMConstPtr(lc_var->getReferencePoint()) ); - - std::vector<float> vec = lc_var->getCovMatrix(); - for(unsigned j=0,N=vec.size(); j<N; j++){ - pl_var.setCovMatrix( j, vec[j] ); - } - - // QUEST: boolean to int: isPrimary, str2int: getAlgorithmType; - // pl_var.setStartVertex( lc_var->getStartVertex() ) - // ignorant; - std::array<float, 6> arr_6; - EVENT::FloatVec fvec = lc_var->getStartVertex()->getCovMatrix(); - for(unsigned j=0; j<6; j++){ - arr_6[j] = fvec[j]; - } - pl_var.setStartVertex( plcio::ConstVertex( - lc_var->getStartVertex()->isPrimary(), - lc_var->getStartVertex()->getChi2(), - lc_var->getStartVertex()->getProbability(), - FloatThreeFROMConstPtr( lc_var->getStartVertex()->getPosition() ), - arr_6, - 0 - //lc_var->getStartVertex()->getAlgorithmType() - ) ); - - //pl_var.setParticleIDUsed( lc_var->getParticleIDUsed() ); - EVENT::ParticleID* lc_locx = lc_var->getParticleIDUsed(); - CollectionsVec vec_cols = map_cols["ParticleID"]; - EVENT::LCCollection* lc_mapcol = (EVENT::LCCollection*)vec_cols[0].first; - plcio::ParticleIDCollection* pl_mapcol = (plcio::ParticleIDCollection*)vec_cols[0].second; - - for(unsigned k=0, LCsize=lc_mapcol->getNumberOfElements(); k<LCsize; k++){ - if(lc_locx == lc_mapcol->getElementAt(k)) - pl_var.setParticleIDUsed(pl_mapcol->at(k)); - } - - - //pl_var.addCluster(); - std::vector<EVENT::Cluster*> vec_clust = lc_var->getClusters(); - for(unsigned j=0; j<vec_clust.size(); j++){ - CollectionsVec vec_cols = map_cols["Cluster"]; - EVENT::LCCollection* lc_mapcol = (EVENT::LCCollection*)vec_cols[0].first; - plcio::ClusterCollection* pl_mapcol = (plcio::ClusterCollection*)vec_cols[0].second; - - for(unsigned k=0; k<lc_mapcol->getNumberOfElements(); k++){ - if( vec_clust[j] == lc_mapcol->getElementAt(k) ) - pl_var.addCluster( pl_mapcol->at(k) ); - } - } - - //pl_var.addTrack(); - EVENT::TrackVec vec_track = lc_var->getTracks(); - for(unsigned j=0; j<vec_track.size(); j++){ - CollectionsVec vec_cols = map_cols["Track"]; - EVENT::LCCollection* lc_mapcol = (EVENT::LCCollection*)vec_cols[0].first; - plcio::TrackCollection* pl_mapcol = (plcio::TrackCollection*)vec_cols[0].second; - - for(unsigned k=0; k<lc_mapcol->getNumberOfElements(); k++) - if(vec_track[j] == lc_mapcol->getElementAt(k)) - pl_var.addTrack(pl_mapcol->at(k)); - } - - //pl_var.addParticleID( lc->getParticleIDs); - EVENT::ParticleIDVec vec_ParticleID = lc_var->getParticleIDs(); - for(unsigned j=0; j<vec_ParticleID.size(); j++){ - CollectionsVec vec_cols = map_cols["ParticleID"]; - EVENT::LCCollection* lc_mapcol = (EVENT::LCCollection*)vec_cols[0].first; - plcio::ParticleIDCollection* pl_mapcol = (plcio::ParticleIDCollection*)vec_cols[0].second; - - for(unsigned k=0,M=lc_mapcol->getNumberOfElements(); k<M; k++){ - if(vec_ParticleID[j] == lc_mapcol->getElementAt(k)) - pl_var.addParticleID( pl_mapcol->at(k) ); - } - } - } - //pl_var.addParticle(); - for(unsigned i=0, N=lc_col->getNumberOfElements(); i<N; i++){ - EVENT::ReconstructedParticle* lc_var = (EVENT::ReconstructedParticle*)lc_col->getElementAt(i); - EVENT::ReconstructedParticleVec vec_RecPtc = lc_var->getParticles(); - - for(unsigned j=0; j<vec_RecPtc.size(); j++){ - for(unsigned k=0, M=lc_col->getNumberOfElements(); k<M; k++){ - if(vec_RecPtc[j] == lc_col->getElementAt(k)) - pl_col->at(i).addParticle( pl_col->at(k) ); - } - } - } - - return pl_col; -} - -podio::CollectionBase* LCIO2Plcio::Convertor_TrackerHit(EVENT::LCCollection* lc_col){ - plcio::TrackerHitCollection* pl_col = new plcio::TrackerHitCollection(); - - for(unsigned i=0,N=lc_col->getNumberOfElements(); i<N; i++){ - EVENT::TrackerHit* lc_var = (EVENT::TrackerHit*) lc_col->getElementAt(i); - plcio::TrackerHit pl_var = (plcio::TrackerHit) pl_col->create(); - - pl_var.setCellID0(lc_var->getCellID0()); - pl_var.setCellID1(lc_var->getCellID1()); - - pl_var.setType(lc_var->getType()); - pl_var.setQuality(lc_var->getQuality()); - pl_var.setTime(lc_var->getTime()); - pl_var.setEDep(lc_var->getEDep()); - pl_var.setEDepError(lc_var->getEDepError()); - pl_var.setEdx(lc_var->getdEdx()); - pl_var.setPosition( DoubleThreeFROMConstPtr(lc_var->getPosition())); - pl_var.setCovMatrix( vec6_2_arr6(lc_var->getCovMatrix())); - } - return pl_col; -} - -podio::CollectionBase* LCIO2Plcio::Convertor_Track(EVENT::LCCollection* lc_col){ - plcio::TrackCollection* pl_col = new plcio::TrackCollection(); - - for(unsigned i=0,N=lc_col->getNumberOfElements(); i<N; i++){ - EVENT::Track* lc_var = (EVENT::Track*) lc_col->getElementAt(i); - plcio::Track pl_var = (plcio::Track) pl_col->create(); - - pl_var.setType( lc_var->getType() ); - pl_var.setChi2( lc_var->getChi2() ); - pl_var.setNdf( lc_var->getNdf() ); - pl_var.setDEdx( lc_var->getdEdx() ); - pl_var.setDEdxError( lc_var->getdEdxError() ); - pl_var.setRadiusOfInnermostHit( lc_var->getRadiusOfInnermostHit() ); - - //pl_var.addTrackerHit( lc_var->getTrackerHits() ); - //rely on TrackerHits collection; - //corresoponding with TrackerHit collection; - EVENT::TrackerHitVec lcio_seq1 = lc_var->getTrackerHits(); - for(unsigned j=0; j<lcio_seq1.size(); j++){ - EVENT::TrackerHit* lc_locx = lcio_seq1[j]; - CollectionsVec vec_cols = map_cols["TrackerHit"]; - EVENT::LCCollection* lc_mapcol = (EVENT::LCCollection*)vec_cols[0].first; - plcio::TrackerHitCollection* pl_mapcol = (plcio::TrackerHitCollection*) vec_cols[0].second; - - for(unsigned k=0; k<lc_mapcol->getNumberOfElements(); k++){ - if( lc_locx == lc_mapcol->getElementAt(k) ) - pl_var.addTrackerHit( pl_mapcol->at(k) ); - } - } - - //pl_var.( lc_var->getSubdetectorHitNumbers() ); - std::vector<int> lcio_IntVec1 = lc_var->getSubdetectorHitNumbers(); - for(unsigned j=0; j<lcio_IntVec1.size(); j++){ - pl_var.addSubDetectorHitNumber(lcio_IntVec1[j]); - } - - //pl_var.( lc_var->getTrackStates() ); - EVENT::TrackStateVec lcio_seq3 = lc_var->getTrackStates(); - for(unsigned j=0; j<lcio_seq3.size(); j++){ - EVENT::TrackState* lc_locx = lcio_seq3[j]; - std::array<float, 15> tmp_covM; - for(unsigned k=0; k<15; k++){ - tmp_covM[k] = lc_locx->getCovMatrix()[k]; - } - - plcio::TrackState tmp; - tmp.D0 = lc_locx->getD0(); - tmp.Z0 = lc_locx->getZ0(); - tmp.covMatrix = tmp_covM; - tmp.location = lc_locx->getLocation(); - tmp.omega = lc_locx->getOmega(); - tmp.phi = lc_locx->getPhi(); - tmp.referencePoint = FloatThreeFROMConstPtr( lc_locx->getReferencePoint() ); - tmp.tanLambda = lc_locx->getTanLambda(); - pl_var.addTrackState( tmp ); - } - } - - //pl_var.( lc_var->getTracks() ); - for(unsigned i=0; i<lc_col->getNumberOfElements(); i++){ - EVENT::Track* lc_var = (EVENT::Track*)lc_col->getElementAt(i); - EVENT::TrackVec lcio_seq2 = lc_var->getTracks(); - - for(unsigned j=0; j<lcio_seq2.size(); j++){ - EVENT::Track* lc_locx = lcio_seq2[j]; - for(unsigned k=0; k<lc_col->getNumberOfElements(); k++){ - if( lc_locx == lc_col->getElementAt(k) ) - pl_col->at(i).addTrack(pl_col->at(k)); - } - } - } - return pl_col; -} - -podio::CollectionBase* LCIO2Plcio::Convertor_Vertex(EVENT::LCCollection* lc_col){ - plcio::VertexCollection* pl_col = new plcio::VertexCollection(); - - for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::Vertex* lc_var = (EVENT::Vertex*) lc_col->getElementAt(i); - plcio::Vertex pl_var = (plcio::Vertex) pl_col->create(); - - // Quest: data.primary is an int value, set by boolean number; - pl_var.setPrimary( lc_var->isPrimary() ); - pl_var.setChi2( lc_var->getChi2() ); - pl_var.setProbability( lc_var->getProbability() ); - - float plcio_v[3]; - const float* lcio_v = lc_var->getPosition(); - plcio_v[0] = lcio_v[0]; - plcio_v[1] = lcio_v[1]; - plcio_v[2] = lcio_v[2]; - pl_var.setPosition( plcio::FloatThree(plcio_v) ); - - std::vector<float> vec_pra = lc_var->getParameters(); - for( unsigned j=0,M=vec_pra.size(); j<M; j++){ - pl_var.addParameter(vec_pra[j]); - } - - // convert string into int(type code); -// pl_var.setAlgorithmType( lc_var->getAlgorithmType() ); -// pl_var.setCovMatrix( lc_var->() ); -// pl_var.setAssociatedParticle( lc_var->() ); - } - return pl_col; -} - -podio::CollectionBase* LCIO2Plcio::Convertor_TPCHit(EVENT::LCCollection* lc_col){ - plcio::TPCHitCollection* pl_col = new plcio::TPCHitCollection(); - - for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::TPCHit* lc_var = (EVENT::TPCHit*) lc_col->getElementAt(i); - plcio::TPCHit pl_var = (plcio::TPCHit) pl_col->create(); - - pl_var.setCellID(lc_var->getCellID()); - pl_var.setTime(lc_var->getTime()); - pl_var.setCharge(lc_var->getCharge()); - pl_var.setQuality(lc_var->getQuality()); - - for( unsigned j=0,M=lc_var->getNRawDataWords(); j<M; j++){ - pl_var.addRawDataWord(lc_var->getRawDataWord(j)); - } - } - return pl_col; -} - -bool LCIO2Plcio::isReady(const std::string& TypeName){ - if( TypeName == "SimTrackerHit" ){ - std::vector<std::string>::iterator it = find( - vec_Types.begin(), vec_Types.end(), "MCParticle" - ); - if( it != vec_Types.end() ) - return true; - } - return false; -} - -podio::CollectionBase* LCIO2Plcio::Convertor_getPlcio(EVENT::LCCollection* lc_col){ - - podio::CollectionBase* collection(nullptr); - TypeName = lc_col->getTypeName(); - -// lp_info("Converting "+TypeName); - bool ready = true; - if( !ready ){ - lp_info("Not ready yet."); - lp_info("Please put MCParticle firstly in the python file, Please"); - return nullptr; - } - - fptr fp; - if( map_cvt.find(TypeName) == map_cvt.end()){ - lp_info("unrecognized "+TypeName); - }else{ - fp = *map_cvt[TypeName]; - } - - fp = *map_cvt[TypeName]; - collection = fp(lc_col); - -// maintain map<TypeName, CollVec>; - map_cols[TypeName].push_back( - std::pair<EVENT::LCCollection*, podio::CollectionBase*>(lc_col, collection) - ); - -// lp_info("done."); - return collection; -} diff --git a/FWCore/src/components/LCIO2Plcio.h b/FWCore/src/components/LCIO2Plcio.h deleted file mode 100644 index 3729105ce2c7dbf763c15d4524b4bde333b6d7a2..0000000000000000000000000000000000000000 --- a/FWCore/src/components/LCIO2Plcio.h +++ /dev/null @@ -1,108 +0,0 @@ -#ifndef FWCORE_CONVERTOR_H -#define FWCORE_CONVERTOR_H - -// LCIO - -#include <map> -#include <iostream> -#include <string> -#include "lcio.h" -// #include "IO/LCReader.h" -// #include "EVENT/LCCollection.h" -#include "EVENT/Vertex.h" -#include "EVENT/SimTrackerHit.h" -#include "plcio/SimTrackerHit.h" -#include "plcio/SimTrackerHitCollection.h" -#include "EVENT/SimCalorimeterHit.h" -#include "plcio/SimCalorimeterHit.h" -#include "plcio/SimCalorimeterHitCollection.h" -#include "EVENT/MCParticle.h" -#include "plcio/MCParticle.h" -#include "plcio/MCParticleCollection.h" -#include "plcio/VertexCollection.h" -#include "EVENT/TPCHit.h" -#include "plcio/TPCHit.h" -#include "plcio/TPCHitCollection.h" -#include "EVENT/Cluster.h" -#include "plcio/Cluster.h" -#include "plcio/ClusterCollection.h" -#include "EVENT/ParticleID.h" -#include "EVENT/CalorimeterHit.h" -#include "plcio/CalorimeterHit.h" -#include "podio/CollectionIDTable.h" -#include "EVENT/Track.h" -#include "EVENT/TrackerHit.h" -#include "EVENT/TrackState.h" -#include "plcio/Track.h" -#include "plcio/TrackerHit.h" -#include "plcio/TrackCollection.h" -#include "plcio/TrackerHitCollection.h" -#include "EVENT/ReconstructedParticle.h" -#include "plcio/ReconstructedParticle.h" -#include "plcio/ReconstructedParticleCollection.h" -#include "plcio/ParticleID.h" -#include "plcio/ParticleIDCollection.h" - -#include <utility> -// Forward declarations - -/** @class LCIO2Plcio LCIO2Plcio.h - * - * An LCIO2Plcio for Converting from LCCollection to plcio collection; - * - * @author jhZou, gjCao - */ - -// typedef plcio::MCParticleCollection* (*fptr) (EVENT::LCCollection*); -typedef podio::CollectionBase* (*fptr) (EVENT::LCCollection*); -typedef std::vector<std::pair<EVENT::LCCollection*, podio::CollectionBase*>> CollectionsVec; -typedef std::map<std::string, CollectionsVec> CollectionsMap; - -class LCIO2Plcio{ -public: - - /// Standard Constructor - LCIO2Plcio(); - LCIO2Plcio(EVENT::LCCollection*); - - /// Standard Destructor - virtual ~LCIO2Plcio(){} - - void test(){ printf("MYTESTFUC\n"); } - void clear(){ map_cols.clear(); }; - -// plcio::MCParticleCollection* Convertor_getPlcio(EVENT::LCCollection*); - podio::CollectionBase* Convertor_getPlcio(EVENT::LCCollection*); - static podio::CollectionBase* Convertor_MCParticle(EVENT::LCCollection*); - static podio::CollectionBase* Convertor_LCRunHeader(EVENT::LCCollection*); - static podio::CollectionBase* Convertor_SimTrackerHit(EVENT::LCCollection*); - static podio::CollectionBase* Convertor_SimCalorimeterHit(EVENT::LCCollection*); - static podio::CollectionBase* Convertor_Cluster(EVENT::LCCollection*); - static podio::CollectionBase* Convertor_Track(EVENT::LCCollection*); - static podio::CollectionBase* Convertor_TrackerHit(EVENT::LCCollection*); - static podio::CollectionBase* Convertor_TPCHit(EVENT::LCCollection*); - static podio::CollectionBase* Convertor_ReconstructedParticle(EVENT::LCCollection*); - static podio::CollectionBase* Convertor_ParticleID(EVENT::LCCollection*); - - static podio::CollectionBase* Convertor_LCRelation(EVENT::LCCollection*); - static podio::CollectionBase* Convertor_Vertex(EVENT::LCCollection*); - - static void setMCParticle(EVENT::MCParticle*, plcio::MCParticle&); - void setCollName(const std::string &collName){ CollName = collName; }; - - bool isReady(const std::string&); - -private: - std::string TypeName; - static std::string CollName; - // maintain a log vec about data read; - std::vector<std::string> vec_Types; - - // maintain a map from keyword to function pointer. - std::map<std::string, fptr> map_cvt; - static CollectionsMap map_cols; - -// plcio::MCParticleCollection* hitcol_pl; -// EVENT::LCCollection* hitcol_lc; -}; -#endif // CORE_CONVERTOR_H diff --git a/FWCore/src/components/LCIODataSvc.cpp b/FWCore/src/components/LCIODataSvc.cpp deleted file mode 100644 index a807be847902c81973c872851edb2d9785241e6d..0000000000000000000000000000000000000000 --- a/FWCore/src/components/LCIODataSvc.cpp +++ /dev/null @@ -1,212 +0,0 @@ -#include "FWCore/LCIODataSvc.h" -#include "LCIO2Plcio.h" -#include "GaudiKernel/IConversionSvc.h" -#include "GaudiKernel/IEventProcessor.h" -#include "GaudiKernel/ISvcLocator.h" - -#include "IOIMPL/LCFactory.h" -#include "FWCore/DataWrapper.h" -#include "lcio.h" -#include "plcio/MCParticleCollection.h" -#include "plcio/MCParticle.h" -#include "plcio/EventHeaderCollection.h" -#include "EVENT/MCParticle.h" - -#include "TTree.h" - -typedef std::vector<lcio::MCParticle*> MCParticleVec ; - -DECLARE_COMPONENT(LCIODataSvc) -/// Service initialisation -StatusCode LCIODataSvc::initialize() { - // Nothing to do: just call base class initialisation - StatusCode status = DataSvc::initialize(); - ISvcLocator* svc_loc = serviceLocator(); - - // Attach data loader facility - m_cnvSvc = svc_loc->service("EventPersistencySvc"); - status = setDataLoader(m_cnvSvc); - - if ( name() != "EventDataSvc" ) { - service("EventDataSvc", m_pIDP, true); - if ( m_pIDP == nullptr ) { - error() << "Could not get the EventDataSvc instance" << endmsg; - return StatusCode::FAILURE; - } - } - - m_reader = IOIMPL::LCFactory::getInstance()->createLCReader(); - - if (m_filename != "") { - m_filenames.push_back(m_filename); - } - - if (m_filenames.size() > 0) { - m_reader->open(m_filenames[0]); - m_eventMax = m_reader->getNumberOfEvents(); - } - - return status; -} -/// Service reinitialisation -StatusCode LCIODataSvc::reinitialize() { - // Do nothing for this service - return StatusCode::SUCCESS; -} -/// Service finalization -StatusCode LCIODataSvc::finalize() { - m_reader->close(); - delete m_reader; - m_reader = nullptr; - m_cnvSvc = 0; // release - DataSvc::finalize().ignore(); - return StatusCode::SUCCESS; -} - -StatusCode LCIODataSvc::clearStore() { - for (auto& collNamePair : m_collections) { - if (collNamePair.second != nullptr) { - collNamePair.second->clear(); - } - } - for (auto& collNamePair : m_readCollections) { - if (collNamePair.second != nullptr) { - collNamePair.second->clear(); - } - } - DataSvc::clearStore().ignore(); - m_collections.clear(); - m_readCollections.clear(); - return StatusCode::SUCCESS; -} - -void LCIODataSvc::endOfRead() { - if (m_eventMax != -1) { - // m_provider.clearCaches(); - // m_reader.endOfEvent(); - if ( ++m_eventNum >= m_eventMax ) { - if ( ++m_fileIndex < m_filenames.size() ) { // move to next file - m_reader->close(); - m_reader->open( m_filenames[m_fileIndex] ); - m_eventMax += m_reader->getNumberOfEvents(); - } - else { // reach to the end of the file list - info() << "Reached end of file with event " << m_eventMax << endmsg; - IEventProcessor* eventProcessor; - service("ApplicationMgr", eventProcessor); - eventProcessor->stopRun(); - } - } - } - evt = nullptr; -} - -void LCIODataSvc::setCollectionIDs(podio::CollectionIDTable* collectionIds) { - if (m_collectionIDs != nullptr) { - delete m_collectionIDs; - } - m_collectionIDs = collectionIds; -} - -/// Standard Constructor -LCIODataSvc::LCIODataSvc(const std::string& name, ISvcLocator* svc) - : DataSvc(name, svc), m_collectionIDs(new podio::CollectionIDTable()) { - - m_eventDataTree = new TTree("events", "Events tree"); - declareProperty("inputs", m_filenames = {}, "Names of the files to read"); - declareProperty("input", m_filename = "", "Name of the file to read"); - - } - -/// Standard Destructor -LCIODataSvc::~LCIODataSvc() {} - - -StatusCode LCIODataSvc::readCollection(const std::string& collName, int collectionID) { - - StatusCode stat = StatusCode::SUCCESS; - podio::CollectionBase* collection(nullptr); - - if( evt == nullptr ){ - evt = m_reader->readNextEvent(); - cvtor.clear(); - - // basicly set EventHeader; - pl_evtcol = new plcio::EventHeaderCollection(); - plcio::EventHeader evt_header; - evt_header = (plcio::EventHeader) pl_evtcol->create(); - evt_header.setEventNumber( evt->getEventNumber() ); - evt_header.setRunNumber( evt->getRunNumber() ); - evt_header.setTimeStamp( evt->getTimeStamp() ); - evt_header.setDetectorName( evt->getDetectorName() ); - - // wrap event header collection into Data service; - auto wrapper = new DataWrapper<podio::CollectionBase>; - int id = m_collectionIDs->add("EventHeader"); - pl_evtcol->setID(id); - wrapper->setData(pl_evtcol); - - if ( m_pIDP ) { - m_pIDP->registerObject("EventHeader", wrapper); - } - else { - m_readCollections.emplace_back(std::make_pair("EventHeader", pl_evtcol)); - DataSvc::registerObject("EventHeader", wrapper); - } - } - - debug() << "reading collection name: " << collName << "." << endmsg; - EVENT::LCCollection* lc_col; - std::vector<std::string> vec_colns = *evt->getCollectionNames(); - std::vector<std::string>::iterator it = find(vec_colns.begin(), vec_colns.end(), collName); - if( it != vec_colns.end() ){ - lc_col = evt->getCollection(collName); - } - else - return stat; -// debug() << "Got collection: " << collName << "." << endmsg; - - std::string TypeName = lc_col->getTypeName(); -// if( !exist_MCP && (TypeName == "MCParticle") ) exist_MCP = true; -// if( TypeName == "MCParticle" ){ -// if( !exist_MCP ) exist_MCP = true; -// mcpcol_pl = LCIO2Plcio::Core_MCParticle(lc_col); -// LCIO2Plcio::setLCIOMCParticleCollection(mcpcol_lc); -// LCIO2Plcio::setPlcioMCParticleCollection(mcpcol_pl); -// } - cvtor.setCollName(collName); - collection = cvtor.Convertor_getPlcio( lc_col ); - pl_evtcol->at(0)->addCollectionName(collName); - pl_evtcol->at(0)->addCollectionType(TypeName); - - auto wrapper = new DataWrapper<podio::CollectionBase>; - int id = m_collectionIDs->add(collName); - collection->setID(id); - wrapper->setData(collection); - -// info() << "readCollection completed." << endmsg; - - if ( m_pIDP ) { - stat = m_pIDP->registerObject(collName, wrapper); - } - else { - m_readCollections.emplace_back(std::make_pair(collName, collection)); - stat = DataSvc::registerObject(collName, wrapper); - } - return stat; -} - -StatusCode LCIODataSvc::registerObject(const std::string& fullPath, DataObject* pObject) { - DataWrapperBase* wrapper = dynamic_cast<DataWrapperBase*>(pObject); - if (wrapper != nullptr) { - podio::CollectionBase* coll = wrapper->collectionBase(); - if (coll != nullptr) { - size_t pos = fullPath.find_last_of("/"); - std::string shortPath(fullPath.substr(pos + 1, fullPath.length())); - int id = m_collectionIDs->add(shortPath); - coll->setID(id); - m_collections.emplace_back(std::make_pair(shortPath, coll)); - } - } - return DataSvc::registerObject(fullPath, pObject); -} diff --git a/FWCore/src/components/LCIOInput.cpp b/FWCore/src/components/LCIOInput.cpp deleted file mode 100644 index dab645881d2f0afce2407416e5a581bb76ae7c0a..0000000000000000000000000000000000000000 --- a/FWCore/src/components/LCIOInput.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "LCIOInput.h" - -#include "TFile.h" -#include "TROOT.h" - -#include "FWCore/DataWrapper.h" -#include "FWCore/LCIODataSvc.h" - -DECLARE_COMPONENT(LCIOInput) - -LCIOInput::LCIOInput(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) {} - -StatusCode LCIOInput::initialize() { - if (GaudiAlgorithm::initialize().isFailure()) return StatusCode::FAILURE; - - // check whether we have the LCIOEvtSvc active - auto pSvc = service( m_dataSvc ); - m_LCIODataSvc = dynamic_cast<LCIODataSvc*>(pSvc.get()); - if (nullptr == m_LCIODataSvc) return StatusCode::FAILURE; - - auto idTable = m_LCIODataSvc->getCollectionIDs(); - for (auto& name : m_collectionNames) { - debug() << "Finding collection " << name << " in collection registry." << endmsg; -/* - if (!idTable->present(name)) { - error() << "Requested product " << name << " not found." << endmsg; - return StatusCode::FAILURE; - } -*/ - m_collectionIDs.push_back(idTable->add(name)); - } - return StatusCode::SUCCESS; -} - -StatusCode LCIOInput::execute() { - size_t cntr = 0; - // Re-create the collections from ROOT file - for (auto& id : m_collectionIDs) { - const std::string& collName = m_collectionNames.value().at(cntr++); - debug() << "Registering collection to read " << collName << " with id " << id << endmsg; - if (m_LCIODataSvc->readCollection(collName, id).isFailure()) { - return StatusCode::FAILURE; - } - } - // Tell data service that we are done with requested collections - m_LCIODataSvc->endOfRead(); - return StatusCode::SUCCESS; -} - -StatusCode LCIOInput::finalize() { - if (GaudiAlgorithm::finalize().isFailure()) return StatusCode::FAILURE; - return StatusCode::SUCCESS; -} diff --git a/FWCore/src/components/LCIOInput.h b/FWCore/src/components/LCIOInput.h deleted file mode 100644 index 252a504c657af62a40fd4adf3f92a1244572c852..0000000000000000000000000000000000000000 --- a/FWCore/src/components/LCIOInput.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef FWCORE_LCIOINPUT_H -#define FWCORE_LCIOINPUT_H -// Gaaudi -#include "GaudiAlg/GaudiAlgorithm.h" - -// STL -#include <string> -#include <vector> - -// forward declarations -// from FWCore: -class LCIODataSvc; - -/** @class LCIOInput FWCore/components/LCIOInput.h LCIOInput.h - * - * Class that allows to read ROOT files written with LCIOInput - * - * @author J. Lingemann - */ - -class LCIOInput : public GaudiAlgorithm { - -public: - /// Constructor. - LCIOInput(const std::string& name, ISvcLocator* svcLoc); - /// Initialization of LCIOInput. Acquires the data service, opens root file and creates trees. - virtual StatusCode initialize(); - /// Execute. Re-creates collections that are specified to be read and sets references. - virtual StatusCode execute(); - /// Finalize. Closes ROOT file. - virtual StatusCode finalize(); - -private: - /// Name of collections to read. Set by option collections (this is temporary) - Gaudi::Property<std::string> m_dataSvc{ this, "DataSvc", "LCIOInputSvc" }; - Gaudi::Property<std::vector<std::string>> m_collectionNames{this, "collections", {}, "Places of collections to read"}; - /// Collection IDs (retrieved with CollectionIDTable from ROOT file, using collection names) - std::vector<int> m_collectionIDs; - /// Data service: needed to register objects and get collection IDs. Just an observing pointer. - LCIODataSvc* m_LCIODataSvc; -}; - -#endif diff --git a/FWCore/src/components/PodioInput.cpp b/FWCore/src/components/PodioInput.cpp deleted file mode 100644 index f031744cdbe8c27728eeed3356cc8bc030fcf9d5..0000000000000000000000000000000000000000 --- a/FWCore/src/components/PodioInput.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "PodioInput.h" - -#include "TFile.h" -#include "TROOT.h" - -#include "FWCore/DataWrapper.h" -#include "FWCore/PodioDataSvc.h" - -DECLARE_COMPONENT(PodioInput) - -PodioInput::PodioInput(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) {} - -StatusCode PodioInput::initialize() { - if (GaudiAlgorithm::initialize().isFailure()) return StatusCode::FAILURE; - - // check whether we have the PodioEvtSvc active - m_podioDataSvc = dynamic_cast<PodioDataSvc*>(evtSvc().get()); - if (nullptr == m_podioDataSvc) return StatusCode::FAILURE; - - auto idTable = m_podioDataSvc->getCollectionIDs(); - for (auto& name : m_collectionNames) { - debug() << "Finding collection " << name << " in collection registry." << endmsg; - if (!idTable->present(name)) { - error() << "Requested product " << name << " not found." << endmsg; - return StatusCode::FAILURE; - } - m_collectionIDs.push_back(idTable->collectionID(name)); - } - return StatusCode::SUCCESS; -} - -StatusCode PodioInput::execute() { - size_t cntr = 0; - // Re-create the collections from ROOT file - for (auto& id : m_collectionIDs) { - const std::string& collName = m_collectionNames.value().at(cntr++); - debug() << "Registering collection to read " << collName << " with id " << id << endmsg; - if (m_podioDataSvc->readCollection(collName, id).isFailure()) { - return StatusCode::FAILURE; - } - } - // Tell data service that we are done with requested collections - m_podioDataSvc->endOfRead(); - return StatusCode::SUCCESS; -} - -StatusCode PodioInput::finalize() { - if (GaudiAlgorithm::finalize().isFailure()) return StatusCode::FAILURE; - return StatusCode::SUCCESS; -} diff --git a/FWCore/src/components/PodioInput.h b/FWCore/src/components/PodioInput.h deleted file mode 100644 index 42b2157f8bad865a61e333e2a858276de61090fa..0000000000000000000000000000000000000000 --- a/FWCore/src/components/PodioInput.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef FWCORE_PODIOINPUT_H -#define FWCORE_PODIOINPUT_H -// Gaaudi -#include "GaudiAlg/GaudiAlgorithm.h" - -// STL -#include <string> -#include <vector> - -// forward declarations -// from FWCore: -class PodioDataSvc; - -/** @class PodioInput FWCore/components/PodioInput.h PodioInput.h - * - * Class that allows to read ROOT files written with PodioOutput - * - * @author J. Lingemann - */ - -class PodioInput : public GaudiAlgorithm { - -public: - /// Constructor. - PodioInput(const std::string& name, ISvcLocator* svcLoc); - /// Initialization of PodioInput. Acquires the data service, opens root file and creates trees. - virtual StatusCode initialize(); - /// Execute. Re-creates collections that are specified to be read and sets references. - virtual StatusCode execute(); - /// Finalize. Closes ROOT file. - virtual StatusCode finalize(); - -private: - /// Name of collections to read. Set by option collections (this is temporary) - Gaudi::Property<std::vector<std::string>> m_collectionNames{this, "collections", {}, "Places of collections to read"}; - /// Collection IDs (retrieved with CollectionIDTable from ROOT file, using collection names) - std::vector<int> m_collectionIDs; - /// Data service: needed to register objects and get collection IDs. Just an observing pointer. - PodioDataSvc* m_podioDataSvc; -}; - -#endif diff --git a/FWCore/src/components/PodioOutput.cpp b/FWCore/src/components/PodioOutput.cpp deleted file mode 100644 index 26e6e37f6c367ec2a494b01a5606c578678e5de3..0000000000000000000000000000000000000000 --- a/FWCore/src/components/PodioOutput.cpp +++ /dev/null @@ -1,153 +0,0 @@ -#include "PodioOutput.h" -#include "GaudiKernel/IJobOptionsSvc.h" -#include "FWCore/PodioDataSvc.h" -#include "TFile.h" - -DECLARE_COMPONENT(PodioOutput) - -PodioOutput::PodioOutput(const std::string& name, ISvcLocator* svcLoc) - : GaudiAlgorithm(name, svcLoc), m_firstEvent(true) {} - -StatusCode PodioOutput::initialize() { - if (GaudiAlgorithm::initialize().isFailure()) return StatusCode::FAILURE; - - // check whether we have the PodioEvtSvc active - m_podioDataSvc = dynamic_cast<PodioDataSvc*>(evtSvc().get()); - if (0 == m_podioDataSvc) return StatusCode::FAILURE; - - m_file = std::unique_ptr<TFile>(new TFile(m_filename.value().c_str(), "RECREATE", "data file")); - // Both trees are written to the ROOT file and owned by it - // PodioDataSvc has ownership of EventDataTree - m_datatree = m_podioDataSvc->eventDataTree(); - m_metadatatree = new TTree("metadata", "Metadata tree"); - m_switch = KeepDropSwitch(m_outputCommands); - return StatusCode::SUCCESS; -} - -void PodioOutput::resetBranches(const std::vector<std::pair<std::string, podio::CollectionBase*>>& collections, - bool prepare) { - for (auto& collNamePair : collections) { - auto collName = collNamePair.first; - if (m_switch.isOn(collName)) { - // Reconnect branches and collections - m_datatree->SetBranchAddress(collName.c_str(), collNamePair.second->getBufferAddress()); - auto colls = collNamePair.second->referenceCollections(); - if (colls != nullptr) { - int j = 0; - for (auto& c : (*colls)) { - m_datatree->SetBranchAddress((collName + "#" + std::to_string(j)).c_str(), &c); - ++j; - } - } - // vector members - auto vminfo = collNamePair.second->vectorMembers(); - if ( vminfo != nullptr ) { - int j = 0; - for ( auto& c : (*vminfo) ) { - m_datatree->SetBranchAddress((collName+"_"+std::to_string(j)).c_str(), c.second); - ++j; - } - } - } - if (prepare) { - collNamePair.second->prepareForWrite(); - } - } -} - -void PodioOutput::createBranches(const std::vector<std::pair<std::string, podio::CollectionBase*>>& collections, - bool prepare) { - for (auto& collNamePair : collections) { - auto collName = collNamePair.first; - // TODO: we need the class name in a better way - std::string className(typeid(*(collNamePair.second)).name()); - size_t pos = className.find_first_not_of("0123456789"); - className.erase(0, pos); - // demangling the namespace: due to namespace additional characters were introduced: - // e.g. N3fcc18TrackHit - // remove any number+char before the namespace: - pos = className.find_first_of("0123456789"); - size_t pos1 = className.find_first_not_of("0123456789", pos); - className.erase(0, pos1); - // replace any numbers between namespace and class with "::" - pos = className.find_first_of("0123456789"); - pos1 = className.find_first_not_of("0123456789", pos); - className.replace(pos, pos1 - pos, "::"); - - pos = className.find("Collection"); - className.erase(pos, pos + 10); - std::string collClassName = "vector<" + className + "Data>"; - int isOn = 0; - if (m_switch.isOn(collName)) { - isOn = 1; - m_datatree->Branch(collName.c_str(), collClassName.c_str(), collNamePair.second->getBufferAddress()); - // Create branches for collections holding relations - auto colls = collNamePair.second->referenceCollections(); - if (colls != nullptr) { - int j = 0; - for (auto& c : (*colls)) { - m_datatree->Branch((collName + "#" + std::to_string(j)).c_str(), c); - ++j; - } - } - // vector members - auto vminfo = collNamePair.second->vectorMembers(); - if ( vminfo != nullptr ) { - int j = 0; - for ( auto& c : (*vminfo) ) { - std::string typeName = "vector<" + c.first + ">"; - void* add = c.second; - m_datatree->Branch((collName+"_"+std::to_string(j)).c_str(), typeName.c_str(), add); - ++j; - } - } - } - debug() << isOn << " Registering collection " << collClassName << " " << collName.c_str() << " containing type " - << className << endmsg; - if (prepare) { - collNamePair.second->prepareForWrite(); - } - } -} - -StatusCode PodioOutput::execute() { - // for now assume identical content for every event - // register for writing - if (m_firstEvent) { - createBranches(m_podioDataSvc->getCollections(), true); - createBranches(m_podioDataSvc->getReadCollections(), false); - } else { - resetBranches(m_podioDataSvc->getCollections(), true); - resetBranches(m_podioDataSvc->getReadCollections(), false); - } - m_firstEvent = false; - debug() << "Filling DataTree .." << endmsg; - m_datatree->Fill(); - return StatusCode::SUCCESS; -} - -StatusCode PodioOutput::finalize() { - if (GaudiAlgorithm::finalize().isFailure()) return StatusCode::FAILURE; - // retrieve the configuration of the job - // and write it to file as vector of strings - std::vector<std::string> config_data; - auto jobOptionsSvc = service<IJobOptionsSvc>("JobOptionsSvc"); - auto configured_components = jobOptionsSvc->getClients(); - for (const auto& name : configured_components) { - auto properties = jobOptionsSvc->getProperties(name); - std::stringstream config_stream; - for (const auto& property : *properties) { - config_stream << name << " : " << property->name() << " = " << property->toString() << std::endl; - } - config_data.push_back(config_stream.str()); - } - m_metadatatree->Branch("gaudiConfigOptions", &config_data); - - m_metadatatree->Branch("CollectionIDs", m_podioDataSvc->getCollectionIDs()); - m_metadatatree->Fill(); - m_datatree->Write(); - m_file->Write(); - m_file->Close(); - info() << "Data written to: " << m_filename << endmsg; - return StatusCode::SUCCESS; -} diff --git a/FWCore/src/components/PodioOutput.h b/FWCore/src/components/PodioOutput.h deleted file mode 100644 index 2a7de0c06c7a0e54dad03bc641691bf90261d979..0000000000000000000000000000000000000000 --- a/FWCore/src/components/PodioOutput.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef FWCORE_PODIOOUTPUT_H -#define FWCORE_PODIOOUTPUT_H - -#include "FWCore/KeepDropSwitch.h" -#include "GaudiAlg/GaudiAlgorithm.h" -#include "podio/CollectionBase.h" - -#include "TTree.h" - -#include <vector> - -// forward declarations -class TFile; -class PodioDataSvc; - -class PodioOutput : public GaudiAlgorithm { - -public: - /// Constructor. - PodioOutput(const std::string& name, ISvcLocator* svcLoc); - - /// Initialization of PodioOutput. Acquires the data service, creates trees and root file. - virtual StatusCode initialize(); - /// Execute. For the first event creates branches for all collections known to PodioDataSvc and prepares them for - /// writing. For the following events it reconnects the branches with collections and prepares them for write. - virtual StatusCode execute(); - /// Finalize. Writes the meta data tree; writes file and cleans up all ROOT-pointers. - virtual StatusCode finalize(); - -private: - void resetBranches(const std::vector<std::pair<std::string, podio::CollectionBase*>>& collections, bool prepare); - void createBranches(const std::vector<std::pair<std::string, podio::CollectionBase*>>& collections, bool prepare); - /// First event or not - bool m_firstEvent; - /// Root file name the output is written to - Gaudi::Property<std::string> m_filename{this, "filename", "output.root", "Name of the file to create"}; - /// Commands which output is to be kept - Gaudi::Property<std::vector<std::string>> m_outputCommands{ - this, "outputCommands", {"keep *"}, "A set of commands to declare which collections to keep or drop."}; - /// Switch for keeping or dropping outputs - KeepDropSwitch m_switch; - /// Needed for collection ID table - PodioDataSvc* m_podioDataSvc; - /// The actual ROOT file - std::unique_ptr<TFile> m_file; - /// The tree to be filled with collections - TTree* m_datatree; - /// The tree to be filled with meta data - TTree* m_metadatatree; - /// The stored collections - std::vector<podio::CollectionBase*> m_storedCollections; -}; - -#endif