ATLAS Offline Software
Loading...
Searching...
No Matches
VP1Alg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "VP1Algs/VP1Alg.h"
6
7#include "VP1Gui/VP1Gui.h"
9
12
13#include "GaudiKernel/IToolSvc.h"
14#include "GaudiKernel/FileIncident.h"
15#include "GaudiKernel/ServiceHandle.h"
16#include "GaudiKernel/IEvtSelector.h"
17#include "GaudiKernel/IIncidentSvc.h"
18
19#include <vector>
20#include <stdexcept>
21#include <iostream>
22#include <iomanip>
23#include <cstdint> // for uint64_t (unsigned long long)
24#include <cstdlib> //For setenv
25
26
27//____________________________________________________________________
28VP1Alg::VP1Alg(const std::string& name, ISvcLocator* svcLocator):
29 AthAlgorithm(name, svcLocator),
30 m_vp1gui(0)
31{
32
33
34 /*
35 // This is Work In Progress
36 // Those properties are needed in VP1 configurations, which
37 // still need to be migrated to CA.
38 // See the header file for details.
39 //
40 declareProperty("InitiallyLoadedVP1Files",m_initialvp1files);
41 declareProperty("InitialCruiseMode",m_initialCruiseMode="NONE");
42 declareProperty("InitialCruiseModePeriod",m_initialCruiseSeconds=10);
43
44 declareProperty("NoGui",m_noGui=false);
45
46 // **** MF ****
47 declareProperty("MultipleFilesON",m_mfOn=false);
48 declareProperty("MFNumFileLimit",m_mfLimit=10);
49 declareProperty("MFSourceDir",m_mfSourceDir="");
50 declareProperty("MFLocalCopyDir",m_mfLocalCopyDir="");
51 declareProperty("MFAvailableLocalInputDirectories",m_mfAvailableLocalInputDirectories);
52*/
53
54 // Two ways of running in multiple files mode:
55 //
56 // 1) Source is directory on filesystem (e.g. for use in the control room).
57 // * MFSourceDir indicates the directory where files can be found.
58 // * MFLocalCopyDir indicates the temporary directory where
59 // files are copied before we tell pool to get them there.
60 // 2) Source is web directory
61 // * MFSourceDir indicates http url to small text file (to be
62 // parsed by VP1Gui/VP1EvtsOnServerInfo), with a list of
63 // available files (assumed to be in the same dir).
64 // Example value: "http://pcatdwww.cern.ch/atlas-point1/vp1events/fileinfo.txt"
65 // * MFLocalCopyDir has same meaning as before, but this time a
66 // subdirectory of it, "active_downloads", will be used to
67 // download files before they are subsequently moved to
68 // MFLocalCopyDir itself.
69
70 // **** MF ****
71
72 // Pick up patched Coin
73 ::setenv("LCGPATCH_COINMULTISELECT","1",1);
74}
75
76//____________________________________________________________________
80
81//____________________________________________________________________
83{
84 msg(MSG::INFO) << " in initialize() " << endmsg;
85
86 std::vector<std::string>::iterator it, itE = m_initialvp1files.end();
87 for (it = m_initialvp1files.begin();it!=itE;++it) {
88 std::string file = PathResolver::find_file (*it, "DATAPATH");
89 if (file=="")
90 file = PathResolver::find_file (*it+".vp1", "DATAPATH");
91 if (file!="")
92 *it = std::move(file);
93 }
94
95 // use the incident service to register a handler
96 SmartIF<IIncidentSvc> incsvc{service("IncidentSvc")};
97 ATH_CHECK( incsvc.isValid() );
98
99 std::string endfilekey("EndTagFile");
100 incsvc->addListener(this, endfilekey, 0);
101 msg(MSG::DEBUG) << "Added listener on "<<endfilekey << endmsg;
102
103 //Create VP1 gui object and see if it considers settings to be valid.
104 m_vp1gui = new VP1Gui(&(*evtStore()),&(*detStore()),serviceLocator(),toolSvc(),
108 (m_mfOn ? m_mfSourceDir.value() : ""),
109 (m_mfOn ? m_mfLocalCopyDir.value() : ""),
110 m_mfLimit,
111 ( m_mfOn ? m_mfAvailableLocalInputDirectories : Gaudi::Property<std::vector<std::string>>() ) );
112 if (!m_vp1gui->argumentsAreValid()) {
113 delete m_vp1gui;
114 m_vp1gui = 0;
115 exit(1);//Should we do this? It is kind of nice to not have to dig through the logfile to find the failure.
116 return StatusCode::FAILURE;
117 }
118 return StatusCode::SUCCESS;
119}
120
121//____________________________________________________________________
122StatusCode VP1Alg::execute()
123{
124
125 // Here you do everything that needs to be done on every single
126 // events, e.g. read input variables, apply cuts, and fill
127 // histograms and trees, if any.
128
129 msg(MSG::DEBUG) <<" in execute() " << endmsg;
130
131 if (!m_vp1gui)
132 return StatusCode::FAILURE;
133
134 if (!m_noGui&&!m_vp1gui->hasBeenInitialised()) {
135 m_vp1gui->init();//Launch!
136 }
137
138
139
140
141 unsigned int trigType = 0;
142
143 // retrieve the eventInfo object from the event store
144 const xAOD::EventInfo *eventInfo = nullptr;
145 StatusCode status = evtStore()->retrieve (eventInfo, "EventInfo");
146
147 if(status.isSuccess()) {
148 // Get run/event number:
149 const unsigned long long eventNumber = eventInfo->eventNumber();
150 const uint32_t runNumber = eventInfo->runNumber();
151 msg(MSG::DEBUG) << " Got run number = " << runNumber
152 << ", event number = " << eventNumber << endmsg;
153
154 trigType = eventInfo->level1TriggerType();
155
156 // Get time stamp:
157 uint32_t time = eventInfo->timeStamp();//0 means no info.
158
159 if (m_noGui||m_vp1gui->executeNewEvent(runNumber,eventNumber,trigType,time)) {
160 return StatusCode::SUCCESS;
161 } else {
162 msg(MSG::INFO) << " Ending application gracefully." << endmsg;
163 return StatusCode::FAILURE;
164 }
165 return StatusCode::SUCCESS;
166 }
167
168 msg(MSG::DEBUG) << " Unable to retrieve EventInfo from StoreGate... using dummy values" << endmsg;
169
170 if (m_noGui||m_vp1gui->executeNewEvent(999,999,trigType,0)) {
171 return StatusCode::SUCCESS;
172 } else {
173 msg(MSG::INFO) << " Ending application gracefully." << endmsg;
174 return StatusCode::FAILURE;
175 }
176
177 return StatusCode::SUCCESS;
178
179}
180
181//____________________________________________________________________
183{
184 msg(MSG::INFO) <<" in finalize() " << endmsg;
185
186 if (!m_vp1gui)
187 return StatusCode::FAILURE;
188
189 if (!m_noGui)
190 m_vp1gui->cleanup();
191 delete m_vp1gui;
192
193 return StatusCode::SUCCESS;
194}
195
196//____________________________________________________________________
197void VP1Alg::handle(const Incident& inc)
198{
199 msg(MSG::INFO) << "Handling incident '" << inc.type() << "'" << endmsg;
200
201 if (!m_vp1gui) {
202 msg(MSG::INFO) << "Aborting due to null VP1Gui pointer." << endmsg;
203 return;
204 }
205
206 const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
207 if(fileInc == 0) {
208 msg(MSG::WARNING) << " Unable to cast to file incident" << endmsg;
209 return;
210 }
211 else
212 msg(MSG::DEBUG) << " Casting to file incident successful" << endmsg;
213
214 // Locate the EventSelector
215 ServiceHandle<IEvtSelector> pEvtSelector("EventSelector", this->name());
216 StatusCode sc = pEvtSelector.retrieve();
217
218 if(!sc.isSuccess() || 0 == pEvtSelector) {
219 msg(MSG::WARNING) << "Could not find EventSelector" << endmsg;
220 return;
221 }
222 else
223 msg(MSG::DEBUG) << " Got EventSelector" << endmsg;
224
225 IProperty* propertyServer = dynamic_cast<IProperty*>(pEvtSelector.operator->());
226 if (!propertyServer) {
227 msg(MSG::WARNING) << "Could not get propertyServer" << endmsg;
228 return;
229 }
230
231 std::vector<std::string> vect;
232 StringArrayProperty inputCollections("InputCollections", vect);
233
234 sc = propertyServer->getProperty(&inputCollections);
235 if(!sc.isSuccess()) {
236 msg(MSG::INFO) << "Could not get InputCollections property" << endmsg;
237 return;
238 }
239 else
240 msg(MSG::DEBUG) << " Got InputCollections property" << endmsg;
241
242 for (const std::string& s : inputCollections.value()) {
243 if(s != fileInc->fileName())
244 vect.push_back(s);
245 }
246
247 if(m_mfOn) {
248 std::string strNewFileName = m_vp1gui->nextRequestedEventFile();
249
250 if (strNewFileName.empty())
251 return;
252 if (!VP1FileUtilities::fileExistsAndReadable(strNewFileName)) {
253 msg(MSG::WARNING) << " File requested by VP1 does not exists or is not readable: "<<strNewFileName<<". Ending." << endmsg;
254 return;
255 }
256
257 vect.push_back(strNewFileName);
258 msg(MSG::INFO) << " Setting next event file: " << strNewFileName<< endmsg;
259 }
260 else {
261 std::vector<std::string> strNewFileNames = m_vp1gui->userRequestedFiles();
262 for(unsigned i=0; i<strNewFileNames.size(); ++i) {
263 const std::string& strNewFileName = strNewFileNames[i];
264 if (strNewFileName.empty())
265 continue;
266 if (!VP1FileUtilities::fileExistsAndReadable(strNewFileName)) {
267 msg(MSG::WARNING) << " File requested by VP1 does not exists or is not readable: " << strNewFileName << endmsg;
268 continue;
269 }
270 vect.push_back(strNewFileName);
271 msg(MSG::INFO) << " Setting next event file: " << strNewFileName<< endmsg;
272 }
273 }
274
275 StringArrayProperty newInputCollections("InputCollections", vect);
276
277 if(propertyServer->setProperty(newInputCollections)!=StatusCode::SUCCESS)
278 msg(MSG::WARNING) << "Could not set new InputCollections property" << endmsg;
279 else
280 msg(MSG::DEBUG) << " InputCollections property set" << endmsg;
281}
282
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
static Double_t sc
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Gaudi::Property< std::string > m_mfLocalCopyDir
Definition VP1Alg.h:56
Gaudi::Property< int > m_mfLimit
Definition VP1Alg.h:52
Gaudi::Property< bool > m_noGui
Definition VP1Alg.h:68
Gaudi::Property< std::string > m_cruiseInitialMode
Definition VP1Alg.h:61
~VP1Alg()
Definition VP1Alg.cxx:77
virtual StatusCode execute() override
Definition VP1Alg.cxx:122
VP1Gui * m_vp1gui
Definition VP1Alg.h:72
Gaudi::Property< bool > m_mfOn
Definition VP1Alg.h:50
Gaudi::Property< std::vector< std::string > > m_initialvp1files
Definition VP1Alg.h:65
Gaudi::Property< unsigned > m_cruiseInitialUpdateSeconds
Definition VP1Alg.h:63
virtual StatusCode finalize() override
Definition VP1Alg.cxx:182
virtual StatusCode initialize() override
Definition VP1Alg.cxx:82
VP1Alg(const std::string &name, ISvcLocator *pSvcLocator)
Definition VP1Alg.cxx:28
Gaudi::Property< std::vector< std::string > > m_mfAvailableLocalInputDirectories
Definition VP1Alg.h:58
void handle(const Incident &inc) override
Definition VP1Alg.cxx:197
Gaudi::Property< std::string > m_mfSourceDir
Definition VP1Alg.h:54
static bool fileExistsAndReadable(const std::string &)
uint16_t level1TriggerType() const
The Level-1 trigger type.
uint32_t timeStamp() const
POSIX time in seconds from 1970. January 1st.
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
EventInfo_v1 EventInfo
Definition of the latest event info version.
TFile * file