DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CreateDatabaseWidget.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: no.
5
7#include<QFileDialog>
8#include<QMessageBox>
15#include "conffwk/Schema.hpp"
16#include "dbe/Exceptions.hpp"
17#include "dbe/messenger.hpp"
18#include "dbe/FileInfo.hpp"
19
20using namespace dunedaq::conffwk;
21
22dbe::CreateDatabaseWidget::CreateDatabaseWidget ( QWidget * parent, bool Include,
23 const QString & CreateDir )
24 : QWidget ( parent ),
25 StatusBar ( nullptr ),
26 DirToCreate ( CreateDir ),
27 CreateToInclude ( Include )
28{
29 setupUi ( this );
30
31 connect ( SchemaButton, SIGNAL ( clicked() ), this, SLOT ( DefineSchema() ),
32 Qt::UniqueConnection );
33 connect ( SelectButton, SIGNAL ( clicked() ), this, SLOT ( DefineDatabaseFile() ),
34 Qt::UniqueConnection );
35
36 if ( !CreateToInclude )
37 {
38 connect ( CreateDatabaseButton, SIGNAL ( clicked() ), this,
39 SLOT ( CreateDatabaseFileLoad() ),
40 Qt::UniqueConnection );
41 connect ( CreateNoLoadDatabaseButton, SIGNAL ( clicked() ), this,
42 SLOT ( CreateDatabaseFileNoLoad() ), Qt::UniqueConnection );
43 }
44 else
45 {
46 connect ( CreateDatabaseButton, SIGNAL ( clicked() ), this,
47 SLOT ( CreateDatabaseFileInclude() ), Qt::UniqueConnection );
48 CreateDatabaseButton->setText ( "Create Database File" );
49 CreateNoLoadDatabaseButton->hide();
50 }
51
52 StatusBar = new QStatusBar ( StatusFrame );
53 StatusBar->setSizeGripEnabled ( false );
54 StatusFrame->setFrameStyle ( QFrame::NoFrame );
55 StatusLayout->addWidget ( StatusBar );
56
57 StatusBar->setAutoFillBackground ( true );
58 StatusBar->showMessage ( "Select schema files and define new database file!" );
59 CreateDatabaseButton->setDisabled ( true );
60 CreateNoLoadDatabaseButton->setDisabled ( true );
61
62 DatabaseName->setReadOnly ( true );
63}
64
66{
67 auto fd = new QFileDialog ( this, tr ( "Select Schema File" ),
68 DirToCreate.append("./"),
69 tr ( "XML schema files (*.schema.xml)" ) );
70 fd->setFileMode ( QFileDialog::ExistingFile );
71 fd->setViewMode ( QFileDialog::Detail );
72 fd->setAcceptMode ( QFileDialog::AcceptOpen );
73 fd->setSidebarUrls(FileInfo::get_path_urls());
74 if (!(fd->exec() == QDialog::Accepted)) {
75 return;
76 }
77 auto files = fd->selectedFiles();
78 for (auto file: files) {
79 QFileInfo SchemaFile = QFileInfo (file);
80 if ( !SchemaFile.isFile() ) {
82 StatusBar->showMessage ( QString ( "The file is not accessible. Check before usage" ) );
83 }
84 else {
85 if (SchemaFile.fileName().contains("schema")) {
86 schema_list->addItem(FileInfo::prune_path(file));
87 }
88 else {
90 StatusBar->showMessage (
91 QString ( "The file %1 is not a schema file" ).arg ( SchemaFile.absoluteFilePath() ) );
92 }
93 }
94 }
95
96 if (schema_list->count()>0 && !DatabaseName->text().isEmpty()) {
97 CreateDatabaseButton->setEnabled ( true );
98 CreateNoLoadDatabaseButton->setEnabled ( true );
99 }
100}
101
103{
104 QString Dir;
105
106 if ( DirToCreate.isEmpty() )
107 {
108 Dir = QString ( "./NewDatabaseFile.data.xml" );
109 }
110 else
111 {
112 Dir = DirToCreate.append ( "/NewDatabaseFile.data.xml" );
113 }
114
115 auto fd = new QFileDialog ( this, tr("Select new DB File"),
116 Dir,
117 tr("XML data files (*.data.xml)"));
118 fd->setFileMode ( QFileDialog::AnyFile );
119 fd->setViewMode ( QFileDialog::Detail );
120 fd->setAcceptMode ( QFileDialog::AcceptSave );
121 fd->setSidebarUrls(FileInfo::get_path_urls());
122 if (!(fd->exec() == QDialog::Accepted)) {
123 return;
124 }
125 auto files = fd->selectedFiles();
126
127 DatabaseFile = QFileInfo (files.at(0));
128
129 DatabaseName->setText ( DatabaseFile.absoluteFilePath() );
130
131 if (schema_list->count()>0) {
132 CreateDatabaseButton->setEnabled ( true );
133 CreateNoLoadDatabaseButton->setEnabled ( true );
134 }
135}
136
138 std::list<std::string> includes;
139
140 for (int row=0; row<schema_list->count(); ++row) {
141 auto item = schema_list->item(row)->text();
142 includes.push_back(item.toStdString());
143 }
144 return includes;
145}
146
147
149{
150 Configuration db ( "oksconflibs" );
151 try {
152 const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString();
153 db.create ( DatabaseName, get_includes());
154 db.commit();
155
156 QMessageBox::information (
157 0, tr ( "DBE" ),
158 QString ( "Database was created.\nNow the DB will be loaded into the Editor!\n" ),
159 QMessageBox::Ok );
160 emit CanLoadDatabase ( DatabaseFile.absoluteFilePath() );
161 close();
162 }
163 catch ( dunedaq::conffwk::Exception const & ex )
164 {
165 FAIL ( "Database creation failure", dbe::config::errors::parse ( ex ).c_str() );
166 }
167}
168
170{
171 Configuration db ( "oksconflibs" );
172 try {
173 const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString();
174 db.create (DatabaseName, get_includes());
175 db.commit();
176
177 QMessageBox::information ( 0, tr ( "DBE" ), QString ( "The Database was created.\n" ),
178 QMessageBox::Ok );
179 close();
180 }
181 catch ( dunedaq::conffwk::Exception const & ex )
182 {
183 FAIL ( "Database creation failure", dbe::config::errors::parse ( ex ).c_str() );
184 }
185}
186
188{
189 Configuration db ( "oksconflibs" );
190 try {
191 const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString();
192 db.create (DatabaseName, get_includes());
193 db.commit();
194
195 QMessageBox::information ( 0, tr ( "DBE" ), QString ( "The Database was created.\n" ),
196 QMessageBox::Ok );
197 emit CanIncludeDatabase ( DatabaseFile.absoluteFilePath() );
198 close();
199 }
200 catch ( dunedaq::conffwk::Exception const & ex )
201 {
202 FAIL ( "Database creation error", dbe::config::errors::parse ( ex ).c_str() );
203 }
204}
void CanLoadDatabase(const QString &DatabasePath)
std::list< std::string > get_includes()
void CanIncludeDatabase(const QString &DatabasePath)
CreateDatabaseWidget(QWidget *parent=nullptr, bool Include=false, const QString &CreateDir=QString())
static QList< QUrl > get_path_urls()
Definition FileInfo.cpp:91
static QString prune_path(QString file)
Definition FileInfo.cpp:51
static QPalette AlertStatusBarPallete
Defines base class for cache of template objects.
void create(const std::string &at, const std::string &class_name, const std::string &id, ConfigObject &object)
Create new object by class name and object id.
void commit(const std::string &log_message="")
Commit database changes.
conffwk entry point
#define FAIL(...)
std::string const parse(ers::Issue const &)