/[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.2 by kusanagi, Sun Oct 17 12:28:15 2004 UTC revision 2.3 by kusanagi, Fri Dec 3 22:04:04 2004 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Author: kusanagi $   * $Author: kusanagi $
3   * $Date: 2004/09/24 11:57:32 $   * $Date: 2004/10/17 12:28:15 $
4   * $Revision: 2.1 $   * $Revision: 2.2 $
5   *   *
6   * Implementation of the PamelaRun class.   * Implementation of the PamelaRun class.
7   */   */
# Line 194  static std::list<std::string> GetRootFil Line 194  static std::list<std::string> GetRootFil
194    std::list<std::string> files;    std::list<std::string> files;
195    DIR *dir = opendir(path.c_str());    DIR *dir = opendir(path.c_str());
196    if (dir == 0) {    if (dir == 0) {
197      oss.flush();      oss.str("");
198      oss <<  "Could not open " << path;      oss <<  "Could not open " << path;
199      logger->debug(oss.str().c_str());      logger->debug(oss.str().c_str());
200      throw Exception("Could not open " + path);      //throw Exception("Could not open " + path);
201    }    }
202        
203    for (struct dirent *d = readdir(dir); d != NULL; d = readdir(dir)) {    for (struct dirent *d = readdir(dir); d != NULL; d = readdir(dir)) {
# Line 217  static std::list<std::string> GetRootFil Line 217  static std::list<std::string> GetRootFil
217        if (stat(nextfilename.c_str(), &buf) == 0) {        if (stat(nextfilename.c_str(), &buf) == 0) {
218          filename.insert(filename.size()-5, "*");          filename.insert(filename.size()-5, "*");
219        }        }
220        oss.flush();        oss.str("");
221        oss <<  "Using " << filename;        oss <<  "Using " << filename;
222        logger->debug(oss.str().c_str());        logger->debug(oss.str().c_str());
223        files.push_back(filename);        files.push_back(filename);
# Line 257  static void AddAllAsFriend(TChain* tree, Line 257  static void AddAllAsFriend(TChain* tree,
257    }    }
258    TFile* File = new TFile(BaseFileName.c_str(), "read");    TFile* File = new TFile(BaseFileName.c_str(), "read");
259    if (!File->IsOpen()) {    if (!File->IsOpen()) {
260      oss.flush();      oss.str("");
261      oss <<  "Could not open file " << BaseFileName << " for reading.";      oss <<  "Could not open file " << BaseFileName << " for reading.";
262      logger->warn(oss.str().c_str());      logger->warn(oss.str().c_str());
263      return;      return;
# Line 270  static void AddAllAsFriend(TChain* tree, Line 270  static void AddAllAsFriend(TChain* tree,
270          TChain* FriendChain = new TChain(TreeName.c_str());          TChain* FriendChain = new TChain(TreeName.c_str());
271          FriendChain->Add(FileName.c_str());          FriendChain->Add(FileName.c_str());
272          tree->AddFriend(FriendChain, TreeName.c_str());          tree->AddFriend(FriendChain, TreeName.c_str());
273          oss.flush();          oss.str("");
274          oss << "Adding chain " << TreeName << " with "          oss << "Adding chain " << TreeName << " with "
275              << FriendChain->GetEntries() << " entries as Friend";              << FriendChain->GetEntries() << " entries as Friend";
276          logger->warn(oss.str().c_str());          logger->warn(oss.str().c_str());
# Line 283  static void AddAllAsFriend(TChain* tree, Line 283  static void AddAllAsFriend(TChain* tree,
283          std::string TreeName = k->GetName();          std::string TreeName = k->GetName();
284          TTree* FriendTree = (TTree *)File->Get(TreeName.c_str());          TTree* FriendTree = (TTree *)File->Get(TreeName.c_str());
285          tree->AddFriend(FriendTree, TreeName.c_str());            tree->AddFriend(FriendTree, TreeName.c_str());  
286          oss.flush();          oss.str("");
287          oss << "Adding tree " << TreeName << " with "          oss << "Adding tree " << TreeName << " with "
288              << FriendTree->GetEntries() << " entries as Friend";              << FriendTree->GetEntries() << " entries as Friend";
289          logger->debug(oss.str().c_str());          logger->debug(oss.str().c_str());
# Line 299  static void AddAllAsFriend(TChain* tree, Line 299  static void AddAllAsFriend(TChain* tree,
299   * @return The root trees with the friends.   * @return The root trees with the friends.
300   */   */
301  TTree* PamelaRun::ReadTTree(const PacketType* type) {  TTree* PamelaRun::ReadTTree(const PacketType* type) {
302    oss.flush();    oss.str("");
303    oss <<  "Getting root files of " << type->GetName();    oss <<  "Getting root files of " << type->GetName();
304    logger->debug(oss.str().c_str());    logger->debug(oss.str().c_str());
305    RootTreeMap::iterator t = TTreeMap.find(type);    RootTreeMap::iterator t = TTreeMap.find(type);
306    if (t != TTreeMap.end()) {    if (t != TTreeMap.end()) {
307      return t->second;      return t->second;
308    } else {    } else {
309      oss.flush();      oss.str("");
310      oss <<  "Reading root files of " << type->GetName();      oss <<  "Reading root files of " << type->GetName();
311      logger->debug(oss.str().c_str());      logger->debug(oss.str().c_str());
312      EventHeader header(type);      EventHeader header(type);
# Line 346  void PamelaRun::ReadSubPacket(void* subp Line 346  void PamelaRun::ReadSubPacket(void* subp
346        branch->SetAddress(subpacket);        branch->SetAddress(subpacket);
347        SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));        SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));
348      } else {      } else {
349          oss.flush();          oss.str("");
350          oss <<  "Could not find data for " << packet->GetPacketType()->GetName() << "/" << name ;          oss <<  "Could not find data for " << packet->GetPacketType()->GetName() << "/" << name ;
351          logger->error(oss.str().c_str());          logger->error(oss.str().c_str());
352      }      }
# Line 405  TTree* PamelaRun::CreateTTree(Algorithm* Line 405  TTree* PamelaRun::CreateTTree(Algorithm*
405    TFile* File = new TFile(FileName.c_str(), "create");    TFile* File = new TFile(FileName.c_str(), "create");
406    File->SetCompressionLevel(5);    File->SetCompressionLevel(5);
407    if (!File->IsOpen()) {    if (!File->IsOpen()) {
408      oss.flush();      oss.str("");
409      oss <<  "Could not open file " << FileName ;      oss <<  "Could not open file " << FileName ;
410      logger->error(oss.str().c_str());      logger->error(oss.str().c_str());
411      throw Exception("Could not open file " + FileName);      //throw Exception("Could not open file " + FileName);
412    }    }
413    std::string TreeName = GetTreeName(packet);    std::string TreeName = GetTreeName(packet);
414    TTree *tree = new TTree(TreeName.c_str(), algo->GetAlgorithmName().c_str());    TTree *tree = new TTree(TreeName.c_str(), algo->GetAlgorithmName().c_str());
# Line 417  TTree* PamelaRun::CreateTTree(Algorithm* Line 417  TTree* PamelaRun::CreateTTree(Algorithm*
417    AlgorithmInfo ai(algo);    AlgorithmInfo ai(algo);
418    ai.Write();    ai.Write();
419    info.Write();    info.Write();
420    oss.flush();    oss.str("");
421    oss <<  "Creating file " << FileName << " with Tree " << TreeName;    oss <<  "Creating file " << FileName << " with Tree " << TreeName;
422    logger->info(oss.str().c_str());    logger->info(oss.str().c_str());
423    return tree;    return tree;
# Line 437  TTree* PamelaRun::CreateTTree(Algorithm* Line 437  TTree* PamelaRun::CreateTTree(Algorithm*
437  void PamelaRun::WriteSubPacket(Algorithm *algo, void* subpacket,  void PamelaRun::WriteSubPacket(Algorithm *algo, void* subpacket,
438                                 const TClass *c, std::string name) {                                 const TClass *c, std::string name) {
439    SubPacket *packet = *(SubPacket **)subpacket;    SubPacket *packet = *(SubPacket **)subpacket;
440    oss.flush();    oss.str("");
441    oss <<  "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)";    oss <<  "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)";
442    logger->debug(oss.str().c_str());    logger->debug(oss.str().c_str());
443    TTree* HeaderTree = ReadTTree(packet->GetPacketType());    TTree* HeaderTree = ReadTTree(packet->GetPacketType());
444    TTree* tree = CreateTTree(algo, packet, name);    TTree* tree = CreateTTree(algo, packet, name);
445    oss.flush();    oss.str("");
446    oss <<  "Branch: " << name << " Class: " << c->GetName();    oss <<  "Branch: " << name << " Class: " << c->GetName();
447    logger->debug(oss.str().c_str());    logger->debug(oss.str().c_str());
448    tree->Branch(name.c_str(), c->GetName(),  subpacket);    tree->Branch(name.c_str(), c->GetName(),  subpacket);
# Line 476  void PamelaRun::WriteSubPacket(Algorithm Line 476  void PamelaRun::WriteSubPacket(Algorithm
476   */   */
477  void PamelaRun::WriteHeader(Algorithm* algo, EventHeader** subpacket,  void PamelaRun::WriteHeader(Algorithm* algo, EventHeader** subpacket,
478                              const PacketType* type) {                              const PacketType* type) {
   oss.flush();  
   oss <<  "Creating header tree for " << type->GetName();  
   logger->debug(oss.str().c_str());  
479    EventHeader header(type);    EventHeader header(type);
480    std::string FileName = GetFileName(&header, GetDefaultBranchName(&header));    std::string FileName = GetFileName(&header, GetDefaultBranchName(&header));
481    std::string EventType = (&header)->GetPacketType()->GetName();    std::string EventType = (&header)->GetPacketType()->GetName();
482    CreateDirectoryStructure(FileName.c_str());    CreateDirectoryStructure(FileName.c_str());
483    TFile* File = new TFile(FileName.c_str(), "create");    TFile* File = new TFile(FileName.c_str(), "create");
484    if (!File->IsOpen()) {    if (!File->IsOpen()) {
485      oss.flush();      oss.str("");
486      oss     <<  "Could not open file " << FileName ;      oss     <<  "Could not open file " << FileName ;
487      logger->error(oss.str().c_str());      logger->error(oss.str().c_str());
488      throw Exception("Could not open file " + FileName);      //throw Exception("Could not open file " + FileName);
489    }    }
490    //std::string TreeName = GetTreeName(packet);    //std::string TreeName = GetTreeName(packet);
491    TTree *tree = new TTree("Pscu", algo->GetAlgorithmName().c_str());    TTree *tree = new TTree("Pscu", algo->GetAlgorithmName().c_str());
# Line 497  void PamelaRun::WriteHeader(Algorithm* a Line 494  void PamelaRun::WriteHeader(Algorithm* a
494    AlgorithmInfo ai(algo);    AlgorithmInfo ai(algo);
495    ai.Write();    ai.Write();
496    info.Write();    info.Write();
497    oss.flush();    oss.str("");
498    oss <<  "Creating file " << FileName << " with Tree Pscu";    oss <<  "Created file " << FileName << " with Tree Pscu";
499    logger->info(oss.str().c_str());    logger->info(oss.str().c_str());
500    tree->Branch(GetDefaultBranchName(&header).c_str(),    tree->Branch(GetDefaultBranchName(&header).c_str(),
501                 (*subpacket)->Class()->GetName(), subpacket);                 (*subpacket)->Class()->GetName(), subpacket);

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

  ViewVC Help
Powered by ViewVC 1.1.23