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