BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
getSetupList.C
Go to the documentation of this file.
1#include <fstream>
2#include <iostream>
3#include <map>
4#include <sstream>
5#include <stdlib.h>
6#include <string>
7
8// #define SQLITE_OPEN_URI 0x00000040
9// #define SQLITE_VERSION_NUMBER 3005000
10int getSetupList(const char* dbPath = NULL)
11{
12 /* TClass* cl = TClass::GetClass("FairCave");
13 std::cout<<"TClass:"<<cl<<std::endl;
14 FairModule* f_cl = (FairModule*) cl->New();
15 f_cl->SetName("Cave");
16 std::cout<<"FairCave:"<<f_cl->GetName()<<std::endl;
17 */
18 std::ostringstream stringStream;
19 if (dbPath != NULL)
20 stringStream << "sqlite://" << dbPath;
21 else {
22 // the database file is located in the parent directory of its storage given by GEOMPATH
23 TString storagePath = gSystem->Getenv("GEOMPATH");
24 gSystem->ExpandPathName(storagePath);
25 while (storagePath.Length() > 1 && storagePath.EndsWith("/"))
26 storagePath.Chop();
27 stringStream << "sqlite://" << gSystem->GetDirName(storagePath) << "/local.db";
28 }
29 std::cout << stringStream.str().c_str() << std::endl;
30
31 TSQLiteServer db(stringStream.str().c_str()); // TSQLiteServer db("sqlite://test.db");
32 stringStream.str("");
33 stringStream << "select setup_tag,creation_date,author,desc from setup";
34 TSQLResult* resQ = db.Query(stringStream.str().c_str());
35 if (resQ == 0 || resQ->GetRowCount() == 0) {
36 std::cerr << "No setups in selected DB" << std::endl;
37 return -1;
38 }
39
40 std::cout << "Setup list:" << std::endl;
41 std::cout << "--------------------------------------------------------------------" << std::endl;
42 std::cout << "Tag Date Author Description" << std::endl;
43 TSQLRow* row;
44 while ((row = resQ->Next()) != 0) {
45 const char* tag = row->GetField(0);
46 std::cout << tag;
47 int i = 0;
48 for (i = strlen(tag); i < 22; i++)
49 std::cout << " ";
50 const char* date = row->GetField(1);
51 std::cout << date;
52 for (i = strlen(date); i < 15; i++)
53 std::cout << " ";
54 const char* author = row->GetField(2);
55 std::cout << author;
56 for (i = strlen(author); i < 20; i++)
57 std::cout << " ";
58 // if(row->IsValid(3)){
59 try {
60 const char* desc = row->GetField(3);
61 if (desc != 0)
62 std::cout << desc;
63 } catch (...) {}
64 std::cout << std::endl;
65 }
66
67 std::cout << "-----------------------------------------------------------------------------------" << std::endl;
68 db.Close();
69 return 0;
70}
int i
Definition P4_F32vec4.h:22
R__EXTERN TSystem * gSystem
virtual Int_t GetRowCount() const
virtual TSQLRow * Next()=0
virtual const char * GetField(Int_t field)=0
TSQLResult * Query(const char *sql) final
void Close(Option_t *opt="") final
Ssiz_t Length() const
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
TString & Chop()
int getSetupList(const char *dbPath=NULL)