33 #include "G4SDManager.hh"
34 #include "G4RunManager.hh"
35 #include "G4UnitsTable.hh"
37 #include "G4Threading.hh"
39 #ifdef G4MULTITHREADED
40 #include "G4AutoLock.hh"
41 namespace { G4Mutex buildMutex = G4MUTEX_INITIALIZER; }
52 fRecordOption(record_option),
56 G4SDManager* SDman = G4SDManager::GetSDMpointer();
62 collcaloID = SDman->GetCollectionID(
"CopClusterHits");
80 fBaseName(
"SToGS_Ascii"),
81 fMaxEvents(1900000000),
86 std::ifstream file(conf.data());
87 if ( file.is_open() == false ) {
88 G4cout <<
" ** SToGS::Ascii WARNING ** Cannot open file " << conf <<
", default parameters to be used "<< G4endl;
91 std::string aline; getline(file,aline);
92 while ( file.good() && !file.eof() ) {
94 if ( aline[0] ==
'#' ){
99 std::string key, what, option; std::istringstream decode(aline);
102 if ( key ==
"path:" ) {
105 if ( key ==
"basename:" ) {
108 if ( key ==
"modulo:" ) {
111 if ( key ==
"max_event:" ) {
114 if ( key ==
"record_option:" ) {
144 #ifdef G4MULTITHREADED
145 G4AutoLock lock(&buildMutex);
151 thread_id = G4Threading::G4GetThreadId();
153 std::ostringstream filename;
155 filename << fPathToData <<
"/" << fBaseName <<
"_Thread" << std::setfill(
'0') << std::setw(2) << thread_id
156 <<
"_Run" << std::setw(3) << run_id <<
".root";
158 fRootFile =
new TFile(filename.str().data(),
"UPDATE");
162 #ifdef G4MULTITHREADED
163 G4AutoLock lock(&buildMutex);
168 delete fRootFile; fRootFile = 0x0;
174 G4cout <<
" In BaseROOTAction, Begin of Run " << aRun->GetRunID()
175 <<
", Number of events to be simulated " << aRun->GetNumberOfEventToBeProcessed() << G4endl;
177 OpenFile(aRun->GetRunID());
181 G4cout <<
" In BaseROOTAction, End of Run " << aRun->GetRunID()
182 <<
", Number of simulated events " << aRun->GetNumberOfEvent() << G4endl;
188 G4int evtNb = evt->GetEventID();
189 if ( evtNb % fPrintModulo == 0 ) {
190 G4cout <<
" In BaseROOTAction, Begin of event: " << evtNb << G4endl;
195 G4int evtNb = evt->GetEventID();
196 if ( evtNb % fPrintModulo == 0 ) {
197 G4cout <<
" In BaseROOTAction, End of event: " << evtNb << G4endl;
204 fTreeName(
"SToGSTree"),
205 fTreeTitle(
"Tree produced by SToGS")
208 std::ifstream file(conffile.data());
209 if ( file.is_open() == false ) {
210 G4cout <<
" ** SToGS::BaseROOTTreeAction WARNING ** Cannot open file " << conffile <<
", default parameters to be used "<< G4endl;
213 std::string aline; getline(file,aline);
214 while ( file.good() && !file.eof() ) {
216 if ( aline[0] ==
'#' ){
221 std::string key, what, option; std::istringstream decode(aline); decode.clear();
224 if ( key ==
"tree:" ) {
227 size_t pos_title = aline.find(fTreeName);
228 if ( pos_title != std::string::npos ) {
247 #ifdef G4MULTITHREADED
248 G4AutoLock lock(&buildMutex);
255 thread_id = G4Threading::G4GetThreadId();
258 std::ostringstream filename;
260 filename << fPathToData <<
"/" << fBaseName <<
"_Thread" << std::setfill(
'0') << std::setw(2) << thread_id
261 <<
"_Run" << std::setw(3) << run_id <<
".root";
263 fRootFile =
new TFile(filename.str().data(),
"UPDATE");
264 if ( fRootFile->IsOpen() ) {
265 G4cout <<
" The File " << filename.str() <<
" is open to record data " << G4endl;
267 fTree->DirectoryAutoAdd(fRootFile);
272 #ifdef G4MULTITHREADED
273 G4AutoLock lock(&buildMutex);
277 TFile *current_root = fTree->GetCurrentFile();
278 if ( current_root ) {
279 G4cout <<
" Closing File " << current_root->GetName() <<
" " << G4endl;
280 current_root->Write();
281 fTree->SetDirectory(0x0);
282 delete current_root; fRootFile = 0x0;
285 delete fTree; fTree = 0x0;
G4String fBaseName
base for all the files
BaseROOTAction(G4String conffile="setup/SToGS_root_actions.conf")
BaseROOTTreeAction(G4String conffile="setup/SToGS_root_actions.conf")
virtual void CloseFile()
Make sure ths file is closed properly.
virtual void EndOfRunAction(const G4Run *)
virtual void OpenFile(G4int run_id)
Open the stream depending of the configuration and attach the Tree to the file.
G4int fRecordOption
0 [default] means keep all, 1 only events which gives at least one hit in the full detector ...
virtual void BeginOfRunAction(const G4Run *)
G4int fPrintModulo
to print out status any fPrintModulo events
virtual ~BaseROOTTreeRun()
virtual void EndOfEventAction(const G4Event *)
G4String fPathToData
directory where to output data
This class just print out once a new run begins/ends with the run number and the number of events to ...
G4int fMaxEvents
max numer of event per files ... better to limit because of BaseROOT file could be uged ! ...
virtual void BeginOfEventAction(const G4Event *)
virtual void CloseFile()
Make sure ths file is closed properly.
virtual void OpenFile(G4int run_id)
Just check if there are collected hits in the collection.
virtual ~BaseROOTTreeAction()
BaseROOTTreeRun(G4int record_option=0)
Base class that regroups in the same space all user's hooks. Convenient for sharing similar data...