MpdMiniDstFileSource.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. #include "MpdMiniDstFileSource.h"
  2. #include <FairLogger.h>
  3. #include <FairRootManager.h>
  4. #include <TROOT.h>
  5. #include <TChainElement.h>
  6. #include <TRandom.h>
  7. #include <set>
  8. #include <algorithm>
  9. //_____________________________________________________________________________
  10. MpdMiniDstFileSource::MpdMiniDstFileSource(TFile *f, const char* Title, UInt_t identifier)
  11. : FairSource(),
  12. fInputTitle(Title)
  13. , fRootFile(f)
  14. , fCurrentEntryNr(0)
  15. , fFriendFileList()
  16. , fInputChainList()
  17. , fFriendTypeList()
  18. , fCheckInputBranches()
  19. , fInputLevel()
  20. , fRunIdInfoAll()
  21. , fInChain(0)
  22. , fInTree(0)
  23. , fListFolder(new TObjArray(16))
  24. , fRtdb(FairRuntimeDb::instance())
  25. , fCbmout(0)
  26. , fCbmroot(0)
  27. , fSourceIdentifier(0)
  28. , fNoOfEntries(-1)
  29. , IsInitialized(kFALSE)
  30. , fEvtHeader(0)
  31. , fFileHeader(0)
  32. , fEvtHeaderIsNew(kFALSE)
  33. , fCurrentEntryNo(0)
  34. , fTimeforEntryNo(-1)
  35. , fEventTimeMin(0.)
  36. , fEventTimeMax(0.)
  37. , fEventTime(0.)
  38. , fBeamTime(-1.)
  39. , fGapTime(-1.)
  40. , fEventMeanTime(0.)
  41. , fTimeProb(0)
  42. , fCheckFileLayout(kTRUE) {
  43. if (fRootFile->IsZombie())
  44. Fatal("MpdMiniDstFileSource::MpdMiniDstFileSource", "Error opening the Input file");
  45. }
  46. //_____________________________________________________________________________
  47. MpdMiniDstFileSource::MpdMiniDstFileSource(const TString* RootFileName, const char* Title, UInt_t identifier)
  48. : FairSource()
  49. , fInputTitle(Title)
  50. , fRootFile(0)
  51. , fCurrentEntryNr(0)
  52. , fFriendFileList()
  53. , fInputChainList()
  54. , fFriendTypeList()
  55. , fCheckInputBranches()
  56. , fInputLevel()
  57. , fRunIdInfoAll()
  58. , fInChain(0)
  59. , fInTree(0)
  60. , fListFolder(new TObjArray(16))
  61. , fRtdb(FairRuntimeDb::instance())
  62. , fCbmout(0)
  63. , fCbmroot(0)
  64. , fSourceIdentifier(0)
  65. , fNoOfEntries(-1)
  66. , IsInitialized(kFALSE)
  67. , fEvtHeader(0)
  68. , fFileHeader(0)
  69. , fEvtHeaderIsNew(kFALSE)
  70. , fCurrentEntryNo(0)
  71. , fTimeforEntryNo(-1)
  72. , fEventTimeMin(0.)
  73. , fEventTimeMax(0.)
  74. , fEventTime(0.)
  75. , fBeamTime(-1.)
  76. , fGapTime(-1.)
  77. , fEventMeanTime(0.)
  78. , fTimeProb(0)
  79. , fCheckFileLayout(kTRUE) {
  80. fRootFile = new TFile(RootFileName->Data());
  81. if (fRootFile->IsZombie())
  82. Fatal("MpdMiniDstFileSource::MpdMiniDstFileSource", "Error opening the Input file");
  83. }
  84. //_____________________________________________________________________________
  85. MpdMiniDstFileSource::MpdMiniDstFileSource(const TString RootFileName, const char* Title, UInt_t identifier)
  86. : FairSource()
  87. , fInputTitle(Title)
  88. , fRootFile(0)
  89. , fCurrentEntryNr(0)
  90. , fFriendFileList()
  91. , fInputChainList()
  92. , fFriendTypeList()
  93. , fCheckInputBranches()
  94. , fInputLevel()
  95. , fRunIdInfoAll()
  96. , fInChain(0)
  97. , fInTree(0)
  98. , fListFolder(new TObjArray(16))
  99. , fRtdb(FairRuntimeDb::instance())
  100. , fCbmout(0)
  101. , fCbmroot(0)
  102. , fSourceIdentifier(0)
  103. , fNoOfEntries(-1)
  104. , IsInitialized(kFALSE)
  105. , fEvtHeader(0)
  106. , fFileHeader(0)
  107. , fEvtHeaderIsNew(kFALSE)
  108. , fCurrentEntryNo(0)
  109. , fTimeforEntryNo(-1)
  110. , fEventTimeMin(0.)
  111. , fEventTimeMax(0.)
  112. , fEventTime(0.)
  113. , fBeamTime(-1.)
  114. , fGapTime(-1.)
  115. , fEventMeanTime(0.)
  116. , fTimeProb(0)
  117. , fCheckFileLayout(kTRUE) {
  118. fRootFile = new TFile(RootFileName.Data());
  119. if (fRootFile->IsZombie())
  120. Fatal("MpdMiniDstFileSource::MpdMiniDstFileSource", "Error opening the Input file");
  121. else {
  122. // fInTree = (TTree*) fRootFile->Get("MiniDst");
  123. fInChain = new TChain("MiniDst");
  124. FairRootManager::Instance()->SetInChain(fInChain);
  125. }
  126. }
  127. //_____________________________________________________________________________
  128. MpdMiniDstFileSource::~MpdMiniDstFileSource() {
  129. }
  130. //_____________________________________________________________________________
  131. Bool_t MpdMiniDstFileSource::Init() {
  132. if (IsInitialized) {
  133. LOG(INFO) << "MpdMiniDstFileSource already initialized";
  134. return kTRUE;
  135. }
  136. if (!fInChain) {
  137. fInChain = new TChain(FairRootManager::GetTreeName(), "/cbmroot");
  138. LOG(DEBUG) << "MpdMiniDstFileSource::Init() chain created";
  139. FairRootManager::Instance()->SetInChain(fInChain);
  140. }
  141. fInChain->Add(fRootFile->GetName());
  142. // Get The list of branches from the input file and add it to the
  143. // actual list of existing branches.
  144. // Add this list of branches also to the map of input trees, which
  145. // stores the information which branches belong to which input tree.
  146. // There is at least one primary input tree, but there can be many
  147. // additional friend trees.
  148. // This information is needed to add new files to the correct friend
  149. // tree. With this information it is also possible to check if the
  150. // input files which are added to the input chain all have the same
  151. // branch structure. Without this check it is possible to add trees
  152. // with a different branch structure but the same tree name. ROOT
  153. // probably only checks if the name of the tree is the same.
  154. TString chainName = fInputTitle;
  155. fInputLevel.push_back(chainName);
  156. fCheckInputBranches[chainName] = new list<TString>;
  157. TObjArray* fBranchList = fInChain->GetListOfBranches();
  158. // if no any branches then exit (some errors occured)
  159. if (fBranchList == NULL)
  160. return kFALSE;
  161. LOG(DEBUG) << "Entries in the chain " << fBranchList->GetEntries();
  162. TObject** ppObj = new TObject*[fBranchList->GetEntries()];
  163. for (int i = 0; i < fBranchList->GetEntries(); i++) {
  164. TBranch* pBranch = (TBranch*) fBranchList->At(i);
  165. TString ObjName = pBranch->GetName();
  166. LOG(DEBUG) << "Branch name " << ObjName.Data();
  167. fCheckInputBranches[chainName]->push_back(ObjName.Data());
  168. FairRootManager::Instance()->AddBranchToList(ObjName.Data());
  169. ppObj[i] = NULL;
  170. //ActivateObject(&(ppObj[i]), ObjName);
  171. fInChain->SetBranchAddress(ObjName, &ppObj[i]);
  172. FairRootManager::Instance()->RegisterInputObject(ObjName, ppObj[i]);
  173. }
  174. // Add all additional input files to the input chain and do a
  175. // consitency check
  176. list<TString>::const_iterator iter;
  177. for (iter = fInputChainList.begin(); iter != fInputChainList.end(); iter++) {
  178. // Store global gFile pointer for safety reasons.
  179. // Set gFile to old value at the end of the routine.R
  180. TFile* temp = gFile;
  181. // Temporarily open the input file to extract information which
  182. // is needed to bring the friend trees in the correct order
  183. TFile* inputFile = new TFile(*iter);
  184. if (inputFile->IsZombie())
  185. LOG(FATAL) << "Error opening the file " << (*iter).Data() << " which should be added to the input chain or as friend chain";
  186. // Check if the branchlist is the same as for the first input file.
  187. Bool_t isOk = CompareBranchList(inputFile, chainName);
  188. if (!isOk) {
  189. LOG(FATAL) << "Branch structure of the input file " << fRootFile->GetName() << " and the file to be added " << (*iter).Data() << " are different.";
  190. return kFALSE;
  191. }
  192. // Add the file to the input chain
  193. fInChain->Add(*iter);
  194. // Close the temporarly file and restore the gFile pointer.
  195. inputFile->Close();
  196. gFile = temp;
  197. }
  198. fNoOfEntries = fInChain->GetEntries();
  199. LOG(DEBUG) << "Entries in this Source " << fNoOfEntries;
  200. AddFriendsToChain();
  201. return kTRUE;
  202. }
  203. //_____________________________________________________________________________
  204. void MpdMiniDstFileSource::SetInTree(TTree* tempTree) {
  205. fInTree = tempTree;
  206. fRootFile = (TFile*) tempTree->GetCurrentFile();
  207. fInChain->Reset();
  208. IsInitialized = kFALSE;
  209. Init();
  210. }
  211. //_____________________________________________________________________________
  212. Int_t MpdMiniDstFileSource::ReadEvent(UInt_t i) {
  213. fCurrentEntryNo = i;
  214. SetEventTime();
  215. if (fInChain->GetEntry(i))
  216. return 0;
  217. return 1;
  218. }
  219. //_____________________________________________________________________________
  220. void MpdMiniDstFileSource::Close() {
  221. CloseInFile();
  222. }
  223. //_____________________________________________________________________________
  224. void MpdMiniDstFileSource::Reset() {
  225. }
  226. //_____________________________________________________________________________
  227. void MpdMiniDstFileSource::AddFriend(TString fName) {
  228. fFriendFileList.push_back(fName);
  229. }
  230. //_____________________________________________________________________________
  231. void MpdMiniDstFileSource::AddFile(TString FileName) {
  232. fInputChainList.push_back(FileName);
  233. }
  234. //_____________________________________________________________________________
  235. void MpdMiniDstFileSource::AddFriendsToChain() {
  236. // Loop over all Friend files and extract the type. The type is defined by
  237. // the tree which is stored in the file. If there is already a chain of with
  238. // this type of tree then the file will be added to this chain.
  239. // If there is no such chain it will be created.
  240. //
  241. // In the old way it was needed sometimes to add a freind file more
  242. // than once. This is not needed any longer, so we remove deuplicates
  243. // from the list and display a warning.
  244. list<TString> friendList;
  245. list<TString>::iterator iter1;
  246. for (iter1 = fFriendFileList.begin(); iter1 != fFriendFileList.end(); iter1++) {
  247. if (find(friendList.begin(), friendList.end(), *iter1) == friendList.end())
  248. friendList.push_back(*iter1);
  249. }
  250. TFile* temp = gFile;
  251. Int_t friendType = 1;
  252. // Loop over all files which have been added as friends
  253. for (iter1 = friendList.begin(); iter1 != friendList.end(); iter1++) {
  254. list<TString>::iterator iter;
  255. TString inputLevel;
  256. // Loop over all already defined input levels to check if this type
  257. // of friend tree is already added.
  258. // If this type of friend tree already exist add the file to the
  259. // then already existing friend chain. If this type of friend tree
  260. // does not exist already create a new friend chain and add the file.
  261. Bool_t inputLevelFound = kFALSE;
  262. TFile* inputFile;
  263. for (iter = fInputLevel.begin(); iter != fInputLevel.end(); iter++) {
  264. inputLevel = (*iter);
  265. inputFile = new TFile((*iter1));
  266. if (inputFile->IsZombie())
  267. LOG(FATAL) << "Error opening the file " << (*iter).Data() << " which should be added to the input chain or as friend chain";
  268. // Check if the branchlist is already stored in the map. If it is
  269. // already stored add the file to the chain.
  270. Bool_t isOk = CompareBranchList(inputFile, inputLevel);
  271. if (isOk) {
  272. inputLevelFound = kTRUE;
  273. inputFile->Close();
  274. continue;
  275. }
  276. inputFile->Close();
  277. }
  278. if (!inputLevelFound) {
  279. inputLevel = Form("FriendTree_%i", friendType);
  280. CreateNewFriendChain(*iter1, inputLevel);
  281. friendType++;
  282. }
  283. TChain* chain = static_cast<TChain*> (fFriendTypeList[inputLevel]);
  284. chain->AddFile((*iter1), 1234567890, FairRootManager::GetTreeName());
  285. }
  286. gFile = temp;
  287. // Add all the friend chains which have been created to the
  288. // main input chain
  289. map< TString, TChain* >::iterator mapIterator;
  290. for (mapIterator = fFriendTypeList.begin(); mapIterator != fFriendTypeList.end(); mapIterator++) {
  291. TChain* chain = static_cast<TChain*> (mapIterator->second);
  292. fInChain->AddFriend(chain);
  293. }
  294. // Print some output about the input structure
  295. PrintFriendList();
  296. }
  297. //_____________________________________________________________________________
  298. void MpdMiniDstFileSource::PrintFriendList() {
  299. // Print information about the input structure
  300. // List files from the input chain together with all files of all friend chains
  301. LOG(INFO) << "The input consists out of the following trees and files: \n" << " - " << fInChain->GetName();
  302. TObjArray* fileElements = fInChain->GetListOfFiles();
  303. TIter next(fileElements);
  304. TChainElement* chEl = 0;
  305. while (chEl = (TChainElement*) next())
  306. LOG(INFO) << " - " << chEl->GetTitle();
  307. map<TString, TChain*>::iterator mapIterator;
  308. for (mapIterator = fFriendTypeList.begin(); mapIterator != fFriendTypeList.end(); mapIterator++) {
  309. TChain* chain = (TChain*) mapIterator->second;
  310. LOG(INFO) << " - " << chain->GetName();
  311. fileElements = chain->GetListOfFiles();
  312. TIter next1(fileElements);
  313. chEl = 0;
  314. while (chEl = (TChainElement*) next1())
  315. LOG(INFO) << " - " << chEl->GetTitle();
  316. }
  317. }
  318. //_____________________________________________________________________________
  319. void MpdMiniDstFileSource::CheckFriendChains() {
  320. multimap< TString, multimap<TString, TArrayI> >::iterator it1;
  321. multimap<TString, TArrayI> map1;
  322. // Get the structure from the input chain
  323. it1 = fRunIdInfoAll.find("InputChain");
  324. map1 = it1->second;
  325. vector<Int_t> runid;
  326. vector<Int_t> events;
  327. multimap<TString, TArrayI>::iterator it;
  328. for (it = map1.begin(); it != map1.end(); it++) {
  329. TArrayI bla = (*it).second;
  330. runid.push_back(bla[0]);
  331. events.push_back(bla[1]);
  332. }
  333. // Now loop over all chains except the input chain and comapare the
  334. // runids and event numbers.
  335. // If there is a mismatch stop the execution.
  336. Int_t errorFlag = 0;
  337. TString inputLevel;
  338. list<TString>::iterator listit;
  339. for (listit = fInputLevel.begin(); listit != fInputLevel.end(); listit++) {
  340. inputLevel = (*listit);
  341. if (!inputLevel.Contains("InputChain")) {
  342. it1 = fRunIdInfoAll.find(inputLevel);
  343. map1 = it1->second;
  344. if (runid.size() != map1.size()) {
  345. errorFlag = 1;
  346. // goto error_label;
  347. break;
  348. }
  349. Int_t counter = 0;
  350. for (it = map1.begin(); it != map1.end(); it++) {
  351. TArrayI bla = (*it).second;
  352. if ((bla[0] != runid[counter]) || (bla[1] != events[counter])) {
  353. errorFlag = 2;
  354. // goto error_label;
  355. break;
  356. }
  357. counter++;
  358. }
  359. if (errorFlag > 0)
  360. break;
  361. }
  362. }
  363. // Use goto to leave double loop at once in case of error
  364. // error_label:
  365. if (errorFlag > 0) {
  366. LOG(ERROR) << "The input chain and the friend chain " << inputLevel.Data() << " have a different structure:";
  367. if (errorFlag == 1) {
  368. LOG(ERROR) << "The input chain has the following runids and event numbers:";
  369. for (UInt_t i = 0; i < runid.size(); i++)
  370. LOG(ERROR) << " - Runid " << runid[i] << " with " << events[i] << " events";
  371. LOG(ERROR) << "The " << inputLevel.Data() << " chain has the following runids and event numbers:";
  372. for (it = map1.begin(); it != map1.end(); it++) {
  373. TArrayI bla = (*it).second;
  374. LOG(ERROR) << " - Runid " << bla[0] << " with " << bla[1] << " events";
  375. }
  376. }
  377. if (errorFlag == 2) {
  378. Int_t counter = 0;
  379. for (it = map1.begin(); it != map1.end(); it++) {
  380. TArrayI bla = (*it).second;
  381. LOG(ERROR) << "Runid Input Chain, " << inputLevel.Data() << " chain: " << bla[0] << ", " << runid[counter];
  382. LOG(ERROR) << "Event number Input Chain, " << inputLevel.Data() << " chain: " << bla[1] << ", " << events[counter];
  383. counter++;
  384. }
  385. }
  386. LOG(FATAL) << "Event structure mismatch";
  387. }
  388. }
  389. //_____________________________________________________________________________
  390. void MpdMiniDstFileSource::CreateNewFriendChain(TString inputFile, TString inputLevel) {
  391. TFile* temp = gFile;
  392. TFile* f = new TFile(inputFile);
  393. TString chainName = inputLevel;
  394. fInputLevel.push_back(chainName);
  395. fCheckInputBranches[chainName] = new list<TString>;
  396. /**Get The list of branches from the friend file and add it to the actual list*/
  397. TChain* chain = new TChain(inputLevel);
  398. chain->Add(inputFile);
  399. TObjArray* fBranchList = chain->GetListOfBranches();
  400. for (int i = 0; i < fBranchList->GetEntries(); i++) {
  401. TString ObjName = ((TNamed*) fBranchList->At(i))->GetName();
  402. fCheckInputBranches[chainName]->push_back(ObjName.Data());
  403. FairRootManager::Instance()->AddBranchToList(ObjName.Data());
  404. }
  405. fFriendTypeList[inputLevel] = chain;
  406. f->Close();
  407. gFile = temp;
  408. }
  409. //_____________________________________________________________________________
  410. Bool_t MpdMiniDstFileSource::CompareBranchList(TFile* fileHandle, TString inputLevel) {
  411. // fill a set with the original branch structure
  412. // This allows to use functions find and erase
  413. set<TString> branches;
  414. list<TString>::const_iterator iter;
  415. for (iter = fCheckInputBranches[inputLevel]->begin(); iter != fCheckInputBranches[inputLevel]->end(); iter++)
  416. branches.insert(*iter);
  417. // To do so we have to loop over the branches in the file and to compare
  418. // the branches. If both lists are equal everything is okay
  419. // Get The list of branches from the input file one by one and compare
  420. // it to the reference list of branches which is defined for this tree.
  421. // If a branch with the same name is found, this branch is removed from
  422. // the list. If in the end no branch is left in the list everything is fine
  423. set<TString>::iterator iter1;
  424. TChain* fileTree = new TChain("MiniDst", "/cbmroot");
  425. fileTree->Add(fileHandle->GetName());
  426. TObjArray* fBranchList = fileTree->GetListOfBranches();
  427. for (int i = 0; i < fBranchList->GetEntries(); i++) {
  428. TString ObjName = ((TNamed*) fBranchList->At(i))->GetName();
  429. iter1 = branches.find(ObjName.Data());
  430. if (iter1 != branches.end()) branches.erase(iter1);
  431. else
  432. // Not found is an error because branch structure is
  433. // different. It is impossible to add to tree with a
  434. // different branch structure
  435. return kFALSE;
  436. }
  437. // If the size of branches is !=0 after removing all branches also in the
  438. // reference list, this is also a sign that both branch list are not the
  439. // same
  440. if (branches.size() != 0) {
  441. LOG(INFO) << "Compare Branch List will return kFALSE. The list has " << branches.size() << " branches:";
  442. for (set<TString>::iterator it = branches.begin(); it != branches.end(); it++)
  443. LOG(INFO) << " -> " << *it;
  444. return kFALSE;
  445. }
  446. return kTRUE;
  447. }
  448. //_____________________________________________________________________________
  449. Bool_t MpdMiniDstFileSource::ActivateObject(TObject** obj, const char* BrName) {
  450. if (fInTree) {
  451. fInTree->SetBranchStatus(BrName, 1);
  452. fInTree->SetBranchAddress(BrName, obj);
  453. }
  454. if (fInChain) {
  455. fInChain->SetBranchStatus(BrName, 1);
  456. fInChain->SetBranchAddress(BrName, obj);
  457. }
  458. return kTRUE;
  459. }
  460. //_____________________________________________________________________________
  461. void MpdMiniDstFileSource::SetInputFile(TString name) {
  462. fRootFile = new TFile(name.Data());
  463. if (fRootFile->IsZombie())
  464. LOG(FATAL) << "Error opening the Input file";
  465. LOG(INFO) << "MpdMiniDstFileSource set------------";
  466. }
  467. //_____________________________________________________________________________
  468. Int_t MpdMiniDstFileSource::CheckMaxEventNo(Int_t EvtEnd) {
  469. Int_t MaxEventNo = 0;
  470. if (EvtEnd != 0)
  471. MaxEventNo = EvtEnd;
  472. MaxEventNo = fInChain->GetEntries();
  473. return MaxEventNo;
  474. }
  475. //_____________________________________________________________________________
  476. void MpdMiniDstFileSource::SetEventMeanTime(Double_t mean) {
  477. fEventMeanTime = mean;
  478. fTimeProb = new TF1("TimeProb", "(1/[0])*exp(-x/[0])", 0., mean * 10);
  479. fTimeProb->SetParameter(0, mean);
  480. fTimeProb->GetRandom();
  481. }
  482. //_____________________________________________________________________________
  483. void MpdMiniDstFileSource::SetEventTimeInterval(Double_t min, Double_t max) {
  484. fEventTimeMin = min;
  485. fEventTimeMax = max;
  486. fEventMeanTime = (fEventTimeMin + fEventTimeMax) / 2;
  487. }
  488. //_____________________________________________________________________________
  489. void MpdMiniDstFileSource::SetBeamTime(Double_t beamTime, Double_t gapTime) {
  490. fBeamTime = beamTime;
  491. fGapTime = gapTime;
  492. }
  493. //_____________________________________________________________________________
  494. void MpdMiniDstFileSource::SetEventTime() {
  495. LOG(DEBUG) << "Set event time for Entry = " << fTimeforEntryNo << " , where the current entry is " << fCurrentEntryNo << " and eventTime is " << fEventTime;
  496. if (fBeamTime < 0)
  497. fEventTime += GetDeltaEventTime();
  498. else {
  499. do {
  500. fEventTime += GetDeltaEventTime();
  501. } while (fmod(fEventTime, fBeamTime + fGapTime) > fBeamTime);
  502. }
  503. LOG(DEBUG) << "New time = " << fEventTime;
  504. fTimeforEntryNo = fCurrentEntryNo;
  505. }
  506. //_____________________________________________________________________________
  507. Double_t MpdMiniDstFileSource::GetDeltaEventTime() {
  508. Double_t deltaTime = 0;
  509. if (fTimeProb != 0) {
  510. deltaTime = fTimeProb->GetRandom();
  511. LOG(DEBUG) << "Time set via sampling method : " << deltaTime;
  512. } else {
  513. deltaTime = gRandom->Uniform(fEventTimeMin, fEventTimeMax);
  514. LOG(DEBUG) << "Time set via Uniform Random : " << deltaTime;
  515. }
  516. return deltaTime;
  517. }
  518. //_____________________________________________________________________________
  519. Double_t MpdMiniDstFileSource::GetEventTime() {
  520. LOG(DEBUG) << "-- Get Event Time --";
  521. if (!fEvtHeaderIsNew && fEvtHeader != 0) {
  522. Double_t EvtTime = fEvtHeader->GetEventTime();
  523. if (!(EvtTime < 0))
  524. return EvtTime;
  525. }
  526. if (fTimeforEntryNo != fCurrentEntryNo)
  527. SetEventTime();
  528. LOG(DEBUG) << "Calculate event time from user input : " << fEventTime << " ns";
  529. return fEventTime;
  530. }
  531. //_____________________________________________________________________________
  532. void MpdMiniDstFileSource::ReadBranchEvent(const char* BrName) {
  533. /**fill the object with content if the other branches in this tree entry were already read**/
  534. if (fEvtHeader == 0)
  535. return; //No event header, Reading will start later
  536. if (fInTree) fInTree->FindBranch(BrName)->GetEntry(fEvtHeader->GetMCEntryNumber());
  537. else
  538. if (fInChain) fInChain->FindBranch(BrName)->GetEntry(fEvtHeader->GetMCEntryNumber());
  539. return;
  540. }
  541. //_____________________________________________________________________________
  542. void MpdMiniDstFileSource::ReadBranchEvent(const char* BrName, Int_t Entry) {
  543. if (fInTree) fInTree->FindBranch(BrName)->GetEntry(Entry);
  544. else
  545. if (fInChain) fInChain->FindBranch(BrName)->GetEntry(Entry);
  546. return;
  547. }
  548. //_____________________________________________________________________________
  549. void MpdMiniDstFileSource::FillEventHeader(FairEventHeader* feh) {
  550. feh->SetEventTime(fEventTime);
  551. if (fEvtHeader) {
  552. feh->SetRunId(fEvtHeader->GetRunId());
  553. feh->SetMCEntryNumber(fEvtHeader->GetMCEntryNumber());
  554. }
  555. feh->SetInputFileId(0);
  556. return;
  557. }
  558. ClassImp(MpdMiniDstFileSource)