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

Diff of /yoda/event/PamelaRun.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2.3 by kusanagi, Fri Dec 3 22:04:04 2004 UTC revision 6.7 by kusanagi, Wed Aug 16 13:23:00 2006 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Author: kusanagi $   * $Author: kusanagi $
3   * $Date: 2004/10/17 12:28:15 $   * $Date: 2006/06/26 08:43:20 $
4   * $Revision: 2.2 $   * $Revision: 6.6 $
5   *   *
6   * Implementation of the PamelaRun class.   * Implementation of the PamelaRun class.
7   */   */
8  #include <iostream>  #include <iostream>
9  #include <iomanip>  #include <iomanip>
 #include <sstream>  
10  #include <list>  #include <list>
11  #include <exception>  #include <exception>
 #include <string>  
12  #include <log4cxx/logger.h>  #include <log4cxx/logger.h>
13    
14  #include <TFile.h>  //Substituted by Maurizio 05 Feb 2004  #include <TFile.h>  //Substituted by Maurizio 05 Feb 2004
# Line 35  extern "C" { Line 33  extern "C" {
33  using namespace pamela;  using namespace pamela;
34    
35  static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.PamelaRun"));  static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.PamelaRun"));
 static std::stringstream oss;  
36    
37  /**  /**
38   * Get the run name according to a certain run number.   * Get the run name according to a certain run number.
# Line 43  static std::stringstream oss; Line 40  static std::stringstream oss;
40   * @return a string with the run name.   * @return a string with the run name.
41   */   */
42  std::string PamelaRun::GetRunName(int run) {  std::string PamelaRun::GetRunName(int run) {
43    std::ostringstream t_Stream;    std::stringstream temp;
44    t_Stream << std::setw( 4 ) << std::setfill( '0' ) << run;    temp.str("");
45    return "Run" + t_Stream.str();    temp << std::setw( 4 ) << std::setfill( '0' ) << run;
46      return "Run" + temp.str();
47  }  }
48    
49  /**  /**
# Line 53  std::string PamelaRun::GetRunName(int ru Line 51  std::string PamelaRun::GetRunName(int ru
51   * @param int run - Number of the run to check   * @param int run - Number of the run to check
52   * @return int   * @return int
53   */   */
54  /*int PamelaRun::RunExists(int run) throw (std::exception){   void PamelaRun::RunExists(std::string input) throw (std::exception){
  int res;  
  DIR *dirp;  
  std::string pathDir((char*)getenv("YODA_DATA"));  
  pathDir = pathDir + "/";  
  pathDir = pathDir + GetRunName(run);  
 // Open the directory  
 if ((dirp = opendir(pathDir.c_str())) == NULL) {  
 res = 0;  
 } else {  
 closedir(dirp);  
 res = 1;  
 }  
 return res;  
 }*/  
   
   
 /**  
  * Check if the run number is already assigned  
  * @param int run - Number of the run to check  
  * @return int  
  */  
  std::string PamelaRun::RunExists(std::string input) throw (std::exception){  
55   int res;   int res;
56   DIR *dirp;   DIR *dirp;
57   std::string fileName;   std::string fileName;
58   std::string pathDir((char*)getenv("YODA_DATA"));   //std::string pathDir((char*)getenv("YODA_DATA"));
59     std::string pathDir(GetPath());
60   std::string tempName;   std::string tempName;
61   std::string::size_type pos;   std::string::size_type pos;
62   std::ostringstream t_Stream;  
   
63   pos = input.find_last_of("/");   pos = input.find_last_of("/");
  //if ((pos == std::string::npos) && !input.empty()) ;//throw Exception("Directories not allowed....");  
64   fileName = input.substr(pos+1);   fileName = input.substr(pos+1);
65   pos = fileName.find_last_of(".");   pos = fileName.find_last_of(".");
66   fileName = fileName.substr(0,pos);   fileName = fileName.substr(0,pos);
67   pathDir = pathDir + "/";   pathDir = pathDir + "/";
68   tempName = pathDir + fileName;   tempName = pathDir + fileName;
69     oss.str("");
70   int i = 0;   oss << Path << "/" << fileName;
71   while (res){   UnpackPath = oss.str();
72      if ((dirp = opendir(tempName.c_str())) == NULL) {   oss.str("");
73          res = 0;   oss << fileName;
74      } else {   Run = oss.str();
         closedir(dirp);  
         t_Stream.str("");  
         t_Stream << std::setw( 2 ) << std::setfill( '0' ) << ++i;  
         tempName = pathDir + fileName + t_Stream.str() ;  
         res = 1;  
     }  
  }  
 return (fileName + t_Stream.str());  
75  }  }
76    
77  /**  /**
# Line 112  return (fileName + t_Stream.str()); Line 79  return (fileName + t_Stream.str());
79   * @param run Run number   * @param run Run number
80   * @param path Base path name to the data   * @param path Base path name to the data
81   */   */
82  PamelaRun::PamelaRun(std::string fileName, std::string path):  PamelaRun::PamelaRun(std::string fileName, std::string path, bool multiple, short compr):
83    Path(path),    Path(path),
84    RunNumber(1){ //veirificare se è possibilie eliminare questa variabile    Run(fileName),
85      RunNumber(1),//veirificare se è possibilie eliminare questa variabile
86      Multiple(multiple),
87      SingleFile(0),
88      compression(compr){
89    logger->debug(_T("Constructor"));    logger->debug(_T("Constructor"));
90    Run = RunExists(fileName);    //Run = RunExists(fileName);
91      RunExists(fileName);
92    info = RunInfo(this);    info = RunInfo(this);
93  }  }
94    
# Line 127  PamelaRun::PamelaRun(std::string fileNam Line 99  PamelaRun::PamelaRun(std::string fileNam
99   * @return the complete path for this event type.   * @return the complete path for this event type.
100   */   */
101  std::string PamelaRun::GetDirName(PacketType const * type) const {  std::string PamelaRun::GetDirName(PacketType const * type) const {
102    std::string EventType = type->GetName();      //std::stringstream oss;
103    return Path + "/" + Run + "/" + EventType;      //std::string name = type->GetName();
104        //oss.str("");
105        //oss << Path << "/" << Run << "/" << "pippo";
106        //return oss.str();
107        //return "pippo";
108      //std::string EventType = type->GetName();
109        return Path + "/" + Run + "/" + type->GetName();
110  }  }
111    
112  /**  /**
# Line 137  std::string PamelaRun::GetDirName(Packet Line 115  std::string PamelaRun::GetDirName(Packet
115   * @param name subpacket name.   * @param name subpacket name.
116   * @return the complete path and file name.   * @return the complete path and file name.
117   */   */
118  std::string PamelaRun::GetFileName(const SubPacket* type, std::string name) const {  std::string PamelaRun::GetFileName(const SubPacket* type, std::string name) {
119    if (type->IsDetectorSpecific()) {    if (type->IsDetectorSpecific()) {
120      return GetDirName(type->GetPacketType()) + "/"      return UnpackPath + "/" + type->GetPacketType()->GetName() + "/"
121        + type->GetSubDetector()->GetName() + "/"        + Run + "." + type->GetPacketType()->GetName() + "."
       + Run + "." + type->GetPacketType()->GetName() + "."  
122        + type->GetSubDetector()->GetName() + "."        + type->GetSubDetector()->GetName() + "."
123        + name + ".root";        + name + ".root";
124    } else {    } else {
125      return GetDirName(type->GetPacketType()) + "/"      return UnpackPath + "/" + type->GetPacketType()->GetName() + "/"
126        + Run + "." + type->GetPacketType()->GetName() + "."        + Run + "." + type->GetPacketType()->GetName() + "."
127        + name + ".root";        + name + ".root";
128       /*
129        return Path + "/" + type->GetPacketType()->GetName() + "/"
130          + Run + "." + type->GetPacketType()->GetName() + "."
131          + name + ".root"; */
132    }    }
133  }  }
134    
# Line 156  std::string PamelaRun::GetFileName(const Line 137  std::string PamelaRun::GetFileName(const
137   * @param type subpacket type.   * @param type subpacket type.
138   * @return the complete path and file name.   * @return the complete path and file name.
139   */   */
140  std::string PamelaRun::GetFileName(const SubPacket* type) const {  std::string PamelaRun::GetFileName(const SubPacket* type)  {
141    return GetFileName(type, type->GetSubPacketName());    //return GetFileName(type, type->GetSubPacketName());
142        return GetFileName(type, "pippo");
143  }  }
144    
145  /**  /**
# Line 194  static std::list<std::string> GetRootFil Line 176  static std::list<std::string> GetRootFil
176    std::list<std::string> files;    std::list<std::string> files;
177    DIR *dir = opendir(path.c_str());    DIR *dir = opendir(path.c_str());
178    if (dir == 0) {    if (dir == 0) {
179      oss.str("");      logger->debug("Could not open " + path);
     oss <<  "Could not open " << path;  
     logger->debug(oss.str().c_str());  
180      //throw Exception("Could not open " + path);      //throw Exception("Could not open " + path);
181    }    }
182        
# Line 217  static std::list<std::string> GetRootFil Line 197  static std::list<std::string> GetRootFil
197        if (stat(nextfilename.c_str(), &buf) == 0) {        if (stat(nextfilename.c_str(), &buf) == 0) {
198          filename.insert(filename.size()-5, "*");          filename.insert(filename.size()-5, "*");
199        }        }
200        oss.str("");        logger->debug("Using " + filename);
       oss <<  "Using " << filename;  
       logger->debug(oss.str().c_str());  
201        files.push_back(filename);        files.push_back(filename);
202      }      }
203    }    }
# Line 257  static void AddAllAsFriend(TChain* tree, Line 235  static void AddAllAsFriend(TChain* tree,
235    }    }
236    TFile* File = new TFile(BaseFileName.c_str(), "read");    TFile* File = new TFile(BaseFileName.c_str(), "read");
237    if (!File->IsOpen()) {    if (!File->IsOpen()) {
238      oss.str("");      logger->error("Could not open file " + BaseFileName + " for reading.");
     oss <<  "Could not open file " << BaseFileName << " for reading.";  
     logger->warn(oss.str().c_str());  
239      return;      return;
240    }    }
241    TList* list = File->GetListOfKeys();    TList* list = File->GetListOfKeys();
# Line 270  static void AddAllAsFriend(TChain* tree, Line 246  static void AddAllAsFriend(TChain* tree,
246          TChain* FriendChain = new TChain(TreeName.c_str());          TChain* FriendChain = new TChain(TreeName.c_str());
247          FriendChain->Add(FileName.c_str());          FriendChain->Add(FileName.c_str());
248          tree->AddFriend(FriendChain, TreeName.c_str());          tree->AddFriend(FriendChain, TreeName.c_str());
249          oss.str("");          //logger->warn("Adding chain " + TreeName + " with " + FriendChain->GetEntries() + " entries as Friend");
         oss << "Adding chain " << TreeName << " with "  
             << FriendChain->GetEntries() << " entries as Friend";  
         logger->warn(oss.str().c_str());  
250        }        }
251      }      }
252      File->Close();      File->Close();
# Line 283  static void AddAllAsFriend(TChain* tree, Line 256  static void AddAllAsFriend(TChain* tree,
256          std::string TreeName = k->GetName();          std::string TreeName = k->GetName();
257          TTree* FriendTree = (TTree *)File->Get(TreeName.c_str());          TTree* FriendTree = (TTree *)File->Get(TreeName.c_str());
258          tree->AddFriend(FriendTree, TreeName.c_str());            tree->AddFriend(FriendTree, TreeName.c_str());  
259          oss.str("");          //logger->debug("Adding tree " + TreeName + " with " + FriendTree->GetEntries() + " entries as Friend");
         oss << "Adding tree " << TreeName << " with "  
             << FriendTree->GetEntries() << " entries as Friend";  
         logger->debug(oss.str().c_str());  
260        }        }
261      }      }
262    }    }
# Line 399  void PamelaRun::ReadSubPacket(const Algo Line 369  void PamelaRun::ReadSubPacket(const Algo
369  TTree* PamelaRun::CreateTTree(Algorithm* algo, const SubPacket* packet,  TTree* PamelaRun::CreateTTree(Algorithm* algo, const SubPacket* packet,
370                                std::string name)                                std::string name)
371    throw (std::exception) {    throw (std::exception) {
372    std::string FileName = GetFileName(packet, name);    std::string FileName = "";
373    std::string EventType = packet->GetPacketType()->GetName();    std::string EventType = packet->GetPacketType()->GetName();
374      TFile* File = 0;
375      std::string TreeName = GetTreeName(packet);
376      TTree *tree = 0;
377      FileName = GetFileName(packet, name);
378    CreateDirectoryStructure(FileName.c_str());    CreateDirectoryStructure(FileName.c_str());
379    TFile* File = new TFile(FileName.c_str(), "create");    File = new TFile(FileName.c_str(), "create");
380    File->SetCompressionLevel(5);    tree = new TTree(TreeName.c_str(), algo->GetAlgorithmName().c_str());
381      WritingRootTrees[packet->GetPacketType()].push_back(tree);
382      
383      File->SetCompressionLevel(compression);
384    if (!File->IsOpen()) {    if (!File->IsOpen()) {
385      oss.str("");      logger->error("Could not open file " + FileName);
     oss <<  "Could not open file " << FileName ;  
     logger->error(oss.str().c_str());  
386      //throw Exception("Could not open file " + FileName);      //throw Exception("Could not open file " + FileName);
387    }    }
388    std::string TreeName = GetTreeName(packet);    logger->debug("Creating file " + FileName + " with Tree " + TreeName);
   TTree *tree = new TTree(TreeName.c_str(), algo->GetAlgorithmName().c_str());  
   WritingRootTrees[packet->GetPacketType()].push_back(tree);  
   tree->GetCurrentFile()->cd();  
   AlgorithmInfo ai(algo);  
   ai.Write();  
   info.Write();  
   oss.str("");  
   oss <<  "Creating file " << FileName << " with Tree " << TreeName;  
   logger->info(oss.str().c_str());  
389    return tree;    return tree;
390  }  }
391    
# Line 441  void PamelaRun::WriteSubPacket(Algorithm Line 407  void PamelaRun::WriteSubPacket(Algorithm
407    oss <<  "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)";    oss <<  "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)";
408    logger->debug(oss.str().c_str());    logger->debug(oss.str().c_str());
409    TTree* HeaderTree = ReadTTree(packet->GetPacketType());    TTree* HeaderTree = ReadTTree(packet->GetPacketType());
   TTree* tree = CreateTTree(algo, packet, name);  
   oss.str("");  
   oss <<  "Branch: " << name << " Class: " << c->GetName();  
   logger->debug(oss.str().c_str());  
   tree->Branch(name.c_str(), c->GetName(),  subpacket);  
   HeaderTree->AddFriend(tree, tree->GetName());  
   
410    std::string FullName = packet->GetPacketType()->GetName() + "." + name;    std::string FullName = packet->GetPacketType()->GetName() + "." + name;
411    SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));    if (Multiple) {
412            TTree* tree = CreateTTree(algo, packet, name);
413            oss.str("");
414            oss <<  "Branch: " << name << " Class: " << c->GetName();
415            logger->debug(oss.str().c_str());
416            tree->Branch(name.c_str(), c->GetName(),  subpacket);
417            HeaderTree->AddFriend(tree, tree->GetName());
418            SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));
419      } else {
420            std::string nameBranch(name);
421            HeaderTree->Branch(nameBranch.c_str(), c->GetName(),  subpacket);
422            SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));
423      }
424  }  }
425    
426  /**  /**
# Line 468  void PamelaRun::WriteSubPacket(Algorithm Line 439  void PamelaRun::WriteSubPacket(Algorithm
439  }  }
440    
441  /**  /**
  * Write the header packet of a specified packet type. This is mainly used  
  * for the raw reader to create the base for the event structure.  
  * @param algo Algorithm that produces this SubPacket.  
  * @param subpacket A pointer to the pointer of the packet.  
  * @param type The packet type.  
  */  
 void PamelaRun::WriteHeader(Algorithm* algo, EventHeader** subpacket,  
                             const PacketType* type) {  
   EventHeader header(type);  
   std::string FileName = GetFileName(&header, GetDefaultBranchName(&header));  
   std::string EventType = (&header)->GetPacketType()->GetName();  
   CreateDirectoryStructure(FileName.c_str());  
   TFile* File = new TFile(FileName.c_str(), "create");  
   if (!File->IsOpen()) {  
     oss.str("");  
     oss     <<  "Could not open file " << FileName ;  
     logger->error(oss.str().c_str());  
     //throw Exception("Could not open file " + FileName);  
   }  
   //std::string TreeName = GetTreeName(packet);  
   TTree *tree = new TTree("Pscu", algo->GetAlgorithmName().c_str());  
   WritingRootTrees[(&header)->GetPacketType()].push_back(tree);  
   tree->GetCurrentFile()->cd();  
   AlgorithmInfo ai(algo);  
   ai.Write();  
   info.Write();  
   oss.str("");  
   oss <<  "Created file " << FileName << " with Tree Pscu";  
   logger->info(oss.str().c_str());  
   tree->Branch(GetDefaultBranchName(&header).c_str(),  
                (*subpacket)->Class()->GetName(), subpacket);  
   TTreeMap.insert(RootTreeMap::value_type(type, tree));  
 }  
   
   
 /**  
442   * Write the header packet to all ROOT files in the tree. Intended to   * Write the header packet to all ROOT files in the tree. Intended to
443   * be used for raw data readers that create the initial event structure.   * be used for raw data readers that create the initial event structure.
444   * @param algo Algorithm that produces this SubPacket.   * @param algo Algorithm that produces this SubPacket.
445   * @param subpacket A pointer to the pointer of the header packet.   * @param subpacket A pointer to the pointer of the header packet.
446   */   */
447  void PamelaRun::WriteHeaders(Algorithm* algo, EventHeader** subpacket) {  void PamelaRun::WriteHeaders(Algorithm* algo, EventHeader** subpacket) {
   
448      WriteHeader(algo, subpacket, PacketType::PhysEndRun);      WriteHeader(algo, subpacket, PacketType::PhysEndRun);
449      WriteHeader(algo, subpacket, PacketType::CalibCalPulse1);      WriteHeader(algo, subpacket, PacketType::CalibCalPulse1);
450      WriteHeader(algo, subpacket, PacketType::CalibCalPulse2);      WriteHeader(algo, subpacket, PacketType::CalibCalPulse2);
# Line 518  void PamelaRun::WriteHeaders(Algorithm* Line 452  void PamelaRun::WriteHeaders(Algorithm*
452      WriteHeader(algo, subpacket, PacketType::CalibTrkBoth);      WriteHeader(algo, subpacket, PacketType::CalibTrkBoth);
453      WriteHeader(algo, subpacket, PacketType::CalibTrk1);      WriteHeader(algo, subpacket, PacketType::CalibTrk1);
454      WriteHeader(algo, subpacket, PacketType::CalibTrk2);      WriteHeader(algo, subpacket, PacketType::CalibTrk2);
     WriteHeader(algo, subpacket, PacketType::CalibTrd);  
455      WriteHeader(algo, subpacket, PacketType::CalibTof);      WriteHeader(algo, subpacket, PacketType::CalibTof);
456      WriteHeader(algo, subpacket, PacketType::CalibS4);      WriteHeader(algo, subpacket, PacketType::CalibS4);
457      WriteHeader(algo, subpacket, PacketType::CalibCalPed);      WriteHeader(algo, subpacket, PacketType::CalibCalPed);
458      WriteHeader(algo, subpacket, PacketType::CalibAc);      WriteHeader(algo, subpacket, PacketType::Calib1_Ac1);
459        WriteHeader(algo, subpacket, PacketType::Calib1_Ac2);
460        WriteHeader(algo, subpacket, PacketType::Calib2_Ac1);
461        WriteHeader(algo, subpacket, PacketType::Calib2_Ac2);
462        WriteHeader(algo, subpacket, PacketType::CalibCal);
463      WriteHeader(algo, subpacket, PacketType::RunHeader);      WriteHeader(algo, subpacket, PacketType::RunHeader);
464      WriteHeader(algo, subpacket, PacketType::RunTrailer);      WriteHeader(algo, subpacket, PacketType::RunTrailer);
465      WriteHeader(algo, subpacket, PacketType::CalibHeader);      WriteHeader(algo, subpacket, PacketType::CalibHeader);
# Line 530  void PamelaRun::WriteHeaders(Algorithm* Line 467  void PamelaRun::WriteHeaders(Algorithm*
467      WriteHeader(algo, subpacket, PacketType::InitHeader);      WriteHeader(algo, subpacket, PacketType::InitHeader);
468      WriteHeader(algo, subpacket, PacketType::InitTrailer);      WriteHeader(algo, subpacket, PacketType::InitTrailer);
469      WriteHeader(algo, subpacket, PacketType::EventTrk);      WriteHeader(algo, subpacket, PacketType::EventTrk);
     WriteHeader(algo, subpacket, PacketType::TestTrk);  
     WriteHeader(algo, subpacket, PacketType::TestTof);  
470      WriteHeader(algo, subpacket, PacketType::Log);      WriteHeader(algo, subpacket, PacketType::Log);
471      WriteHeader(algo, subpacket, PacketType::VarDump);      WriteHeader(algo, subpacket, PacketType::VarDump);
472      WriteHeader(algo, subpacket, PacketType::ArrDump);      WriteHeader(algo, subpacket, PacketType::ArrDump);
# Line 539  void PamelaRun::WriteHeaders(Algorithm* Line 474  void PamelaRun::WriteHeaders(Algorithm*
474      WriteHeader(algo, subpacket, PacketType::Tmtc);      WriteHeader(algo, subpacket, PacketType::Tmtc);
475      WriteHeader(algo, subpacket, PacketType::Mcmd);      WriteHeader(algo, subpacket, PacketType::Mcmd);
476      WriteHeader(algo, subpacket, PacketType::ForcedFECmd);      WriteHeader(algo, subpacket, PacketType::ForcedFECmd);
477      WriteHeader(algo, subpacket, PacketType::AcInit);      WriteHeader(algo, subpacket, PacketType::Ac1Init);
478      WriteHeader(algo, subpacket, PacketType::CalInit);      WriteHeader(algo, subpacket, PacketType::CalInit);
479      WriteHeader(algo, subpacket, PacketType::TrkInit);      WriteHeader(algo, subpacket, PacketType::TrkInit);
480      WriteHeader(algo, subpacket, PacketType::TofInit);      WriteHeader(algo, subpacket, PacketType::TofInit);
481      WriteHeader(algo, subpacket, PacketType::TrgInit);          WriteHeader(algo, subpacket, PacketType::TrgInit);    
482      WriteHeader(algo, subpacket, PacketType::NdInit);          WriteHeader(algo, subpacket, PacketType::NdInit);    
483        WriteHeader(algo, subpacket, PacketType::S4Init);    
484        WriteHeader(algo, subpacket, PacketType::Ac2Init);
485      WriteHeader(algo, subpacket, PacketType::CalAlarm);          WriteHeader(algo, subpacket, PacketType::CalAlarm);    
486      WriteHeader(algo, subpacket, PacketType::AcAlarm);          WriteHeader(algo, subpacket, PacketType::Ac1Alarm);    
487      WriteHeader(algo, subpacket, PacketType::TrkAlarm);          WriteHeader(algo, subpacket, PacketType::TrkAlarm);    
488      WriteHeader(algo, subpacket, PacketType::TrgAlarm);          WriteHeader(algo, subpacket, PacketType::TrgAlarm);    
489      WriteHeader(algo, subpacket, PacketType::TofAlarm);          WriteHeader(algo, subpacket, PacketType::TofAlarm);
490        WriteHeader(algo, subpacket, PacketType::S4Alarm);
491        WriteHeader(algo, subpacket, PacketType::Ac2Alarm);    
492        WriteHeader(algo, subpacket, PacketType::TsbT);
493        WriteHeader(algo, subpacket, PacketType::TsbB);
494  }  }
495    
496  /**  /**
# Line 568  void PamelaRun::WriteFiles(void) { Line 509  void PamelaRun::WriteFiles(void) {
509         i != WritingRootTrees.end(); i++) {         i != WritingRootTrees.end(); i++) {
510      for (TTreeList::iterator j = i->second.begin();      for (TTreeList::iterator j = i->second.begin();
511           j != i->second.end(); j++) {           j != i->second.end(); j++) {
512        (*j)->GetCurrentFile()->Write();        (*j)->GetCurrentFile()->Write(0,TObject::kOverwrite);
513      }      }
514    }    }
515  }  }
# Line 578  void PamelaRun::WriteFiles(void) { Line 519  void PamelaRun::WriteFiles(void) {
519   * @param type the package type of the trees to fill.   * @param type the package type of the trees to fill.
520   */   */
521  void PamelaRun::FillTrees(const PacketType* type) {  void PamelaRun::FillTrees(const PacketType* type) {
522    for (TTreeList::iterator j = WritingRootTrees[type].begin();    try{
523         j != WritingRootTrees[type].end(); j++) {      for (TTreeList::iterator j = WritingRootTrees[type].begin();
524      (*j)->Fill();          j != WritingRootTrees[type].end(); j++) {
525      ;              (*j)->Fill();
526        }
527      } catch(Exception exc){
528        logger->fatal("ORRORE!!!");
529    }    }
530  }  }
531    
532    
533    /**
534     * Write the header packet of a specified packet type. This is mainly used
535     * for the raw reader to create the base for the event structure.
536     * @param algo Algorithm that produces this SubPacket.
537     * @param subpacket A pointer to the pointer of the packet.
538     * @param type The packet type.
539     */
540    void PamelaRun::WriteHeader(Algorithm* algo, EventHeader** subpacket,
541                                const PacketType* type) {
542      EventHeader header(type);
543      std::string EventType = (&header)->GetPacketType()->GetName();
544    
545      std::string FileName = "";
546      TFile* File = 0;
547      Long64_t maxsize = 5000000000LL;
548      TTree::SetMaxTreeSize(maxsize);
549      TTree *tree = 0;
550      if ( Multiple ){
551            FileName = GetFileName(&header, GetDefaultBranchName(&header));
552            CreateDirectoryStructure(FileName.c_str());
553            File = new TFile(FileName.c_str(), "create");
554            File->SetCompressionLevel(compression);
555            tree = new TTree("Pscu", algo->GetAlgorithmName().c_str());
556            WritingRootTrees[(&header)->GetPacketType()].push_back(tree);
557            tree->GetCurrentFile()->cd();
558            tree->Branch(GetDefaultBranchName(&header).c_str(),
559                   (*subpacket)->Class()->GetName(), subpacket);
560            TTreeMap.insert(RootTreeMap::value_type(type, tree));
561      } else {
562            if (!Multiple && (SingleFile == NULL)){
563                    //std::string pathDir((char*)getenv("YODA_DATA"));
564                    SingleFile = new TFile((GetPath() + "/" + Run + ".root").c_str(), "update");
565                    SingleFile->SetCompressionLevel(compression);
566            }
567            tree = new TTree(EventType.c_str(), algo->GetAlgorithmName().c_str());
568            WritingRootTrees[type].push_back(tree);
569            tree->GetCurrentFile()->cd();
570            tree->Branch(GetDefaultBranchName(&header).c_str(),
571                   (*subpacket)->Class()->GetName(), subpacket);
572            TTreeMap.insert(RootTreeMap::value_type(type, tree));
573      }
574    }

Legend:
Removed from v.2.3  
changed lines
  Added in v.6.7

  ViewVC Help
Powered by ViewVC 1.1.23