ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FastOpenGlDisplayer/src/SimEvent.cpp
(Generate patch)

Comparing UserCode/FastOpenGlDisplayer/src/SimEvent.cpp (file contents):
Revision 1.1 by querten, Fri Mar 14 18:31:08 2008 UTC vs.
Revision 1.14 by querten, Sun Jun 8 06:42:32 2008 UTC

# Line 19 | Line 19 | MySimEvent::~MySimEvent()
19   }
20  
21  
22 < int MySimEvent::LoadEvent(FILE* f)
22 > void MySimEvent::LoadEvent(FILE* pFile, stChunk* ParentChunk)
23   {      
24 <        Chunk primary_chunk;
25 <
26 <        primary_chunk.read  =fread(&primary_chunk.type,sizeof(int),1,f) * sizeof(int);
27 <        primary_chunk.read +=fread(&primary_chunk.size,sizeof(int),1,f) * sizeof(int);
28 <
29 <        if(primary_chunk.type!=C_EVENT) return 0;
24 > /*
25 >        unsigned short temp;
26 >        fread(&temp,1,2,pFile);
27 >        fseek(pFile,-2,SEEK_CUR);
28 >        printf("Parent = %i --> Current ChunkId = %i to read = %i\n",ParentChunk->type,temp,0);
29 > */
30 >        stChunk* CurrentChunk  = new stChunk;
31 >        ReadChunk(pFile, CurrentChunk);
32  
33 <        while(primary_chunk.read<primary_chunk.size)
33 >        switch(CurrentChunk->type)
34          {
35 <                primary_chunk.read += LoadChunk(f);
36 <        }
35 >                case C_EVENT:                   // Event                        
36 >                        while(CurrentChunk->read<CurrentChunk->size){
37 >                                LoadEvent(pFile,CurrentChunk);
38 >                        }
39 >                        break;
40  
36 //      ComputeLine();
41  
42 <        return primary_chunk.read;
43 < }
42 >        ///////////////////////////SIM DATA//////////////////////////
43 >                case C_SIM:                         // SimData
44 >                        while(CurrentChunk->read<CurrentChunk->size){
45 >                                LoadEvent(pFile,CurrentChunk);
46 >                        }
47 >                        break;
48  
49 +                case C_SIM_TRACKHIT:{   // PSimHit              
50 +                        while(CurrentChunk->read<CurrentChunk->size){
51 +                                MyPSimHit* temp_SimHit = new MyPSimHit;
52 +                                CurrentChunk->read += fread(temp_SimHit,sizeof(MyPSimHit),1,pFile) * sizeof(MyPSimHit);
53 +                                MyPSimHitCollection.push_back(temp_SimHit);
54 +                        }
55 +                        }break;
56  
57 < void MySimEvent::SaveEvent(FILE* f)
58 < {
59 <        Chunk Primary_chunk;
60 <        Primary_chunk.type  = C_EVENT;
61 <        Primary_chunk.read  = 2*sizeof(int);
62 <        Primary_chunk.size = Chunk_size();
57 >                case C_SIM_CALOHIT:{            // PCaloHit                            
58 >                        while(CurrentChunk->read<CurrentChunk->size){
59 >                                MyPCaloHit* temp_PSimCaloHit = new MyPCaloHit;
60 >                                CurrentChunk->read += fread(temp_PSimCaloHit,sizeof(MyPCaloHit),1,pFile) * sizeof(MyPCaloHit);
61 >                                MyPCaloHitCollection.push_back(temp_PSimCaloHit);
62 >                        }
63 >                        }break;
64  
65 <        fwrite(&Primary_chunk.type,sizeof(int),1,f);
66 <        fwrite(&Primary_chunk.size,sizeof(int),1,f);
65 >                case C_SIM_VERTEX:{             // SimVertex
66 >                        while(CurrentChunk->read<CurrentChunk->size){
67 >                                MySimVertex* temp_SimVertex = new MySimVertex;
68 >                                CurrentChunk->read += fread(temp_SimVertex,sizeof(MySimVertex),1,pFile) * sizeof(MySimVertex);
69 >                                MySimVertexCollection.push_back(temp_SimVertex);
70 >                        }
71 >                        }break;
72  
73 <        Chunk chunk_temp;
73 >                case C_SIM_TRACK:{              // SimTrack
74 >                        while(CurrentChunk->read<CurrentChunk->size){
75 >                                MySimTrack* temp_SimTrack = new MySimTrack;
76 >                                CurrentChunk->read += fread(temp_SimTrack,sizeof(MySimTrack),1,pFile) * sizeof(MySimTrack);
77 >                                MySimTrackCollection.push_back(temp_SimTrack);
78 >                        }
79 >                        }break;
80  
54        unsigned int i;
55        for(i=0;i<MyPSimHitCollection.size();i++){              
56                chunk_temp.type = C_PSIMHIT;
57                chunk_temp.size = 2*sizeof(int)+sizeof(MyPSimHit);
58
59                fwrite(&chunk_temp.type,sizeof(int),1,f);
60                fwrite(&chunk_temp.size,sizeof(int),1,f);
61                fwrite(&MyPSimHitCollection[i],sizeof(MyPSimHit),1,f);
81  
63                Primary_chunk.read+= chunk_temp.size;
64        }
82  
83 <        for(i=0;i<MyPCaloHitCollection.size();i++){            
84 <                chunk_temp.type = C_PCALOHIT;
85 <                chunk_temp.size = 2*sizeof(int)+sizeof(MyPCaloHit);
86 <
87 <                fwrite(&chunk_temp.type,sizeof(int),1,f);
88 <                fwrite(&chunk_temp.size,sizeof(int),1,f);
72 <                fwrite(&MyPCaloHitCollection[i],sizeof(MyPCaloHit),1,f);
83 >                //////////////////////////RECO DATA//////////////////////////
84 >                case C_RECO:                // RecoData
85 >                        while(CurrentChunk->read<CurrentChunk->size){
86 >                                LoadEvent(pFile,CurrentChunk);
87 >                        }
88 >                        break;
89  
90 <                Primary_chunk.read+= chunk_temp.size;
91 <        }
90 >                case C_RECO_TRACK:{             // RecoTrack
91 >                        MyRecoTrackCollection.push_back(new MyRecoTrack);
92 >                        while(CurrentChunk->read<CurrentChunk->size){
93 >                                LoadEvent(pFile,CurrentChunk);
94 >                        }
95 >                        }break;
96  
97 <        for(i=0;i<MySimVertexCollection.size();i++){            
98 <                chunk_temp.type = C_SIMVERTEX;
99 <                chunk_temp.size = 2*sizeof(int)+sizeof(MySimVertex);
100 <
101 <                fwrite(&chunk_temp.type,sizeof(int),1,f);
102 <                fwrite(&chunk_temp.size,sizeof(int),1,f);
103 <                fwrite(&MySimVertexCollection[i],sizeof(MySimVertex),1,f);
97 >                case C_RECO_TRACKHIT:{  // RecHits              
98 >                        while(CurrentChunk->read<CurrentChunk->size){
99 >                                MyRecoHit* temp_RecoHit = new MyRecoHit;
100 >                                CurrentChunk->read += fread(temp_RecoHit,sizeof(MyRecoHit),1,pFile) * sizeof(MyRecoHit);
101 >                                MyRecoTrackCollection[MyRecoTrackCollection.size()-1]->Hits.push_back(temp_RecoHit);                            
102 >                        }
103 >                        }break;
104  
105 <                Primary_chunk.read+= chunk_temp.size;
106 <        }
105 >                case C_RECO_TRACKINFO:{ // TrackInfo                                    
106 >                                MyRecoTrackInfo* temp_Info = new MyRecoTrackInfo;
107 >                                CurrentChunk->read += fread(temp_Info,sizeof(MyRecoTrackInfo),1,pFile) * sizeof(MyRecoTrackInfo);
108 >                                MyRecoTrackCollection[MyRecoTrackCollection.size()-1]->Info = temp_Info;
109 >                        }break;
110 >
111 >                case C_RECO_ECALHIT:{   // ECAL Hits            
112 >                        while(CurrentChunk->read<CurrentChunk->size){
113 >                                MyCaloHit* temp_EcalHit = new MyCaloHit;
114 >                                CurrentChunk->read += fread(temp_EcalHit,sizeof(MyCaloHit),1,pFile) * sizeof(MyCaloHit);                        
115 >                                MyEcalCaloHitCollection.push_back(temp_EcalHit);
116 >                        }
117 >                        }break;
118  
119 <        for(i=0;i<MySimTrackCollection.size();i++){            
120 <                chunk_temp.type = C_SIMTRACK;
121 <                chunk_temp.size = 2*sizeof(int)+sizeof(MySimTrack);
122 <
123 <                fwrite(&chunk_temp.type,sizeof(int),1,f);
124 <                fwrite(&chunk_temp.size,sizeof(int),1,f);
125 <                fwrite(&MySimTrackCollection[i],sizeof(MySimTrack),1,f);
119 >                case C_RECO_HCALHIT:{   // HCAL Hits    
120 >                        while(CurrentChunk->read<CurrentChunk->size){
121 >                                MyCaloHit* temp_HcalHit = new MyCaloHit;
122 >                                CurrentChunk->read += fread(temp_HcalHit,sizeof(MyCaloHit),1,pFile) * sizeof(MyCaloHit);                        
123 >                                MyHcalCaloHitCollection.push_back(temp_HcalHit);
124 >                        }
125 >                        }break;
126  
127 <                Primary_chunk.read+= chunk_temp.size;
128 <        }              
127 >                case C_RECO_MUONSEG:{           // Muon Segments        
128 >                        while(CurrentChunk->read<CurrentChunk->size){
129 >                                MyMuonSegment* temp_MuonSeg = new MyMuonSegment;
130 >                                CurrentChunk->read += fread(temp_MuonSeg,sizeof(MyMuonSegment),1,pFile) * sizeof(MyMuonSegment);
131 >                                MyMuonSegmentCollection.push_back(temp_MuonSeg);
132 >                        }
133 >                        }break;
134  
135  
136 <        for(i=0;i<MyRecoTrackCollection.size();i++){            
137 <                chunk_temp.type = C_RECOTRACK;
138 < //              chunk_temp.size = 2*sizeof(int)+sizeof(MyRecoTrack);
139 <                chunk_temp.size = 2*sizeof(int)+sizeof(int)+MyRecoTrackCollection[i].N * sizeof(MyRecoHit);
140 <
141 <                fwrite(&chunk_temp.type,sizeof(int),1,f);
142 <                fwrite(&chunk_temp.size,sizeof(int),1,f);
107 <                fwrite(&MyRecoTrackCollection[i].N,sizeof(int),1,f);
108 <          
109 <                for(int j=0;j<MyRecoTrackCollection[i].N;j++){
110 <                        fwrite(&MyRecoTrackCollection[i].Hits[j],sizeof(MyRecoHit),1,f);
111 <                }
136 >                case C_RECO_MUONHIT:{           // Muon Hits
137 >                        while(CurrentChunk->read<CurrentChunk->size){
138 >                                MyMuonHit* temp_MuonHit = new MyMuonHit;
139 >                                CurrentChunk->read += fread(temp_MuonHit,sizeof(MyMuonHit),1,pFile) * sizeof(MyMuonHit);
140 >                                MyMuonHitCollection.push_back(temp_MuonHit);
141 >                        }
142 >                        }break;
143  
113                Primary_chunk.read+= chunk_temp.size;
114        }              
144  
145 +                ////////////////////////UNKOWN CHUNK ////////////////////////
146 +                default:
147 +                        printf("Unknown ChunkID (%i)\n",CurrentChunk->type);
148 +                        printf("Chunk will be skipped\n");
149 +                        printf("The program can not run properly\n");
150 +                        fseek (pFile,CurrentChunk->size-CurrentChunk->read,SEEK_CUR);
151 +                        CurrentChunk->read += CurrentChunk->size-CurrentChunk->read;
152 +                        break;
153 +        }              
154  
155 +        ParentChunk->read += CurrentChunk->read;
156   }
157  
158 < int MySimEvent::LoadChunk (FILE* f)
158 >
159 >
160 > void MySimEvent::SaveEvent(stChunkToSave* ParentChunk)
161   {
162 <        Chunk chunk;
162 >        unsigned int i;
163 >        stChunkToSave* CurrentChunk;
164 >        void* data_buffer;
165          
166 <        chunk.read  =fread(&chunk.type,sizeof(int),1,f) * sizeof(int);
124 <        chunk.read +=fread(&chunk.size,sizeof(int),1,f) * sizeof(int);
125 <        switch(chunk.type)
166 >        switch(ParentChunk->type)
167          {
168 <                case C_PSIMHIT:                 // PSimHit                              
169 <                        MyPSimHit temp_SimHit;
170 <                        chunk.read += fread(&temp_SimHit,sizeof(MyPSimHit),1,f) * sizeof(MyPSimHit);
171 <                        MyPSimHitCollection.push_back(temp_SimHit);
168 >                case C_PRIMARY:                 // PrimaryChunk        
169 >                        CurrentChunk = new stChunkToSave;
170 >                        CurrentChunk->type = C_EVENT;
171 >                        CurrentChunk->size = 6;
172 >                        ParentChunk->daughters.push_back(CurrentChunk);
173                          break;
174  
175 <                case C_PCALOHIT:                // PCaloHit                            
176 <                        MyPCaloHit temp_CaloHit;
177 <                        chunk.read += fread(&temp_CaloHit,sizeof(MyPCaloHit),1,f) * sizeof(MyPCaloHit);
178 <                        MyPCaloHitCollection.push_back(temp_CaloHit);
175 >                case C_EVENT:                   // Event                        
176 >                        CurrentChunk = new stChunkToSave;
177 >                        CurrentChunk->type = C_SIM;                                    
178 >                        CurrentChunk->size = 6;
179 >                        ParentChunk->daughters.push_back(CurrentChunk);
180 >
181 >                        CurrentChunk = new stChunkToSave;
182 >                        CurrentChunk->type = C_RECO;                                    
183 >                        CurrentChunk->size = 6;
184 >                        ParentChunk->daughters.push_back(CurrentChunk);
185                          break;
186 +        
187 +                case C_SIM:                         // SimData
188 +                        if(MyPSimHitCollection.size()>0){
189 +                                CurrentChunk       = new stChunkToSave;
190 +                                CurrentChunk->type = C_SIM_TRACKHIT;
191 +                                CurrentChunk->size = 6 + sizeof(MyPSimHit)*MyPSimHitCollection.size();
192 +                                data_buffer        = new void*[CurrentChunk->size-6];                                          
193 +                                CurrentChunk->data = data_buffer;
194 +                                for(i=0;i<MyPSimHitCollection.size();i++){              
195 +                                        memcpy( data_buffer, MyPSimHitCollection[i], sizeof(MyPSimHit) );
196 +                                        data_buffer = (void*)((unsigned long)data_buffer + sizeof(MyPSimHit));                                  
197 +                                }      
198 +                                ParentChunk->daughters.push_back(CurrentChunk);
199 +                        }
200  
201 <                case C_SIMVERTEX:               // SimVertex
202 <                        MySimVertex temp_SimVertex;
203 <                        chunk.read += fread(&temp_SimVertex,sizeof(MySimVertex),1,f) * sizeof(MySimVertex);
204 <                        MySimVertexCollection.push_back(temp_SimVertex);
205 <                        break;
201 >                        if(MyPCaloHitCollection.size()>0){
202 >                                CurrentChunk       = new stChunkToSave;
203 >                                CurrentChunk->type = C_SIM_CALOHIT;
204 >                                CurrentChunk->size = 6 + sizeof(MyPCaloHit)*MyPCaloHitCollection.size();
205 >                                data_buffer        = new void*[CurrentChunk->size-6];                                          
206 >                                CurrentChunk->data = data_buffer;
207 >                                for(i=0;i<MyPCaloHitCollection.size();i++){            
208 >                                        memcpy( data_buffer, MyPCaloHitCollection[i], sizeof(MyPCaloHit) );
209 >                                        data_buffer = (void*)((unsigned long)data_buffer + sizeof(MyPCaloHit));                                
210 >                                }      
211 >                                ParentChunk->daughters.push_back(CurrentChunk);
212 >                        }
213  
214 <                case C_SIMTRACK:                // SimTrack
215 <                        MySimTrack temp_SimTrack;
216 <                        chunk.read += fread(&temp_SimTrack,sizeof(MySimTrack),1,f) * sizeof(MySimTrack);
217 <                        MySimTrackCollection.push_back(temp_SimTrack);
214 >                        if(MySimVertexCollection.size()>0){
215 >                                CurrentChunk       = new stChunkToSave;
216 >                                CurrentChunk->type = C_SIM_VERTEX;
217 >                                CurrentChunk->size = 6 + sizeof(MySimVertex)*MySimVertexCollection.size();
218 >                                data_buffer        = new void*[CurrentChunk->size-6];                                          
219 >                                CurrentChunk->data = data_buffer;
220 >                                for(i=0;i<MySimVertexCollection.size();i++){            
221 >                                        memcpy( data_buffer, MySimVertexCollection[i], sizeof(MySimVertex) );
222 >                                        data_buffer = (void*)((unsigned long)data_buffer + sizeof(MySimVertex));                                        
223 >                                }      
224 >                                ParentChunk->daughters.push_back(CurrentChunk);
225 >                        }
226 >
227 >                        if(MySimTrackCollection.size()>0){
228 >                                CurrentChunk       = new stChunkToSave;
229 >                                CurrentChunk->type = C_SIM_TRACK;
230 >                                CurrentChunk->size = 6 + sizeof(MySimTrack)*MySimTrackCollection.size();
231 >                                data_buffer        = new void*[CurrentChunk->size-6];                                          
232 >                                CurrentChunk->data = data_buffer;
233 >                                for(i=0;i<MySimTrackCollection.size();i++){            
234 >                                        memcpy( data_buffer, MySimTrackCollection[i], sizeof(MySimTrack) );
235 >                                        data_buffer = (void*)((unsigned long)data_buffer + sizeof(MySimTrack));                                
236 >                                }      
237 >                                ParentChunk->daughters.push_back(CurrentChunk);
238 >                        }              
239                          break;
240  
241 <                case C_RECOTRACK:               // RecoTrack
242 <                        MyRecoTrack temp_RecoTrack;
243 <                        chunk.read += fread(&temp_RecoTrack.N,sizeof(int),1,f) * sizeof(int);
244 <                        temp_RecoTrack.Hits = new MyRecoHit[temp_RecoTrack.N];
241 >                case C_RECO:                // RecoData
242 >                        for(i=0;i<MyRecoTrackCollection.size();i++){            
243 >                                CurrentChunk         = new stChunkToSave;
244 >                                CurrentChunk->type   = C_RECO_TRACK;
245 >                                CurrentChunk->size   = 6;
246 >                                CurrentChunk->buffer = MyRecoTrackCollection[i];
247 >                                ParentChunk->daughters.push_back(CurrentChunk);
248 >                        }      
249  
250 <                        for(int j=0;j<temp_RecoTrack.N;j++){
251 <                                chunk.read += fread(&temp_RecoTrack.Hits[j],sizeof(MyRecoHit),1,f) * sizeof(MyRecoHit);
250 >                        
251 >                        if(MyEcalCaloHitCollection.size()>0){
252 >                                CurrentChunk       = new stChunkToSave;
253 >                                CurrentChunk->type = C_RECO_ECALHIT;
254 >                                CurrentChunk->size = 6 + sizeof(MyCaloHit)*MyEcalCaloHitCollection.size();
255 >                                data_buffer        = new void*[CurrentChunk->size-6];                                          
256 >                                CurrentChunk->data = data_buffer;
257 >                                for(i=0;i<MyEcalCaloHitCollection.size();i++){          
258 >                                        memcpy( data_buffer, MyEcalCaloHitCollection[i], sizeof(MyCaloHit) );
259 >                                        data_buffer = (void*)((unsigned long)data_buffer + sizeof(MyCaloHit));                                  
260 >                                }      
261 >                                ParentChunk->daughters.push_back(CurrentChunk);
262                          }
263  
264 <                        MyRecoTrackCollection.push_back(temp_RecoTrack);
265 <                        break;
264 >                        if(MyHcalCaloHitCollection.size()>0){
265 >                                CurrentChunk       = new stChunkToSave;
266 >                                CurrentChunk->type = C_RECO_HCALHIT;
267 >                                CurrentChunk->size = 6 + sizeof(MyCaloHit)*MyHcalCaloHitCollection.size();
268 >                                data_buffer        = new void*[CurrentChunk->size-6];                                          
269 >                                CurrentChunk->data = data_buffer;
270 >                                for(i=0;i<MyHcalCaloHitCollection.size();i++){          
271 >                                        memcpy( data_buffer, MyHcalCaloHitCollection[i], sizeof(MyCaloHit) );
272 >                                        data_buffer = (void*)((unsigned long)data_buffer + sizeof(MyCaloHit));                                  
273 >                                }      
274 >                                ParentChunk->daughters.push_back(CurrentChunk);
275 >                        }
276  
277 +                        if(MyMuonSegmentCollection.size()>0){
278 +                                CurrentChunk       = new stChunkToSave;
279 +                                CurrentChunk->type = C_RECO_MUONSEG;
280 +                                CurrentChunk->size = 6 + sizeof(MyMuonSegment)*MyMuonSegmentCollection.size();
281 +                                data_buffer        = new void*[CurrentChunk->size-6];                                          
282 +                                CurrentChunk->data = data_buffer;
283 +                                for(i=0;i<MyMuonSegmentCollection.size();i++){          
284 +                                        memcpy( data_buffer, MyMuonSegmentCollection[i], sizeof(MyMuonSegment) );
285 +                                        data_buffer = (void*)((unsigned long)data_buffer + sizeof(MyMuonSegment));                                      
286 +                                }      
287 +                                ParentChunk->daughters.push_back(CurrentChunk);
288 +                        }
289  
290 <                default:
291 <                        fseek (f,chunk.size-chunk.read,SEEK_CUR);
292 <                        chunk.read += chunk.size-chunk.read;
290 >                        if(MyMuonHitCollection.size()>0){
291 >                                CurrentChunk       = new stChunkToSave;
292 >                                CurrentChunk->type = C_RECO_MUONHIT;
293 >                                CurrentChunk->size = 6 + sizeof(MyMuonHit)*MyMuonHitCollection.size();
294 >                                data_buffer        = new void*[CurrentChunk->size-6];                                          
295 >                                CurrentChunk->data = data_buffer;
296 >                                for(i=0;i<MyMuonHitCollection.size();i++){              
297 >                                        memcpy( data_buffer, MyMuonHitCollection[i], sizeof(MyMuonHit) );
298 >                                        data_buffer = (void*)((unsigned long)data_buffer + sizeof(MyMuonHit));                                  
299 >                                }      
300 >                                ParentChunk->daughters.push_back(CurrentChunk);
301 >                        }                                      
302                          break;
168        }              
303  
170        return chunk.read;
171 }
172
173 int  MySimEvent::Chunk_size()
174 {
175        int size  = 2*sizeof(int);      
176                size += MyPSimHitCollection.size()  *(sizeof(MyPSimHit)  + 2*sizeof(int));
177                size += MyPCaloHitCollection.size() *(sizeof(MyPCaloHit) + 2*sizeof(int));
178                size += MySimVertexCollection.size()*(sizeof(MySimVertex)+ 2*sizeof(int));
179                size += MySimTrackCollection.size() *(sizeof(MySimTrack) + 2*sizeof(int));
180                
181                for(unsigned int i=0;i<MyRecoTrackCollection.size();i++){
182                        size += 2*sizeof(int) + sizeof(int);
183                        size += MyRecoTrackCollection[i].N * sizeof(MyRecoHit);
184                }
304  
305 <        return size;
306 < }
305 >                case C_RECO_TRACK:     // RecoTrack    
306 >                        if(((MyRecoTrack*)ParentChunk->buffer)->Hits.size()>0){
307 >                                CurrentChunk       = new stChunkToSave;
308 >                                CurrentChunk->type = C_RECO_TRACKHIT;
309 >                                CurrentChunk->size = 6 + sizeof(MyRecoHit)*((MyRecoTrack*)ParentChunk->buffer)->Hits.size();
310 >                                data_buffer        = new void*[CurrentChunk->size-6];                                          
311 >                                CurrentChunk->data = data_buffer;
312 >                                for(i=0;i<((MyRecoTrack*)ParentChunk->buffer)->Hits.size();i++){                
313 >                                        memcpy( data_buffer, ((MyRecoTrack*)ParentChunk->buffer)->Hits[i], sizeof(MyRecoHit) );
314 >                                        data_buffer = (void*)((unsigned long)data_buffer + sizeof(MyRecoHit));                                  
315 >                                }      
316 >                                ParentChunk->daughters.push_back(CurrentChunk);
317 >
318 >                                if(((MyRecoTrack*)ParentChunk->buffer)->Info!=NULL){
319 >                                        CurrentChunk       = new stChunkToSave;
320 >                                        CurrentChunk->type = C_RECO_TRACKINFO;
321 >                                        CurrentChunk->size = 6 + sizeof(MyRecoTrackInfo);
322 >                                        data_buffer        = new void*[CurrentChunk->size-6];                                          
323 >                                        CurrentChunk->data = data_buffer;
324 >                                        memcpy( data_buffer, ((MyRecoTrack*)ParentChunk->buffer)->Info, sizeof(MyRecoTrackInfo) );                              
325 >                                        ParentChunk->daughters.push_back(CurrentChunk);
326 >                                }
327 >                        }              
328 >                        break;
329  
330 < void MySimEvent::Open(char* path)
331 < {
332 <        FILE* f = fopen(path,"wb" );            
192 <        SaveEvent(f);
193 <        fclose(f);
330 >                default:
331 >                        break;
332 >        }      
333  
334 +        
335 +        for(unsigned int i=0; i<ParentChunk->daughters.size();i++)
336 +        {
337 +                if( !(ParentChunk->type == C_PRIMARY && i!=ParentChunk->daughters.size()-1))
338 +                        SaveEvent(ParentChunk->daughters[i]);                                          
339 +                ParentChunk->size += ParentChunk->daughters[i]->size;          
340 +        }
341  
196        FILE* g = fopen(path,"rb" );            
197        LoadEvent(g);
198        fclose(g);      
342   }
343  
201
202
203
204
205 ////////////////////////// SIM EVENTS ///////////////////////////
206
207
344   MySimEvents::MySimEvents()
345   {
346   /*
# Line 212 | Line 348 | MySimEvents::MySimEvents()
348                  MySimEvent* temp_Event = new MySimEvent;                
349                  for(int j=0;j<2;j++){
350                          MyPSimHit temp;
351 <                        temp.x  = float(rand()%200-100);
352 <                        temp.y  = float(rand()%200-100);
353 <                        temp.z  = float(rand()%200-100);
354 <                        temp.dEdX = float(1+rand()%10);
351 >                        temp.x    = (float)(1.0f);
352 >                        temp.y    = (float)(2.0f);
353 >                        temp.z    = (float)(3.0f);
354 >                        temp.dEdX = 0.01f;
355 >                        temp.ProcessType = 255;
356                          temp_Event->MyPSimHitCollection.push_back(temp);
357                  
358                          MyPCaloHit temp2;
359 <                        temp2.x = float(rand()%200-100);
360 <                        temp2.y = float(rand()%200-100);
361 <                        temp2.z = float(rand()%200-100);
362 <                        temp2.E = float(1+rand()%3);
359 >                        temp2.x = (float)(rand()%200-100);
360 >                        temp2.y = (float)(rand()%200-100);
361 >                        temp2.z = (float)(rand()%200-100);
362 >                        temp2.E = 0.01f;
363 >                        temp2.ProcessType = 255;
364                          temp_Event->MyPCaloHitCollection.push_back(temp2);
365                          
366                          MySimVertex temp3;
367 <                        temp3.x = float(rand()%200-100);
368 <                        temp3.y = float(rand()%200-100);
369 <                        temp3.z = float(rand()%200-100);
367 >                        temp3.x = (float)(rand()%200-100);
368 >                        temp3.y = (float)(rand()%200-100);
369 >                        temp3.z = (float)(rand()%200-100);
370 >                        temp3.parentTrack_id = 255;                    
371                          temp_Event->MySimVertexCollection.push_back(temp3);
372                          
373                          MySimTrack temp4;
374 <                        temp4.Px = 10;
374 >                        temp4.Px = (float)(rand()%200-100);
375 >                        temp4.Py = (float)(rand()%200-100);
376 >                        temp4.Pz = (float)(rand()%200-100);
377 >                        temp4.E  = 1;
378 >                        temp4.track_id = 255;
379 >                        temp4.Type     = 255;
380 >                        temp4.charge   = 0;
381                          temp_Event->MySimTrackCollection.push_back(temp4);
382  
383 < //                      MyRecoTrack temp5;
384 < //                      temp5.N = rand()%5+1;
385 < //                      temp5.Hits = new MyRecoHit[10];
386 < //                      for(int h=0;h<temp5.N;h++){
387 < //                              temp5.Hits[h].x = (float)(rand()%200-100);
388 < //                              temp5.Hits[h].y = (float)(rand()%200-100);
389 < //                              temp5.Hits[h].z = (float)(rand()%200-100);
390 < //                              temp5.Hits[h].DetId = rand()%2000;
391 < //                              temp5.Hits[h].Charge = rand()%500;
392 < //                      }
393 < //                      temp_Event->MyRecoTrackCollection.push_back(temp5);
383 >                        MyRecoTrack temp5;                      
384 >                        for(unsigned int h=0;h<2;h++){
385 >                                MyRecoHit tmp;
386 >                                tmp.x = (float)(rand()%200-100);
387 >                                tmp.y = (float)(rand()%200-100);
388 >                                tmp.z = (float)(rand()%200-100);
389 >                                tmp.DetId = 255;
390 >                                tmp.Charge = rand()%500;
391 >                                temp5.Hits.push_back(tmp);
392 >                        }
393 >                        temp_Event->MyRecoTrackCollection.push_back(temp5);
394  
395 <                }
396 <                
395 >                        MyCaloHit temp6;
396 >                        temp6.t  = (float)(rand()%200-100);
397 >                        temp6.E  = (float)(rand()%200-100);
398 >                        temp6.DetId = 10;
399 >                        temp_Event->MyEcalCaloHitCollection.push_back(temp6);
400 >
401 >                        MyCaloHit temp7;
402 >                        temp7.t  = (float)(rand()%200-100);
403 >                        temp7.E  = (float)(rand()%200-100);
404 >                        temp7.DetId = 20;
405 >                        temp_Event->MyHcalCaloHitCollection.push_back(temp7);
406 >                }              
407                  Events.push_back(temp_Event);
408          }
409   */
255 //      Current_Event = 1;
410   }
411  
412  
# Line 261 | Line 415 | MySimEvents::~MySimEvents()
415  
416   }
417  
418 < void MySimEvents::Load(char* path)
418 > void MySimEvents::Load(const char* path)
419   {
420 <        FILE* f = fopen(path,"rb" );
421 <
422 <        Chunk primary_chunk;
420 >        FILE* f = fopen(path,"rb" );    
421 >        if(f==NULL){
422 >                printf("The file %s can not be open !\n",path);
423 >                exit(0);
424 >        }
425  
426 <        primary_chunk.read  =fread(&primary_chunk.type,sizeof(int),1,f) * sizeof(int);
271 <        primary_chunk.read +=fread(&primary_chunk.size,sizeof(int),1,f) * sizeof(int);
426 >        stChunk* PrimaryChunk = new stChunk;
427  
428 <        if(primary_chunk.type!=C_PRIMARY) return;
428 >        PrimaryChunk->read  =fread(&PrimaryChunk->type,1,2,f);
429 >        PrimaryChunk->read +=fread(&PrimaryChunk->size,1,4,f);
430  
431 +        if(PrimaryChunk->type!=C_PRIMARY){
432 +                printf("PrimaryChunk has not a good Id (%i!=%i)\n",PrimaryChunk->type,C_PRIMARY);
433 +                printf("Exiting...\n");
434 +                exit(0);
435 +        }
436          
437 <        while(primary_chunk.read<primary_chunk.size)
437 >        while(PrimaryChunk->read<PrimaryChunk->size)
438          {      
439                  MySimEvent* temp = new MySimEvent;
440 <                primary_chunk.read += temp->LoadEvent(f);
440 >                temp->LoadEvent(f,PrimaryChunk);
441                  Events.push_back(temp);
442          }
443          fclose(f);
# Line 284 | Line 445 | void MySimEvents::Load(char* path)
445          Current_Event = 0;
446  
447  
448 <
448 > /*
449          FILE* g = fopen("LOG.txt","w+" );              
450          for(unsigned int i=0;i<Events.size();i++)
451          {      
# Line 317 | Line 478 | void MySimEvents::Load(char* path)
478                  for(j=0;j<Events[i]->MyRecoTrackCollection.size();j++)
479                  {
480                          MyRecoTrack track = Events[i]->MyRecoTrackCollection[j];
481 <                        fprintf(g,"RecoTrack\t%8i\n",track.N);
482 <                        for(int h=0;h<track.N;h++){
481 >                        fprintf(g,"RecoTrack\t%4i\n",track.Hits.size());
482 >                        for(unsigned int h=0;h<track.Hits.size();h++){
483                                  MyRecoHit hit = track.Hits[h];
484 <                                fprintf(g,"\t\t\tHit : %6.2f\t%6.2f\t%6.2f\t%8i\t%8i\n",hit.x,hit.y,hit.z,hit.Charge,hit.DetId);
484 >                                fprintf(g,"   Hit : %6.2f\t%6.2f\t%6.2f\t%8i\t%8i\n",hit.x,hit.y,hit.z,hit.Charge,hit.DetId);
485                          }
486 +                }              
487 +
488 +                for(j=0;j<Events[i]->MyEcalCaloHitCollection.size();j++)
489 +                {
490 +                        MyCaloHit calohit = Events[i]->MyEcalCaloHitCollection[j];
491 +                        fprintf(g,"CaloHit\t%6.2f\t%6.2f\t%i\n",calohit.E,calohit.t,calohit.DetId);
492 +                }
493 +
494 +                for(j=0;j<Events[i]->MyHcalCaloHitCollection.size();j++)
495 +                {
496 +                        MyCaloHit calohit = Events[i]->MyHcalCaloHitCollection[j];
497 +                        fprintf(g,"CaloHit\t%6.2f\t%6.2f\t%i\n",calohit.E,calohit.t,calohit.DetId);
498                  }
326                
499          }
500          fclose(g);
501 <
501 > */
502  
503   }
504  
505  
506 < void MySimEvents::Save(char* path)
506 > void MySimEvents::Save(const char* path)
507   {
508 <        FILE* f = fopen(path,"wb" );
509 <
510 <        Chunk Primary_chunk;
508 >        stChunkToSave* Primary_chunk = new stChunkToSave;
509 >        
510 >        Primary_chunk->type  = C_PRIMARY;      
511 >        Primary_chunk->size =  6;
512          
513 <        Primary_chunk.type  = C_PRIMARY;
514 <        Primary_chunk.read  = 2*sizeof(int);    
342 <        Primary_chunk.size =  2*sizeof(int);
343 <        for(unsigned int i=0;i<Events.size();i++){
344 <                Primary_chunk.size += Events[i]->Chunk_size();
513 >        for(unsigned int i=0;i<Events.size();i++){              
514 >                Events[i]->SaveEvent(Primary_chunk);
515          }
516  
517 <        fwrite(&Primary_chunk.type,sizeof(int),1,f);
518 <        fwrite(&Primary_chunk.size,sizeof(int),1,f);
519 <
520 <        for(unsigned int i=0;i<Events.size();i++){
521 <                Events[i]->SaveEvent(f);
517 >        Primary_chunk->size =  6;
518 >        for(unsigned int i=0;i<Primary_chunk->daughters.size();i++){
519 >                Primary_chunk->size += Primary_chunk->daughters[i]->size;
520 >        }      
521 > /*
522 >        printf("%i (%i)\n",Primary_chunk->type,Primary_chunk->size);
523 >        for(unsigned int i=0;i<Primary_chunk->daughters.size();i++){
524 >                stChunkToSave* tmp = Primary_chunk->daughters[i];
525 >                printf("    %i (%i)\n",tmp->type,tmp->size);
526 >                for(unsigned int j=0;j<tmp->daughters.size();j++){
527 >                        stChunkToSave* Tmp = tmp->daughters[j];
528 >                        printf("        %i (%i)\n",Tmp->type,Tmp->size);
529 >                        for(unsigned int k=0;k<Tmp->daughters.size();k++){
530 >                                stChunkToSave* TMp = Tmp->daughters[k];
531 >                                printf("            %i (%i)\n",TMp->type,TMp->size);
532 >                                for(unsigned int l=0;l<TMp->daughters.size();l++){
533 >                                        stChunkToSave* TMP = TMp->daughters[l];
534 >                                        printf("                %i (%i)\n",TMP->type,TMP->size);
535 >                                }                              
536 >                        }                      
537 >                }              
538          }
539 + */
540  
541 <        fclose(f);
542 <
543 < //      Events.clear();
541 >        FILE* pFile = fopen(path,"wb" );        
542 >                WriteChunk(pFile, Primary_chunk);
543 >        fclose(pFile);  
544   }
545  
546  
# Line 363 | Line 550 | void MySimEvents::NextEvent()
550                  Current_Event++;
551  
552   }
553 +
554 + void MySimEvents::GoToEvent(unsigned int i)
555 + {
556 +        if(i<Events.size()) Current_Event=i;
557 + }
558 +
559   void MySimEvents::PreviousEvent()
560   {
561          if(Current_Event-1>=0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines