12#include "Gaudi/Interfaces/IOptionsSvc.h"
13#include "GaudiKernel/IAlgManager.h"
14#include "GaudiKernel/ISvcLocator.h"
15#include "GaudiKernel/IAddressCreator.h"
16#include "GaudiKernel/IOpaqueAddress.h"
17#include "GaudiKernel/MsgStream.h"
18#include "GaudiKernel/ITHistSvc.h"
19#include "GaudiKernel/TypeNameString.h"
20#include "GaudiKernel/ServiceHandle.h"
21#include "GaudiKernel/IIoComponentMgr.h"
28#include "CoralBase/AttributeList.h"
29#include "CoralBase/AttributeListSpecification.h"
31#include "EventInfo/EventInfo.h"
39#include "TInterpreter.h"
88 if ( !iomgr->io_register (
this,
89 IIoComponentMgr::IoMode::WRITE,
92 <<
m_fileName <<
"] with the I/O component manager !");
93 return StatusCode::FAILURE;
106 m_attribSpec->extend( name_EventNumber,
"unsigned int" );
127 return AthLegacySequence::initialize();
144 return StatusCode::SUCCESS;
157 std::string curDir = gDirectory->GetPath();
163 gInterpreter->ExecuteMacro(
m_macro.c_str());
165 gDirectory->cd(curDir.c_str());
168 return AthLegacySequence::finalize();
185 if (
sc.isFailure() )
191 std::map<std::string,std::string> inputRefs;
200 StatusCode status =
evtStore()->retrieve(beg,ending);
201 if (status.isFailure() || beg==ending)
204 return StatusCode::FAILURE;
208 for (; beg != ending; ++beg)
214 return StatusCode::FAILURE;
224 return StatusCode::FAILURE;
234 std::vector<DataHeaderElement>::const_iterator it =
236 std::vector<DataHeaderElement>::const_iterator itE =
239 for (; it!=itE; ++it)
241 std::string tmpRef = (*it).getToken() != NULL
242 ? (*it).getToken()->toString()
244 inputRefs.insert(std::make_pair(it->getKey(),tmpRef));
245 ATH_MSG_DEBUG (
"Found ref for input header: Key=" << it->getKey()
246 <<
", Ref=" << tmpRef);
257 unsigned int runNumber = 0;
258 unsigned int eventNumber = 0;
273 runNumber = eventInfo->
event_ID()->run_number();
274 eventNumber = eventInfo->
event_ID()->event_number();
278 newAttr[ name_RunNumber ].setValue( runNumber );
279 newAttr[ name_EventNumber ].setValue( eventNumber );
284 std::map<std::string,std::string>::iterator itRef = inputRefs.begin();
285 std::map<std::string,std::string>::iterator itRefE = inputRefs.end();
286 for (; itRef != itRefE; ++itRef)
288 std::string name = itRef->first +
"_ref";
289 if (extraRefs.end() != std::find(extraRefs.begin(),extraRefs.end(),itRef->first))
291 newAttr[name].setValue(std::string(itRef->second));
292 ATH_MSG_DEBUG (
" Added extra ref to new attribute list - name: "
293 << name <<
" " << itRef->second);
307 catch (std::exception &e)
310 (
"Caught exception from collection add of Pool attributes. "
311 "Message: " << e.what());
312 return StatusCode::FAILURE;
318 return StatusCode::SUCCESS;
325 TDirectory::TContext save;
330 for( coral::AttributeListSpecification::const_iterator iter =
m_attribSpec->begin();
332 all.m_layout.push_back( make_pair( iter->name(), iter->typeName() ) );
335 all.Write(c_attributeListLayoutName);
341 static const std::map<std::string,char> typeDict = {
343 {
"long double",
'D'},
346 {
"unsigned int",
'I'},
348 {
"unsigned long",
'I'},
350 {
"unsigned short",
'S'},
352 {
"unsigned char",
'B'},
359 TDirectory::TContext save;
366 for(coral::AttributeListSpecification::const_iterator iter=
m_attribSpec->begin(); iter!=
m_attribSpec->end(); ++iter)
368 std::string
type =
"/?";
369 type[1] = typeDict.at(iter->typeName());
370 std::string leaflist = iter->name() +
type;
371 m_tree->Branch(iter->name().c_str(),0,leaflist.c_str());
375 std::string leaflist = c_tokenBranchName;
377 m_tree->Branch(c_tokenBranchName,0,leaflist.c_str());
390 itemProxy =
evtStore()->proxy(
id, key);
394 return(StatusCode::FAILURE);
398 ATH_MSG_DEBUG (
" found proxy for ("<<
id <<
",\"" << key <<
"\") ");
404 return(StatusCode::FAILURE);
408 IOpaqueAddress* addr = itemProxy->
address();
412 << itemProxy->
clID() <<
" " << itemProxy->
name());
413 return( StatusCode::FAILURE);
420 StatusCode
sc =
m_persSvc->convertAddress(addr, saddr);
424 (
"Could not get string from IOpaqueAddress for clid " <<
id
426 <<
" is BAD_STORAGE_TYPE: "<< (
sc == IConversionSvc::Status::BAD_STORAGE_TYPE));
427 return( StatusCode::FAILURE);
437 ATH_MSG_ERROR (
"Could not get split off token. string address " << saddr);
438 return( StatusCode::FAILURE);
443 return StatusCode::SUCCESS;
450 const std::string&
match,
451 std::string& address_header,
452 std::string& address_data )
const
455 <<
" address : " << address
456 <<
" match : " <<
match);
458 std::string::size_type p1;
460 p1 = address.find(
match );
461 if (p1 != std::string::npos)
463 address_header = address.substr( 0, p1+
match.size());
465 address_data = address.substr( p1+
match.size() );
469 return StatusCode::FAILURE;
474 <<
" address_data : " << address_data);
476 return StatusCode::SUCCESS;
484 coral::AttributeList::const_iterator attIter = attributeList.begin();
485 const TObjArray* branches =
m_tree->GetListOfBranches();
486 std::vector<std::string> tokenStringDump;
488 for (
unsigned int i=0; i<attributeList.size(); ++i)
490 TBranch* branch = (TBranch*)branches->UncheckedAt(i);
492 if (attIter->specification().type() ==
typeid(std::string))
494 const std::string&
str = attIter->data<std::string>();
497 throw std::runtime_error(
"String is too long : RootCollection::pool2Root<std::string>");
499 branch->SetAddress( (
void*)
str.c_str() );
502 else if(attIter->specification().typeName() ==
"Token")
504 tokenStringDump.push_back( attIter->data<std::string>() );
505 branch->SetAddress( (
void*) tokenStringDump.back().c_str() );
510 branch->SetAddress( (
void*)attIter->addressOfData() );
531 StatusCode
sc = StatusCode::SUCCESS;
542 Gaudi::Utils::TypeNameString tn(name);
546 sc = createSubAlgorithm( tn.type(), tn.name(), algo );
550 return StatusCode::FAILURE;
561 StatusCode
sc = StatusCode::SUCCESS;
565 const EventContext& ctx = Gaudi::Hive::currentContext();
572 if (! (*(this->subAlgorithms()))[i]->isEnabled()) continue ;
574 sc = (*(this->subAlgorithms()))[i]->
execute(ctx);
579 return StatusCode::FAILURE;
593 return StatusCode::SUCCESS;
601 SmartIF<IAlgorithm> ialg{theAlgMgr->algorithm(name)};
605 return StatusCode::FAILURE;
611 return StatusCode::SUCCESS;
625 const EventContext& ctx = Gaudi::Hive::currentContext();
630 if ( alg->execState(ctx).state() == AlgExecState::State::Done &&
631 ( ! alg->execState(ctx).filterPassed() ) )
654 return StatusCode::SUCCESS;
667 if ( !iomgr->io_hasitem (
this) ) {
668 ATH_MSG_ERROR (
"I/O component mgr does not know about ourselves !");
669 return StatusCode::FAILURE;
673 if ( !iomgr->io_contains (
this,
m_fileName) ) {
675 (
"I/O component mgr does not have any entry about ["<<
m_fileName<<
"]");
676 return StatusCode::SUCCESS;
679 if ( !iomgr->io_retrieve (
this,
m_fileName).isSuccess() ) {
681 return StatusCode::FAILURE;
685 std::vector<std::string> outvec = {
"AANT DATAFILE='" +
m_fileName +
"' OPT='RECREATE'"};
686 josvc->set(
"THistSvc.Output", Gaudi::Utils::toString(outvec));
695 return StatusCode::SUCCESS;
const boost::regex ref(r_ef)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
uint32_t CLID
The Class ID type.
static void setTree(const std::string &stream, TTree *tree)
void setupTree()
setup Tree
std::string m_treeName
Name of the output tree.
BooleanProperty m_lateSchema
write schema in execute()
virtual StatusCode execute()
Working entry point.
std::vector< std::string > m_membersNames
AANTupleStream(const std::string &name, ISvcLocator *pSvcLocator)
Standard AANTupleStream Constructor.
virtual ~AANTupleStream()
Standard Destructor.
StatusCode io_reinit()
callback method to reinitialize the internal state of the component for I/O purposes (e....
StatusCode initCollection()
Initialize the output collection.
virtual StatusCode initialize()
Initialize AANTupleStream.
bool writeTokenAttrList(const std::string &token, const coral::AttributeList &attributeList)
write Token and AttributeList
bool m_schemaDone
first event
StatusCode getFilters()
get filter alogs
ServiceHandle< IAddressCreator > m_persSvc
Persistency service.
StatusCode splitAddress(const std::string &address, const std::string &match, std::string &address_header, std::string &address_data) const
Split the address to get pool token.
std::vector< IAlgorithm * > m_acceptAlgs
Vector of Algorithms that this stream accepts.
BooleanProperty m_writeInputDH
Flag to signal whether or not to write input data header.
StatusCode initialize_subAlgos()
initialize sub-algos
TBranch * m_tokenBranch
TBranch which contains Token info.
char m_tokenCString[s_maxLengthOfStrings]
StringArrayProperty m_extraRefNames
Vector of extra parent ref names to register in collection.
static const unsigned int s_maxLengthOfStrings
for string branches
std::vector< std::string > m_acceptNames
Vector of names of Algorithms that this stream accepts.
coral::AttributeListSpecification * m_attribSpec
Collection attribute specification.
BooleanProperty m_existDH
Flag to signal whether data header exists.
StatusCode execute_subAlgos()
execute sub-algos
std::string m_fileName
Name of the output collection.
virtual StatusCode finalize()
Terminate AANTupleStream.
StatusCode getRef(CLID id, const std::string &key, std::string &ref)
Get ref from a proxy.
ServiceHandle< ITHistSvc > m_tHistSvc
THistSvc.
std::string m_streamName
Name of Stream.
bool isEventAccepted() const
check filters passed
void writeAttributeListSpecification()
write schema of AttributeList
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
Alias for backward compatibility.
EventID * event_ID()
the unique identification of the event.
a const_iterator facade to DataHandle.
CLID clID() const
Retrieve clid.
virtual const name_type & name() const override final
Retrieve data object key == string.
virtual IOpaqueAddress * address() const override final
Retrieve IOpaqueAddress.
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
bool match(std::string s1, std::string s2)
match the individual directories of two strings
static const std::string c_streamName
static const std::string c_treeName
EventInfo_v1 EventInfo
Definition of the latest event info version.