CFEL - ASG Software Suite  2.5.0
CASS
rootfile_helper.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file rootfile_helper.cpp contains singleton definition for creating root files
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <sstream>
10 #include <algorithm>
11 #include <tr1/functional>
12 
13 #include <QtCore/QMutexLocker>
14 
15 #include <TFile.h>
16 
17 #include "rootfile_helper.h"
18 
19 using namespace cass;
20 using namespace std;
21 using std::tr1::bind;
22 using std::tr1::placeholders::_1;
23 
26 
27 TFile* ROOTFileHelper::create(const std::string& rootfilename, const std::string& options)
28 {
29  QMutexLocker lock(&_mutex);
30  if (_rootfiles.find(rootfilename) == _rootfiles.end())
31  {
32  _rootfiles[rootfilename] = TFile::Open(rootfilename.c_str(),options.c_str());
33  }
34  return _rootfiles[rootfilename];
35 }
36 
37 void ROOTFileHelper::close(TFile *rootfile)
38 {
39  QMutexLocker lock(&_mutex);
40  rootfiles_t::iterator iFile(
41  find_if(_rootfiles.begin(),_rootfiles.end(),
42  std::tr1::bind<bool>(equal_to<TFile*>(),rootfile,
43  std::tr1::bind<TFile*>(&rootfiles_t::value_type::second,_1))));
44  if (iFile != _rootfiles.end())
45  {
46  rootfile->SaveSelf();
47  rootfile->Close();
48  iFile->second = 0;
49  }
50 }
STL namespace.
static TFile * create(const std::string &rootfilename, const std::string &options="RECREATE")
create and return an instance of the rootfile
std::map< std::string, TFile * > rootfiles_t
easier code
static QMutex _mutex
Singleton Mutex to lock write operations.
contains singleton definition for creating root files
static void close(TFile *rootfile)
close root file
static rootfiles_t _rootfiles
container for all the root files