diff --git a/Generators/GeneratorObjectsAthenaPool/cmt/requirements b/Generators/GeneratorObjectsAthenaPool/cmt/requirements new file mode 100755 index 0000000000000000000000000000000000000000..33f0b329c5e2753868176cb7e19771b9c4dcae89 --- /dev/null +++ b/Generators/GeneratorObjectsAthenaPool/cmt/requirements @@ -0,0 +1,29 @@ +package GeneratorObjectsAthenaPool + +author Georgios Stavropoulos <George.Stavropoulos@cern.ch> +author Sebastien Binet <binet@cern.ch> + +use AtlasPolicy AtlasPolicy-* +use AtlasReflex AtlasReflex-* External +use DataModel DataModel-* Control +use AtlasSealCLHEP AtlasSealCLHEP-* Database -no_auto_imports +use AthenaPoolUtilities AthenaPoolUtilities-* Database/AthenaPOOL + +use AtlasHepMC AtlasHepMC-* External +use GeneratorObjects GeneratorObjects-* Generators +use GeneratorObjectsTPCnv GeneratorObjectsTPCnv-* Generators + +branches src share + +# apply_pattern declare_runtime +apply_pattern declare_joboptions files="*.py" + +# +# Create the list of files for which we want to generate a POOL converter +macro genObjAthenaPoolCnv "" +macro_append genObjAthenaPoolCnv "-s=${GeneratorObjects_root}/GeneratorObjects" +macro_append genObjAthenaPoolCnv " HijingEventParams.h" +macro_append genObjAthenaPoolCnv " McEventCollection.h" + +apply_pattern poolcnv files=$(genObjAthenaPoolCnv) + diff --git a/Generators/GeneratorObjectsAthenaPool/doc/mainpage.h b/Generators/GeneratorObjectsAthenaPool/doc/mainpage.h new file mode 100644 index 0000000000000000000000000000000000000000..0d15bd5f381ba8f55cb0fe2cb67ed07727e114f5 --- /dev/null +++ b/Generators/GeneratorObjectsAthenaPool/doc/mainpage.h @@ -0,0 +1,26 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** +@mainpage GeneratorObjectsAthenaPool Package + +The package which defines POOL converters for general Monte-Carlo classes. + +@authors Sebastien Binet, Georgios Stavropoulos, Davide Costanzo + +@section GeneratorObjectsAthenaPoolIntro Introduction + +The MonteCarlo classes (e.g. @c HepMC::GenEvent ) are stored on disk through the so-called POOL persistification technology which insulates client code (Athena) from technology details and provides transparent switch of different storage backends (ROOT, MySQL,...) + +This package provides the needed boilerplate code to use the T/P converters provided by the GeneratorObjectsTPCnv package (see twiki page about Transient/Persistent separation: https://twiki.cern.ch/twiki/bin/view/Atlas/TransientPersistentSeparation) and make them available to the GAUDI framework. + +@section GeneratorObjectsAthenaPoolSeeAlso See also + +You may also be interested in having a look at the GeneratorObjectsTPCnv package which defines and provides various T/P converters for the MonteCarlo classes. + +@htmlinclude used_packages.html + +@include requirements + +*/ diff --git a/Generators/GeneratorObjectsAthenaPool/share/readGenEventFromPool.py b/Generators/GeneratorObjectsAthenaPool/share/readGenEventFromPool.py new file mode 100755 index 0000000000000000000000000000000000000000..a367605d67d67f459fc6d6382ff5cb8c30b651bb --- /dev/null +++ b/Generators/GeneratorObjectsAthenaPool/share/readGenEventFromPool.py @@ -0,0 +1,47 @@ +############################################################### +# +# Job options file +# +#============================================================== +#-------------------------------------------------------------- +# Event related parameters +#-------------------------------------------------------------- +theApp.EvtMax = 5 +#-------------------------------------------------------------- +# Load POOL support +#-------------------------------------------------------------- +import AthenaPoolCnvSvc.ReadAthenaPool +svcMgr.EventSelector.InputCollections = ["mc.event.pool"] + +#-------------------------------------------------------------- +# Private Application Configuration options +#-------------------------------------------------------------- +# Load "user algorithm" +#top algorithms to be run, and the libraries that house them +from AthenaCommon.AlgSequence import AlgSequence +job = AlgSequence() +job += CfgMgr.DumpMC("DumpMC") + +#-------------------------------------------------------------- +# Output options +#-------------------------------------------------------------- +import AthenaPoolCnvSvc.WriteAthenaPool +job += CfgMgr.AthenaOutputStream( + "OutStream", + WritingTool = "AthenaPoolOutputStreamTool" + ) +job.OutStream.ItemList += [ + "EventInfo#*", + "McEventCollection#*" + ] +job.OutStream.OutputFile = "reaccessed.mc.event.pool" + +#-------------------------------------------------------------- +# Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL ) +#-------------------------------------------------------------- +svcMgr.MessageSvc.OutputLevel = 2 +#============================================================== +# +# End of job options file +# +############################################################### diff --git a/Generators/GeneratorObjectsAthenaPool/share/writeGenEventToPool.py b/Generators/GeneratorObjectsAthenaPool/share/writeGenEventToPool.py new file mode 100755 index 0000000000000000000000000000000000000000..7df3a3ff7f16a05779d7a1525a7f36184e368d05 --- /dev/null +++ b/Generators/GeneratorObjectsAthenaPool/share/writeGenEventToPool.py @@ -0,0 +1,60 @@ +############################################################### +# +# Job options file +# +#============================================================== +#-------------------------------------------------------------- +# General Application Configuration options +#-------------------------------------------------------------- +import AthenaCommon.AtlasUnixGeneratorJob + +import AthenaCommon.Constants as Lvl +from AthenaCommon.AppMgr import ServiceMgr as svcMgr +from AthenaCommon.AppMgr import theApp + +#-------------------------------------------------------------- +# Private Application Configuration options +#-------------------------------------------------------------- +from AthenaCommon.AlgSequence import AlgSequence +job = AlgSequence() + +## generator algorithm +job += CfgMgr.Pythia() + +## algorithm to dump GenEvent's content on screen +job += CfgMgr.DumpMC() + +svcMgr.MessageSvc.OutputLevel = Lvl.DEBUG + +#-------------------------------------------------------------- +# Event related parameters +#-------------------------------------------------------------- +svcMgr += CfgMgr.AtRndmGenSvc() +svcMgr.AtRndmGenSvc.Seeds = [ + "PYTHIA 4789899 989240512", "PYTHIA_INIT 820021 2347532" + ] + +Pythia = job.Pythia +Pythia.PythiaCommand = ["pysubs msel 13","pysubs ckin 3 18.","pypars mstp 43 2"] + +# Number of events to be processed (default is 10) +theApp.EvtMax = 5 + +#--------------------------------------------------------------- +# Pool Persistency +#--------------------------------------------------------------- +import AthenaPoolCnvSvc.WriteAthenaPool +job += CfgMgr.AthenaOutputStream( + "OutStream", + WritingTool = "AthenaPoolOutputStreamTool" + ) +job.OutStream.ItemList += [ + "EventInfo#*", + "McEventCollection#*" + ] +job.OutStream.OutputFile = "mc.event.pool" +#============================================================== +# +# End of job options file +# +############################################################### diff --git a/Generators/GeneratorObjectsAthenaPool/src/McEventCollectionCnv.cxx b/Generators/GeneratorObjectsAthenaPool/src/McEventCollectionCnv.cxx new file mode 100755 index 0000000000000000000000000000000000000000..72a4fea7feca93d6c41b4190c242c231cbee61da --- /dev/null +++ b/Generators/GeneratorObjectsAthenaPool/src/McEventCollectionCnv.cxx @@ -0,0 +1,114 @@ +///////////////////////// -*- C++ -*- ///////////////////////////// + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// McEventCollectionCnv.cxx +// Implementation file for class McEventCollectionCnv +// Author: S.Binet<binet@cern.ch> +/////////////////////////////////////////////////////////////////// + +// STL includes + +// Framework includes +#include "GaudiKernel/MsgStream.h" + +// GeneratorObjectsTPCnv includes +#include "GeneratorObjectsTPCnv/McEventCollectionCnv_p1.h" +#include "GeneratorObjectsTPCnv/McEventCollectionCnv_p2.h" +#include "GeneratorObjectsTPCnv/McEventCollectionCnv_p3.h" +#include "GeneratorObjectsTPCnv/McEventCollectionCnv_p4.h" +#include "GeneratorObjectsTPCnv/McEventCollectionCnv_p5.h" + +// GeneratorObjectsAthenaPool includes +#include "McEventCollectionCnv.h" + +/////////////////////////////////////////////////////////////////// +/// Public methods: +/////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////// +/// Const methods: +/////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////// +// Protected methods: +/////////////////////////////////////////////////////////////////// + + +McEventCollection_PERS* +McEventCollectionCnv::createPersistent( McEventCollection* transCont ) +{ + MsgStream msg( msgSvc(), "McEventCollectionCnv" ); + + McEventCollectionCnv_p5 cnv; + McEventCollection_PERS *persObj = cnv.createPersistent( transCont, msg ); + + msg << MSG::DEBUG << "::createPersistent [Success]" << endreq; + return persObj; +} + +McEventCollection* McEventCollectionCnv::createTransient() +{ + MsgStream msg( msgSvc(), "McEventCollectionConverter" ); + + McEventCollection *transObj = 0; + + static pool::Guid tr_guid("6DE62B45-7C72-4539-92F2-3A8E739A4AC3"); + static pool::Guid p1_guid("BF93438C-D1D3-4F1C-8850-EB690AB7C416"); + static pool::Guid p2_guid("851BB1D2-1964-4B0A-B83A-6BD596CFB5E2"); + static pool::Guid p3_guid("6FC41599-64D6-4DB9-973E-9493166F6291"); + static pool::Guid p4_guid("C517102A-94DE-407C-B07F-09BD81F6172E"); + static pool::Guid p5_guid("D52391A4-F951-46BF-A0D5-E407698D2917"); + + // Hook to disable datapool if we are doing pileup + bool isPileup(false); + if(serviceLocator()->existsService("PileUpEventLoopMgr")) { + isPileup=true; + msg << MSG::DEBUG << "Pile run, disable datapool for McEventCollection " << endreq; + } + + if ( compareClassGuid(tr_guid) ) { + + // regular object from before the T/P separation + return poolReadObject<McEventCollection>(); + + } else if ( compareClassGuid(p1_guid) ) { + + // using auto_ptr ensures deletion of the persistent object + std::auto_ptr<McEventCollection_p1> persObj( poolReadObject<McEventCollection_p1>() ); + McEventCollectionCnv_p1 cnv; + transObj = cnv.createTransient( persObj.get(), msg ); + } else if ( compareClassGuid(p2_guid) ) { + + // using auto_ptr ensures deletion of the persistent object + std::auto_ptr<McEventCollection_p2> persObj( poolReadObject<McEventCollection_p2>() ); + McEventCollectionCnv_p2 cnv; + transObj = cnv.createTransient( persObj.get(), msg ); + } else if ( compareClassGuid(p3_guid) ) { + + // using auto_ptr ensures deletion of the persistent object + std::auto_ptr<McEventCollection_p3> persObj( poolReadObject<McEventCollection_p3>() ); + McEventCollectionCnv_p3 cnv; + transObj = cnv.createTransient( persObj.get(), msg ); + } else if ( compareClassGuid(p4_guid) ) { + + // using auto_ptr ensures deletion of the persistent object + std::auto_ptr<McEventCollection_p4> persObj( poolReadObject<McEventCollection_p4>() ); + McEventCollectionCnv_p4 cnv; + if(isPileup) cnv.setPileup(); + transObj = cnv.createTransient( persObj.get(), msg ); + } else if ( compareClassGuid(p5_guid) ) { + + // using auto_ptr ensures deletion of the persistent object + std::auto_ptr<McEventCollection_p5> persObj( poolReadObject<McEventCollection_p5>() ); + McEventCollectionCnv_p5 cnv; + if(isPileup) cnv.setPileup(); + transObj = cnv.createTransient( persObj.get(), msg ); + } else { + throw std::runtime_error("Unsupported persistent version of McEventCollection"); + } + + return transObj; +} diff --git a/Generators/GeneratorObjectsAthenaPool/src/McEventCollectionCnv.h b/Generators/GeneratorObjectsAthenaPool/src/McEventCollectionCnv.h new file mode 100755 index 0000000000000000000000000000000000000000..88dc9efee32b7d878fad1e0101b72e356e01eb99 --- /dev/null +++ b/Generators/GeneratorObjectsAthenaPool/src/McEventCollectionCnv.h @@ -0,0 +1,69 @@ +///////////////////////// -*- C++ -*- ///////////////////////////// + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// McEventCollectionCnv.h +// Header file for class McEventCollectionCnv +// Author: S.Binet<binet@cern.ch> +/////////////////////////////////////////////////////////////////// +#ifndef GENERATOROBJECTSATHENAPOOL_MCEVENTCOLLECTIONCNV_H +#define GENERATOROBJECTSATHENAPOOL_MCEVENTCOLLECTIONCNV_H + +// STL includes + +// HepMC / CLHEP includes +#include "GeneratorObjects/McEventCollection.h" + +// AthenaPoolCnvSvc includes +#include "AthenaPoolCnvSvc/T_AthenaPoolCustomCnv.h" + +// GeneratorObjectsTPCnv includes +#include "GeneratorObjectsTPCnv/McEventCollection_p5.h" + +// Forward declaration + +// the latest persistent representation type of DataCollection: +typedef McEventCollection_p5 McEventCollection_PERS; + +class McEventCollectionCnv: public T_AthenaPoolCustomCnv< + McEventCollection, + McEventCollection_PERS + > + +{ + + // make the factory for this converter our friend + friend class CnvFactory<McEventCollectionCnv>; + + /////////////////////////////////////////////////////////////////// + // Protected methods: + /////////////////////////////////////////////////////////////////// + protected: + + /** Create the converter from the service locator + */ + McEventCollectionCnv(ISvcLocator* svcloc); + + /** Build the persistent representation from the transient one. + */ + virtual McEventCollection_PERS* + createPersistent( McEventCollection* transCont ); + + /** Build the transient representation from a persistent one + */ + virtual McEventCollection* createTransient(); + +}; + +/////////////////////////////////////////////////////////////////// +/// Inline methods: +/////////////////////////////////////////////////////////////////// + +inline McEventCollectionCnv::McEventCollectionCnv( ISvcLocator* svcLocator ) : + T_AthenaPoolCustomCnv<McEventCollection, McEventCollection_PERS>(svcLocator) +{} + +#endif //> GENERATOROBJECTSATHENAPOOL_MCEVENTCOLLECTIONCNV_H +