diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/CMakeLists.txt b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/CMakeLists.txt index f80aa38c7ab43fc44f7b0c7f3efa4d24bcfcaad1..275633dffd28044ece621b7817efb1c0f275dfda 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/CMakeLists.txt +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/CMakeLists.txt @@ -39,6 +39,7 @@ atlas_add_root_dictionary( ISF_FastCaloSimEvent _dictSource ISF_FastCaloSimEvent/TFCS2DFunction.h ISF_FastCaloSimEvent/TFCS2DFunctionHistogram.h ISF_FastCaloSimEvent/TFCSParametrizationBase.h + ISF_FastCaloSimEvent/TFCSParametrizationPlaceholder.h ISF_FastCaloSimEvent/TFCSParametrization.h ISF_FastCaloSimEvent/TFCSInvisibleParametrization.h ISF_FastCaloSimEvent/TFCSInitWithEkin.h diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/LinkDef.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/LinkDef.h index 0d81d35cc1e9b82246b8a3754532c06a0f638293..e0f2f70b6b11dee541a4a1d5edc36d437efa7c26 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/LinkDef.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/LinkDef.h @@ -17,6 +17,7 @@ #include "ISF_FastCaloSimEvent/TFCS2DFunctionHistogram.h" #include "ISF_FastCaloSimEvent/TFCSParametrizationBase.h" +#include "ISF_FastCaloSimEvent/TFCSParametrizationPlaceholder.h" #include "ISF_FastCaloSimEvent/TFCSParametrization.h" #include "ISF_FastCaloSimEvent/TFCSInvisibleParametrization.h" #include "ISF_FastCaloSimEvent/TFCSInitWithEkin.h" @@ -122,12 +123,13 @@ #pragma link C++ class TFCS2DFunction+; #pragma link C++ class TFCS2DFunctionHistogram+; #pragma link C++ class TFCSParametrizationBase+; +#pragma link C++ class TFCSParametrizationPlaceholder+; #pragma link C++ class TFCSParametrization+; #pragma link C++ class TFCSInvisibleParametrization+; #pragma link C++ class TFCSInitWithEkin+; #pragma link C++ class TFCSEnergyInterpolationLinear+; #pragma link C++ class TFCSEnergyInterpolationSpline+; -#pragma link C++ class TFCSParametrizationChain+; +#pragma link C++ class TFCSParametrizationChain-; #pragma link C++ class TFCSParametrizationBinnedChain+; #pragma link C++ class TFCSParametrizationFloatSelectChain+; #pragma link C++ class TFCSParametrizationPDGIDSelectChain+; diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSParametrizationBase.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSParametrizationBase.h index 5d11ae369f132fcf724d8f6f4d7ea9997c46eabd..5fc382f4a03d876aebeec15e622a63906b7a7dde 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSParametrizationBase.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSParametrizationBase.h @@ -135,6 +135,10 @@ public: ///Print object information. void Print(Option_t *option = "") const; + + ///Deletes all objects from the s_cleanup_list. + ///This list can get filled during streaming operations, where an immediate delete is not possible + static void DoCleanup(); protected: const double init_Ekin_nominal=0; @@ -144,6 +148,8 @@ protected: const double init_eta_min=-100; const double init_eta_max=100; + static std::vector< TFCSParametrizationBase* > s_cleanup_list; + #if defined(__FastCaloSimStandAlone__) public: /// Update outputlevel diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSParametrizationChain.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSParametrizationChain.h index 6d97dc41bc6049cd82d9669b5ec2cdb7830b8112..7f7dc86bb9b4e8100325e66108774fb9ed932b1a 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSParametrizationChain.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSParametrizationChain.h @@ -12,6 +12,15 @@ public: TFCSParametrizationChain(const char* name=nullptr, const char* title=nullptr):TFCSParametrization(name,title) {}; TFCSParametrizationChain(const TFCSParametrizationChain& ref):TFCSParametrization(ref.GetName(),ref.GetTitle()),m_chain(ref.chain()) {}; + ///Status bit for chain persistency + enum FCSSplitChainObjects { + kSplitChainObjects = BIT(16) ///< Set this bit in the TObject bit field if the TFCSParametrizationBase objects in the chain should be written as separate keys into the root file instead of directly writing the objects. This is needed if the sum of all objects in the chain use >1GB of memory, which can't be handeled by TBuffer. Drawback is that identical objects will get stored as multiple instances + }; + + bool SplitChainObjects() const {return TestBit(kSplitChainObjects);}; + void set_SplitChainObjects() {SetBit(kSplitChainObjects);}; + void reset_SplitChainObjects() {ResetBit(kSplitChainObjects);}; + typedef std::vector< TFCSParametrizationBase* > Chain_t; virtual unsigned int size() const override {return m_chain.size();}; virtual const TFCSParametrizationBase* operator[](unsigned int ind) const override {return m_chain[ind];}; @@ -26,6 +35,9 @@ public: virtual FCSReturnCode simulate(TFCSSimulationState& simulstate,const TFCSTruthState* truth, const TFCSExtrapolationState* extrapol) override; void Print(Option_t *option = "") const override; + + //THIS CLASS HAS A CUSTOM STREAMER! CHANGES IN THE VERSIONING OR DATA TYPES NEED TO BE IMPLEMENTED BY HAND! + //void TFCSParametrizationChain::Streamer(TBuffer &R__b) protected: void recalc_pdgid_intersect(); void recalc_pdgid_union(); @@ -46,13 +58,13 @@ protected: private: Chain_t m_chain; - ClassDefOverride(TFCSParametrizationChain,1) //TFCSParametrizationChain + ClassDefOverride(TFCSParametrizationChain,2) //TFCSParametrizationChain }; #include "ISF_FastCaloSimEvent/TFCSParametrizationChain.icc" #if defined(__ROOTCLING__) && defined(__FastCaloSimStandAlone__) -#pragma link C++ class TFCSParametrizationChain+; +#pragma link C++ class TFCSParametrizationChain-; #endif #endif diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSParametrizationPlaceholder.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSParametrizationPlaceholder.h new file mode 100644 index 0000000000000000000000000000000000000000..ccfc30f42b6dbe972455a57e15d23005660dea0a --- /dev/null +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSParametrizationPlaceholder.h @@ -0,0 +1,27 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ISF_FASTCALOSIMEVENT_TFCSParametrizationPlaceholder_h +#define ISF_FASTCALOSIMEVENT_TFCSParametrizationPlaceholder_h + +#include "ISF_FastCaloSimEvent/TFCSParametrizationBase.h" + +class TFCSParametrizationPlaceholder:public TFCSParametrizationBase { +public: + TFCSParametrizationPlaceholder(const char* name=nullptr, const char* title=nullptr):TFCSParametrizationBase(name,title) {}; + + virtual bool is_match_Ekin_bin(int /*Ekin_bin*/) const override {return true;}; + virtual bool is_match_calosample(int /*calosample*/) const override {return true;}; + + virtual FCSReturnCode simulate(TFCSSimulationState& simulstate,const TFCSTruthState* truth, const TFCSExtrapolationState* extrapol) override; +private: + + ClassDefOverride(TFCSParametrizationPlaceholder,1) //TFCSParametrizationPlaceholder +}; + +#if defined(__ROOTCLING__) && defined(__FastCaloSimStandAlone__) +#pragma link C++ class TFCSParametrizationPlaceholder+; +#endif + +#endif diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSParametrizationBase.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSParametrizationBase.cxx index 2b5ec52785edecab66065bca78eb0f43532888b0..772b2a6ddbde2d76dc19dbb2322f0d976475cd01 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSParametrizationBase.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSParametrizationBase.cxx @@ -10,6 +10,7 @@ //============================================= std::set< int > TFCSParametrizationBase::s_no_pdgid; +std::vector< TFCSParametrizationBase* > TFCSParametrizationBase::s_cleanup_list; #ifndef __FastCaloSimStandAlone__ //Initialize only in constructor to make sure the needed services are ready @@ -75,3 +76,14 @@ void TFCSParametrizationBase::Print(Option_t *option) const ATH_MSG_INFO(optprint<<GetTitle()); } } + +void TFCSParametrizationBase::DoCleanup() +{ + //Do cleanup only at the end of read/write operations + for(auto ptr:s_cleanup_list) if(ptr) { + delete ptr; + } + s_cleanup_list.resize(0); +} + + diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSParametrizationChain.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSParametrizationChain.cxx index 0fa9806b76e5fe45af8253935bcf4cf77741b794..69db3e27aff4eebceb36e9a7b6d6521f91c6d5b7 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSParametrizationChain.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSParametrizationChain.cxx @@ -3,8 +3,11 @@ */ #include "ISF_FastCaloSimEvent/TFCSParametrizationChain.h" +#include "ISF_FastCaloSimEvent/TFCSParametrizationPlaceholder.h" #include <algorithm> #include <iterator> +#include "TBuffer.h" +#include "TDirectory.h" //============================================= //======= TFCSParametrizationChain ========= @@ -149,3 +152,97 @@ void TFCSParametrizationChain::Print(Option_t *option) const count++; } } + +void TFCSParametrizationChain::Streamer(TBuffer &R__b) +{ + // Stream an object of class TFCSParametrizationChain. + + UInt_t R__s, R__c; + TDirectory* dir=nullptr; + + if (R__b.IsReading()) { + Version_t R__v = R__b.ReadVersion(&R__s, &R__c); + if (R__v==1) { + R__b.SetBufferOffset(R__s); + R__b.ReadClassBuffer(TFCSParametrizationChain::Class(),this); + } else { + TFCSParametrization::Streamer(R__b); + + TObject* parent=R__b.GetParent(); + if(R__b.GetParent()) { + if(parent->InheritsFrom(TDirectory::Class())) { + dir=(TDirectory*)parent; + } + } + + TFCSParametrizationChain::Chain_t &R__stl = m_chain; + R__stl.clear(); + TClass *R__tcl1 = TFCSParametrizationBase::Class(); + if (R__tcl1==0) { + Error("m_chain streamer","Missing the TClass object for class TFCSParametrizationBase *!"); + return; + } + int R__i, R__n; + R__b >> R__n; + R__stl.reserve(R__n); + for (R__i = 0; R__i < R__n; R__i++) { + TFCSParametrizationBase* R__t; + R__t = (TFCSParametrizationBase*)R__b.ReadObjectAny(R__tcl1); + if(R__t!=nullptr) { + if(R__t->InheritsFrom(TFCSParametrizationPlaceholder::Class())) { + TFCSParametrizationBase* new_R__t=nullptr; + + if(dir) new_R__t=(TFCSParametrizationBase*)dir->Get(R__t->GetName()); + + if(new_R__t) { + delete R__t; + R__t=new_R__t; + } else { + Error("TFCSParametrizationChain::Streamer","Found placeholder object in the parametrization chain, but could not read the real object from the file!"); + } + } + } + R__stl.push_back(R__t); + } + + R__b.CheckByteCount(R__s, R__c, TFCSParametrizationChain::IsA()); + } + } else { + R__c = R__b.WriteVersion(TFCSParametrizationChain::IsA(), kTRUE); + TFCSParametrization::Streamer(R__b); + + if(SplitChainObjects()) { + TObject* parent=R__b.GetParent(); + if(R__b.GetParent()) { + if(parent->InheritsFrom(TDirectory::Class())) { + dir=(TDirectory*)parent; + } + } + } + + TFCSParametrizationChain::Chain_t &R__stl = m_chain; + int R__n=int(R__stl.size()); + R__b << R__n; + if(R__n) { + TFCSParametrizationChain::Chain_t::iterator R__k; + int R__i=0; + for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) { + TFCSParametrizationBase* R__t = *R__k; + TFCSParametrizationBase* new_R__t=nullptr; + if(dir && R__t!=nullptr) { + dir->WriteTObject(R__t); + new_R__t=new TFCSParametrizationPlaceholder(R__t->GetName(),TString("Placeholder for: ")+R__t->GetTitle()); + R__t=new_R__t; + } + R__b << R__t; + + //delete new_R__t only after the end of read/write operations by calling TFCSParametrizationBase::DoCleanup(); + if(new_R__t) s_cleanup_list.push_back(new_R__t); + + ++R__i; + } + } + R__b.SetByteCount(R__c, kTRUE); + } +} + diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSParametrizationPlaceholder.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSParametrizationPlaceholder.cxx new file mode 100644 index 0000000000000000000000000000000000000000..96c1fcea73250463997f34132832cffe83fed992 --- /dev/null +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSParametrizationPlaceholder.cxx @@ -0,0 +1,16 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +*/ + +#include "ISF_FastCaloSimEvent/TFCSParametrizationPlaceholder.h" + +//============================================= +//======= TFCSParametrizationPlaceholder ========= +//============================================= + +FCSReturnCode TFCSParametrizationPlaceholder::simulate(TFCSSimulationState& /*simulstate*/,const TFCSTruthState* /*truth*/, const TFCSExtrapolationState* /*extrapol*/) +{ + ATH_MSG_ERROR("TFCSParametrizationPlaceholder::simulate(). This is a placeholder and should never get called. Likely a problem in the reading of the parametrization file occured and this class was not replaced with the real parametrization"); + return FCSFatal; +} +