Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PgPostBankWrapperManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PgPostBankWrapperManager.cc
2 #include "PgPostBankWrapper.h"
3 
4 #include <pdbcalbase/PdbBankID.h>
5 
6 #include <phool/phool.h>
7 
8 #include <algorithm>
9 #include <cstdlib>
10 #include <iomanip>
11 #include <iostream>
12 #include <string>
13 
14 //_____________________________________________________________________________
17 {
18  static PgPostBankWrapperManager instance__;
19  return instance__;
20 }
21 
22 //_____________________________________________________________________________
24 {
25  // We simply clear the vector. Does not care about the pointers,
26  // as we are *not* owners.
27  fWrappers.clear();
28 }
29 
30 //_____________________________________________________________________________
32 {
33  WVECTOR::const_iterator it;
34 
35  for (it = fWrappers.begin(); it != fWrappers.end(); ++it)
36  {
37  (*it)->commit();
38  }
39  // Once committed, forget about the registered wrappers.
40  clear();
41  return true;
42 }
43 
44 //_____________________________________________________________________________
46 {
47  WVECTOR::const_iterator it;
48  size_t i = 0;
49 
50  for (it = fWrappers.begin(); it != fWrappers.end(); ++it)
51  {
52  PgPostBankWrapper* wrapper = *it;
53  if (!wrapper)
54  {
55  std::cout << PHWHERE << " invalid wrapper pointer in list, exiting" << std::endl;
56  exit(1);
57  }
58  std::cout << "Wrapper " << std::setw(4) << i
59  << " "
60  << " is " << std::hex << wrapper
61  << " BankID=" << std::dec
62  << wrapper->getBankID().getInternalValue()
63  << " Table=" << wrapper->getTableName()
64  << std::endl;
65  ++i;
66  }
67 }
68 
69 //_____________________________________________________________________________
71 {
72  if (!wrapper)
73  {
74  std::cerr << PHWHERE << "Cannot register a null wrapper!!!"
75  << std::endl;
76  return false;
77  }
78 
79  WVECTOR::const_iterator it =
80  std::find(fWrappers.begin(), fWrappers.end(), wrapper);
81 
82  if (it != fWrappers.end())
83  {
84  std::cerr << PHWHERE << "This wrapper is already registered!!!"
85  << std::endl;
86  return false;
87  }
88  fWrappers.push_back(wrapper);
89  return true;
90 }
91 
92 //_____________________________________________________________________________
94 {
95  if (!wrapper)
96  {
97  std::cerr << PHWHERE << "Cannot unregister a null wrapper!!!"
98  << std::endl;
99  return false;
100  }
101 
102  WVECTOR::iterator it =
103  std::find(fWrappers.begin(), fWrappers.end(), wrapper);
104 
105  if (it != fWrappers.end())
106  {
107  fWrappers.erase(it);
108  return true;
109  }
110  else
111  {
112  // std::cerr << PHWHERE << "This wrapper cannot be unregistered, as it's "
113  // << " not there !!!!"
114  // << std::endl;
115  return false;
116  }
117 }