LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CollectionParameterMap.cc
Go to the documentation of this file.
2 #include "EVENT/LCParameters.h"
3 #include "Exceptions.h"
4 #include<sstream>
5 
6 #include <iostream>
7 
8 using namespace EVENT;
9 
10 namespace UTIL{
11 
12  CollectionParameterMap::CollectionParameterMap( const std::string& keyName ,
13  const std::string& valueName,
14  LCCollection* col ) :
15  _keyName( keyName ) ,
16  _valueName( valueName ) ,
17  _col( col ) {
18 
19  init( col ) ;
20 
21  }
22 
24  const std::string& valueName,
25  const LCCollection* col ) :
26  _keyName( keyName ) ,
27  _valueName( valueName ) ,
28  _col( 0 ) { // if const we don't update
29 
30  init( col ) ;
31  }
32 
34 
35  StringVec keys ;
36 
37  col->getParameters().getStringVals( _keyName , keys ) ;
38 
39  IntVec values ;
40 
41  col->getParameters().getIntVals( _valueName , values ) ;
42 
43 
44  // ------ do some checks: -------------------------
45  if( keys.size() != values.size() ) {
46 
47  std::stringstream sstr ;
48 
49  sstr << " CollectionParameterMap::init() - inconsistent parameter sizes for "
50  << _keyName << " [" << keys.size() << "] and "
51  << _valueName << " [" << values.size() << "] " ;
52 
53  throw Exception( sstr.str() ) ;
54  }
55 
56  unsigned nKeys = keys.size() ;
57  for(unsigned i=0;i<nKeys;++i){
58 
59  _map.insert( std::make_pair( keys[i] , values[i] ) ) ;
60  }
61 
62  }
63 
64 
66 
67 
68  if( _col != 0 ){
69 
70  StringVec keys ;
71  IntVec values ;
72 
73  for(map_type::iterator it= _map.begin() ; it!=_map.end() ;++it){
74 
75  keys.push_back( it->first ) ;
76  values.push_back( it->second ) ;
77 
78  // std::cout << " CollectionParameterMap::~CollectionParameterMap - "
79  // << it->first << " mapped to : " << it->second
80  // << std::endl ;
81  }
82 
83  _col->parameters().setValues( _keyName , keys ) ;
84  _col->parameters().setValues( _valueName , values ) ;
85 
86 
87  // std::cout << " CollectionParameterMap::~CollectionParameterMap - "
88  // << " setValues( " << _keyName << " ,...) and " << keys.size()
89  // << " setValues( " << _valueName << " ,...) "<< values.size()
90  // << std::endl ;
91  }
92 
93  }
94 
95 
96 
97 
98 }
Base exception class for LCIO - all other exceptions extend this.
Definition: Exceptions.h:21
T end(T...args)
STL class.
T push_back(T...args)
virtual LCParameters & parameters()=0
Parameters defined for this collection.
~CollectionParameterMap()
Update the collection parameters keyName and valueName when going out of scope.
T str(T...args)
T make_pair(T...args)
virtual void setValues(const std::string &key, const IntVec &values)=0
Set integer values for the given key.
T insert(T...args)
T size(T...args)
virtual StringVec & getStringVals(const std::string &key, StringVec &values) const =0
Adds all string values for the given key to values.
The generic collection used in LCIO.
Definition: LCCollection.h:29
T begin(T...args)
virtual IntVec & getIntVals(const std::string &key, IntVec &values) const =0
Adds all integer values for the given key to values.
virtual const LCParameters & getParameters() const =0
Parameters defined for this collection.
void init(const EVENT::LCCollection *col)