ATLAS Offline Software
VP1AODSelection.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Header file for class VP1AODSelection //
8 // //
9 // Description: Dialog for the selection of a xAOD file //
10 // //
11 // Author: Sebastian Andreas Merkt (sebastian.andreas.merkt@cern.ch) //
12 // Initial version: November 2017 //
13 // //
15 
16 #include "VP1Gui/VP1AODSelection.h"
17 
18 #include <QPushButton>
19 #include <QGridLayout>
20 #include <QLabel>
21 #include <QComboBox>
22 #include <QFileInfo>
23 
24 #if __GNUC__ >= 14
25 // suppress warning seen in qfutureinterface.h
26 # pragma GCC diagnostic push
27 # pragma GCC diagnostic ignored "-Wtemplate-id-cdtor"
28 #endif
29 #include <QtWidgets>
30 #if __GNUC__ >= 14
31 # pragma GCC diagnostic pop
32 #endif
33 
35 {
36  //Set default dialog size
37  int nWidth = 800;
38  int nHeight = 220;
39  if (parent != NULL)
40  setGeometry(parent->x() + parent->width()/2 - nWidth/2,
41  parent->y() + parent->height()/2 - nHeight/2,
42  nWidth, nHeight);
43  else
44  resize(nWidth, nHeight);
45 
46  //Browse button to select database
47  m_browseButton = new QPushButton(tr("&Browse..."), this);
48  connect(m_browseButton, &QAbstractButton::clicked, this, &VP1AODSelection::on_browseButton_clicked);
49 
50  //Buttonbox to set Open, Cancel buttons
51  m_buttonBox = new QDialogButtonBox(this);
52  m_openButton = m_buttonBox->addButton(tr("&Open"), QDialogButtonBox::AcceptRole);
53  m_cancelButton = m_buttonBox->addButton(tr("&Cancel"),QDialogButtonBox::RejectRole);
54  connect(m_openButton, &QPushButton::clicked, this, &VP1AODSelection::loadDatabase);
55  connect(m_cancelButton, &QPushButton::clicked, this, &VP1AODSelection::reject);
56 
57  //Open QSettings to store path do database
58  QSettings settings("ATLAS", "VP1Light");
59  QString text;
60 
61  //If no xAOD file has been provided via command line argument, the "xaod/path" value is ""
62  if(settings.value("aod/path").toString()==""){
63  m_openButton->setEnabled(false);
64  text = "(*)";
65  } else { //If a xAOD file has been provided show it in the combobox
66  text = settings.value("aod/path").toString();
67  }
68  //Create the combobox
70 
71  //Create the main layout
72  QGridLayout *mainLayout = new QGridLayout(this);
73  mainLayout->addWidget(new QLabel(tr("Select AOD file:")), 0, 0);
74  mainLayout->addWidget(m_directoryComboBox, 1, 0, 1, 2);
75  mainLayout->addWidget(m_browseButton, 1, 4);
76  mainLayout->addWidget(m_buttonBox, 3, 4);
77 
78  m_browseButton->setMinimumWidth(200);
79  m_buttonBox->setMinimumWidth(200);
80  m_browseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
81  m_buttonBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
82 }
83 
84 //Method to create the drop down combobox
85 QComboBox *VP1AODSelection::createComboBox(const QString &text)
86 {
87  QComboBox *comboBox = new QComboBox;
88  comboBox->setMinimumWidth(600);
89  comboBox->setEditable(false);
90  comboBox->addItem(text);
91  comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
92  return comboBox;
93 }
94 
95 //Animate the click
97 {
98  m_openButton->animateClick();
99 }
100 
101 //Open the file selection dialog
103 {
104  m_fileName = QFileDialog::getOpenFileName(this,
105  tr("Select AOD file"), QDir::currentPath(),
106  tr("AOD Files (*)"));
107 
108  // Add the selected file to the combobox
109  if (!m_fileName.isEmpty()) {
110  if (m_directoryComboBox->findText(m_fileName) == -1)
112  m_directoryComboBox->setCurrentIndex(m_directoryComboBox->findText(m_fileName));
113 
114  //When valid a database is selected, enable the Open button to confirm
115  m_openButton->setEnabled(true);
116  }
117 
118 }
119 
120 //Check and Save the settings
122 
123  //Save xAOD path to settings
124  QSettings settings("ATLAS", "VP1Light");
125  settings.setValue("aod/path", m_directoryComboBox->itemText(m_directoryComboBox->currentIndex()));
126 
127  //If the selected xAOD does not exists, go back
128  if (!QFileInfo::exists(m_directoryComboBox->itemText(m_directoryComboBox->currentIndex()))){
129  QMessageBox msgBox;
130  msgBox.setWindowTitle("Virtual Point 1");
131  msgBox.setText("AOD file does not exist. Please choose another file.");
132  msgBox.exec();
133  return;
134  }
135  VP1AODSelection::setResult(1);
137 }
VP1AODSelection::on_browseButton_clicked
void on_browseButton_clicked()
Definition: VP1AODSelection.cxx:102
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
VP1AODSelection::m_cancelButton
QPushButton * m_cancelButton
Definition: VP1AODSelection.h:44
VP1AODSelection::m_browseButton
QPushButton * m_browseButton
Definition: VP1AODSelection.h:42
VP1AODSelection::m_buttonBox
QDialogButtonBox * m_buttonBox
Definition: VP1AODSelection.h:45
VP1AODSelection::animateFindClick
void animateFindClick()
Definition: VP1AODSelection.cxx:96
VP1AODSelection::m_directoryComboBox
QComboBox * m_directoryComboBox
Definition: VP1AODSelection.h:41
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VP1AODSelection::VP1AODSelection
VP1AODSelection(QWidget *parent=0)
Definition: VP1AODSelection.cxx:34
VP1AODSelection::m_fileName
QString m_fileName
Definition: VP1AODSelection.h:40
VP1AODSelection::loadDatabase
void loadDatabase()
Definition: VP1AODSelection.cxx:121
makeTransCanvas.text
text
Definition: makeTransCanvas.py:11
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9
VP1AODSelection.h
VP1AODSelection::createComboBox
QComboBox * createComboBox(const QString &text=QString())
Definition: VP1AODSelection.cxx:85
VP1AODSelection::m_openButton
QPushButton * m_openButton
Definition: VP1AODSelection.h:43