10#include "MemoryMapManager.h"
13#include "CutCollection.h"
14#include "CutContainer.h"
15#include "DataFormatManager.h"
16#include "DataManager.h"
28 fUseCompression(kFALSE),
32 fEventCollectionsNo(1),
33 fTrackCollectionsNo(1),
37 fTotalTracks(nullptr),
41 fMaxTrackCollectionNo(0),
42 fCurrentEvent(nullptr),
44 fTrackCounter(nullptr) {}
49 fEventToTrackNo =
new Int_t[fEventCollectionsNo];
56 for (
int i = 0; i < fEventCollectionsNo; i++) {
58 fMaxTrackCollectionNo = TMath::Max(fEventToTrackNo[i], fMaxTrackCollectionNo);
63 if (fUseCompression) {
64 CalculateCompressedMap(collection);
65 Event* uevent = fEvents[collection]->
At(fCounter[collection]);
66 uevent->
Build(fCurrentEvent, fCompression);
75 Event* uevent = fEvents[collection]->
At(fCounter[collection]);
76 uevent->
Build(fCurrentEvent);
79#ifdef MEMORYMAMANGER_COMPRESSION_DEBUG_
80 std::cout <<
"MEMORY MANAGER DEBUG MAPS" << std::endl;
81 std::cout <<
"ORYGINAL EVENT" << std::endl;
84 if (total > 50) total = 50;
85 for (
int i = 0; i < total; i++) {
87 std::cout << tr->GetId() <<
" " << tr->
GetLinks()->GetLinks(0) << std::endl;
89 std::cout <<
"COPIED EVENT" << std::endl;
90 temp = fEvents[collection]->
At(fCounter[collection]);
92 if (total > 50) total = 50;
93 for (
int i = 0; i < total; i++) {
95 std::cout << tr->GetId() <<
" " << tr->
GetLinks()->GetLinks(0) << std::endl;
97 std::cout <<
"==============" << std::endl;
101 void MemoryMapManager::ReloadMap(Int_t size) {
103 fTrackMapSize = size;
114 if (!fDirectAcces) fCurrentEvent->
Update(fInterface);
116 for (
int i = 0; i < fEventCollectionsNo; i++) {
120 return fCurrentEvent;
124 if (direct.size() > 0) {
125 fDirectAcces = kTRUE;
127 fDirectAcces = kFALSE;
130 fUseCompression = compress;
131 if (event_factor > 1) {
132 Int_t* old_map = fEventToTrackNo;
133 Int_t realEventCol = fEventCollectionsNo;
134 fEventCollectionsNo = fEventCollectionsNo * event_factor;
135 fEventToTrackNo =
new Int_t[fEventCollectionsNo];
136 for (
int i = 0; i < realEventCol; i++) {
137 for (
int j = 0; j < event_factor; j++) {
138 fEventToTrackNo[j + i * event_factor] = old_map[i];
140 fMaxTrackCollectionNo = TMath::Max(fEventToTrackNo[i], fMaxTrackCollectionNo);
145 fEvents =
new EventArray*[fEventCollectionsNo];
146 for (Int_t i = 0; i < fEventCollectionsNo; i++) {
147 fEvents[i] =
new EventArray(fFormatID, fMixSize);
151 if (fDirectAcces == kFALSE) {
152 fCurrentEvent = dataManager->
GetNewEvent(fFormatID, EFormatDepth::kNonBuffered);
154 fInterface->ConnectToTree(Hal::EventInterface::eMode::kRead);
156 for (
auto brName : direct) {
157 Event* ev =
dynamic_cast<Event*
>(DataManager::Instance()->GetObject(brName));
164 fTotalTracks =
new Int_t[fEventCollectionsNo];
167 fTrackCounter->
MakeBigger(fEventCollectionsNo, fTrackCollectionsNo, fMixSize);
168 fTrackMap->
MakeBigger(fEventCollectionsNo, fTrackCollectionsNo, fMixSize, fTrackMapSize);
169 fReadyToMix =
new Bool_t[fEventCollectionsNo];
170 for (
int i = 0; i < fEventCollectionsNo; i++) {
171 fReadyToMix[i] = kFALSE;
173 fCounter =
new Int_t[fEventCollectionsNo];
174 for (
int i = 0; i < fEventCollectionsNo; i++) {
180 return fTrackCounter->
Get(event_collection, track_collection, fCounter[event_collection]);
190 fCounter[collection] = -1;
191 for (
int i = 0; i < fEventToTrackNo[collection]; i++) {
192 for (
int j = 0; j < fMixSize; j++) {
193 fTrackCounter->
Set(collection, i, j, 0);
196 for (Int_t i = 0; i < fMixSize; i++)
197 fEvents[collection]->At(i)->Clear(
"C");
198 fReadyToMix[collection] = kFALSE;
202 Int_t counter = fCounter[event_collection];
203 fTrackMap->
Set(event_collection,
206 fTrackCounter->
IncrementAfter(event_collection, track_collection, counter),
210 void MemoryMapManager::ResetTrackMaps(Int_t event_collection, Int_t counter) {
211 for (
int i = 0; i < fTrackCollectionsNo; i++)
212 fTrackCounter->
Set(event_collection, i, counter, 0);
215 void MemoryMapManager::ResetTrackMaps(Int_t event_collection, Int_t track_collection, Int_t counter) {
217 fTrackCounter->
Set(event_collection, track_collection, counter, 0);
222 return fTrackCounter->
Get(event_collection, track_collection, counter);
225 Int_t MemoryMapManager::GetTrackCollectionsNo(Int_t event_collection)
const {
return fEventToTrackNo[event_collection]; }
235 return (fEvents[event_collection]->At(fCounter[event_collection]))
236 ->GetTrack(fTrackMap->
Get(event_collection, track_collection, fCounter[event_collection], index));
240 return (fEvents[event_collection]->At(fCounter[event_collection]))->GetTrack(index);
246 return (fEvents[event_collection]->At(counter))->GetTrack(fTrackMap->
Get(event_collection, track_collection, counter, index));
250 return (fEvents[event_collection]->At(counter))->GetTrack(index);
256 for (
int ev_trig = 0; ev_trig < fEventCollectionsNo; ev_trig++) {
257 for (
int count = 0; count < fMixSize; count++) {
259 std::cout << Form(
"Event %d collection %d", count, ev_trig) << std::endl;
263 for (
int tr_trig = 0; tr_trig < fTrackCollectionsNo; tr_trig++) {
264 std::cout << Form(
"buffered %i",
GetTracksNo(ev_trig, tr_trig, count)) << std::endl;
265 for (
int k = 0; k <
GetTracksNo(ev_trig, tr_trig, count); k++) {
268 Int_t pos = fTrackMap->
Get(ev_trig, tr_trig, count, k);
271 std::cout << Form(
"%i val %i", k, pos) << std::endl;
273 ptr1 =
GetTrack(ev_trig, tr_trig, count, k);
282 for (
int i = 0; i < fTrackCollectionsNo; i++)
283 fTrackCounter->
Set(event_collection, i, fCounter[event_collection], 0);
284 --fCounter[event_collection];
287 Int_t MemoryMapManager::GetCounter(Int_t event_collection)
const {
return fCounter[event_collection]; }
291 fCurrentEvent->
Clear();
294 void MemoryMapManager::CalculateCompressedMap(Int_t event_collection) {
296 int collections = fEventToTrackNo[event_collection];
298 Int_t counter = fCounter[event_collection];
299 fCompression.
Reset(total_tracks);
301 std::vector<int> links;
304 for (
int iTrackCollection = 0; iTrackCollection < collections; iTrackCollection++) {
305 for (
int j = 0; j <
GetTracksNo(event_collection, iTrackCollection); j++) {
306 Int_t index = fTrackMap->
Get(event_collection, iTrackCollection, counter, j);
309 for (
int iLink = 0; iLink < size; iLink++) {
315 for (
int iTrackCollection = 0; iTrackCollection < collections; iTrackCollection++) {
316 auto submap = fTrackMap->
At(event_collection)->
At(iTrackCollection)->
At(counter);
317 for (
int iTrack = 0; iTrack <
GetTracksNo(event_collection, iTrackCollection); iTrack++) {
318 Int_t old_index = submap->Get(iTrack);
319 submap->Set(iTrack, fCompression.
GetNewIndex(old_index));
323#ifdef MAPMANAGER_DEBUG
324 std::cout <<
" collections at" << counter << std::endl;
325 for (
int i = 0; i < collections; i++) {
326 std::cout <<
"Collection " << i <<
" end = " << End[i] << std::endl;
327 for (
int j = 0; j < fTrackCounter->
Get(event_collection, i, counter); j++) {
328 std::cout << Form(
" %4d", fTrackMap->
Get(event_collection, i, counter, j));
330 std::cout << std::endl;
332 std::cout <<
"compression" << std::endl;
335#ifdef MAPMANAGER_DEBUG
336 std::cout <<
"SUMM" << std::endl;
337 for (
int i = 0; i < fSumMapSize; i++) {
340 std::cout << std::endl;
341 for (
int i = 0; i < fSumMapSize; i++) {
342 std::cout << Form(
" %4d", fSumMap[i]);
344 std::cout << std::endl;
349 Int_t dif = fMixSize - fCounter[collection];
351 case 1: fCounter[collection] = -1;
break;
352 case 2: fReadyToMix[collection] = kTRUE;
break;
355 ++fCounter[collection];
356 ResetTrackMaps(collection, fCounter[collection]);
359 MemoryMapManager::~MemoryMapManager() {
361 for (
int i = 0; i < fEventCollectionsNo; i++)
365 delete fTrackCounter;
367 delete[] fReadyToMix;
368 delete[] fTotalTracks;
369 delete[] fEventToTrackNo;
371 if (fInterface)
delete fInterface;
377 for (
int i = 0; i <
fSize; i++) {
383 return fCurrentEvent->
GetTrack(fTrackMap->
Get(event_collection, track_collection, fCounter[event_collection], index));
Array_1< T > * At(const Int_t i)
Array_2< T > * At(Int_t i) const
void Set(Int_t A, Int_t B, Int_t C, T val)
void MakeBigger(Int_t sizeA, Int_t sizeB, Int_t sizeC)
T IncrementAfter(Int_t A, Int_t B, Int_t C)
T Get(Int_t A, Int_t B, Int_t C) const
void Set(Int_t A, Int_t B, Int_t C, Int_t D, T val)
Array_3< T > * At(Int_t i) const
T Get(Int_t A, Int_t B, Int_t C, Int_t D) const
void MakeBigger(Int_t sizeA, Int_t sizeB, Int_t sizeC, Int_t sizeD)
Int_t GetNewIndex(Int_t old_index) const
void MarkAsGood(Int_t old_index)
static void PrintInfo(TString text, Hal::EInfo status)
Int_t GetEventCollectionsNo() const
CutCollection * GetEventCollection(Int_t collection) const
Int_t GetTrackCollectionsNo() const
EventArray(Int_t task_id, Int_t size=1)
Event * At(const Int_t size)
void Build(Event *event, const CompressionMap &map)
virtual void Update(EventInterface *interface)
Int_t GetTotalTrackNo() const
virtual EventInterface * CreateInterface() const =0
virtual void Print(Option_t *opt="") const
virtual void Clear(Option_t *opt=" ")
virtual Int_t GetMaxExpectedLinks() const
Track * GetTrack(Int_t i) const
void Init(Int_t event_factor, Int_t task_id, Bool_t compress, std::vector< TString > direct)
Event * GetTemporaryEvent()
Int_t GetTracksNo(Int_t event_collection, Int_t track_collection) const
Track * GetRawTrack(Int_t event_collection, Int_t index) const
void AddTrackToMapTrack(Int_t event_collection, Int_t track_collection, Int_t index)
void SetMixSize(Int_t mix_size)
Event * GetEvent(Int_t collection) const
Int_t GetTemporaryTotalTracksNo() const
void RejectLastEvent(Int_t event_collection)
void BufferEvent(Int_t collection)
Bool_t IsReadyToMixing(Int_t collection) const
Track * GetTrack(Int_t event_collection, Int_t track_collection, Int_t index) const
Int_t GetRawTracksNo(Int_t event_collection) const
void ManualUpdate(Event *event)
void PrepareMaps(Int_t collection)
void ResetEventCollection(Int_t collection)
Track * GetTemporaryTrack(Int_t event_collection, Int_t track_collection, Int_t index) const
virtual void Print(Option_t *option="") const
void TranslateLinks(const CompressionMap &map)
std::vector< int > GetLinks() const
virtual Int_t GetLinksFast(std::vector< int > &vec, Bool_t fast=kTRUE) const