// File: 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
movq %rsp, %rbp
subq $0x380, %rsp            # imm = 0x380
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
movl -0xc(%rbp), %esi
callq 0xac1e0
movl %eax, -0x10(%rbp)
cmpl $0x0, -0xc(%rbp)
jb 0xa878a
movq -0x2c8(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, -0x2cc(%rbp)
movq 0xa8(%rax), %rdi
callq 0x8dec0
movl %eax, %ecx
movl -0x2cc(%rbp), %eax
cmpl %ecx, %eax
ja 0xa878a
movq -0x2c8(%rbp), %rdi
addq $0x78, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0x45190
cmpq $0x0, (%rax)
je 0xa878a
movq -0x2c8(%rbp), %rdi
addq $0x90, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xb3430
movq %rax, %rdi
callq 0xb3a10
testb $0x1, %al
jne 0xa878a
jmp 0xa8ade
cmpl $0x0, -0xc(%rbp)
jae 0xa87a3
movq 0x22c7b9(%rip), %rdi    # 0x2d4f50
leaq 0x133909(%rip), %rsi    # 0x1dc0a7
callq 0x2ff50
movq -0x2c8(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, -0x2d0(%rbp)
movq 0xa8(%rax), %rdi
callq 0x8dec0
movl %eax, %ecx
movl -0x2d0(%rbp), %eax
cmpl %ecx, %eax
jb 0xa87de
movq 0x22c77e(%rip), %rdi    # 0x2d4f50
leaq 0x1338d2(%rip), %rsi    # 0x1dc0ab
callq 0x2ff50
movq -0x2c8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0xb2a40
cmpq $0x0, %rax
jne 0xa8806
movq 0x22c756(%rip), %rdi    # 0x2d4f50
leaq 0x1338ae(%rip), %rsi    # 0x1dc0af
callq 0x2ff50
movq -0x2c8(%rbp), %rdi
addq $0x78, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0x45190
cmpq $0x0, (%rax)
jne 0xa8834
movq 0x22c728(%rip), %rdi    # 0x2d4f50
leaq 0x133884(%rip), %rsi    # 0x1dc0b3
callq 0x2ff50
movq -0x2c8(%rbp), %rdi
addq $0x90, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xb3430
movq %rax, %rdi
callq 0xb3a10
testb $0x1, %al
jne 0xa885a
jmp 0xa886d
movq 0x22c6ef(%rip), %rdi    # 0x2d4f50
leaq 0x13384f(%rip), %rsi    # 0x1dc0b7
callq 0x2ff50
movq -0x2c8(%rbp), %rax
movl 0x40(%rax), %esi
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x17e460
movq -0x2d8(%rbp), %rdx
leaq 0x133823(%rip), %rsi    # 0x1dc0bb
leaq -0xd0(%rbp), %rdi
callq 0x8e0f0
jmp 0xa88a6
leaq 0x132c85(%rip), %rdx    # 0x1db532
leaq -0xb0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x441f0
jmp 0xa88c2
movl -0xc(%rbp), %esi
leaq -0x120(%rbp), %rdi
callq 0x17e460
jmp 0xa88d3
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0x9c7d0
jmp 0xa88ef
leaq 0x13268e(%rip), %rdx    # 0x1daf84
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x441f0
jmp 0xa8908
movl -0x10(%rbp), %esi
leaq -0x140(%rbp), %rdi
callq 0x17e460
jmp 0xa8919
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x9c7d0
jmp 0xa892f
leaq 0x132d17(%rip), %rdx    # 0x1db64d
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x441f0
jmp 0xa8945
leaq -0x30(%rbp), %rdi
callq 0x17e420
jmp 0xa8950
leaq -0x30(%rbp), %rdi
callq 0x311e8
leaq -0x50(%rbp), %rdi
callq 0x311e8
leaq -0x140(%rbp), %rdi
callq 0x311e8
leaq -0x70(%rbp), %rdi
callq 0x311e8
leaq -0x90(%rbp), %rdi
callq 0x311e8
leaq -0x120(%rbp), %rdi
callq 0x311e8
leaq -0xb0(%rbp), %rdi
callq 0x311e8
leaq -0xd0(%rbp), %rdi
callq 0x311e8
leaq -0xf0(%rbp), %rdi
callq 0x311e8
jmp 0xa8ade
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xa8acd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xa8ac1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xa8ab5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xa8aa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xa8a9d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xa8a94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xa8a88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xa8a7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x311e8
leaq -0x50(%rbp), %rdi
callq 0x311e8
leaq -0x140(%rbp), %rdi
callq 0x311e8
leaq -0x70(%rbp), %rdi
callq 0x311e8
leaq -0x90(%rbp), %rdi
callq 0x311e8
leaq -0x120(%rbp), %rdi
callq 0x311e8
leaq -0xb0(%rbp), %rdi
callq 0x311e8
leaq -0xd0(%rbp), %rdi
callq 0x311e8
leaq -0xf0(%rbp), %rdi
callq 0x311e8
jmp 0xa911c
movq -0x2c8(%rbp), %rax
movq 0xa8(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xa8b43
movq 0x22c454(%rip), %rdi    # 0x2d4f50
leaq 0x1335e5(%rip), %rsi    # 0x1dc0e8
callq 0x2ff50
movq %rax, %rdi
movq -0x2c8(%rbp), %rax
movl 0x40(%rax), %esi
callq 0x30640
movq %rax, %rdi
leaq 0x13befd(%rip), %rsi    # 0x1e4a21
callq 0x2ff50
movq %rax, %rdi
movl -0x10(%rbp), %esi
callq 0x30640
movq %rax, %rdi
movq 0x22c48a(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
leaq -0x170(%rbp), %rdi
callq 0x8de10
movq -0x2c8(%rbp), %rdi
addq $0x90, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xb3430
movq %rax, -0x2e0(%rbp)
jmp 0xa8b70
movq -0x2e0(%rbp), %rdi
callq 0xb4350
movq %rax, -0x178(%rbp)
movq -0x2c8(%rbp), %rdi
addq $0x90, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xb3430
movq %rax, -0x2e8(%rbp)
jmp 0xa8ba4
movq -0x2e8(%rbp), %rdi
callq 0xb3a90
movq %rax, -0x180(%rbp)
leaq -0x178(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0xb4380
testb $0x1, %al
jne 0xa8bd3
jmp 0xa90fb
leaq -0x178(%rbp), %rdi
callq 0xb43b0
movq %rax, %rdi
addq $0x20, %rdi
movl $0x1, -0x18c(%rbp)
leaq -0x18c(%rbp), %rsi
callq 0xb3c00
movq %rax, -0x2f0(%rbp)
jmp 0xa8c05
movq -0x2f0(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
callq 0x8e350
movq %rax, -0x188(%rbp)
leaq -0x178(%rbp), %rdi
callq 0xb43b0
movq %rax, %rdi
addq $0x20, %rdi
movl $0x1, -0x19c(%rbp)
leaq -0x19c(%rbp), %rsi
callq 0xb3c00
movq %rax, -0x2f8(%rbp)
jmp 0xa8c50
movq -0x2f8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
callq 0x8e3b0
movq %rax, -0x198(%rbp)
leaq -0x188(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x8e380
testb $0x1, %al
jne 0xa8c85
jmp 0xa8ff5
leaq -0x1d0(%rbp), %rdi
callq 0x955e0
leaq -0x188(%rbp), %rdi
callq 0x8e4c0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x8e4e0
movq %rax, -0x1d8(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x8e4c0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x8e540
movq %rax, -0x1e0(%rbp)
leaq -0x1d8(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x8e510
testb $0x1, %al
jne 0xa8ceb
jmp 0xa8f3d
xorps %xmm0, %xmm0
movsd %xmm0, -0x1e8(%rbp)
movl $0x0, -0x1ec(%rbp)
movl $0x1, -0x1f0(%rbp)
movq -0x2c8(%rbp), %rcx
movl -0x1f0(%rbp), %eax
movq 0xa8(%rcx), %rcx
cmpl 0x1658(%rcx), %eax
ja 0xa8e5f
movq -0x2c8(%rbp), %rdi
addq $0x90, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xb3430
movq %rax, -0x300(%rbp)
jmp 0xa8d4b
leaq -0x178(%rbp), %rdi
callq 0xb43b0
movq -0x300(%rbp), %rdi
movq %rax, %rsi
callq 0xb3b60
movq %rax, -0x308(%rbp)
jmp 0xa8d6f
movq -0x308(%rbp), %rdi
movl -0x1f0(%rbp), %eax
movl %eax, -0x1f4(%rbp)
leaq -0x1f4(%rbp), %rsi
callq 0xb3c00
movq %rax, -0x310(%rbp)
jmp 0xa8d97
movq -0x310(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0x320(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x8e4c0
movq -0x320(%rbp), %rdi
movq %rax, %rsi
callq 0xb3cf0
movq %rax, -0x318(%rbp)
jmp 0xa8dcf
leaq -0x1d8(%rbp), %rdi
callq 0x8e590
movq -0x318(%rbp), %rdi
movq %rax, %rsi
callq 0xb3dc0
movq %rax, -0x328(%rbp)
jmp 0xa8df3
movq -0x328(%rbp), %rax
movsd (%rax), %xmm0
addsd -0x1e8(%rbp), %xmm0
movsd %xmm0, -0x1e8(%rbp)
movl -0x1ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ec(%rbp)
movl -0x1f0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1f0(%rbp)
jmp 0xa8d0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xa9110
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xa8fe4
movsd -0x1e8(%rbp), %xmm0
cvtsi2sdl -0x1ec(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x200(%rbp)
leaq -0x210(%rbp), %rdi
callq 0xb43d0
jmp 0xa8e89
leaq -0x1d8(%rbp), %rdi
callq 0x8e590
movq %rax, %rdi
leaq -0x200(%rbp), %rsi
callq 0xb43f0
movsd %xmm1, -0x338(%rbp)
movsd %xmm0, -0x330(%rbp)
jmp 0xa8eb6
movsd -0x338(%rbp), %xmm0
movsd -0x330(%rbp), %xmm1
movsd %xmm1, -0x220(%rbp)
movsd %xmm0, -0x218(%rbp)
leaq -0x210(%rbp), %rdi
movq %rdi, -0x350(%rbp)
leaq -0x220(%rbp), %rsi
callq 0xb4430
movq -0x350(%rbp), %rsi
leaq -0x1d0(%rbp), %rdi
callq 0xb4460
movb %dl, -0x341(%rbp)
movq %rax, -0x340(%rbp)
jmp 0xa8f12
movb -0x341(%rbp), %al
movq -0x340(%rbp), %rcx
movq %rcx, -0x230(%rbp)
movb %al, -0x228(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x8e5e0
jmp 0xa8cb0
leaq -0x188(%rbp), %rdi
callq 0x8e4c0
movq %rax, %rsi
leaq -0x280(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
callq 0xb44e0
jmp 0xa8f61
leaq -0x170(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0xb44a0
movb %dl, -0x359(%rbp)
movq %rax, -0x358(%rbp)
jmp 0xa8f83
movb -0x359(%rbp), %al
movq -0x358(%rbp), %rcx
movq %rcx, -0x290(%rbp)
movb %al, -0x288(%rbp)
leaq -0x280(%rbp), %rdi
callq 0xb4540
leaq -0x1d0(%rbp), %rdi
callq 0x8eba0
leaq -0x188(%rbp), %rdi
callq 0x8e6f0
jmp 0xa8c1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x280(%rbp), %rdi
callq 0xb4540
leaq -0x1d0(%rbp), %rdi
callq 0x8eba0
jmp 0xa9110
leaq -0x178(%rbp), %rdi
callq 0xb43b0
movq %rax, %rcx
movq -0x2c8(%rbp), %rax
addq $0x20, %rcx
movq %rcx, -0x370(%rbp)
movq 0xa8(%rax), %rax
movl 0x1658(%rax), %eax
incl %eax
movl %eax, -0x2a4(%rbp)
movl $0x160, %edi            # imm = 0x160
callq 0x2f3b0
movq %rax, -0x368(%rbp)
jmp 0xa903e
movq -0x368(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x8da60
jmp 0xa9053
movq -0x368(%rbp), %rax
movq %rax, -0x2b0(%rbp)
leaq -0x2a0(%rbp), %rdi
leaq -0x2a4(%rbp), %rsi
leaq -0x2b0(%rbp), %rdx
callq 0xb4570
jmp 0xa907d
movq -0x370(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0xb3550
movb %dl, -0x379(%rbp)
movq %rax, -0x378(%rbp)
jmp 0xa909f
movb -0x379(%rbp), %al
movq -0x378(%rbp), %rcx
movq %rcx, -0x2c0(%rbp)
movb %al, -0x2b8(%rbp)
leaq -0x170(%rbp), %rdi
callq 0xb45a0
leaq -0x178(%rbp), %rdi
callq 0xb45c0
jmp 0xa8b83
movq -0x368(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
movl $0x160, %esi            # imm = 0x160
callq 0x2f2a0
jmp 0xa9110
leaq -0x170(%rbp), %rdi
callq 0x8de50
addq $0x380, %rsp            # imm = 0x380
popq %rbp
retq
leaq -0x170(%rbp), %rdi
callq 0x8de50
movq -0xf8(%rbp), %rdi
callq 0x30170
nopl (%rax,%rax)