ATLAS Offline Software
Loading...
Searching...
No Matches
FloatArrayStore.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "GaudiKernel/MsgStream.h"
8#include <iostream>
9
11 std::multimap<int,Identifier> indexmap;
12
13 map_citr itr=m_bufmap.begin();
14 for (;itr!=m_bufmap.end();++itr)
15 indexmap.insert(std::pair<int,Identifier>(std::abs(itr->second),itr->first));
16 std::vector< std::vector<float> > tmp(m_buf);
17 dbg();
18 this->clear();
19 int i(-tmp.size());
20 for (;i<(int)tmp.size();i++){
21 bool first(true);
22 Identifier shared_id;
23 std::multimap<int,Identifier>::iterator pos;
24 for ( pos=indexmap.lower_bound(i); pos!=indexmap.upper_bound(i); ++pos){
25 if (first){
26 first=false;
27 shared_id=pos->second;
28 this->push_back(shared_id,tmp[std::abs(i)]);
29 } else
30 this->share(pos->second,shared_id);
31 }
32 }
33}
34
36 std::cout << "dbg:" << m_bufmap.size() << " " << m_buf.size() << std::endl;
37}
38
39
40std::ostream& operator<<(std::ostream& os, const FloatArrayStore& store){
41 os << store.tag() << std::endl ;
42 // it is a bit of a heck, but the FloatArrayStore doesn't allow for more.
43 // first make an inverse map
44 std::map<int, std::vector<Identifier> > indextoidentmap ;
45 for(auto it : store)
46 indextoidentmap[it.second].push_back(it.first) ;
47 // store the number of lines
48 os << indextoidentmap.size() << std::endl ;
49 // now store all elements, as follows
50 // each line is: #idents ident1 ident2 ...indentN vectorsize element1 element2 ... elementN
51 for( std::map<int, std::vector<Identifier> >::const_iterator it = indextoidentmap.begin() ;
52 it != indextoidentmap.end(); ++it) {
53 os << it->second.size() << " " ;
54 for(auto vit : it->second)
55 os << vit << " " ;
56 const std::vector<float>& data = store[it->second.front()] ;
57 os << data.size() << " " ;
58 for(float vit : data)
59 os << vit << " " ;
60 os << std::endl ;
61 }
62 return os ;
63}
64
65std::istream& operator>>(std::istream& is, FloatArrayStore& store){
66 store.clear() ;
67 std::string tag ;
68 is >> tag ;
69 store = FloatArrayStore(tag) ;
70 std::vector<int> identifiers(0) ;
71 std::vector<float> data(0) ;
72 constexpr int maxLines=2000000;//max 2 million lines
73 constexpr int maxSize=2000000; //max size 2 million
74 int nlines ;
75 is >> nlines ;
76 if ((nlines>=0) and (nlines<maxLines)) {
77 for(int iline = 0; iline <nlines; ++iline) {
78 int size ;
79 is >> size ;
80 if ((size>=0) and (size<maxSize)){
81 identifiers.resize(size) ;
82 for(int i=0; i<size; ++i) is >> (identifiers[i]) ;
83 }
84 else {
85 MsgStream log(Athena::getMessageSvc(), "FloatArrayStore");
86 log << MSG::ERROR << "size of identifier is incorrect" << endmsg;
87 return is;
88 }
89 is >> size ;
90 if ((size>=0) and (size<maxSize)){
91 data.resize(size) ;
92 for(int i=0; i<size; ++i) is >> (data[i]) ;
93 }
94 else {
95 MsgStream log(Athena::getMessageSvc(), "FloatArrayStore");
96 log << MSG::ERROR << "size of data is incorrect" << endmsg;
97 return is;
98 }
99 Identifier reference(identifiers.front()) ;
100 store.push_back( reference, data ) ;
101 std::vector<int>::const_iterator it = identifiers.begin() ;
102 for( ++it; it!= identifiers.end(); ++it) store.share(Identifier(*it),reference) ;
103 }
104 }
105 return is ;
106}
#define endmsg
std::ostream & operator<<(std::ostream &os, const FloatArrayStore &store)
std::istream & operator>>(std::istream &is, FloatArrayStore &store)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
size_t size() const
Number of registered mappings.
class FloatArrayStore Access and manipulate an indexed storage of float vectors
void cleanUp()
remove data with no index pointing to it
void share(const Identifier &ident, const Identifier &referenceIdent)
makes index ident share data with referenceIdent
BufferMap::const_iterator map_citr
void clear()
remove all
BufferMap m_bufmap
The std::map.
void push_back(const Identifier &ident, const std::vector< float > &value)
makes new indices
void dbg() const
print method
Buffer m_buf
The std::vector<float> stored in each second element.
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)