9 #include <MT/LCWriter.h> 10 #include <IMPL/LCRunHeaderImpl.h> 11 #include <UTIL/LCTOOLS.h> 12 #include <EVENT/LCCollection.h> 13 #include <IMPL/LCCollectionVec.h> 55 typedef std::vector< IMPL::LCCollectionVec* >
SubSetVec ;
56 typedef std::shared_ptr<MT::LCWriter>
Writer ;
85 "Name of the LCIO output file",
"outputfile.slcio" } ;
88 "Write mode for output file: WRITE_APPEND, WRITE_NEW or None",
"None" } ;
91 "drops the named collections from the event", {
"TPCHits",
"HCalHits"} } ;
94 "drops all collections of the given type from the event", {
"SimTrackerHit",
"SimCalorimeterHit"} } ;
97 "force keep of the named collections - overrules DropCollectionTypes (and DropCollectionNames)", {
"MyPreciousSimTrackerHits"} } ;
113 setDescription(
"Writes the current event to the specified LCIO outputfile." ) ;
124 _writer = std::make_shared<Writer::element_type>() ;
139 auto rhdr = std::make_unique<IMPL::LCRunHeaderImpl>() ;
143 auto activeSubdets = run->
parameter<std::vector<std::string>>(
"ActiveSubdetectors" ).
value() ;
144 for(
auto &det : activeSubdets ) {
145 rhdr->addActiveSubdetector( det ) ;
147 auto intKeys = run->
parameter<std::vector<std::string>>(
"LCIntKeys" ).
value() ;
148 auto floatKeys = run->
parameter<std::vector<std::string>>(
"LCFloatKeys" ).
value() ;
149 auto strKeys = run->
parameter<std::vector<std::string>>(
"LCStrKeys" ).
value() ;
151 for(
auto &key :
keys ) {
152 if( key ==
"ActiveSubdetectors" ) {
155 if( std::find( intKeys.begin(), intKeys.end(), key ) != intKeys.end() ) {
157 rhdr->parameters().setValues( key, values ) ;
160 if( std::find( floatKeys.begin(), floatKeys.end(), key ) != floatKeys.end() ) {
162 rhdr->parameters().setValues( key, values ) ;
165 if( std::find( strKeys.begin(), strKeys.end(), key ) != strKeys.end() ) {
166 auto values = run->
parameter<std::vector<std::string>>( key ).
value() ;
167 rhdr->parameters().setValues( key, values ) ;
172 _writer->writeRunHeader( rhdr.release() ) ;
179 auto colNames = evt->getCollectionNames() ;
180 std::set<std::string> writeCollections {} ;
182 for(
auto colName : *colNames ) {
183 auto col = evt->getCollection( colName ) ;
184 std::string collectionType = col->getTypeName() ;
197 writeCollections.insert( colName ) ;
199 return writeCollections ;
205 auto lcevent = evt->
event<EVENT::LCEvent>() ;
206 if(
nullptr == lcevent ) {
210 _writer->writeEvent( lcevent.get(), writeCols ) ;
217 log<MESSAGE4>() << std::endl
218 <<
"LCIOOutputProcessor::end() " <<
name()
219 <<
": " <<
_nEvents.load() <<
" events in " <<
_nRuns.load() <<
" runs written to file "
StringVectorParameter _dropCollectionNames
const std::string & name() const
Get the component name.
std::shared_ptr< T > event() const
Get the underlying event to a specific type.
void init()
Open the LCIO outputfile.
std::atomic< int > _nRuns
void setRuntimeOption(ERuntimeOption option, bool value)
Force the runtime option to a given boolean value.
StringParameter _lcioWriteMode
constexpr unsigned long long value(const Flag_t &flag)
StringVectorParameter _dropCollectionTypes
void processEvent(EventStore *evt)
Write every event.
LCIOOutputProcessor & operator=(const LCIOOutputProcessor &)=delete
std::vector< IMPL::LCCollectionVec *> SubSetVec
#define MARLINMT_DECLARE_PROCESSOR(Class)
void setDescription(const std::string &desc)
Set the component description.
std::set< std::string > getWriteCollections(EVENT::LCEvent *evt) const
static void abort(const Processor *const proc, const std::string &reason)
Abort program execution properly.
void end()
Close outputfile.
StringParameter _lcioOutputFile
Whether the processor has to be executed in a critical section.
Default output processor.
T get() const
Get the parameter value.
void processRunHeader(RunHeader *run)
Write every run header.
StringVectorParameter _keepCollectionNames
void printParameters() const
Print the component parameters.
std::atomic< int > _nEvents
~LCIOOutputProcessor()=default
std::vector< K > keys(const std::map< K, V > &m)
bool isSet() const
Whether the parameter has been set.
std::shared_ptr< MT::LCWriter > Writer