// File: /workspace/github_cpp_makefile_star2_O2/richardposner[P]BioNetFit2/src/code/Particle.cpp
// Function: Particle::smoothRuns(unsigned int)
void Particle::smoothRuns(unsigned int mid) {
	unsigned int subParID = calcsubParID(mid);
	//if ((mid<0)|| (mid >= swarm_->getNumModels()) || (!getSubParticle(mid)) || (!models.at(mid)) || (dataFiles_.at(mid).empty())){
	if ((mid<0)|| (mid > swarm_->getNumModels()) || (!models.at(mid)) || (dataFiles_.at(mid).empty())){ //Raquel: the test !getSubParticle(mid) is not working correctly


	if (mid<0)  cout<<"E1\n";
	if (mid >= swarm_->getNumModels()) cout<<"E2\n";
	if (!getSubParticle(mid)) cout<<"E3\n";
	if (!models.at(mid))  cout<<"E4\n";
	if (dataFiles_.at(mid).empty()) cout<<"E5\n";


		outputError("smoothRun Failed. Invalid SubParticle.  PID:"+ toString(id_) + "  model id:" + toString(mid)+ "  subParID:" + toString(subParID)+". Quitting !!!");
	}

	if (swarm_->options.verbosity >= 3) {
		cout << "Smoothing simulation outputs for particle:"<<id_<<" subParticle: "<<subParID<<endl;
	}

	map<string, map<double, double> > dataSet;
	// For each action/prefix/exp file
	for (auto action = dataFiles_.at(mid).begin(); action != dataFiles_.at(mid).end(); ++action) {
		// For each column
		// Insert a new iteration into the prefix set
		//cout << "action loop " << action->first << endl;
		for (auto col = action->second.at(1)->dataCurrent->begin(); col != action->second.at(1)->dataCurrent->end(); ++col) {
			// For each timepoint
			// This map holds time/param value pairs
			//cout << "col loop " << col->first << endl;
			map<double, double> timePairs;
			for (auto time = col->second.begin(); time != col->second.end(); ++time) {
				double sum = 0;
				int i = 0;
				// For each iteration
				for (unsigned int iteration = 1; iteration <= swarm_->options.smoothing; ++iteration) {
					//cout << "it loop " << iteration << endl;
					sum += dataFiles_.at(mid).at(action->first).at(iteration)->dataCurrent->at(col->first).at(time->first);
					++i;
				}
				double average = sum / (double)i;
				//cout << "average: " << average << endl;
				pair<double, double> timePair;
				timePair = make_pair(time->first, average);
				timePairs.insert(timePair);
			}
			dataSet.insert(pair<string, map<double, double> >(col->first, timePairs));
		}
		action->second.insert(pair<int, Data*>(swarm_->options.smoothing + 1, new Data(dataSet)));
		dataSet.clear();
	}


	/*
	std::cout.precision(18);

	for (auto action = dataFiles_.begin(); action != dataFiles_.end(); ++action) {
		cout << action->first << endl;
		Data * data = action->second.at(swarm_->options.smoothing + 1);
		for (auto col = data->dataCurrent->begin(); col != data->dataCurrent->end(); ++col) {
			cout << col->first << endl;
			for (auto tp = col->second.begin(); tp != col->second.end(); ++tp) {
				cout << tp->second << endl;
			}
		}
	}
	 */
	//cout << id_ << " done smoothing" << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movl %esi, %r15d
movq %rdi, %rbx
callq 0x5645e
movq 0xa8(%rbx), %rcx
movq 0x15c8(%rcx), %rdx
subq 0x15c0(%rcx), %rdx
movl %eax, %ebp
shrq $0x3, %rdx
movl %r15d, %r12d
cmpl %r15d, %edx
jb 0x53f0f
leaq 0x78(%rbx), %rdi
movq %r12, %rsi
callq 0x3374c
cmpq $0x0, (%rax)
je 0x53f0f
leaq 0x90(%rbx), %rdi
movq %r12, %rsi
callq 0x5a176
cmpq $0x0, 0x28(%rax)
jne 0x540f8
movq 0xa8(%rbx), %rax
movq 0x15c8(%rax), %rcx
subq 0x15c0(%rax), %rcx
shrq $0x3, %rcx
cmpl %r15d, %ecx
ja 0x53f40
movq 0x112064(%rip), %rdi    # 0x165f98
leaq 0x83811(%rip), %rsi     # 0xd774c
callq 0x289f0
movq %rbx, %rdi
movl %r15d, %esi
callq 0x59f90
testq %rax, %rax
jne 0x53f63
movq 0x112041(%rip), %rdi    # 0x165f98
leaq 0x837f2(%rip), %rsi     # 0xd7750
callq 0x289f0
leaq 0x78(%rbx), %rdi
movq %r12, %rsi
callq 0x3374c
cmpq $0x0, (%rax)
jne 0x53f88
movq 0x11201c(%rip), %rdi    # 0x165f98
leaq 0x837d1(%rip), %rsi     # 0xd7754
callq 0x289f0
leaq 0x90(%rbx), %rdi
movq %r12, %rsi
callq 0x5a176
cmpq $0x0, 0x28(%rax)
jne 0x53fb1
movq 0x111ff3(%rip), %rdi    # 0x165f98
leaq 0x837ac(%rip), %rsi     # 0xd7758
callq 0x289f0
movl 0x40(%rbx), %esi
leaq 0x198(%rsp), %r14
movq %r14, %rdi
callq 0x9f56b
leaq 0x83791(%rip), %rsi     # 0xd775c
leaq 0x138(%rsp), %rdi
movq %r14, %rdx
callq 0x4933b
leaq 0x82bf5(%rip), %rdx     # 0xd6bd7
leaq 0x158(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x3336c
leaq 0x118(%rsp), %rdi
movl %r15d, %esi
callq 0x9f56b
leaq 0x28(%rsp), %rdi
leaq 0x158(%rsp), %rsi
leaq 0x118(%rsp), %rdx
callq 0x4e6ed
leaq 0x8265c(%rip), %rdx     # 0xd6684
leaq 0x78(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x3336c
leaq 0xf8(%rsp), %rdi
movl %ebp, %esi
callq 0x9f56b
leaq 0xa8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
callq 0x4e6ed
leaq 0x82c8b(%rip), %rdx     # 0xd6cf2
leaq 0x178(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x3336c
leaq 0x178(%rsp), %rdi
callq 0x9f54b
leaq 0x178(%rsp), %rdi
callq 0x295a0
leaq 0xa8(%rsp), %rdi
callq 0x295a0
leaq 0xf8(%rsp), %rdi
callq 0x295a0
leaq 0x78(%rsp), %rdi
callq 0x295a0
leaq 0x28(%rsp), %rdi
callq 0x295a0
leaq 0x118(%rsp), %rdi
callq 0x295a0
leaq 0x158(%rsp), %rdi
callq 0x295a0
leaq 0x138(%rsp), %rdi
callq 0x295a0
leaq 0x198(%rsp), %rdi
callq 0x295a0
movq %r12, 0x8(%rsp)
movq 0xa8(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x5414c
movq 0x111e84(%rip), %rdi    # 0x165f98
leaq 0x8366e(%rip), %rsi     # 0xd7789
callq 0x289f0
movl 0x40(%rbx), %esi
movq %rax, %rdi
callq 0x286e0
leaq 0x8be1c(%rip), %rsi     # 0xdff4e
movq %rax, %rdi
callq 0x289f0
movl %ebp, %esi
movq %rax, %rdi
callq 0x286e0
movq %rax, %rdi
callq 0x284a0
leaq 0x80(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %rbx, %r12
leaq 0x90(%rbx), %rdi
movq %rdi, 0x20(%rsp)
movq 0x8(%rsp), %rsi
callq 0x5a176
movq 0x18(%rax), %rbx
leaq 0xa8(%rsp), %r13
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x5a176
addq $0x8, %rax
cmpq %rax, %rbx
je 0x543b3
leaq 0x40(%rbx), %rdi
movl $0x1, 0xa8(%rsp)
movq %rdi, 0x18(%rsp)
movq %r13, %rsi
callq 0x5a342
movq %rbx, 0x58(%rsp)
leaq 0x20(%rbx), %rbp
movq (%rax), %rax
movq (%rax), %rax
movq 0x18(%rax), %rbx
movl $0x1, 0xa8(%rsp)
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x5a342
movq (%rax), %rax
movq (%rax), %rax
addq $0x8, %rax
cmpq %rax, %rbx
je 0x5434e
andl $0x0, 0x30(%rsp)
andq $0x0, 0x38(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %rax, 0x48(%rsp)
andq $0x0, 0x50(%rsp)
leaq 0x20(%rbx), %r15
movq 0x58(%rbx), %rcx
leaq 0x48(%rbx), %rax
movq %rax, 0x68(%rsp)
movq %rbx, 0x60(%rsp)
cmpq 0x68(%rsp), %rcx
je 0x5430f
movq %rcx, 0x70(%rsp)
leaq 0x20(%rcx), %r14
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
pushq $0x1
popq %rbx
movq 0xa8(%r12), %rax
cmpl 0x1658(%rax), %ebx
ja 0x542c4
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x5a176
movq %rax, %rdi
movq %rbp, %rsi
callq 0x5a2fc
movl %ebx, 0xa8(%rsp)
movq %rax, %rdi
movq %r13, %rsi
callq 0x5a342
movq (%rax), %rax
movq (%rax), %rdi
movq %r15, %rsi
callq 0x5a37a
movq %rax, %rdi
movq %r14, %rsi
callq 0x5a3c0
movsd 0x10(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
incl %ebx
jmp 0x5425b
decl %ebx
cvtsi2sd %ebx, %xmm0
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd (%r14), %xmm0
movsd %xmm0, 0xa8(%rsp)
movsd %xmm1, 0xb0(%rsp)
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x5f7d0
movq 0x70(%rsp), %rdi
callq 0x28700
movq %rax, %rcx
movq 0x60(%rsp), %rbx
jmp 0x5423a
movq %r13, %rdi
movq %r15, %rsi
leaq 0x28(%rsp), %rdx
callq 0x5a552
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x5f864
movq %r13, %rdi
callq 0x5a588
leaq 0x28(%rsp), %rdi
callq 0x49554
movq %rbx, %rdi
callq 0x28700
movq %rax, %rbx
jmp 0x541d9
movq 0xa8(%r12), %rax
movl 0x1658(%rax), %ebx
movl $0x160, %edi            # imm = 0x160
callq 0x28a10
movq 0x58(%rsp), %r15
movq %rax, %r14
movq %rax, %rdi
leaq 0x78(%rsp), %rsi
callq 0x48eb6
incl %ebx
movl %ebx, 0xa8(%rsp)
movq %r14, 0xb0(%rsp)
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x5d6de
leaq 0x78(%rsp), %rdi
callq 0x5f936
movq %r15, %rdi
callq 0x28700
movq %rax, %rbx
jmp 0x5418e
leaq 0x78(%rsp), %rdi
callq 0x494da
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x295a0
jmp 0x543e4
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x295a0
jmp 0x543f6
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x295a0
jmp 0x54408
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x295a0
jmp 0x54417
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x295a0
leaq 0x118(%rsp), %rdi
callq 0x295a0
leaq 0x158(%rsp), %rdi
callq 0x295a0
leaq 0x138(%rsp), %rdi
callq 0x295a0
leaq 0x198(%rsp), %rdi
callq 0x295a0
jmp 0x544b9
movq %rax, %rbx
jmp 0x54421
movq %rax, %rbx
jmp 0x5442e
movq %rax, %rbx
jmp 0x5443b
movq %rax, %rbx
jmp 0x54448
jmp 0x54499
movq %rax, %rbx
movl $0x160, %esi            # imm = 0x160
movq %r14, %rdi
callq 0x28a50
jmp 0x544af
jmp 0x54499
jmp 0x54499
jmp 0x54499
jmp 0x544a2
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x5a588
jmp 0x544a5
movq %rax, %rbx
jmp 0x544af
jmp 0x544a2
jmp 0x544a2
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x49554
leaq 0x78(%rsp), %rdi
callq 0x494da
movq %rbx, %rdi
callq 0x292f0
nop