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"
27#include "CoralBase/AttributeList.h"
28#include "CoralBase/AttributeListSpecification.h"
30#include "EventInfo/EventInfo.h"
38#include "TInterpreter.h"
87 if ( !iomgr->io_register (
this,
88 IIoComponentMgr::IoMode::WRITE,
91 <<
m_fileName <<
"] with the I/O component manager !");
92 return StatusCode::FAILURE;
105 m_attribSpec->extend( name_EventNumber,
"unsigned int" );
126 return AthLegacySequence::initialize();
143 return StatusCode::SUCCESS;
156 std::string curDir = gDirectory->GetPath();
162 gInterpreter->ExecuteMacro(
m_macro.c_str());
164 gDirectory->cd(curDir.c_str());
167 return AthLegacySequence::finalize();
184 if (
sc.isFailure() )
190 std::map<std::string,std::string> inputRefs;
199 StatusCode status =
evtStore()->retrieve(beg,ending);
200 if (status.isFailure() || beg==ending)
203 return StatusCode::FAILURE;
207 for (; beg != ending; ++beg)
213 return StatusCode::FAILURE;
223 return StatusCode::FAILURE;
233 std::vector<DataHeaderElement>::const_iterator it =
235 std::vector<DataHeaderElement>::const_iterator itE =
238 for (; it!=itE; ++it)
240 std::string tmpRef = (*it).getToken() != NULL
241 ? (*it).getToken()->toString()
243 inputRefs.insert(std::make_pair(it->getKey(),tmpRef));
244 ATH_MSG_DEBUG (
"Found ref for input header: Key=" << it->getKey()
245 <<
", Ref=" << tmpRef);
256 unsigned int runNumber = 0;
257 unsigned int eventNumber = 0;
272 runNumber = eventInfo->
event_ID()->run_number();
273 eventNumber = eventInfo->
event_ID()->event_number();
277 newAttr[ name_RunNumber ].setValue( runNumber );
278 newAttr[ name_EventNumber ].setValue( eventNumber );
283 std::map<std::string,std::string>::iterator itRef = inputRefs.begin();
284 std::map<std::string,std::string>::iterator itRefE = inputRefs.end();
285 for (; itRef != itRefE; ++itRef)
287 std::string name = itRef->first +
"_ref";
288 if (extraRefs.end() != std::find(extraRefs.begin(),extraRefs.end(),itRef->first))
290 newAttr[name].setValue(std::string(itRef->second));
291 ATH_MSG_DEBUG (
" Added extra ref to new attribute list - name: "
292 << name <<
" " << itRef->second);
306 catch (std::exception &e)
309 (
"Caught exception from collection add of Pool attributes. "
310 "Message: " << e.what());
311 return StatusCode::FAILURE;
317 return StatusCode::SUCCESS;
324 TDirectory::TContext save;
331 static const std::map<std::string,char> typeDict = {
333 {
"long double",
'D'},
336 {
"unsigned int",
'I'},
338 {
"unsigned long",
'I'},
340 {
"unsigned short",
'S'},
342 {
"unsigned char",
'B'},
349 TDirectory::TContext save;
356 for(coral::AttributeListSpecification::const_iterator iter=
m_attribSpec->begin(); iter!=
m_attribSpec->end(); ++iter)
358 std::string
type =
"/?";
359 type[1] = typeDict.at(iter->typeName());
360 std::string leaflist = iter->name() +
type;
361 m_tree->Branch(iter->name().c_str(),0,leaflist.c_str());
365 std::string leaflist = c_tokenBranchName;
367 m_tree->Branch(c_tokenBranchName,0,leaflist.c_str());
380 itemProxy =
evtStore()->proxy(
id, key);
384 return(StatusCode::FAILURE);
388 ATH_MSG_DEBUG (
" found proxy for ("<<
id <<
",\"" << key <<
"\") ");
394 return(StatusCode::FAILURE);
398 IOpaqueAddress* addr = itemProxy->
address();
402 << itemProxy->
clID() <<
" " << itemProxy->
name());
403 return( StatusCode::FAILURE);
410 StatusCode
sc =
m_persSvc->convertAddress(addr, saddr);
414 (
"Could not get string from IOpaqueAddress for clid " <<
id
416 <<
" is BAD_STORAGE_TYPE: "<< (
sc == IConversionSvc::Status::BAD_STORAGE_TYPE));
417 return( StatusCode::FAILURE);
427 ATH_MSG_ERROR (
"Could not get split off token. string address " << saddr);
428 return( StatusCode::FAILURE);
433 return StatusCode::SUCCESS;
440 const std::string&
match,
441 std::string& address_header,
442 std::string& address_data )
const
445 <<
" address : " << address
446 <<
" match : " <<
match);
448 std::string::size_type p1;
450 p1 = address.find(
match );
451 if (p1 != std::string::npos)
453 address_header = address.substr( 0, p1+
match.size());
455 address_data = address.substr( p1+
match.size() );
459 return StatusCode::FAILURE;
464 <<
" address_data : " << address_data);
466 return StatusCode::SUCCESS;
474 coral::AttributeList::const_iterator attIter = attributeList.begin();
475 const TObjArray* branches =
m_tree->GetListOfBranches();
476 std::vector<std::string> tokenStringDump;
478 for (
unsigned int i=0; i<attributeList.size(); ++i)
480 TBranch* branch = (TBranch*)branches->UncheckedAt(i);
482 if (attIter->specification().type() ==
typeid(std::string))
484 const std::string&
str = attIter->data<std::string>();
487 throw std::runtime_error(
"String is too long : RootCollection::pool2Root<std::string>");
489 branch->SetAddress( (
void*)
str.c_str() );
492 else if(attIter->specification().typeName() ==
"Token")
494 tokenStringDump.push_back( attIter->data<std::string>() );
495 branch->SetAddress( (
void*) tokenStringDump.back().c_str() );
500 branch->SetAddress( (
void*)attIter->addressOfData() );
521 StatusCode
sc = StatusCode::SUCCESS;
532 Gaudi::Utils::TypeNameString tn(name);
536 sc = createSubAlgorithm( tn.type(), tn.name(), algo );
540 return StatusCode::FAILURE;
551 StatusCode
sc = StatusCode::SUCCESS;
555 const EventContext& ctx = Gaudi::Hive::currentContext();
562 if (! (*(this->subAlgorithms()))[i]->isEnabled()) continue ;
564 sc = (*(this->subAlgorithms()))[i]->
execute(ctx);
569 return StatusCode::FAILURE;
583 return StatusCode::SUCCESS;
591 SmartIF<IAlgorithm> ialg{theAlgMgr->algorithm(name)};
595 return StatusCode::FAILURE;
601 return StatusCode::SUCCESS;
615 const EventContext& ctx = Gaudi::Hive::currentContext();
620 if ( alg->execState(ctx).state() == AlgExecState::State::Done &&
621 ( ! alg->execState(ctx).filterPassed() ) )
644 return StatusCode::SUCCESS;
657 if ( !iomgr->io_hasitem (
this) ) {
658 ATH_MSG_ERROR (
"I/O component mgr does not know about ourselves !");
659 return StatusCode::FAILURE;
663 if ( !iomgr->io_contains (
this,
m_fileName) ) {
665 (
"I/O component mgr does not have any entry about ["<<
m_fileName<<
"]");
666 return StatusCode::SUCCESS;
669 if ( !iomgr->io_retrieve (
this,
m_fileName).isSuccess() ) {
671 return StatusCode::FAILURE;
675 std::vector<std::string> outvec = {
"AANT DATAFILE='" +
m_fileName +
"' OPT='RECREATE'"};
676 josvc->set(
"THistSvc.Output", Gaudi::Utils::toString(outvec));
685 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.