/[PAMELA software]/yoda/event/PamelaRun.cpp
ViewVC logotype

Annotation of /yoda/event/PamelaRun.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2.6 - (hide annotations) (download)
Wed Feb 9 22:24:33 2005 UTC (19 years, 10 months ago) by kusanagi
Branch: MAIN
Changes since 2.5: +5 -5 lines
Minor fixes on log output format

1 kusanagi 1.1 /** @file
2 kusanagi 1.2 * $Author: kusanagi $
3 kusanagi 2.6 * $Date: 2004/12/16 17:32:46 $
4     * $Revision: 2.5 $
5 kusanagi 1.1 *
6     * Implementation of the PamelaRun class.
7     */
8     #include <iostream>
9     #include <iomanip>
10     #include <list>
11     #include <exception>
12 kusanagi 2.5 //#include <string>
13 kusanagi 1.6 #include <log4cxx/logger.h>
14 kusanagi 1.1
15     #include <TFile.h> //Substituted by Maurizio 05 Feb 2004
16     #include <TTree.h> //Substituted by Maurizio 05 Feb 2004
17     #include <TChain.h> //Substituted by Maurizio 05 Feb 2004
18     #include <TKey.h> //Substituted by Maurizio 05 Feb 2004
19     #include <TList.h> //Substituted by Maurizio 05 Feb 2004
20    
21    
22     #include "PamelaRun.h"
23     #include "EventHeader.h"
24     #include "Algorithm.h"
25     #include "AlgorithmInfo.h"
26     #include "Exception.h"
27 kusanagi 1.6 #include <sys/stat.h>
28    
29 kusanagi 1.1 extern "C" {
30 kusanagi 1.6 #include <dirent.h>
31 kusanagi 1.1 #include "DirectoryStructure.h"
32     }
33    
34     using namespace pamela;
35    
36 kusanagi 1.6 static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.PamelaRun"));
37 kusanagi 1.1
38     /**
39     * Get the run name according to a certain run number.
40     * @param run Run number.
41     * @return a string with the run name.
42     */
43     std::string PamelaRun::GetRunName(int run) {
44 kusanagi 2.5 std::stringstream temp;
45     temp.str("");
46     temp << std::setw( 4 ) << std::setfill( '0' ) << run;
47     return "Run" + temp.str();
48 kusanagi 1.1 }
49    
50     /**
51     * Check if the run number is already assigned
52     * @param int run - Number of the run to check
53     * @return int
54     */
55     /*int PamelaRun::RunExists(int run) throw (std::exception){
56     int res;
57     DIR *dirp;
58     std::string pathDir((char*)getenv("YODA_DATA"));
59     pathDir = pathDir + "/";
60     pathDir = pathDir + GetRunName(run);
61     // Open the directory
62     if ((dirp = opendir(pathDir.c_str())) == NULL) {
63     res = 0;
64     } else {
65     closedir(dirp);
66     res = 1;
67     }
68     return res;
69     }*/
70    
71    
72     /**
73     * Check if the run number is already assigned
74     * @param int run - Number of the run to check
75     * @return int
76     */
77 kusanagi 2.5 void PamelaRun::RunExists(std::string input) throw (std::exception){
78 kusanagi 1.1 int res;
79     DIR *dirp;
80     std::string fileName;
81     std::string pathDir((char*)getenv("YODA_DATA"));
82     std::string tempName;
83     std::string::size_type pos;
84 kusanagi 2.5
85 kusanagi 1.1 pos = input.find_last_of("/");
86     //if ((pos == std::string::npos) && !input.empty()) ;//throw Exception("Directories not allowed....");
87     fileName = input.substr(pos+1);
88     pos = fileName.find_last_of(".");
89     fileName = fileName.substr(0,pos);
90     pathDir = pathDir + "/";
91 kusanagi 2.5 tempName = pathDir + fileName + "00";
92     //oss << pathDir << fileName << std::setw( 2 ) << std::setfill( '0' );
93     oss.str(tempName.c_str());
94 kusanagi 1.1 int i = 0;
95     while (res){
96 kusanagi 2.5 //if ((dirp = opendir(tempName.c_str())) == NULL) {
97     if ((dirp = opendir(oss.str().c_str())) == NULL) {
98 kusanagi 1.1 res = 0;
99     } else {
100     closedir(dirp);
101 kusanagi 2.5 oss.str("");
102     oss << pathDir << fileName << std::setw( 2 ) << std::setfill( '0' ) << ++i;
103 kusanagi 1.1 res = 1;
104     }
105     }
106 kusanagi 2.5 oss.str("");
107     oss << Path << "/" << fileName << std::setw( 2 ) << std::setfill( '0' ) << i;
108     Path = oss.str();
109     oss.str("");
110     oss << fileName << std::setw( 2 ) << std::setfill( '0' ) << i;
111     Run = oss.str();
112     //return (oss.str());
113 kusanagi 1.1 }
114    
115     /**
116     * Create a new Pamela run.
117     * @param run Run number
118     * @param path Base path name to the data
119     */
120     PamelaRun::PamelaRun(std::string fileName, std::string path):
121 kusanagi 2.5 Path(path),
122     Run(fileName),
123 kusanagi 1.1 RunNumber(1){ //veirificare se รจ possibilie eliminare questa variabile
124 kusanagi 1.6 logger->debug(_T("Constructor"));
125 kusanagi 2.5 //Run = RunExists(fileName);
126     RunExists(fileName);
127 kusanagi 1.1 info = RunInfo(this);
128     }
129    
130     /**
131     * Get the directory name that contains the files of a certain event
132     * type for this run.
133     * @param type the packet type.
134     * @return the complete path for this event type.
135     */
136     std::string PamelaRun::GetDirName(PacketType const * type) const {
137 kusanagi 2.5 //std::stringstream oss;
138     //std::string name = type->GetName();
139     //oss.str("");
140     //oss << Path << "/" << Run << "/" << "pippo";
141     //return oss.str();
142     //return "pippo";
143     //std::string EventType = type->GetName();
144     return Path + "/" + Run + "/" + type->GetName();
145 kusanagi 1.1 }
146    
147     /**
148     * Get the file name for a certain event type.
149     * @param type subpacket type.
150     * @param name subpacket name.
151     * @return the complete path and file name.
152     */
153 kusanagi 2.5 std::string PamelaRun::GetFileName(const SubPacket* type, std::string name) {
154 kusanagi 1.1 if (type->IsDetectorSpecific()) {
155 kusanagi 2.5 return Path + "/" + type->GetPacketType()->GetName() + "/"
156     + Run + "." + type->GetPacketType()->GetName() + "."
157 kusanagi 1.1 + type->GetSubDetector()->GetName() + "."
158     + name + ".root";
159     } else {
160 kusanagi 2.5 return Path + "/" + type->GetPacketType()->GetName() + "/"
161 kusanagi 1.1 + Run + "." + type->GetPacketType()->GetName() + "."
162     + name + ".root";
163 kusanagi 2.5 /*
164     return Path + "/" + type->GetPacketType()->GetName() + "/"
165     + Run + "." + type->GetPacketType()->GetName() + "."
166     + name + ".root"; */
167 kusanagi 1.1 }
168     }
169    
170     /**
171     * Get the file name for a certain event type.
172     * @param type subpacket type.
173     * @return the complete path and file name.
174     */
175 kusanagi 2.5 std::string PamelaRun::GetFileName(const SubPacket* type) {
176     //return GetFileName(type, type->GetSubPacketName());
177     return GetFileName(type, "pippo");
178 kusanagi 1.1 }
179    
180     /**
181     * Get the branch name that corresponds to a certain
182     * subpacket. Usually, this is the name of the subpacket.
183     * @param type subpacket type.
184     * @return the corresponding branch name.
185     */
186     static std::string GetDefaultBranchName(const SubPacket* type) {
187     return type->GetSubPacketName();
188     }
189    
190     /**
191     * Get the tree name for a certain subpacket. This is the name of the
192     * subdetector for detector specific subpackets, and the packet name
193     * ("Physics" etc.) for common packets.
194     * @param type the packet type.
195     * @return the corresponding tree name.
196     */
197     static std::string GetTreeName(const SubPacket* type) {
198     if (type->IsDetectorSpecific()) {
199     return type->GetSubDetector()->GetName();
200     } else {
201     return type->GetPacketType()->GetName();
202     }
203     }
204    
205     /**
206     * Get a list of all root files from a certain path.
207     * @param path Path name to start the search.
208     * @return A list of all file names.
209     */
210     static std::list<std::string> GetRootFiles(std::string path) throw (std::exception) {
211     std::list<std::string> files;
212     DIR *dir = opendir(path.c_str());
213     if (dir == 0) {
214 kusanagi 2.5 logger->debug("Could not open " + path);
215 kusanagi 2.3 //throw Exception("Could not open " + path);
216 kusanagi 1.1 }
217    
218     for (struct dirent *d = readdir(dir); d != NULL; d = readdir(dir)) {
219     if ((strcmp(".",d->d_name) == 0) || (strcmp("..",d->d_name) == 0))
220     continue;
221     std::string filename = path + "/" + d->d_name;
222     struct stat buf;
223     stat(filename.c_str(), &buf);
224     if S_ISDIR(buf.st_mode) {
225     std::list<std::string>toAdd = GetRootFiles(filename);
226     files.insert(files.end(), toAdd.begin(), toAdd.end());
227     } else if ((filename.substr(filename.size()-5, filename.size())
228     == ".root") // correct suffix
229     && (!isdigit(filename[filename.size()-6]))) { // base file
230     std::string nextfilename = filename;
231     nextfilename.insert(filename.size()-5, "_1");
232     if (stat(nextfilename.c_str(), &buf) == 0) {
233     filename.insert(filename.size()-5, "*");
234     }
235 kusanagi 2.5 logger->debug("Using " + filename);
236 kusanagi 1.1 files.push_back(filename);
237     }
238     }
239     return files;
240     }
241    
242     /**
243     * Helper function to open the ROOT TTree of the header within the run
244     * framework.
245     * @param type The packet type.
246     * @return the ROOT TTree.
247     */
248     TChain* PamelaRun::ReadHeaderTree(const PacketType *type)
249     throw (std::exception) {
250     EventHeader header(type);
251     std::string FileName = GetFileName(&header);
252     std::string TreeName = GetTreeName(&header);
253     TChain *tree = new TChain(TreeName.c_str());
254     tree->Add(FileName.c_str());
255     return tree;
256     }
257    
258     /**
259     * All add trees of a file as friend to a given tree. The tree name of
260     * each tree found in the file is used as the name of the friend alias.
261     * @param tree The base tree to add all other as friends.
262     * @param FileName The name of the file with other trees.
263     */
264     static void AddAllAsFriend(TChain* tree, std::string FileName) {
265     std::string BaseFileName = FileName;
266     bool HaveChain = false;
267     if (BaseFileName[BaseFileName.size()-6] == '*') {
268     BaseFileName.erase(BaseFileName.size()-6, 1);
269     HaveChain = true;
270     }
271     TFile* File = new TFile(BaseFileName.c_str(), "read");
272     if (!File->IsOpen()) {
273 kusanagi 2.6 logger->error("Could not open file " + BaseFileName + " for reading.");
274 kusanagi 1.1 return;
275     }
276     TList* list = File->GetListOfKeys();
277     if (HaveChain) {
278     for (TIter i(list); TKey* k = (TKey*)i();) {
279     if (std::string(TTree::Class()->GetName()) == k->GetClassName()) {
280     std::string TreeName = k->GetName();
281     TChain* FriendChain = new TChain(TreeName.c_str());
282     FriendChain->Add(FileName.c_str());
283     tree->AddFriend(FriendChain, TreeName.c_str());
284 kusanagi 2.5 //logger->warn("Adding chain " + TreeName + " with " + FriendChain->GetEntries() + " entries as Friend");
285 kusanagi 1.1 }
286     }
287     File->Close();
288     } else {
289     for (TIter i(list); TKey* k = (TKey*)i();) {
290     if (std::string(TTree::Class()->GetName()) == k->GetClassName()) {
291     std::string TreeName = k->GetName();
292     TTree* FriendTree = (TTree *)File->Get(TreeName.c_str());
293     tree->AddFriend(FriendTree, TreeName.c_str());
294 kusanagi 2.5 //logger->debug("Adding tree " + TreeName + " with " + FriendTree->GetEntries() + " entries as Friend");
295 kusanagi 1.1 }
296     }
297     }
298     }
299    
300     /**
301     * Read all Root TTrees which belong to a certain event type and mount them
302     * together as "friends".
303     * @param type The packet type.
304     * @return The root trees with the friends.
305     */
306     TTree* PamelaRun::ReadTTree(const PacketType* type) {
307 kusanagi 2.3 oss.str("");
308 kusanagi 1.6 oss << "Getting root files of " << type->GetName();
309     logger->debug(oss.str().c_str());
310 kusanagi 1.1 RootTreeMap::iterator t = TTreeMap.find(type);
311     if (t != TTreeMap.end()) {
312     return t->second;
313     } else {
314 kusanagi 2.3 oss.str("");
315 kusanagi 1.6 oss << "Reading root files of " << type->GetName();
316     logger->debug(oss.str().c_str());
317 kusanagi 1.1 EventHeader header(type);
318     std::string HeaderFileName = GetFileName(&header);
319     TChain* HeaderTree = ReadHeaderTree(type);
320     std::list<std::string> rootfiles = GetRootFiles(GetDirName(type));
321     for (std::list<std::string>::iterator i = rootfiles.begin();
322     i != rootfiles.end(); i++){
323     if (*i == HeaderFileName)
324     continue; // dont add the header tree itself.
325     AddAllAsFriend(HeaderTree, *i);
326     }
327     TTreeMap.insert(RootTreeMap::value_type(type, HeaderTree));
328     return HeaderTree;
329     }
330     }
331    
332     /**
333     * Register a certain SubPacket, identified by its name, to be read
334     * from the repository. This function is made for interactive work.
335     * @param subpacket A pointer to the pointer of the packet.
336     * @param name The name of the subpacket
337     */
338     void PamelaRun::ReadSubPacket(void* subpacket, std::string name) {
339     SubPacket *packet = *(SubPacket**)subpacket;
340    
341     // look into the map of subpackets if we already read it.
342     std::string FullName = packet->GetPacketType()->GetName() + "." + name;
343     SubPacketMap::iterator i = SubPacketAddresses.find(FullName);
344     if (i != SubPacketAddresses.end()) { // it is in the map
345     *(SubPacket**)subpacket = i->second;
346     return;
347     } else { // not found in the map of used subpackets
348     TTree* tree = ReadTTree(packet->GetPacketType());
349     TBranch* branch = tree->GetBranch(name.c_str());
350     if (branch != 0) {
351     branch->SetAddress(subpacket);
352     SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));
353     } else {
354 kusanagi 2.3 oss.str("");
355 kusanagi 1.6 oss << "Could not find data for " << packet->GetPacketType()->GetName() << "/" << name ;
356     logger->error(oss.str().c_str());
357 kusanagi 1.1 }
358     }
359     }
360    
361     /**
362     * Register a certain SubPacket, identified by its default name, to be
363     * read from the repository. This function is made for
364     * interactive work.
365     * @param subpacket A pointer to the pointer of the packet.
366     */
367     void PamelaRun::ReadSubPacket(void* subpacket) {
368     SubPacket *packet = *(SubPacket**)subpacket;
369     ReadSubPacket(subpacket, GetDefaultBranchName(packet));
370     }
371    
372     /**
373     * Register a certain SubPacket with its default name, to be read from
374     * the repository. This functions is for use from the algorithm.
375     * @param algo Algorithm that needs this SubPacket.
376     * @param subpacket A pointer to the pointer of the packet.
377     */
378     void PamelaRun::ReadSubPacket(const Algorithm* algo, void* subpacket) {
379     //:TODO: store the request of the algorithm here.
380     ReadSubPacket(subpacket);
381     }
382    
383     /**
384     * Register a certain SubPacket, with a custom name, to
385     * be read from the repository. This functions is for use from
386     * the algorithm.
387     * @param algo Algorithm that needs this SubPacket.
388     * @param subpacket A pointer to the pointer of the packet.
389     * @param name The name of the subpacket
390     */
391     void PamelaRun::ReadSubPacket(const Algorithm* algo, void* subpacket,
392     std::string name) {
393     //:TODO: store the request of the algorithm here.
394     ReadSubPacket(subpacket, name);
395     }
396    
397     /**
398     * Helper function to create a ROOT TTree within the run framework.
399     * @param algo Algorithm that creates this SubPacket.
400     * @param packet subpacket type
401     * @param name the name of the subpacket
402     * @return the ROOT TTree.
403     */
404     TTree* PamelaRun::CreateTTree(Algorithm* algo, const SubPacket* packet,
405     std::string name)
406     throw (std::exception) {
407     std::string FileName = GetFileName(packet, name);
408     std::string EventType = packet->GetPacketType()->GetName();
409     CreateDirectoryStructure(FileName.c_str());
410     TFile* File = new TFile(FileName.c_str(), "create");
411 kusanagi 2.2 File->SetCompressionLevel(5);
412 kusanagi 1.1 if (!File->IsOpen()) {
413 kusanagi 2.5 logger->error("Could not open file " + FileName);
414 kusanagi 2.3 //throw Exception("Could not open file " + FileName);
415 kusanagi 1.1 }
416     std::string TreeName = GetTreeName(packet);
417     TTree *tree = new TTree(TreeName.c_str(), algo->GetAlgorithmName().c_str());
418     WritingRootTrees[packet->GetPacketType()].push_back(tree);
419     tree->GetCurrentFile()->cd();
420     AlgorithmInfo ai(algo);
421     ai.Write();
422     info.Write();
423 kusanagi 2.6 logger->debug("Creating file " + FileName + " with Tree " + TreeName);
424 kusanagi 1.1 return tree;
425     }
426    
427    
428     /**
429     * Register a certain SubPacket to be written to the repository. A
430     * usual call sequence for this function ist
431     * MyEvent *event = new MyEvent();
432     * run->WriteSubPacket(this, &event, event->Class()
433     * @param algo Algorithm that produces this SubPacket.
434     * @param subpacket A pointer to the pointer of the subpacket.
435     * @param c The class the subpacket belongs to.
436     * @param name The name of the packet.
437     */
438     void PamelaRun::WriteSubPacket(Algorithm *algo, void* subpacket,
439     const TClass *c, std::string name) {
440     SubPacket *packet = *(SubPacket **)subpacket;
441 kusanagi 2.3 oss.str("");
442 kusanagi 1.6 oss << "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)";
443     logger->debug(oss.str().c_str());
444 kusanagi 1.1 TTree* HeaderTree = ReadTTree(packet->GetPacketType());
445     TTree* tree = CreateTTree(algo, packet, name);
446 kusanagi 2.3 oss.str("");
447 kusanagi 1.6 oss << "Branch: " << name << " Class: " << c->GetName();
448     logger->debug(oss.str().c_str());
449 kusanagi 1.1 tree->Branch(name.c_str(), c->GetName(), subpacket);
450     HeaderTree->AddFriend(tree, tree->GetName());
451    
452     std::string FullName = packet->GetPacketType()->GetName() + "." + name;
453     SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));
454     }
455    
456     /**
457     * Register a certain SubPacket with its default name to be written to
458     * the repository. A usual call sequence for this function ist
459     * MyEvent *event = new MyEvent();
460     * run->WriteSubPacket(this, &event, event->Class()
461     * @param algo Algorithm that produces this SubPacket.
462     * @param subpacket A pointer to the pointer of the subpacket.
463     * @param c The class the subpacket belongs to.
464     */
465     void PamelaRun::WriteSubPacket(Algorithm *algo, void* subpacket,
466     const TClass *c) {
467     SubPacket *packet = *(SubPacket **)subpacket;
468     WriteSubPacket(algo, subpacket, c, GetDefaultBranchName(packet));
469     }
470    
471     /**
472     * Write the header packet of a specified packet type. This is mainly used
473     * for the raw reader to create the base for the event structure.
474     * @param algo Algorithm that produces this SubPacket.
475     * @param subpacket A pointer to the pointer of the packet.
476     * @param type The packet type.
477     */
478     void PamelaRun::WriteHeader(Algorithm* algo, EventHeader** subpacket,
479     const PacketType* type) {
480     EventHeader header(type);
481     std::string FileName = GetFileName(&header, GetDefaultBranchName(&header));
482     std::string EventType = (&header)->GetPacketType()->GetName();
483     CreateDirectoryStructure(FileName.c_str());
484     TFile* File = new TFile(FileName.c_str(), "create");
485     if (!File->IsOpen()) {
486 kusanagi 2.5 logger->error("Could not open file " + FileName);
487 kusanagi 2.3 //throw Exception("Could not open file " + FileName);
488 kusanagi 1.1 }
489     //std::string TreeName = GetTreeName(packet);
490     TTree *tree = new TTree("Pscu", algo->GetAlgorithmName().c_str());
491     WritingRootTrees[(&header)->GetPacketType()].push_back(tree);
492     tree->GetCurrentFile()->cd();
493     AlgorithmInfo ai(algo);
494     ai.Write();
495     info.Write();
496 kusanagi 2.5 std::stringstream temp;
497     //temp.str("");
498     //temp << "Created file" << FileName.c_str() << " with Tree Pscu" ;
499 kusanagi 2.6 //logger->debug(temp.str());
500 kusanagi 1.1 tree->Branch(GetDefaultBranchName(&header).c_str(),
501     (*subpacket)->Class()->GetName(), subpacket);
502     TTreeMap.insert(RootTreeMap::value_type(type, tree));
503     }
504    
505    
506     /**
507     * Write the header packet to all ROOT files in the tree. Intended to
508     * be used for raw data readers that create the initial event structure.
509     * @param algo Algorithm that produces this SubPacket.
510     * @param subpacket A pointer to the pointer of the header packet.
511     */
512     void PamelaRun::WriteHeaders(Algorithm* algo, EventHeader** subpacket) {
513 kusanagi 1.4
514     WriteHeader(algo, subpacket, PacketType::PhysEndRun);
515     WriteHeader(algo, subpacket, PacketType::CalibCalPulse1);
516     WriteHeader(algo, subpacket, PacketType::CalibCalPulse2);
517 kusanagi 1.1 WriteHeader(algo, subpacket, PacketType::Physics);
518 kusanagi 1.4 WriteHeader(algo, subpacket, PacketType::CalibTrkBoth);
519 kusanagi 1.2 WriteHeader(algo, subpacket, PacketType::CalibTrk1);
520     WriteHeader(algo, subpacket, PacketType::CalibTrk2);
521 kusanagi 1.1 WriteHeader(algo, subpacket, PacketType::CalibTrd);
522     WriteHeader(algo, subpacket, PacketType::CalibTof);
523     WriteHeader(algo, subpacket, PacketType::CalibS4);
524 kusanagi 1.4 WriteHeader(algo, subpacket, PacketType::CalibCalPed);
525 kusanagi 2.5 WriteHeader(algo, subpacket, PacketType::Calib1_Ac1);
526     WriteHeader(algo, subpacket, PacketType::Calib1_Ac2);
527     WriteHeader(algo, subpacket, PacketType::Calib2_Ac1);
528     WriteHeader(algo, subpacket, PacketType::Calib2_Ac2);
529 kusanagi 1.1 WriteHeader(algo, subpacket, PacketType::RunHeader);
530     WriteHeader(algo, subpacket, PacketType::RunTrailer);
531 kusanagi 1.4 WriteHeader(algo, subpacket, PacketType::CalibHeader);
532     WriteHeader(algo, subpacket, PacketType::CalibTrailer);
533     WriteHeader(algo, subpacket, PacketType::InitHeader);
534     WriteHeader(algo, subpacket, PacketType::InitTrailer);
535     WriteHeader(algo, subpacket, PacketType::EventTrk);
536     WriteHeader(algo, subpacket, PacketType::TestTrk);
537 kusanagi 1.6 WriteHeader(algo, subpacket, PacketType::TestTof);
538 kusanagi 1.4 WriteHeader(algo, subpacket, PacketType::Log);
539     WriteHeader(algo, subpacket, PacketType::VarDump);
540     WriteHeader(algo, subpacket, PacketType::ArrDump);
541     WriteHeader(algo, subpacket, PacketType::TabDump);
542     WriteHeader(algo, subpacket, PacketType::Tmtc);
543     WriteHeader(algo, subpacket, PacketType::Mcmd);
544     WriteHeader(algo, subpacket, PacketType::ForcedFECmd);
545 kusanagi 2.5 WriteHeader(algo, subpacket, PacketType::Ac1Init);
546 kusanagi 1.4 WriteHeader(algo, subpacket, PacketType::CalInit);
547     WriteHeader(algo, subpacket, PacketType::TrkInit);
548     WriteHeader(algo, subpacket, PacketType::TofInit);
549     WriteHeader(algo, subpacket, PacketType::TrgInit);
550 kusanagi 2.1 WriteHeader(algo, subpacket, PacketType::NdInit);
551 kusanagi 2.4 WriteHeader(algo, subpacket, PacketType::S4Init);
552 kusanagi 2.5 WriteHeader(algo, subpacket, PacketType::Ac2Init);
553 kusanagi 1.6 WriteHeader(algo, subpacket, PacketType::CalAlarm);
554     WriteHeader(algo, subpacket, PacketType::AcAlarm);
555     WriteHeader(algo, subpacket, PacketType::TrkAlarm);
556     WriteHeader(algo, subpacket, PacketType::TrgAlarm);
557 kusanagi 2.4 WriteHeader(algo, subpacket, PacketType::TofAlarm);
558     WriteHeader(algo, subpacket, PacketType::S4Alarm);
559 kusanagi 1.1 }
560    
561     /**
562     * Write the ROOT files to disk.
563     */
564     void PamelaRun::WriteFiles(void) {
565     // Workaround: unlink all friend trees first top avoid to store
566     // the links in the header tree file.
567     for (RootTreeMap::iterator i = TTreeMap.begin(); i != TTreeMap.end(); i++) {
568     if (i->second->GetListOfFriends() != 0) {
569     i->second->GetListOfFriends()->Delete();
570     }
571     }
572    
573     for (TTreeListMap::iterator i = WritingRootTrees.begin();
574     i != WritingRootTrees.end(); i++) {
575     for (TTreeList::iterator j = i->second.begin();
576     j != i->second.end(); j++) {
577     (*j)->GetCurrentFile()->Write();
578     }
579     }
580     }
581    
582     /**
583     * Fill all ROOT trees of a certain type that were opened for writing.
584     * @param type the package type of the trees to fill.
585     */
586     void PamelaRun::FillTrees(const PacketType* type) {
587     for (TTreeList::iterator j = WritingRootTrees[type].begin();
588     j != WritingRootTrees[type].end(); j++) {
589     (*j)->Fill();
590     ;
591     }
592     }
593    
594 kusanagi 1.6
595 kusanagi 2.5

  ViewVC Help
Powered by ViewVC 1.1.23