EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairParTSQLIo.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairParTSQLIo.cxx
1 /***************************************
2  * Author: M.Babai (M.Babai@rug.nl) *
3  * License: *
4  * Version: *
5  ***************************************/
6 #include "FairParTSQLIo.h"
7 
8 
9 #include "FairGenericParTSQLIo.h"
10 #include "FairDbMultConnector.h"
11 
13 
14 
18  : FairParIo(),
19  fDefaultDb (-1),
20  fConnections( new FairDbMultConnector() )
21 {
22  std::cout << "\t<DEBUG_INFO>FairParTSQLIo::FairParTSQLIo()\n";
23 }
24 
32  : FairParIo(),
33  fDefaultDb (dbNum),
34  fConnections(new FairDbMultConnector(cons))
35 {
36  std::cout << "\t<DEBUG_INFO>FairParTSQLIo::FairParTSQLIo()12\n";
37 }
38 
43 {
44  disconnect();
45 }
46 
51 {
52  //FairDbMultConnector::Status s;
53  int stat = -100;
54  // Check if at least one DB is connected.
55  if(fDefaultDb != -1) { // Has been specified.
57  if(stat == FairDbMultConnector::kFailed ||
59  std::cerr << "<Error> The connection to specified default Database"
60  << " is not alive.\n";
61  } else { // No selection
62  for(size_t db = 0; db < fConnections->GetNumDb(); ++db) {
63  stat = fConnections->GetStatus(db);
64  }
65  }
66  return kTRUE;
67  //return ( stat == FairDbMultConnector::kOpen);
68 }
69 
74 void FairParTSQLIo::setDetParIo(Text_t* ioName)
75 {
76  if (fConnections) {
77  TObject* io = detParIoList->FindObject(ioName);
78  // If does not exist
79  if(!io) {
80  if (strcmp(ioName, "FairGenericParIo") == 0) {
81  io = new FairGenericParTSQLIo();
82  }
83  if (io) {
84  detParIoList->Add(io);
85  }
86  }
87  }
88 }
89 
94 {
95  if(fConnections) {
96  std::cout << "\n\t<DEBUG> Terminating connection and status = "
98  <<"\n\n";
99  delete fConnections;
100  fConnections = 0;
101  }
102 }
103 
105 {
106  std::cout << "<DEBUG> FairParTSQLIo::activateDetIo()\n";
107  // FIXME FIXME Maybe better to call check first
108  if(!fConnections) {
109  return false;
110  }
112  detParIoList->Add(io);
113  return true;
114 }
115 
122 {
123  std::cout << "<DEBUG> FairParTSQLIo::open()\n";
124  return activateDetIo();
125 }
126 
131 {
132  std::cout << "<DEBUG> FairParTSQLIo::print()\n";
133  if (fConnections) {
134  std::cout << "<INFO> Number of available DBs = " << fConnections->GetNumDb()
135  << std::endl;
136 
137  TIter next(detParIoList);
138  FairDetParIo* io;
139  std::cout << " Number of detector I/Os = " << detParIoList->GetSize()
140  << "\nDetector IO list:\n";
141 
142  while ((io=(FairDetParIo*)next())) {
143  std::cout<<" Name = " << io->GetName();
144  }//while
145  std::cout << std::endl;
146  }//if
147 }//print