Skip to content

Commit 5214be2

Browse files
authored
Fixed ROOT IO in examples in multi-threaded mode: (#84)
- Fixed MCApplication: - Specify threadRank when creating Root IO Manager on workers - Create Root IO Manager in ReadEvent(), if it does not exist - Fixed read.C macros: - Updated for removal of the MCApplication constructor third parameter (Read/Write opyion) - Removed loading libraries - since Root 6 the libraries have to be loaded separately
1 parent 73a6f4d commit 5214be2

13 files changed

Lines changed: 64 additions & 50 deletions

File tree

examples/A01/read.C

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,15 @@
1010
/// \file A01/read.C
1111
/// \brief Macro for reading the A01 simulated data from Root file
1212

13-
#include "../macro/basiclibs.C"
14-
1513
void read()
1614
{
1715
/// Macro for reading the E03 simulated data from Root file
18-
19-
// Load basic libraries
20-
basiclibs();
21-
22-
// Load this example library
23-
gSystem->Load("libexampleA01");
16+
/// Note that since Root 6 the libraries have to be loaded first
17+
/// via load_g4.C.
2418

2519
// MC application
2620
A01MCApplication* appl
27-
= new A01MCApplication("Example A01", "The Example A01 MC application", kRead);
21+
= new A01MCApplication("Example A01", "The Example A01 MC application",);
2822

2923
for (Int_t i=0; i<5; i++) {
3024
cout << " Event no " << i+1 << ":" << endl;

examples/A01/src/A01MCApplication.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ void A01MCApplication::InitOnWorker()
283283
// cout << "A01MCApplication::InitForWorker " << this << endl;
284284

285285
// Create Root manager
286-
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
286+
Int_t threadRank = 1;
287+
// The real thread rank will be set in MCRootManager
288+
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite, threadRank);
287289
// fRootManager->SetDebug(true);
288290

289291
// Set data to MC
@@ -309,6 +311,10 @@ void A01MCApplication::ReadEvent(Int_t i)
309311
/// Read \em i -th event and print hits.
310312
/// \param i The number of event to be read
311313

314+
if ( ! fRootManager ) {
315+
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kRead);
316+
}
317+
312318
fDriftChamberSD1->Register();
313319
fDriftChamberSD2->Register();
314320
fEmCalorimeterSD->Register();

examples/E02/src/Ex02MCApplication.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ void Ex02MCApplication::InitOnWorker()
212212
// cout << "Ex02MCApplication::InitForWorker " << this << endl;
213213

214214
// Create Root manager
215-
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
215+
Int_t threadRank = 1;
216+
// The real thread rank will be set in MCRootManager
217+
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite, threadRank);
216218
// fRootManager->SetDebug(true);
217219

218220
// Set data to MC

examples/E03/E03a/src/Ex03MCApplication.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ void Ex03MCApplication::InitOnWorker()
247247
// cout << "Ex03MCApplication::InitForWorker " << this << endl;
248248

249249
// Create Root manager
250-
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
250+
Int_t threadRank = 1;
251+
// The real thread rank will be set in MCRootManager
252+
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite, threadRank);
251253
// fRootManager->SetDebug(true);
252254

253255
// Set data to MC
@@ -273,6 +275,10 @@ void Ex03MCApplication::ReadEvent(Int_t i)
273275
/// Read \em i -th event and prints hits.
274276
/// \param i The number of event to be read
275277

278+
if ( ! fRootManager ) {
279+
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kRead);
280+
}
281+
276282
fCalorimeterSD->Register();
277283
RegisterStack();
278284
fRootManager->ReadEvent(i);

examples/E03/E03b/src/Ex03bMCApplication.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ void Ex03bMCApplication::InitOnWorker()
247247
// cout << "Ex03bMCApplication::InitForWorker " << this << endl;
248248

249249
// Create Root manager
250-
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
250+
Int_t threadRank = 1;
251+
// The real thread rank will be set in MCRootManager
252+
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite, threadRank);
251253
// fRootManager->SetDebug(true);
252254

253255
// Set data to MC
@@ -273,6 +275,10 @@ void Ex03bMCApplication::ReadEvent(Int_t i)
273275
/// Read \em i -th event and prints hits.
274276
/// \param i The number of event to be read
275277

278+
if ( ! fRootManager ) {
279+
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kRead);
280+
}
281+
276282
fCalorimeterSD->Register();
277283
RegisterStack();
278284
fRootManager->ReadEvent(i);

examples/E03/E03c/src/Ex03cMCApplication.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,9 @@ void Ex03cMCApplication::InitOnWorker()
393393
// cout << "Ex03cMCApplication::InitForWorker " << this << endl;
394394

