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/ITHistSvc.h"
18#include "GaudiKernel/ServiceHandle.h"
19#include "GaudiKernel/IIoComponentMgr.h"
25#include "CoralBase/AttributeList.h"
26#include "CoralBase/AttributeListSpecification.h"
28#include "EventInfo/EventInfo.h"
36#include "TInterpreter.h"
46 : base_class::base_class(name, pSvcLocator),
54 declareProperty(
"OutputName",
m_fileName=
"AANTuple.root");
57 declareProperty(
"ExistDataHeader",
m_existDH=
true);
59 declareProperty(
"LateSchemaWriting",
m_lateSchema=
false);
61 declareProperty(
"Macro",
m_macro=
"");
84 if ( !iomgr->io_register (
this,
85 IIoComponentMgr::IoMode::WRITE,
88 <<
m_fileName <<
"] with the I/O component manager !");
89 return StatusCode::FAILURE;
102 m_attribSpec->extend( name_EventNumber,
"unsigned int" );
120 return StatusCode::SUCCESS;
137 return StatusCode::SUCCESS;
150 std::string curDir = gDirectory->GetPath();
156 gInterpreter->ExecuteMacro(
m_macro.c_str());
158 gDirectory->cd(curDir.c_str());
161 return StatusCode::SUCCESS;
176 std::map<std::string,std::string> inputRefs;
185 StatusCode status = evtStore()->retrieve(beg,ending);
186 if (status.isFailure() || beg==ending)
189 return StatusCode::FAILURE;
193 for (; beg != ending; ++beg)
199 return StatusCode::FAILURE;
209 return StatusCode::FAILURE;
219 std::vector<DataHeaderElement>::const_iterator it =
221 std::vector<DataHeaderElement>::const_iterator itE =
224 for (; it!=itE; ++it)
226 std::string tmpRef = (*it).getToken() != NULL
227 ? (*it).getToken()->toString()
229 inputRefs.insert(std::make_pair(it->getKey(),tmpRef));
230 ATH_MSG_DEBUG (
"Found ref for input header: Key=" << it->getKey()
231 <<
", Ref=" << tmpRef);
242 unsigned int runNumber = 0;
243 unsigned int eventNumber = 0;
247 eventInfo = evtStore()->tryConstRetrieve<
EventInfo>();
252 ATH_CHECK( evtStore()->retrieve(eventInfoX) );
258 runNumber = eventInfo->
event_ID()->run_number();
259 eventNumber = eventInfo->
event_ID()->event_number();
263 newAttr[ name_RunNumber ].setValue( runNumber );
264 newAttr[ name_EventNumber ].setValue( eventNumber );
269 std::map<std::string,std::string>::iterator itRef = inputRefs.begin();
270 std::map<std::string,std::string>::iterator itRefE = inputRefs.end();
271 for (; itRef != itRefE; ++itRef)
273 std::string name = itRef->first +
"_ref";
274 if (extraRefs.end() != std::find(extraRefs.begin(),extraRefs.end(),itRef->first))
276 newAttr[name].setValue(std::string(itRef->second));
277 ATH_MSG_DEBUG (
" Added extra ref to new attribute list - name: "
278 << name <<
" " << itRef->second);
292 catch (std::exception &e)
295 (
"Caught exception from collection add of Pool attributes. "
296 "Message: " << e.what());
297 return StatusCode::FAILURE;
303 return StatusCode::SUCCESS;
310 TDirectory::TContext save;
317 static const std::map<std::string,char> typeDict = {
319 {
"long double",
'D'},
322 {
"unsigned int",
'I'},
324 {
"unsigned long",
'I'},
326 {
"unsigned short",
'S'},
328 {
"unsigned char",
'B'},
335 TDirectory::TContext save;
342 for(coral::AttributeListSpecification::const_iterator iter=
m_attribSpec->begin(); iter!=
m_attribSpec->end(); ++iter)
344 std::string
type =
"/?";
345 type[1] = typeDict.at(iter->typeName());
346 std::string leaflist = iter->name() +
type;
347 m_tree->Branch(iter->name().c_str(),0,leaflist.c_str());
351 std::string leaflist = c_tokenBranchName;
353 m_tree->Branch(c_tokenBranchName,0,leaflist.c_str());
366 itemProxy = evtStore()->proxy(
id, key);
370 return(StatusCode::FAILURE);
374 ATH_MSG_DEBUG (
" found proxy for ("<<
id <<
",\"" << key <<
"\") ");
380 return(StatusCode::FAILURE);
384 IOpaqueAddress* addr = itemProxy->
address();
388 << itemProxy->
clID() <<
" " << itemProxy->
name());
389 return( StatusCode::FAILURE);
396 StatusCode
sc =
m_persSvc->convertAddress(addr, saddr);
400 (
"Could not get string from IOpaqueAddress for clid " <<
id
402 <<
" is BAD_STORAGE_TYPE: "<< (
sc == IConversionSvc::Status::BAD_STORAGE_TYPE));
403 return( StatusCode::FAILURE);
413 ATH_MSG_ERROR (
"Could not get split off token. string address " << saddr);
414 return( StatusCode::FAILURE);
419 return StatusCode::SUCCESS;
426 const std::string&
match,
427 std::string& address_header,
428 std::string& address_data )
const
431 <<
" address : " << address
432 <<
" match : " <<
match);
434 std::string::size_type p1;
436 p1 = address.find(
match );
437 if (p1 != std::string::npos)
439 address_header = address.substr( 0, p1+
match.size());
441 address_data = address.substr( p1+
match.size() );
445 return StatusCode::FAILURE;
450 <<
" address_data : " << address_data);
452 return StatusCode::SUCCESS;
460 coral::AttributeList::const_iterator attIter = attributeList.begin();
461 const TObjArray* branches =
m_tree->GetListOfBranches();
462 std::vector<std::string> tokenStringDump;
464 for (
unsigned int i=0; i<attributeList.size(); ++i)
466 TBranch* branch = (TBranch*)branches->UncheckedAt(i);
468 if (attIter->specification().type() ==
typeid(std::string))
470 const std::string&
str = attIter->data<std::string>();
473 throw std::runtime_error(
"String is too long : RootCollection::pool2Root<std::string>");
475 branch->SetAddress( (
void*)
str.c_str() );
478 else if(attIter->specification().typeName() ==
"Token")
480 tokenStringDump.push_back( attIter->data<std::string>() );
481 branch->SetAddress( (
void*) tokenStringDump.back().c_str() );
486 branch->SetAddress( (
void*)attIter->addressOfData() );
511 return StatusCode::SUCCESS;
519 SmartIF<IAlgorithm> ialg{theAlgMgr->algorithm(name)};
523 return StatusCode::FAILURE;
529 return StatusCode::SUCCESS;
543 const EventContext& ctx = Gaudi::Hive::currentContext();
548 if ( alg->execState(ctx).state() == AlgExecState::State::Done &&
549 ( ! alg->execState(ctx).filterPassed() ) )
572 return StatusCode::SUCCESS;
585 if ( !iomgr->io_hasitem (
this) ) {
586 ATH_MSG_ERROR (
"I/O component mgr does not know about ourselves !");
587 return StatusCode::FAILURE;
591 if ( !iomgr->io_contains (
this,
m_fileName) ) {
593 (
"I/O component mgr does not have any entry about ["<<
m_fileName<<
"]");
594 return StatusCode::SUCCESS;
597 if ( !iomgr->io_retrieve (
this,
m_fileName).isSuccess() ) {
599 return StatusCode::FAILURE;
603 std::vector<std::string> outvec = {
"AANT DATAFILE='" +
m_fileName +
"' OPT='RECREATE'"};
604 josvc->set(
"THistSvc.Output", Gaudi::Utils::toString(outvec));
613 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)
virtual StatusCode execute() override
Working entry point.
void setupTree()
setup Tree
std::string m_treeName
Name of the output tree.
BooleanProperty m_lateSchema
write schema in execute()
AANTupleStream(const std::string &name, ISvcLocator *pSvcLocator)
Standard AANTupleStream Constructor.
virtual ~AANTupleStream()
Standard Destructor.
StatusCode initCollection()
Initialize the output collection.
virtual StatusCode io_reinit() override
callback method to reinitialize the internal state of the component for I/O purposes (e....
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.
virtual StatusCode initialize() override
Initialize AANTupleStream.
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.
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.
std::string m_fileName
Name of the output collection.
virtual StatusCode finalize() override
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
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.
static constexpr CLID ID()