1 |
// Geometry.cpp: implementation of the Geometry class.
|
2 |
//
|
3 |
//////////////////////////////////////////////////////////////////////
|
4 |
|
5 |
#include "../interface/Geometry.h"
|
6 |
#include "../interface/Chunk.h"
|
7 |
#include <algorithm>
|
8 |
|
9 |
|
10 |
void Geometry::Load (char* path)
|
11 |
{
|
12 |
FILE* pFile = fopen(path,"rb" );
|
13 |
if(pFile==NULL){
|
14 |
printf("The file %s can not be open !\n",path);
|
15 |
return;
|
16 |
}
|
17 |
|
18 |
prim = new FROG_Element_Base(C_PRIMARY);
|
19 |
FROG_ELEMENT::Read(pFile,prim,0);
|
20 |
//FROG_ELEMENT::PrintTree(prim);
|
21 |
fclose(pFile);
|
22 |
|
23 |
FillMap(prim);
|
24 |
}
|
25 |
|
26 |
|
27 |
void Geometry::FillMap(FROG_Element_Base* elt) {
|
28 |
const std::vector<FROG_Element_Base*>& dau = elt->daughters();
|
29 |
for( unsigned int i=0; i<dau.size(); ++i) {
|
30 |
if( FROG_Element_Base_With_DetId *mod = dynamic_cast<FROG_Element_Base_With_DetId*>(dau[i])) {
|
31 |
mapByDetId[mod->DetId()] = mod;
|
32 |
}
|
33 |
//if( dau[i]->daughters().size()>0 ) // temporary : could be removed if we use hash_multimap
|
34 |
// mapByType.insert(std::pair<unsigned short,FROG_Element_Base*>(dau[i]->type(),dau[i]));
|
35 |
FillMap(dau[i]);
|
36 |
}
|
37 |
}
|
38 |
|
39 |
|
40 |
void Geometry::Save (char* path)
|
41 |
{
|
42 |
prim->write();
|
43 |
FILE* pFile = fopen(path,"wb" );
|
44 |
unsigned short prim_type = prim->type();
|
45 |
unsigned int prim_size = prim->size();
|
46 |
fwrite(&prim_type,sizeof(prim_type),1,pFile);
|
47 |
fwrite(&prim_size,sizeof(prim_size),1,pFile);
|
48 |
fwrite(prim->data(),prim->size()-6,1,pFile);
|
49 |
fclose(pFile);
|
50 |
prim->clearData();
|
51 |
}
|
52 |
|
53 |
|
54 |
FROG_Element_Base* Geometry::FindByDetId (unsigned int DetId){
|
55 |
Frog_map_it it = mapByDetId.find(DetId);
|
56 |
if(it==mapByDetId.end())return NULL;
|
57 |
return it->second;
|
58 |
}
|
59 |
|
60 |
//Geometry::Frog_multimap_range Geometry::FindByType (unsigned short type){
|
61 |
// Look for mother elements with type = type
|
62 |
// return mapByType.equal_range(type);
|
63 |
//}
|