395395
// Create Root manager
396-
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
396+
Int_t threadRank = 1;
397+
// The real thread rank will be set in MCRootManager
398+
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite, threadRank);
397399
// fRootManager->SetDebug(true);
398400

399401
// Set data to MC
@@ -419,6 +421,10 @@ void Ex03cMCApplication::ReadEvent(Int_t i)
419421
/// Read \em i -th event and prints hits.
420422
/// \param i The number of event to be read
421423

424+
if ( ! fRootManager ) {
425+
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kRead);
426+
}
427+
422428
fCalorimeterSD->Register();
423429
RegisterStack();
424430
fRootManager->ReadEvent(i);

examples/E03/read.C

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@
1111
/// \file E03/read.C
1212
/// \brief Macro for reading the E03 simulated data from Root file
1313

14-
#include "../macro/basiclibs.C"
15-
1614
void read()
1715
{
1816
/// Macro for reading the E03 simulated data from Root file
19-
20-
// Load basic libraries
21-
basiclibs();
22-
23-
// Load this example library
24-
gSystem->Load("libexample03");
17+
/// Note that since Root 6 the libraries have to be loaded first
18+
/// via load_g4a[b,c].C.
2519

2620
// MC application
2721
Ex03MCApplication* appl
28-
= new Ex03MCApplication("Example03", "The example03 MC application", kRead);
22+
= new Ex03MCApplication("Example03", "The example03 MC application");
2923

3024
for (Int_t i=0; i<5; i++) {
3125
cout << " Event no " << i+1 << ":" << endl;

examples/ExGarfield/read.C

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,15 @@
1010
/// \file ExGarfield/read.C
1111
/// \brief Macro for reading the Garfield simulated data from Root file
1212

13-
#include "../macro/basiclibs.C"
14-
1513
void read()
1614
{
1715
/// Macro for reading the Garfield simulated data from Root file
18-
19-
// Load basic libraries
20-
basiclibs();
21-
22-
// Load Garfield library
23-
gSystem->Load("libGarfield");
24-
25-
// Load this example library
26-
gSystem->Load("libvmc_ExGarfield");
16+
/// Note that since Root 6 the libraries have to be loaded first
17+
/// via load_g4.C.
2718

2819
// MC application
2920
VMC::Garfield::MCApplication* appl
30-
= new VMC::ExGarfield::MCApplication("ExampleGarfield", "The example ExGarfield MC application", kRead);
21+
= new VMC::ExGarfield::MCApplication("ExampleGarfield", "The example ExGarfield MC application");
3122

3223
for (Int_t i=0; i<5; i++) {
3324
cout << " Event no " << i+1 << ":" << endl;

examples/ExGarfield/src/MCApplication.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ ClassImp(VMC::ExGarfield::MCApplication)
224224
// cout << "MCApplication::InitForWorker " << this << endl;
225225

226226
// Create Root manager
227-
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
227+
Int_t threadRank = 1;
228+
// The real thread rank will be set in MCRootManager
229+
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite, threadRank);
228230
// fRootManager->SetDebug(true);
229231

230232
// Set data to MC
@@ -249,6 +251,10 @@ ClassImp(VMC::ExGarfield::MCApplication)
249251
/// Read \em i -th event and prints hits.
250252
/// \param i The number of event to be read
251253

254+
if ( ! fRootManager ) {
255+
fRootManager = new TMCRootManager(GetName(), TMCRootManager::kRead);
256+
}
257+
252258
fSensitiveDetector->Register();
253259
RegisterStack();
254260
fRootManager->ReadEvent(i);

examples/Gflash/read.C

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,15 @@
1010
/// \file Gflash/read.C
1111
/// \brief Macro for reading the Gflash simulated data from Root file
1212

13-
#include "../macro/basiclibs.C"
14-
1513
void read()
1614
{
1715
/// Macro for reading the Gflash simulated data from Root file
18-
19-
// Load basic libraries
20-
basiclibs();
21-
22-
// Load this example library
23-
gSystem->Load("libexampleGflash");
16+
/// Note that since Root 6 the libraries have to be loaded first
17+
/// via load_g4.C.
2418

2519
// MC application
2620
VMC::Gflash::MCApplication* appl
27-
= new VMC::Gflash::MCApplication("ExampleGflash", "The exampleGflash MC application", kRead);
21+
= new VMC::Gflash::MCApplication("ExampleGflash", "The exampleGflash MC application");
2822

2923
for (Int_t i=0; i<5; i++) {
3024
cout << " Event no " << i+1 << ":" << endl;

0 commit comments

Comments
 (0)